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