blob: ec1f14c4078e78af482a38ac776c6a2f9eaed67d [file] [log] [blame]
Vidyashree Rama6160be12016-11-24 13:43:31 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Vidyashree Rama6160be12016-11-24 13:43:31 +05303 *
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.Assert;
20import org.junit.Test;
21import org.onosproject.yms.app.ydt.YdtTestUtils;
22import org.onosproject.yms.app.ydt.YangRequestWorkBench;
23import org.onosproject.yms.app.ydt.YdtExtendedContext;
24import org.onosproject.yms.ydt.YdtContext;
25
26import java.io.IOException;
27import java.lang.reflect.Field;
28import java.util.ArrayList;
29
30import static org.junit.Assert.assertEquals;
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();
Jon Halla3fcf672017-03-28 16:53:22 -070051 if ("CustomssupervisorOpParam".equals(aClass.getSimpleName())) {
Vidyashree Rama6160be12016-11-24 13:43:31 +053052 try {
53 Field field = aClass.getDeclaredField("supervisor");
54 Field onosYangNodeOperationType = aClass
55 .getDeclaredField("yangCustomssupervisorOpType");
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 Assert.fail();
64 }
65 } catch (NoSuchFieldException e) {
66 Assert.fail();
67 }
68 }
69
Jon Halla3fcf672017-03-28 16:53:22 -070070 if ("MerchandisersupervisorOpParam".equals(aClass.getSimpleName())) {
Vidyashree Rama6160be12016-11-24 13:43:31 +053071 try {
72 Field field = aClass.getDeclaredField("supervisor");
73 field.setAccessible(true);
74 try {
75 assertEquals("abc", field.get(yangObject).toString());
76 } catch (IllegalAccessException e) {
77 Assert.fail();
78 }
79 } catch (NoSuchFieldException e) {
80 Assert.fail();
81 }
82 }
83
Jon Halla3fcf672017-03-28 16:53:22 -070084 if ("WarehousesupervisorOpParam".equals(aClass.getSimpleName())) {
Vidyashree Rama6160be12016-11-24 13:43:31 +053085 try {
86 Field field = aClass.getDeclaredField("supervisor");
87 field.setAccessible(true);
88 try {
89 ArrayList<String> arrayList =
90 (ArrayList<String>) field.get(yangObject);
91 assertEquals("1", arrayList.get(0));
92 assertEquals("2", arrayList.get(1));
93 assertEquals("3", arrayList.get(2));
94 assertEquals("4", arrayList.get(3));
95 assertEquals("5", arrayList.get(4));
96 } catch (IllegalAccessException e) {
97 Assert.fail();
98 }
99 } catch (NoSuchFieldException e) {
100 Assert.fail();
101 }
102 }
103 childCtx = childCtx.getNextSibling();
104 }
105 }
106}