blob: 663b544daa08d397a81f56092c34269b20a7b919 [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.lang.reflect.Field;
27
28import static org.junit.Assert.assertEquals;
29import static org.junit.Assert.assertNotNull;
30
31public class YobInteger32Test {
32
33 /*
34
35 Positive scenario
36
37 input at boundary for integer
38 i. min value
39 ii. max value
40
41 input at boundary for unsigned integer
42 i. min value
43 ii. max value
44
45 input with in range
46 if range is 10 to 100 for integer
47 i.1. input 11
48 i.2. min value 10
49 i.3. max value 100
50
51 if range is 10 to 100 for unsigned integer
52 i.1. input 11
53 i.2. min value 10
54 i.3. max value 100
55
56 */
57 @Test
58 public void positiveTest() {
59 YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer32Ydt();
60 validateYangObject(defaultYdtBuilder);
61 }
62
63 public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
64
65 YdtContext rootCtx = defaultYdtBuilder.getRootNode();
66
67 YdtContext childCtx = rootCtx.getFirstChild();
68
69 DefaultYobBuilder builder = new DefaultYobBuilder();
70
71 Object yangObject = builder.getYangObject(
72 (YdtExtendedContext) childCtx, YdtTestUtils
73 .getSchemaRegistry());
74 assertNotNull(yangObject);
75 try {
76 Field negInt = yangObject.getClass().getDeclaredField("negInt");
77 negInt.setAccessible(true);
78 assertEquals("-2147483648", negInt.get(yangObject).toString());
79 Field posInt = yangObject.getClass().getDeclaredField("posInt");
80 posInt.setAccessible(true);
81 assertEquals("2147483647", posInt.get(yangObject).toString());
82 Field minIntWithRange = yangObject
83 .getClass().getDeclaredField("minIntWithRange");
84 minIntWithRange.setAccessible(true);
85 assertEquals("10", minIntWithRange.get(yangObject).toString());
86 Field midIntWithRange = yangObject
87 .getClass().getDeclaredField("midIntWithRange");
88 midIntWithRange.setAccessible(true);
89 assertEquals("11", midIntWithRange.get(yangObject).toString());
90 Field maxIntWithRange = yangObject
91 .getClass().getDeclaredField("maxIntWithRange");
92 maxIntWithRange.setAccessible(true);
93 assertEquals("100", maxIntWithRange.get(yangObject).toString());
94 Field minUint = yangObject.getClass().getDeclaredField("minUint");
95 minUint.setAccessible(true);
96 assertEquals("0", minUint.get(yangObject).toString());
97 Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
98 maxUint.setAccessible(true);
99 assertEquals("4294967295", maxUint.get(yangObject).toString());
100 Field minUintWithRange = yangObject
101 .getClass().getDeclaredField("minUintWithRange");
102 minUintWithRange.setAccessible(true);
103 assertEquals("10", minUintWithRange.get(yangObject).toString());
104 Field midUintWithRange = yangObject
105 .getClass().getDeclaredField("midUintWithRange");
106 midUintWithRange.setAccessible(true);
107 assertEquals("11", midUintWithRange.get(yangObject).toString());
108 Field maxUintWithRange = yangObject
109 .getClass().getDeclaredField("maxUintWithRange");
110 maxUintWithRange.setAccessible(true);
111 assertEquals("100", maxUintWithRange.get(yangObject).toString());
112 } catch (IllegalAccessException | NoSuchFieldException e) {
113 Assert.fail();
114 }
115 }
116}