blob: 48eda96901818342c901097448665952dbb1ce1b [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.assertEquals;
30import static org.junit.Assert.assertNotNull;
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 (IllegalAccessException | NoSuchFieldException e) {
78 Assert.fail();
79 }
80 }
81}