blob: ea5ee344b4ccab587e377234288e732eede11108 [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.EMPTY;
23import static org.onosproject.yms.app.ydt.YdtTestConstants.EMPTYNS;
24import static org.onosproject.yms.app.ydt.YdtTestConstants.TYPE;
25import static org.onosproject.yms.app.ydt.YdtTestUtils.emptyTypeYdt;
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 YdtEmptyTest {
32
33 /*
34 EMPTY
35 Positive scenario
36 input with in empty.
37 */
38
39 /**
40 * Creates and validates empty ydt covering different positive scenario.
41 */
42 @Test
43 public void positiveTest() throws YdtException {
44 YangRequestWorkBench ydtBuilder = emptyTypeYdt();
45 validateTree(ydtBuilder);
46 }
47
48 /**
49 * Validates the given built ydt.
50 */
51 private void validateTree(YangRequestWorkBench ydtBuilder) {
52
53 // assign root node to ydtNode for validating purpose.
54 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
55 // Logical root node does not have operation type
56 validateNodeContents(ydtNode, TYPE, null);
57
58 ydtNode = ydtNode.getFirstChild();
59 validateNodeContents(ydtNode, "emptydata", MERGE);
60 ydtNode = ydtNode.getFirstChild();
61 validateNodeContents(ydtNode, "emptyList", MERGE);
62 ydtNode = ydtNode.getFirstChild();
63 validateLeafContents(ydtNode, "empty", "");
64 }
65
66 /*
67 Negative scenario
68
69 input with " "
70 input with "tab"
71 input with """"
72 */
73
74 /**
75 * Tests all the negative scenario's for empty data type.
76 */
77 @Test
78 public void negativeTest() throws YdtException {
79 validateErrMsg("empty", EMPTYNS, " ", EMPTY, "emptyList");
80 validateErrMsg("empty", EMPTYNS, " ", EMPTY, "emptyList");
81 validateErrMsg("empty", EMPTYNS, " ", EMPTY, "emptyList");
82 }
83}