blob: c479afa1f09884c2a04b400b47ec89ead78fdcb5 [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 YobEnumTest {
33
34/*
35 ENUM
36
37 Positive scenario
38
39 input with in enum
40 input with "ten"
41 input with "hundred"
42 input with "thousand"
43*/
44
45 @Test
46 public void positiveTest() {
47 YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.enumYdt();
48 validateYangObject(defaultYdtBuilder);
49 }
50
51 private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
52
53 YdtContext rootCtx = defaultYdtBuilder.getRootNode();
54
55 YdtContext childCtx = rootCtx.getFirstChild();
56
57 DefaultYobBuilder builder = new DefaultYobBuilder();
58
59 Object yangObject = builder.getYangObject(
60 (YdtExtendedContext) childCtx, YdtTestUtils
61 .getSchemaRegistry());
62 assertNotNull(yangObject);
63 try {
64 Field field = yangObject.getClass().getDeclaredField("enumList");
65 field.setAccessible(true);
66 List enumList = (List) field.get(yangObject);
67 assertEquals(false, enumList.isEmpty());
68 Field enumleaf = enumList.get(0)
69 .getClass().getDeclaredField("enumleaf");
70 enumleaf.setAccessible(true);
71 assertEquals("ten", enumleaf
72 .get(enumList.get(0)).toString().toLowerCase());
73 assertEquals("hundred", enumleaf
74 .get(enumList.get(1)).toString().toLowerCase());
75 assertEquals("thousand", enumleaf
76 .get(enumList.get(2)).toString().toLowerCase());
77 } catch (NoSuchFieldException | IllegalAccessException e) {
78 fail("No such field or illegal access exception: " + e);
79 }
80 }
81}