blob: 1c32f86cb4b943a025af4f1a58b61fca94bcbe03 [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.List;
29
30import static org.junit.Assert.assertEquals;
31import static org.junit.Assert.assertNotNull;
32import static org.junit.Assert.assertNull;
33import static org.junit.Assert.assertTrue;
34
35public class YobListTest {
36
37 @Test
38 public void listwithoutcontainerTest() {
39 YangRequestWorkBench defaultYdtBuilder =
40 YdtTestUtils.listWithoutContainerYdt();
41 validateYangObjectList(defaultYdtBuilder);
42 }
43
44 private void validateYangObjectList(
45 YangRequestWorkBench defaultYdtBuilder) {
46
47 YdtContext rootCtx = defaultYdtBuilder.getRootNode();
48
49 YdtContext childCtx = rootCtx.getFirstChild();
50
51 DefaultYobBuilder builder = new DefaultYobBuilder();
52
53 Object yangObject = builder.getYangObject(
54 (YdtExtendedContext) childCtx, YdtTestUtils.
55 getSchemaRegistry());
56 assertNotNull(yangObject);
Jon Halla3fcf672017-03-28 16:53:22 -070057 assertTrue("RootlistOpParam".equals(yangObject.getClass().getSimpleName()));
Vidyashree Rama6160be12016-11-24 13:43:31 +053058 try {
59
60 Field field =
61 yangObject.getClass().getDeclaredField("listwithcontainer");
62 field.setAccessible(true);
63 List listwithcontainer = (List) field.get(yangObject);
64 assertNull(listwithcontainer);
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 Assert.fail();
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);
Jon Halla3fcf672017-03-28 16:53:22 -0700101 assertTrue("RootlistOpParam".equals(yangObject.getClass().getSimpleName()));
Vidyashree Rama6160be12016-11-24 13:43:31 +0530102 try {
103
104 Field field = yangObject.getClass()
105 .getDeclaredField("listwithoutcontainer");
106 field.setAccessible(true);
107 List listwithoutcontainer = (List) field.get(yangObject);
108 assertNull(listwithoutcontainer);
109 Field listwithcontainerField =
110 yangObject.getClass().getDeclaredField("listwithcontainer");
111 listwithcontainerField.setAccessible(true);
112 List listwithcontainer =
113 (List) listwithcontainerField.get(yangObject);
114 Field invalid = listwithcontainer.get(0).getClass()
115 .getDeclaredField("invalid");
116 invalid.setAccessible(true);
117 assertEquals("12",
118 invalid.get(listwithcontainer.get(0)).toString());
119 Field invalidinterval = listwithcontainer.get(0).getClass()
120 .getDeclaredField("invalidinterval");
121 invalidinterval.setAccessible(true);
122 List invalidintervalList =
123 (List) invalidinterval.get(listwithcontainer.get(0));
124 assertEquals("1", invalidintervalList.get(0).toString());
125 assertEquals("2", invalidintervalList.get(1).toString());
126 } catch (NoSuchFieldException | IllegalAccessException e) {
127 Assert.fail();
128 }
129 }
130}