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