blob: 83ce3f67db27dd525bf5d898a4f93ed616d28bc2 [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;
26import java.util.List;
27
28import static org.junit.Assert.assertFalse;
29import static org.junit.Assert.assertNotNull;
30import static org.junit.Assert.assertTrue;
31import static org.junit.Assert.fail;
32
33public class YobBooleanTest {
34
35 private static final String BOOLEAN_LIST = "booleanList";
36 private static final String AUTO_PREFIX_BOOLEAN = "yangAutoPrefixBoolean";
37
38 /*
39 BOOLEAN
40 Positive scenario
41 input with in true and false
42 */
43 @Test
44 public void positiveTest() {
45 YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.booleanYdt();
46 validateYangObject(defaultYdtBuilder);
47 }
48
49 private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
50
51 YdtContext rootCtx = defaultYdtBuilder.getRootNode();
52
53 YdtContext childCtx = rootCtx.getFirstChild();
54
55 DefaultYobBuilder builder = new DefaultYobBuilder();
56
57 Object yangObject = builder.getYangObject(
58 (YdtExtendedContext) childCtx, YdtTestUtils
59 .getSchemaRegistry());
60 assertNotNull(yangObject);
61 try {
62
63 Field field = yangObject.getClass().getDeclaredField(BOOLEAN_LIST);
64 field.setAccessible(true);
65 List booleanList = (List) field.get(yangObject);
66 Field invalidInterval = booleanList.get(0).getClass()
67 .getDeclaredField(AUTO_PREFIX_BOOLEAN);
68 invalidInterval.setAccessible(true);
69 assertTrue((boolean) invalidInterval.get(booleanList.get(0)));
70 assertFalse((boolean) invalidInterval.get(booleanList.get(1)));
71 } catch (NoSuchFieldException | IllegalAccessException e) {
72 fail("No such field or illegal access exception: " + e);
73 }
74 }
75}