blob: 77c2f818f477d49822b11168aa5f41fa21ad0373 [file] [log] [blame]
sonu gupta1bb37b82016-11-11 16:51:18 +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.ydt;
18
19import org.junit.Test;
20import org.onosproject.yms.app.ydt.exceptions.YdtException;
21
22import static org.onosproject.yms.app.ydt.YdtTestConstants.ENUM;
23import static org.onosproject.yms.app.ydt.YdtTestConstants.ENUMNS;
24import static org.onosproject.yms.app.ydt.YdtTestConstants.TYPE;
25import static org.onosproject.yms.app.ydt.YdtTestUtils.enumYdt;
26import static org.onosproject.yms.app.ydt.YdtTestUtils.validateErrMsg;
27import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
28import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
29import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
30
31public class YdtEnumTest {
32
33/*
34 ENUM
35
36 Positive scenario
37
38 input with in enum
39 input with "ten"
40 input with "hundred"
41 input with "thousand"
42*/
43
44 /**
45 * Creates and validates enum ydt covering different positive scenario.
46 */
47 @Test
48 public void positiveTest() throws YdtException {
49 YangRequestWorkBench ydtBuilder = enumYdt();
50 validateTree(ydtBuilder);
51 }
52
53 /**
54 * Validates the given built ydt.
55 */
56 private void validateTree(YangRequestWorkBench ydtBuilder) {
57
58 // assign root node to ydtNode for validating purpose.
59 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
60 // Logical root node does not have operation type
61 validateNodeContents(ydtNode, TYPE, null);
62
63 ydtNode = ydtNode.getFirstChild();
64 validateNodeContents(ydtNode, "enumtest", MERGE);
65 ydtNode = ydtNode.getFirstChild();
66 validateNodeContents(ydtNode, "enumList", MERGE);
67 ydtNode = ydtNode.getFirstChild();
68 validateLeafContents(ydtNode, "enumleaf", "ten");
69 ydtNode = ydtNode.getParent();
70 ydtNode = ydtNode.getNextSibling();
71 validateNodeContents(ydtNode, "enumList", MERGE);
72 ydtNode = ydtNode.getFirstChild();
73 validateLeafContents(ydtNode, "enumleaf", "hundred");
74 ydtNode = ydtNode.getParent();
75 ydtNode = ydtNode.getNextSibling();
76 validateNodeContents(ydtNode, "enumList", MERGE);
77 ydtNode = ydtNode.getFirstChild();
78 validateLeafContents(ydtNode, "enumleaf", "thousand");
79 }
80
81 /*
82 Negative scenario
83
84 input with "10"
85 input with "thousands"
86 */
87
88 /**
89 * Tests all the negative scenario's for enum data type.
90 */
91 @Test
92 public void negativeTest() throws YdtException {
93 validateErrMsg("enumleaf", ENUMNS, "10", ENUM, "enumList");
94 validateErrMsg("enumleaf", ENUMNS, "thousands", ENUM, "enumList");
95 validateErrMsg("enumleaf", ENUMNS, "enumeration", ENUM, "enumList");
96 }
97}