blob: 6a3fc0587002e9b52f70da7352a26b34443e311e [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.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.assertEquals;
29import static org.junit.Assert.assertNotNull;
30import static org.junit.Assert.fail;
31
32/**
33 * Test the YANG object building for the YANG data tree based on the schema
34 * nodes with empty data type.
35 */
36public class YobEmptyTest {
37
38 /*
39 EMPTY
40 Positive scenario
41 input with in empty.
42 */
43 @Test
44 public void positiveTest() {
45 YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.emptyTypeYdt();
46 validateYangObject(defaultYdtBuilder);
47 }
48
49 private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
50 YdtContext rootCtx = defaultYdtBuilder.getRootNode();
51 YdtContext childCtx = rootCtx.getFirstChild();
52 DefaultYobBuilder builder = new DefaultYobBuilder();
53
54 Object yangObject = builder.getYangObject(
55 (YdtExtendedContext) childCtx, YdtTestUtils
56 .getSchemaRegistry());
57 assertNotNull(yangObject);
58
59 try {
60 Field field = yangObject.getClass().getDeclaredField("emptyList");
61 field.setAccessible(true);
62 List booleanList = (List) field.get(yangObject);
63 Field invalidInterval = booleanList.get(0)
64 .getClass().getDeclaredField("empty");
65 invalidInterval.setAccessible(true);
66 assertEquals(true, invalidInterval.get(booleanList.get(0)));
67 } catch (NoSuchFieldException | IllegalAccessException e) {
68 fail();
69 }
70 }
71}