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