blob: d058daed9b28de5b1fb3560355f5e329b70ca353 [file] [log] [blame]
Ai Hamanof59360f2018-12-12 15:39:56 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.odtn.utils.openconfig;
17
18import java.lang.reflect.Field;
19import java.util.ArrayList;
20import java.util.List;
21import org.junit.Assert;
22import org.junit.Before;
23import org.junit.Test;
24import org.onosproject.yang.model.ResourceId;
25import org.onosproject.yang.runtime.AnnotatedNodeInfo;
26
27import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminaldevicetop.DefaultTerminalDevice;
28import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanneltop.DefaultLogicalChannels;
29
30import static org.junit.Assert.assertEquals;
31
32/**
33 * UnitTest class for OpenConfigTerminalDeviceHandler.
34 */
35public class OpenConfigTerminalDeviceHandlerTest {
36 // expected ResourceId
37 ResourceId rid;
38
39 /**
40 * Set up method for UnitTest.
41 */
42 @Before
43 public void setUp() {
44 // expected ResourceId set up
45 rid = ResourceId.builder()
46 .addBranchPointSchema("terminal-device", "http://openconfig.net/yang/terminal-device")
47 .build();
48 }
49
50 /**
51 * UnitTest method for getModelObject.
52 */
53 @Test
54 public void testGetModelObject() {
55 // test Handler
56 OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
57
58 // expected ModelObject
59 DefaultTerminalDevice modelObject = new DefaultTerminalDevice();
60
61 assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n",
62 modelObject, terminalDevice.getModelObject());
63 }
64
65 /**
66 * UnitTest method for setResourceId.
67 */
68 @Test
69 public void testSetResourceId() {
70 // call setResourceId
71 OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
72
73 // get resourceId
74 ResourceId resourceId = null;
75 try {
76 Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId");
77 field.setAccessible(true);
78 resourceId = (ResourceId) field.get(terminalDevice);
79 } catch (NoSuchFieldException e) {
80 Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e);
81 } catch (IllegalAccessException e) {
82 Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e);
83 }
84
85 assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n",
86 rid, resourceId);
87 }
88
89 /**
90 * UnitTest method for getResourceId.
91 */
92 @Test
93 public void testGetResourceId() {
94 // test Handler
95 OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
96
97 assertEquals("[NG]getResourceId:Return is not an expected ResourceId.\n",
98 rid, terminalDevice.getResourceId());
99 }
100
101 /**
102 * UnitTest method for getResourceIdBuilder.
103 */
104 @Test
105 public void testGetResourceIdBuilder() {
106 // test Handler
107 OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
108
109 assertEquals("[NG]getResourceIdBuilder:Return is not an expected ResourceIdBuilder.\n",
110 rid, terminalDevice.getResourceIdBuilder().build());
111 }
112
113 /**
114 * UnitTest method for addAnnotation.
115 */
116 @Test
117 public void testAddAnnotation() {
118 // test Handler
119 OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
120
121 // call addAnnotation
122 terminalDevice.addAnnotation("name", "value");
123
124 // get annotatedNodeInfos
125 List<AnnotatedNodeInfo> annotatedNodeInfos = new ArrayList<AnnotatedNodeInfo>();
126 try {
127 Field field = OpenConfigObjectHandler.class.getDeclaredField("annotatedNodeInfos");
128 field.setAccessible(true);
129 annotatedNodeInfos = (List<AnnotatedNodeInfo>) field.get(terminalDevice);
130 } catch (NoSuchFieldException e) {
131 Assert.fail("[NG]addAnnotation:List of AnnotatedNodeInfo does not exist.\n" + e);
132 } catch (IllegalAccessException e) {
133 Assert.fail("[NG]addAnnotation:Access to list of AnnotatedNodeInfo is illegal.\n" + e);
134 }
135
136 assertEquals("[NG]addAnnotation:List size of AnnotatedNodeInfo is invalid.\n",
137 1, annotatedNodeInfos.size());
138 assertEquals("[NG]addAnnotation:ResourceId of AnnotatedNodeInfo is not an expected one.\n",
139 rid, annotatedNodeInfos.get(0).resourceId());
140 assertEquals("[NG]addAnnotation:List size of Annotation is invalid.\n",
141 1, annotatedNodeInfos.get(0).annotations().size());
142 assertEquals("[NG]addAnnotation:Name of Annotation is not an expected one.\n",
143 "name", annotatedNodeInfos.get(0).annotations().get(0).name());
144 assertEquals("[NG]addAnnotation:Value of Annotation is not an expected one.\n",
145 "value", annotatedNodeInfos.get(0).annotations().get(0).value());
146 }
147
148 /**
149 * UnitTest method for getAnnotatedNodeInfoList.
150 */
151 @Test
152 public void testAnnotatedNodeInfoList() {
153 // test Handler
154 OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
155
156 // set list of AnnotatedNodeInfo
157 terminalDevice.addAnnotation("name", "value");
158
159 assertEquals("[NG]getAnnotatedNodeInfoList:List size of AnnotatedNodeInfo is invalid.\n",
160 1, terminalDevice.getAnnotatedNodeInfoList().size());
161 assertEquals("[NG]getAnnotatedNodeInfoList:ResourceId of AnnotatedNodeInfo is not an expected one.\n",
162 rid, terminalDevice.getAnnotatedNodeInfoList().get(0).resourceId());
163 assertEquals("[NG]getAnnotatedNodeInfoList:List size of Annotation is invalid.\n",
164 1, terminalDevice.getAnnotatedNodeInfoList().get(0).annotations().size());
165 assertEquals("[NG]getAnnotatedNodeInfoList:Name of Annotation is not an expected one.\n",
166 "name", terminalDevice.getAnnotatedNodeInfoList().get(0).annotations().get(0).name());
167 assertEquals("[NG]getAnnotatedNodeInfoList:Value of Annotation is not an expected one.\n",
168 "value", terminalDevice.getAnnotatedNodeInfoList().get(0).annotations().get(0).value());
169 }
170
171 /**
172 * UnitTest method for addLogicalChannels.
173 */
174 @Test
175 public void testAddLogicalChannels() {
176 // test Handler
177 OpenConfigTerminalDeviceHandler terminalDevice = new OpenConfigTerminalDeviceHandler();
178
179 // call addLogicalChannels
180 OpenConfigLogicalChannelsHandler logicalChannels = new OpenConfigLogicalChannelsHandler(terminalDevice);
181
182 // expected ModelObject
183 DefaultTerminalDevice modelObject = new DefaultTerminalDevice();
184 DefaultLogicalChannels logicalChan = new DefaultLogicalChannels();
185 modelObject.logicalChannels(logicalChan);
186
187 assertEquals("[NG]addLogicalChannels:ModelObject(LogicalChannels added) is not an expected one.\n",
188 modelObject, terminalDevice.getModelObject());
189 }
190}