| /* |
| * 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<AnnotatedNodeInfo> annotatedNodeInfos = new ArrayList<AnnotatedNodeInfo>(); |
| try { |
| Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos"); |
| field.setAccessible(true); |
| annotatedNodeInfos = (List<AnnotatedNodeInfo>) 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()); |
| } |
| } |