blob: d0b9f1e31bac32a3e71695fd78e99edceaa45da0 [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 YobDecimal64Test {
32
33 /*
34
35 Positive scenario
36
37 input at boundary for decimal64 with fraction 2
38 i. min value
39 ii. max value
40
41 input at boundary for decimal64 with minimum fraction
42 i. min value
43 ii. mid value
44 iii. max value
45
46 input at boundary for decimal64 with maximum fraction
47 i. min value
48 ii. mid value
49 iii. max value
50
51 input with in range
52 if range is 10 to 100 for integer
53 i.1. input 11
54 i.2. min value 10
55 i.3. max value 100
56
57 input with multi interval range
58 if range is 10..40 | 50..100 for decimal64
59 i.1. input 11
60 i.2. input 10
61 i.3. input 40
62 i.4. input 50
63 i.5. input 55
64 i.6. input 100
65
66 if range is "min .. 3.14 | 10 | 20..max" for decimal64
67 i.1. input min
68 i.2. input 2.505
69 i.3. input 3.14
70 i.4. input 10
71 i.5. input 20
72 i.6. input 92233720368547757
73 i.7. input 92233720368547758.07
74
75 */
76 @Test
77 public void positiveTest() {
78 YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.decimal64Ydt();
79 validateYangObject(defaultYdtBuilder);
80 }
81
82 private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
83
84 YdtContext rootCtx = defaultYdtBuilder.getRootNode();
85
86 YdtContext childCtx = rootCtx.getFirstChild();
87
88 DefaultYobBuilder builder = new DefaultYobBuilder();
89
90 Object yangObject = builder.getYangObject(
91 (YdtExtendedContext) childCtx, YdtTestUtils
92 .getSchemaRegistry());
93 assertNotNull(yangObject);
94 try {
95 Field negInt = yangObject.getClass().getDeclaredField("negInt");
96 negInt.setAccessible(true);
97 assertEquals("-92233720368547758.08", negInt
98 .get(yangObject).toString());
99 Field negIntWithMaxFraction = yangObject.getClass()
100 .getDeclaredField("negIntWithMaxFraction");
101 negIntWithMaxFraction.setAccessible(true);
102 assertEquals("-9.223372036854775808", negIntWithMaxFraction
103 .get(yangObject).toString());
104 Field negIntWithMinFraction = yangObject.getClass()
105 .getDeclaredField("negIntWithMinFraction");
106 negIntWithMinFraction.setAccessible(true);
107 assertEquals("-922337203685477580.8", negIntWithMinFraction
108 .get(yangObject).toString());
109 Field posInt = yangObject.getClass()
110 .getDeclaredField("posInt");
111 posInt.setAccessible(true);
112 assertEquals("92233720368547758.07", posInt
113 .get(yangObject).toString());
114 Field posIntWithMaxFraction = yangObject
115 .getClass().getDeclaredField("posIntWithMaxFraction");
116 posIntWithMaxFraction.setAccessible(true);
117 assertEquals("9.223372036854775807", posIntWithMaxFraction
118 .get(yangObject).toString());
119 Field posIntWithMinFraction = yangObject.getClass()
120 .getDeclaredField("posIntWithMinFraction");
121 posIntWithMinFraction.setAccessible(true);
122 assertEquals("922337203685477580.7", posIntWithMinFraction
123 .get(yangObject).toString());
124 Field minIntWithRange = yangObject.getClass()
125 .getDeclaredField("minIntWithRange");
126 minIntWithRange.setAccessible(true);
127 assertEquals("10", minIntWithRange
128 .get(yangObject).toString());
129 Field midIntWithRange = yangObject
130 .getClass().getDeclaredField("midIntWithRange");
131 midIntWithRange.setAccessible(true);
132 assertEquals("11", midIntWithRange.get(yangObject).toString());
133 Field maxIntWithRange = yangObject
134 .getClass().getDeclaredField("maxIntWithRange");
135 maxIntWithRange.setAccessible(true);
136 assertEquals("100", maxIntWithRange.get(yangObject).toString());
137 } catch (IllegalAccessException | NoSuchFieldException e) {
138 Assert.fail();
139 }
140 }
141}