blob: 5446b51c2f4505ae51e3a478f3ea027f259251a6 [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.BIT;
22import static org.onosproject.yms.app.ydt.YdtTestConstants.BITNS;
23import static org.onosproject.yms.app.ydt.YdtTestUtils.bitYdt;
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 YdtBitTest {
30
31 /*
32 BINARY
33
34 Positive scenario
35 input with position 0
36 input with position 1
37 input with position 2
38 */
39
40 /**
41 * Creates and validates bit ydt covering different positive scenario.
42 */
43 @Test
44 public void positiveTest() {
45 YangRequestWorkBench ydtBuilder = bitYdt();
46 validateTree(ydtBuilder);
47 }
48
49 /**
50 * Validates the given built ydt.
51 */
52 private void validateTree(YangRequestWorkBench ydtBuilder) {
53
54 // assign root node to ydtNode for validating purpose.
55 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
56 // Logical root node does not have operation type
57 validateNodeContents(ydtNode, "builtInType", null);
58 ydtNode = ydtNode.getFirstChild();
59 validateNodeContents(ydtNode, "bit", MERGE);
60 ydtNode = ydtNode.getFirstChild();
61 validateNodeContents(ydtNode, "bitList", MERGE);
62 ydtNode = ydtNode.getFirstChild();
63 validateLeafContents(ydtNode, "bit", "disable-nagle");
64 ydtNode = ydtNode.getParent();
65 ydtNode = ydtNode.getNextSibling();
66 validateNodeContents(ydtNode, "bitList", MERGE);
67 ydtNode = ydtNode.getFirstChild();
68 validateLeafContents(ydtNode, "bit", "auto-sense-speed");
69 ydtNode = ydtNode.getParent();
70 ydtNode = ydtNode.getNextSibling();
71 validateNodeContents(ydtNode, "bitList", MERGE);
72 ydtNode = ydtNode.getFirstChild();
73 validateLeafContents(ydtNode, "bit", "ten-Mb-only");
74 }
75
76 /*
77 Negative scenario
78
79 input with position 0
80 input with position 1
81 input with position 2
82 */
83
84 /**
85 * Tests all the negative scenario's for bit data type.
86 */
87 @Test
88 public void negativeTest() {
89 validateErrMsg("bit", BITNS, "0", BIT, "bitList");
90 validateErrMsg("bit", BITNS, "default", BIT, "bitList");
91 validateErrMsg("bit", BITNS, "1", BIT, "bitList");
92 validateErrMsg("bit", BITNS, "", BIT, "bitList");
93 }
94}