blob: 505c64044ac9d0c04b73118abeab16a868963df6 [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;
20
21import static org.onosproject.yms.app.ydt.YdtTestConstants.BOOL;
22import static org.onosproject.yms.app.ydt.YdtTestConstants.BOOLNS;
23import static org.onosproject.yms.app.ydt.YdtTestUtils.booleanYdt;
24import static org.onosproject.yms.app.ydt.YdtTestUtils.validateErrMsg;
25import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
26import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
27import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
28
29public class YdtBooleanTest {
30
31 /*
32 BOOLEAN
33 Positive scenario
34 input with in "booleanList" and false
35 */
36
37 /**
38 * Creates and validates boolean ydt covering different positive scenario.
39 */
40 @Test
41 public void positiveTest() {
42 YangRequestWorkBench ydtBuilder = booleanYdt();
43 validateTree(ydtBuilder);
44 }
45
46 /**
47 * Validates the given built ydt.
48 */
49 private void validateTree(YangRequestWorkBench ydtBuilder) {
50
51 // assign root node to ydtNode for validating purpose.
52 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
53 // Logical root node does not have operation type
54 validateNodeContents(ydtNode, "builtInType", null);
55 ydtNode = ydtNode.getFirstChild();
56 validateNodeContents(ydtNode, "bool", MERGE);
57 ydtNode = ydtNode.getFirstChild();
58 validateNodeContents(ydtNode, "booleanList", MERGE);
59 ydtNode = ydtNode.getFirstChild();
60 validateLeafContents(ydtNode, "boolean", "true");
61 ydtNode = ydtNode.getParent();
62 ydtNode = ydtNode.getNextSibling();
63 validateNodeContents(ydtNode, "booleanList", MERGE);
64 ydtNode = ydtNode.getFirstChild();
65 validateLeafContents(ydtNode, "boolean", "false");
66 }
67
68 /*
69 Negative scenario
70
71 input with in non zero value in case of "booleanList"
72 input with zero value in case of false
73 input with empty value in case of false
74 */
75
76 /**
77 * Tests all the negative scenario's for boolean data type.
78 */
79 @Test
80 public void negativeTest() {
81 validateErrMsg("boolean", BOOLNS, "10", BOOL, "booleanList");
82 validateErrMsg("boolean", BOOLNS, "0", BOOL, "booleanList");
83 validateErrMsg("boolean", BOOLNS, "", BOOL, "booleanList");
84 validateErrMsg("boolean", BOOLNS, "-1", BOOL, "booleanList");
85 validateErrMsg("boolean", BOOLNS, "tru", BOOL, "booleanList");
86 validateErrMsg("boolean", BOOLNS, "boolean", BOOL, "booleanList");
87 }
88}