diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigAssignmentHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigAssignmentHandlerTest.java new file mode 100755 index 0000000000..97f3ac15b8 --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigAssignmentHandlerTest.java @@ -0,0 +1,218 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmenttop.logicalchannelassignments.assignment.DefaultConfig; +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmenttop.logicalchannelassignments.DefaultAssignment; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigAssignmentHandler. + */ +public class OpenConfigAssignmentHandlerTest { + // parent Handler + OpenConfigLogicalChannelAssignmentsHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + // + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // add + OpenConfigLogicalChannelsHandler logicalChannels = + new OpenConfigLogicalChannelsHandler(terminalDevice); + + // add 1 + OpenConfigChannelHandler channel = + new OpenConfigChannelHandler(1, logicalChannels); + + // add + parent = new OpenConfigLogicalChannelAssignmentsHandler(channel); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("terminal-device", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("logical-channels", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("channel", "http://openconfig.net/yang/terminal-device") + .addKeyLeaf("index", "http://openconfig.net/yang/terminal-device", 1) + .addBranchPointSchema("logical-channel-assignments", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("assignment", "http://openconfig.net/yang/terminal-device") + .addKeyLeaf("index", "http://openconfig.net/yang/terminal-device", 2) + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, parent); + + // expected ModelObject + DefaultAssignment modelObject = new DefaultAssignment(); + modelObject.index(2); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, assignment.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(assignment); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, assignment.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, assignment.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, parent); + + // call addAnnotation + assignment.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(assignment); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, parent); + + // set list of AnnotatedNodeInfo + assignment.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, assignment.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, assignment.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, assignment.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", assignment.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", assignment.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addConfig. + */ + @Test + public void testAddConfig() { + // test Handler + OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, parent); + + // call addConfig + OpenConfigConfigOfAssignmentHandler configOfAssignment = + new OpenConfigConfigOfAssignmentHandler(assignment); + + // expected ModelObject + DefaultAssignment modelObject = new DefaultAssignment(); + modelObject.index(2); + DefaultConfig config = new DefaultConfig(); + modelObject.config(config); + + assertEquals("[NG]addConfig:ModelObject(Config added) is not an expected one.\n", + modelObject, assignment.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigChannelHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigChannelHandlerTest.java new file mode 100755 index 0000000000..999ac36668 --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigChannelHandlerTest.java @@ -0,0 +1,231 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanneltop.logicalchannels.channel.DefaultConfig; +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanneltop.logicalchannels.DefaultChannel; +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmenttop.DefaultLogicalChannelAssignments; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigChannelHandler. + */ +public class OpenConfigChannelHandlerTest { + // parent Handler + OpenConfigLogicalChannelsHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + // + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // add + parent = new OpenConfigLogicalChannelsHandler(terminalDevice); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("terminal-device", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("logical-channels", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("channel", "http://openconfig.net/yang/terminal-device") + .addKeyLeaf("index", "http://openconfig.net/yang/terminal-device", 1) + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, parent); + + // expected ModelObject + DefaultChannel modelObject = new DefaultChannel(); + modelObject.index(1); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, channel.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(channel); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, channel.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, channel.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, parent); + + // call addAnnotation + channel.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(channel); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, parent); + + // set list of AnnotatedNodeInfo + channel.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, channel.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, channel.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, channel.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", channel.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", channel.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addConfig. + */ + @Test + public void testAddConfig() { + // test Handler + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, parent); + + // call addConfig + OpenConfigConfigOfChannelHandler configOfChannel = + new OpenConfigConfigOfChannelHandler(channel); + + // expected ModelObject + DefaultChannel modelObject = new DefaultChannel(); + modelObject.index(1); + DefaultConfig config = new DefaultConfig(); + modelObject.config(config); + + assertEquals("[NG]addConfig:ModelObject(Config added) is not an expected one.\n", + modelObject, channel.getModelObject()); + } + + /** + * UnitTest method for addLogicalChannelAssignments. + */ + @Test + public void testAddLogicalChannelAssignments() { + // test Handler + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, parent); + + // call addLogicalChannelAssignments + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(channel); + + // expected ModelObject + DefaultChannel modelObject = new DefaultChannel(); + modelObject.index(1); + DefaultLogicalChannelAssignments logicalChannel = new DefaultLogicalChannelAssignments(); + modelObject.logicalChannelAssignments(logicalChannel); + + assertEquals( + "[NG]addLogicalChannelAssignments:ModelObject(LogicalChannelAssignments added) is not an expected one.\n", + modelObject, channel.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigComponentHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigComponentHandlerTest.java new file mode 100755 index 0000000000..64c3f5e56f --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigComponentHandlerTest.java @@ -0,0 +1,226 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.component.DefaultConfig; +import org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.DefaultComponent; +import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20180515.openconfigplatformtransceiver.components.component.DefaultAugmentedOcPlatformComponent; +import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20180515.openconfigplatformtransceiver.porttransceivertop.DefaultTransceiver; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigComponentHandler. + */ +public class OpenConfigComponentHandlerTest { + // parent Handler + OpenConfigComponentsHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + parent = new OpenConfigComponentsHandler(); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("components", "http://openconfig.net/yang/platform") + .addBranchPointSchema("component", "http://openconfig.net/yang/platform") + .addKeyLeaf("name", "http://openconfig.net/yang/platform", "name") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent); + + // expected ModelObject + DefaultComponent modelObject = new DefaultComponent(); + modelObject.name("name"); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, component.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(component); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, component.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, component.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent); + + // call addAnnotation + component.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(component); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent); + + // set list of AnnotatedNodeInfo + component.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, component.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, component.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, component.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", component.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", component.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addTransceiver. + */ + @Test + public void testAddTransceiver() { + // test Handler + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent); + + // call addTransceiver + OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(component); + + // expected ModelObject + DefaultComponent modelObject = new DefaultComponent(); + modelObject.name("name"); + DefaultTransceiver trans = new DefaultTransceiver(); + DefaultAugmentedOcPlatformComponent augmentedOcPlatformComponent = new DefaultAugmentedOcPlatformComponent(); + augmentedOcPlatformComponent.transceiver(trans); + modelObject.addAugmentation(augmentedOcPlatformComponent); + + assertEquals("[NG]addTransceiver:ModelObject(Transceiver added) is not an expected one.\n", + modelObject, component.getModelObject()); + } + + /** + * UnitTest method for addConfig. + */ + @Test + public void testAddConfig() { + // test Handler + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent); + + // call addConfig + OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(component); + + // expected ModelObject + DefaultComponent modelObject = new DefaultComponent(); + modelObject.name("name"); + DefaultConfig con = new DefaultConfig(); + modelObject.config(con); + + assertEquals("[NG]addConfig:ModelObject(Config added) is not an expected one.\n", + modelObject, component.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigComponentsHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigComponentsHandlerTest.java new file mode 100755 index 0000000000..9045c16c90 --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigComponentsHandlerTest.java @@ -0,0 +1,191 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.DefaultComponent; +import org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.DefaultComponents; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigComponentsHandler. + */ +public class OpenConfigComponentsHandlerTest { + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("components", "http://openconfig.net/yang/platform") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + // expected ModelObject + DefaultComponents modelObject = new DefaultComponents(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, components.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(components); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, components.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, components.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + // call addAnnotation + components.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(components); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + // set list of AnnotatedNodeInfo + components.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, components.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, components.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, components.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", components.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", components.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addComponent. + */ + @Test + public void testAddComponent() { + // test Handler + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + // call addComponent + OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", components); + + // expected ModelObject + DefaultComponents modelObject = new DefaultComponents(); + DefaultComponent comp = new DefaultComponent(); + comp.name("name"); + modelObject.addToComponent(comp); + + assertEquals("[NG]addComponent:ModelObject(Component added) is not an expected one.\n", + modelObject, components.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfAssignmentHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfAssignmentHandlerTest.java new file mode 100755 index 0000000000..d941cdc1f6 --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfAssignmentHandlerTest.java @@ -0,0 +1,277 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import java.math.BigDecimal; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmenttop.logicalchannelassignments.assignment.DefaultConfig; +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmentconfig.AssignmentTypeEnum; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigConfigOfAssignmentHandler. + */ +public class OpenConfigConfigOfAssignmentHandlerTest { + // parent Handler + OpenConfigAssignmentHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + // + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // add + OpenConfigLogicalChannelsHandler logicalChannels = + new OpenConfigLogicalChannelsHandler(terminalDevice); + + // add 1 + OpenConfigChannelHandler channel = + new OpenConfigChannelHandler(1, logicalChannels); + + // add + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(channel); + + // add 2 + parent = new OpenConfigAssignmentHandler(2, logicalChannelAssignments); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("terminal-device", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("logical-channels", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("channel", "http://openconfig.net/yang/terminal-device") + .addKeyLeaf("index", "http://openconfig.net/yang/terminal-device", 1) + .addBranchPointSchema("logical-channel-assignments", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("assignment", "http://openconfig.net/yang/terminal-device") + .addKeyLeaf("index", "http://openconfig.net/yang/terminal-device", 2) + .addBranchPointSchema("config", "http://openconfig.net/yang/terminal-device") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, config.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(config); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, config.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, config.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + // call addAnnotation + config.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(config); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + // set list of AnnotatedNodeInfo + config.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, config.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, config.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, config.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", config.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", config.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addIndex. + */ + @Test + public void testAddIndex() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + // call addIndex + config.addIndex(Long.valueOf(3)); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + modelObject.index(3); + + assertEquals("[NG]addIndex:ModelObject(Index added) is not an expected one.\n", + modelObject, config.getModelObject()); + } + + /** + * UnitTest method for addAssignmentType. + */ + @Test + public void testAddAssignmentType() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + // call addAssignmentType + config.addAssignmentType(AssignmentTypeEnum.LOGICAL_CHANNEL); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + modelObject.assignmentType(AssignmentTypeEnum.LOGICAL_CHANNEL); + + assertEquals("[NG]addAssignmentType:ModelObject(AssignmentType added) is not an expected one.\n", + modelObject, config.getModelObject()); + } + + /** + * UnitTest method for addLogicalChannel. + */ + @Test + public void testAddLogicalChannel() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + // call addLogicalChannel + config.addLogicalChannel("name"); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + modelObject.logicalChannel("name"); + + assertEquals("[NG]addLogicalChannel:ModelObject(LogicalChannel added) is not an expected one.\n", + modelObject, config.getModelObject()); + } + + /** + * UnitTest method for addAllocation. + */ + @Test + public void testAddAllocation() { + // test Handler + OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent); + + // call addAllocation + config.addAllocation(BigDecimal.valueOf(4)); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + modelObject.allocation(BigDecimal.valueOf(4)); + + assertEquals("[NG]addAllocation:ModelObject(Allocation added) is not an expected one.\n", + modelObject, config.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfChannelHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfChannelHandlerTest.java new file mode 100755 index 0000000000..c12ef78b3d --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfChannelHandlerTest.java @@ -0,0 +1,207 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanneltop.logicalchannels.channel.DefaultConfig; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigConfigOfChannelHandler. + */ +public class OpenConfigConfigOfChannelHandlerTest { + // parent Handler + OpenConfigChannelHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + // + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // add + OpenConfigLogicalChannelsHandler logicalChannels = + new OpenConfigLogicalChannelsHandler(terminalDevice); + + // add 1 + parent = new OpenConfigChannelHandler(1, logicalChannels); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("terminal-device", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("logical-channels", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("channel", "http://openconfig.net/yang/terminal-device") + .addKeyLeaf("index", "http://openconfig.net/yang/terminal-device", 1) + .addBranchPointSchema("config", "http://openconfig.net/yang/terminal-device") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigConfigOfChannelHandler config = new OpenConfigConfigOfChannelHandler(parent); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, config.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigConfigOfChannelHandler config = new OpenConfigConfigOfChannelHandler(parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(config); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigConfigOfChannelHandler config = new OpenConfigConfigOfChannelHandler(parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, config.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigConfigOfChannelHandler config = new OpenConfigConfigOfChannelHandler(parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, config.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigConfigOfChannelHandler config = new OpenConfigConfigOfChannelHandler(parent); + + // call addAnnotation + config.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(config); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigConfigOfChannelHandler config = new OpenConfigConfigOfChannelHandler(parent); + + // set list of AnnotatedNodeInfo + config.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, config.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, config.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, config.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", config.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", config.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addIndex. + */ + @Test + public void testAddIndex() { + // test Handler + OpenConfigConfigOfChannelHandler config = new OpenConfigConfigOfChannelHandler(parent); + + // call addIndex + config.addIndex(2); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + modelObject.index(2); + + assertEquals("[NG]addIndex:ModelObject(Index added) is not an expected one.\n", + modelObject, config.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfComponentHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfComponentHandlerTest.java new file mode 100755 index 0000000000..299f3815de --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfComponentHandlerTest.java @@ -0,0 +1,201 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.component.DefaultConfig; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigConfigOfComponentHandler. + */ +public class OpenConfigConfigOfComponentHandlerTest { + // parent Handler + OpenConfigComponentHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + // add name + parent = new OpenConfigComponentHandler("name", components); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("components", "http://openconfig.net/yang/platform") + .addBranchPointSchema("component", "http://openconfig.net/yang/platform") + .addKeyLeaf("name", "http://openconfig.net/yang/platform", "name") + .addBranchPointSchema("config", "http://openconfig.net/yang/platform") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(parent); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, config.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(config); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, config.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, config.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(parent); + + // call addAnnotation + config.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(config); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testAnnotatedNodeInfoList() { + // test Handler + OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(parent); + + // set list of AnnotatedNodeInfo + config.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, config.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, config.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, config.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", config.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", config.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addName. + */ + @Test + public void testAddName() { + // test Handler + OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(parent); + + // call addName + config.addName("name"); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + modelObject.name("name"); + + assertEquals("[NG]addName:ModelObject(Name added) is not an expected one.\n", + modelObject, config.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfTransceiverHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfTransceiverHandlerTest.java new file mode 100755 index 0000000000..1e11a16055 --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigConfigOfTransceiverHandlerTest.java @@ -0,0 +1,206 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20180515.openconfigplatformtransceiver.porttransceivertop.transceiver.DefaultConfig; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigConfigOfTransceiverHandler. + */ +public class OpenConfigConfigOfTransceiverHandlerTest { + // parent Handler + OpenConfigTransceiverHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + // add name + OpenConfigComponentHandler component + = new OpenConfigComponentHandler("name", components); + + // add + parent = new OpenConfigTransceiverHandler(component); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("components", "http://openconfig.net/yang/platform") + .addBranchPointSchema("component", "http://openconfig.net/yang/platform") + .addKeyLeaf("name", "http://openconfig.net/yang/platform", "name") + .addBranchPointSchema("transceiver", "http://openconfig.net/yang/platform/transceiver") + .addBranchPointSchema("config", "http://openconfig.net/yang/platform/transceiver") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigConfigOfTransceiverHandler config = new OpenConfigConfigOfTransceiverHandler(parent); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, config.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigConfigOfTransceiverHandler config = new OpenConfigConfigOfTransceiverHandler(parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(config); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigConfigOfTransceiverHandler config = new OpenConfigConfigOfTransceiverHandler(parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, config.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigConfigOfTransceiverHandler config = new OpenConfigConfigOfTransceiverHandler(parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, config.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigConfigOfTransceiverHandler config = new OpenConfigConfigOfTransceiverHandler(parent); + + // call addAnnotation + config.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(config); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigConfigOfTransceiverHandler config = new OpenConfigConfigOfTransceiverHandler(parent); + + // set list of AnnotatedNodeInfo + config.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, config.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, config.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, config.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", config.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", config.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addEnabled. + */ + @Test + public void testAddEnabled() { + // test Handler + OpenConfigConfigOfTransceiverHandler config = new OpenConfigConfigOfTransceiverHandler(parent); + + // call addEnabled + config.addEnabled(true); + + // expected ModelObject + DefaultConfig modelObject = new DefaultConfig(); + modelObject.enabled(true); + + assertEquals("[NG]addEnabled:ModelObject(Enabled added) is not an expected one.\n", + modelObject, config.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigLogicalChannelAssignmentsHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigLogicalChannelAssignmentsHandlerTest.java new file mode 100755 index 0000000000..2593593850 --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigLogicalChannelAssignmentsHandlerTest.java @@ -0,0 +1,217 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmenttop.DefaultLogicalChannelAssignments; +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmenttop.logicalchannelassignments.DefaultAssignment; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigLogicalChannelAssignmentsHandler. + */ +public class OpenConfigLogicalChannelAssignmentsHandlerTest { + // parent Handler + OpenConfigChannelHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + // + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // add + OpenConfigLogicalChannelsHandler logicalChannels = + new OpenConfigLogicalChannelsHandler(terminalDevice); + + // add 1 + parent = new OpenConfigChannelHandler(1, logicalChannels); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("terminal-device", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("logical-channels", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("channel", "http://openconfig.net/yang/terminal-device") + .addKeyLeaf("index", "http://openconfig.net/yang/terminal-device", 1) + .addBranchPointSchema("logical-channel-assignments", "http://openconfig.net/yang/terminal-device") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(parent); + + // expected ModelObject + DefaultLogicalChannelAssignments modelObject = new DefaultLogicalChannelAssignments(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, logicalChannelAssignments.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(logicalChannelAssignments); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, logicalChannelAssignments.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, logicalChannelAssignments.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(parent); + + // call addAnnotation + logicalChannelAssignments.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(logicalChannelAssignments); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(parent); + + // set list of AnnotatedNodeInfo + logicalChannelAssignments.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, logicalChannelAssignments.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, logicalChannelAssignments.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, logicalChannelAssignments.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", logicalChannelAssignments.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", logicalChannelAssignments.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addAssignment. + */ + @Test + public void testAddAssignment() { + // test Handler + OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = + new OpenConfigLogicalChannelAssignmentsHandler(parent); + + // call addAssignment + OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, logicalChannelAssignments); + + // expected ModelObject + DefaultLogicalChannelAssignments modelObject = new DefaultLogicalChannelAssignments(); + DefaultAssignment assign = new DefaultAssignment(); + assign.index(2); + modelObject.addToAssignment(assign); + + assertEquals("[NG]addAssignment:ModelObject(Assignment added) is not an expected one.\n", + modelObject, logicalChannelAssignments.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigLogicalChannelsHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigLogicalChannelsHandlerTest.java new file mode 100755 index 0000000000..21cfeaae64 --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigLogicalChannelsHandlerTest.java @@ -0,0 +1,200 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanneltop.DefaultLogicalChannels; +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanneltop.logicalchannels.DefaultChannel; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigLogicalChannelsHandler. + */ +public class OpenConfigLogicalChannelsHandlerTest { + // parent Handler + OpenConfigTerminalDeviceHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + // + parent = new OpenConfigTerminalDeviceHandler(); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("terminal-device", "http://openconfig.net/yang/terminal-device") + .addBranchPointSchema("logical-channels", "http://openconfig.net/yang/terminal-device") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(parent); + + // expected ModelObject + DefaultLogicalChannels modelObject = new DefaultLogicalChannels(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, logicalChannels.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(logicalChannels); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, logicalChannels.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, logicalChannels.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(parent); + + // call addAnnotation + logicalChannels.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(logicalChannels); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testGetAnnotatedNodeInfoList() { + // test Handler + OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(parent); + + // set list of AnnotatedNodeInfo + logicalChannels.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, logicalChannels.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, logicalChannels.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, logicalChannels.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", logicalChannels.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", logicalChannels.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addChannel. + */ + @Test + public void testAddChannel() { + // test Handler + OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(parent); + + // call addChannel + OpenConfigChannelHandler channel = new OpenConfigChannelHandler(1, logicalChannels); + + // expected ModelObject + DefaultLogicalChannels modelObject = new DefaultLogicalChannels(); + DefaultChannel chan = new DefaultChannel(); + chan.index(1); + modelObject.addToChannel(chan); + + assertEquals("[NG]addChannel:ModelObject(Channel added) is not an expected one.\n", + modelObject, logicalChannels.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigTerminalDeviceHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigTerminalDeviceHandlerTest.java new file mode 100755 index 0000000000..d058daed9b --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigTerminalDeviceHandlerTest.java @@ -0,0 +1,190 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminaldevicetop.DefaultTerminalDevice; +import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanneltop.DefaultLogicalChannels; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigTerminalDeviceHandler. + */ +public class OpenConfigTerminalDeviceHandlerTest { + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("terminal-device", "http://openconfig.net/yang/terminal-device") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // expected ModelObject + DefaultTerminalDevice modelObject = new DefaultTerminalDevice(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, terminalDevice.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(terminalDevice); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, terminalDevice.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, terminalDevice.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // call addAnnotation + terminalDevice.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(terminalDevice); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testAnnotatedNodeInfoList() { + // test Handler + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // set list of AnnotatedNodeInfo + terminalDevice.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, terminalDevice.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, terminalDevice.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, terminalDevice.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", terminalDevice.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", terminalDevice.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addLogicalChannels. + */ + @Test + public void testAddLogicalChannels() { + // test Handler + OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler(); + + // call addLogicalChannels + OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(terminalDevice); + + // expected ModelObject + DefaultTerminalDevice modelObject = new DefaultTerminalDevice(); + DefaultLogicalChannels logicalChan = new DefaultLogicalChannels(); + modelObject.logicalChannels(logicalChan); + + assertEquals("[NG]addLogicalChannels:ModelObject(LogicalChannels added) is not an expected one.\n", + modelObject, terminalDevice.getModelObject()); + } +} diff --git a/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigTransceiverHandlerTest.java b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigTransceiverHandlerTest.java new file mode 100755 index 0000000000..0a70a38794 --- /dev/null +++ b/apps/odtn/api/src/test/java/org/onosproject/odtn/utils/openconfig/OpenConfigTransceiverHandlerTest.java @@ -0,0 +1,203 @@ +/* + * Copyright 2018-present Open Networking Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.odtn.utils.openconfig; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.onosproject.yang.model.ResourceId; +import org.onosproject.yang.runtime.AnnotatedNodeInfo; + +import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20180515.openconfigplatformtransceiver.porttransceivertop.DefaultTransceiver; +import org.onosproject.yang.gen.v1.openconfigplatformtransceiver.rev20180515.openconfigplatformtransceiver.porttransceivertop.transceiver.DefaultConfig; + +import static org.junit.Assert.assertEquals; + +/** + * UnitTest class for OpenConfigTransceiverHandler. + */ +public class OpenConfigTransceiverHandlerTest { + // parent Handler + OpenConfigComponentHandler parent; + + // expected ResourceId + ResourceId rid; + + /** + * Set up method for UnitTest. + */ + @Before + public void setUp() { + // parent Handler set up + // create + OpenConfigComponentsHandler components = new OpenConfigComponentsHandler(); + + // add name + parent = new OpenConfigComponentHandler("name", components); + + // expected ResourceId set up + rid = ResourceId.builder() + .addBranchPointSchema("components", "http://openconfig.net/yang/platform") + .addBranchPointSchema("component", "http://openconfig.net/yang/platform") + .addKeyLeaf("name", "http://openconfig.net/yang/platform", "name") + .addBranchPointSchema("transceiver", "http://openconfig.net/yang/platform/transceiver") + .build(); + } + + /** + * UnitTest method for getModelObject. + */ + @Test + public void testGetModelObject() { + // test Handler + OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(parent); + + // expected ModelObject + DefaultTransceiver modelObject = new DefaultTransceiver(); + + assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", + modelObject, transceiver.getModelObject()); + } + + /** + * UnitTest method for setResourceId. + */ + @Test + public void testSetResourceId() { + // call setResourceId + OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(parent); + + // get resourceId + ResourceId resourceId = null; + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId"); + field.setAccessible(true); + resourceId = (ResourceId) field.get(transceiver); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e); + } + + assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", + rid, resourceId); + } + + /** + * UnitTest method for getResourceId. + */ + @Test + public void testGetResourceId() { + // test Handler + OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(parent); + + assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n", + rid, transceiver.getResourceId()); + } + + /** + * UnitTest method for getResourceIdBuilder. + */ + @Test + public void testGetResourceIdBuilder() { + // test Handler + OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(parent); + + assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n", + rid, transceiver.getResourceIdBuilder().build()); + } + + /** + * UnitTest method for addAnnotation. + */ + @Test + public void testAddAnnotation() { + // test Handler + OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(parent); + + // call addAnnotation + transceiver.addAnnotation("name", "value"); + + // get annotatedNodeInfos + List annotatedNodeInfos = new ArrayList(); + try { + Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); + field.setAccessible(true); + annotatedNodeInfos = (List) field.get(transceiver); + } catch (NoSuchFieldException e) { + Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e); + } catch (IllegalAccessException e) { + Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e); + } + + assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n", + 1, annotatedNodeInfos.size()); + assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, annotatedNodeInfos.get(0).resourceId()); + assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n", + 1, annotatedNodeInfos.get(0).annotations().size()); + assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n", + "name", annotatedNodeInfos.get(0).annotations().get(0).name()); + assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n", + "value", annotatedNodeInfos.get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for getAnnotatedNodeInfoList. + */ + @Test + public void testAnnotatedNodeInfoList() { + // test Handler + OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(parent); + + // set list of AnnotatedNodeInfo + transceiver.addAnnotation("name", "value"); + + assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n", + 1, transceiver.getAnnotatedNodeInfoList().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n", + rid, transceiver.getAnnotatedNodeInfoList().get(0).resourceId()); + assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n", + 1, transceiver.getAnnotatedNodeInfoList().get(0).annotations().size()); + assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n", + "name", transceiver.getAnnotatedNodeInfoList().get(0).annotations().get(0).name()); + assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n", + "value", transceiver.getAnnotatedNodeInfoList().get(0).annotations().get(0).value()); + } + + /** + * UnitTest method for addConfig. + */ + @Test + public void testAddConfig() { + // test Handler + OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(parent); + + // call addConfig + OpenConfigConfigOfTransceiverHandler config = new OpenConfigConfigOfTransceiverHandler(transceiver); + + // expected ModelObject + DefaultTransceiver modelObject = new DefaultTransceiver(); + DefaultConfig con = new DefaultConfig(); + modelObject.config(con); + + assertEquals("[NG]addConfig:ModelObject(Config added) is not an expected one.\n", + modelObject, transceiver.getModelObject()); + } +}