blob: 47ec8ef7dfb6fdc0030e88c4595f5246469272ef [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.List;
28
29import static org.junit.Assert.assertEquals;
30import static org.junit.Assert.assertNotNull;
31import static org.junit.Assert.assertTrue;
32import static org.junit.Assert.fail;
33
34public class YobListTest {
35
36 @Test
37 public void listwithoutcontainerTest() {
38 YangRequestWorkBench defaultYdtBuilder =
39 YdtTestUtils.listWithoutContainerYdt();
40 validateYangObjectList(defaultYdtBuilder);
41 }
42
43 private void validateYangObjectList(
44 YangRequestWorkBench defaultYdtBuilder) {
45
46 YdtContext rootCtx = defaultYdtBuilder.getRootNode();
47
48 YdtContext childCtx = rootCtx.getFirstChild();
49
50 DefaultYobBuilder builder = new DefaultYobBuilder();
51
52 Object yangObject = builder.getYangObject(
53 (YdtExtendedContext) childCtx, YdtTestUtils.
54 getSchemaRegistry());
55 assertNotNull(yangObject);
56 assertTrue(yangObject.getClass().getSimpleName()
57 .equals("RootlistOpParam"));
58 try {
59
60 Field field =
61 yangObject.getClass().getDeclaredField("listwithcontainer");
62 field.setAccessible(true);
63 List listwithcontainer = (List) field.get(yangObject);
64 assertEquals(true, listwithcontainer.isEmpty());
65 Field field1 = yangObject.getClass()
66 .getDeclaredField("listwithoutcontainer");
67 field1.setAccessible(true);
68 List listwithoutcontainer = (List) field1.get(yangObject);
69 assertEquals(false, listwithoutcontainer.isEmpty());
70 Field invalidinterval = listwithoutcontainer.get(0).getClass()
71 .getDeclaredField("invalidinterval");
72 invalidinterval.setAccessible(true);
73 assertEquals("12", invalidinterval.get(listwithoutcontainer.get(0))
74 .toString());
75 } catch (NoSuchFieldException | IllegalAccessException e) {
76 fail("No such field or illegal access exception: " + e);
77 }
78 }
79
80 @Test
81 public void listwithcontainerTest()
82 throws IOException {
83 YangRequestWorkBench defaultYdtBuilder =
84 YdtTestUtils.listWithContainerYdt();
85
86 validateYangObject(defaultYdtBuilder);
87 }
88
89 public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
90
91 YdtContext ydtContext = defaultYdtBuilder.getRootNode();
92
93 YdtContext ydtContext1 = ydtContext.getFirstChild();
94
95 DefaultYobBuilder defaultYobBuilder = new DefaultYobBuilder();
96
97 Object yangObject = defaultYobBuilder.getYangObject(
98 (YdtExtendedContext) ydtContext1, YdtTestUtils
99 .getSchemaRegistry());
100 assertNotNull(yangObject);
101 assertTrue(yangObject.getClass().getSimpleName()
102 .equals("RootlistOpParam"));
103 try {
104
105 Field field = yangObject.getClass()
106 .getDeclaredField("listwithoutcontainer");
107 field.setAccessible(true);
108 List listwithoutcontainer = (List) field.get(yangObject);
109 assertEquals(true, listwithoutcontainer.isEmpty());
110 Field listwithcontainerField =
111 yangObject.getClass().getDeclaredField("listwithcontainer");
112 listwithcontainerField.setAccessible(true);
113 List listwithcontainer =
114 (List) listwithcontainerField.get(yangObject);
115 Field invalid = listwithcontainer.get(0).getClass()
116 .getDeclaredField("invalid");
117 invalid.setAccessible(true);
118 assertEquals("12",
119 invalid.get(listwithcontainer.get(0)).toString());
120 Field invalidinterval = listwithcontainer.get(0).getClass()
121 .getDeclaredField("invalidinterval");
122 invalidinterval.setAccessible(true);
123 List invalidintervalList =
124 (List) invalidinterval.get(listwithcontainer.get(0));
125 assertEquals("1", invalidintervalList.get(0).toString());
126 assertEquals("2", invalidintervalList.get(1).toString());
127 } catch (NoSuchFieldException | IllegalAccessException e) {
128 fail("No such field or illegal access exception: " + e);
129 }
130 }
131}