blob: c66f55598a604646d265f571208ac20da5edb326 [file] [log] [blame]
Rama-Huaweib711e5c2016-08-31 07:55:46 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
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 */
16
17package org.onosproject.yms.app.yob;
18
19import org.junit.Test;
20import org.onosproject.yms.app.ydt.YangRequestWorkBench;
21import org.onosproject.yms.app.ydt.YdtExtendedContext;
22import org.onosproject.yms.app.ydt.YdtTestUtils;
23import org.onosproject.yms.ydt.YdtContext;
24
25import java.io.IOException;
26import java.lang.reflect.Field;
27import java.util.ArrayList;
28
29import static org.junit.Assert.assertEquals;
30import static org.junit.Assert.fail;
31
32public class YobLogisticsManagerTest {
33
34 @Test
35 public void logisticsManagerTest() throws IOException {
36 YangRequestWorkBench defaultYdtBuilder = YdtTestUtils
37 .logisticsManagerYdt();
38
39 YdtContext rootCtx = defaultYdtBuilder.getRootNode();
40
41 YdtContext childCtx = rootCtx.getFirstChild();
42
43 DefaultYobBuilder builder = new DefaultYobBuilder();
44
45 while (childCtx != null) {
46
47 Object yangObject = builder.getYangObject(
48 (YdtExtendedContext) childCtx, YdtTestUtils
49 .getSchemaRegistry());
50 Class<?> aClass = yangObject.getClass();
51 if (aClass.getSimpleName().equals("CustomssupervisorOpParam")) {
52 try {
53 Field field = aClass.getDeclaredField("supervisor");
54 Field onosYangNodeOperationType = aClass
55 .getDeclaredField("onosYangNodeOperationType");
56 field.setAccessible(true);
57 onosYangNodeOperationType.setAccessible(true);
58 try {
59 assertEquals("abc", field.get(yangObject).toString());
60 assertEquals("MERGE", onosYangNodeOperationType
61 .get(yangObject).toString());
62 } catch (IllegalAccessException e) {
63 fail("Illegal access exception: " + e);
64 }
65 } catch (NoSuchFieldException e) {
66 fail("No such field exception: " + e);
67 }
68 }
69
70 if (aClass.getSimpleName().equals(
71 "MerchandisersupervisorOpParam")) {
72 try {
73 Field field = aClass.getDeclaredField("supervisor");
74 field.setAccessible(true);
75 try {
76 assertEquals("abc", field.get(yangObject).toString());
77 } catch (IllegalAccessException e) {
78 fail("Illegal access exception: " + e);
79 }
80 } catch (NoSuchFieldException e) {
81 fail("No such field found exception: " + e);
82 }
83 }
84
85 if (aClass.getSimpleName().equals("WarehousesupervisorOpParam")) {
86 try {
87 Field field = aClass.getDeclaredField("supervisor");
88 field.setAccessible(true);
89 try {
90 ArrayList<String> arrayList =
91 (ArrayList<String>) field.get(yangObject);
92 assertEquals("1", arrayList.get(0));
93 assertEquals("2", arrayList.get(1));
94 assertEquals("3", arrayList.get(2));
95 assertEquals("4", arrayList.get(3));
96 assertEquals("5", arrayList.get(4));
97 } catch (IllegalAccessException e) {
98 fail("Illegal access exception: " + e);
99 }
100 } catch (NoSuchFieldException e) {
101 fail("No such field exception: " + e);
102 }
103 }
104 childCtx = childCtx.getNextSibling();
105 }
106 }
107}