blob: ea87ca7d483d7d149eda11b1a2b7ea675f5f426a [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;
27import java.util.List;
28
29import static org.junit.Assert.assertFalse;
30import static org.junit.Assert.assertNotNull;
31import static org.junit.Assert.assertTrue;
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 Assert.fail();
73 }
74 }
75}