blob: a64c4c4613736fe4933adbacf8aea7f2b0585fb9 [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 java.util.ArrayList;
22import java.util.HashSet;
23import java.util.List;
24import java.util.Set;
25
26import static org.onosproject.yms.app.ydt.YdtTestUtils.logisticsManagerYdt;
27import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
28import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafListContents;
29import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
30import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree;
31import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
32
33public class LogisticsManagerTest {
34
35 // Logger list is used for walker testing.
36 private final List<String> logger = new ArrayList<>();
37
38 private Set<String> valueSet = new HashSet();
39
40 private static final String[] EXPECTED = {
41 "Entry Node is logisticsmanager.",
42 "Entry Node is customssupervisor.",
43 "Entry Node is supervisor.",
44 "Exit Node is supervisor.",
45 "Exit Node is customssupervisor.",
46 "Entry Node is merchandisersupervisor.",
47 "Entry Node is supervisor.",
48 "Exit Node is supervisor.",
49 "Exit Node is merchandisersupervisor.",
50 "Entry Node is materialsupervisor.",
51 "Entry Node is supervisor.",
52 "Entry Node is name.",
53 "Exit Node is name.",
54 "Entry Node is departmentId.",
55 "Exit Node is departmentId.",
56 "Exit Node is supervisor.",
57 "Entry Node is supervisor.",
58 "Entry Node is name.",
59 "Exit Node is name.",
60 "Entry Node is departmentId.",
61 "Exit Node is departmentId.",
62 "Exit Node is supervisor.",
63 "Exit Node is materialsupervisor.",
64 "Entry Node is purchasingsupervisor.",
65 "Entry Node is supervisor.",
66 "Entry Node is purchasing-specialist.",
67 "Exit Node is purchasing-specialist.",
68 "Entry Node is support.",
69 "Exit Node is support.",
70 "Exit Node is supervisor.",
71 "Exit Node is purchasingsupervisor.",
72 "Entry Node is warehousesupervisor.",
73 "Entry Node is supervisor.",
74 "Exit Node is supervisor.",
75 "Exit Node is warehousesupervisor.",
76 "Entry Node is tradingsupervisor.",
77 "Entry Node is supervisor.",
78 "Exit Node is supervisor.",
79 "Exit Node is tradingsupervisor.",
80 "Entry Node is employeeid.",
81 "Entry Node is employeeid.",
82 "Exit Node is employeeid.",
83 "Exit Node is employeeid.",
84 "Exit Node is logisticsmanager."
85 };
86
87 /**
88 * Creates and validates logistics manager ydt.
89 */
90 @Test
91 public void logisticsManagerTest() {
92 YangRequestWorkBench ydtBuilder = logisticsManagerYdt();
93 validateTree(ydtBuilder);
94 // walker test
95 walkINTree(ydtBuilder, EXPECTED);
96 }
97
98 /**
99 * Validates the given built ydt.
100 */
101 private void validateTree(YangRequestWorkBench ydtBuilder) {
102 valueSet.add("1");
103 valueSet.add("2");
104 valueSet.add("3");
105 valueSet.add("4");
106 valueSet.add("5");
107 // assign root node to ydtNode for validating purpose.
108 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
109 // Logical root node does not have operation type
110 validateNodeContents(ydtNode, "logisticsmanager", null);
111
112 ydtNode = ydtNode.getFirstChild();
113 // Logical root node does not have operation type
114 validateNodeContents(ydtNode, "customssupervisor", MERGE);
115 ydtNode = ydtNode.getFirstChild();
116 validateLeafContents(ydtNode, "supervisor", "abc");
117
118 ydtNode = ydtNode.getParent();
119
120 ydtNode = ydtNode.getNextSibling();
121 validateNodeContents(ydtNode, "merchandisersupervisor", MERGE);
122 ydtNode = ydtNode.getFirstChild();
123 validateLeafContents(ydtNode, "supervisor", "abc");
124
125 ydtNode = ydtNode.getParent();
126
127 ydtNode = ydtNode.getNextSibling();
128 validateNodeContents(ydtNode, "materialsupervisor", MERGE);
129 ydtNode = ydtNode.getFirstChild();
130 validateNodeContents(ydtNode, "supervisor", MERGE);
131
132 ydtNode = ydtNode.getFirstChild();
133 validateLeafContents(ydtNode, "name", "abc");
134 ydtNode = ydtNode.getNextSibling();
135 validateLeafContents(ydtNode, "departmentId", "xyz");
136
137 ydtNode = ydtNode.getParent();
138
139 ydtNode = ydtNode.getNextSibling();
140 validateNodeContents(ydtNode, "supervisor", MERGE);
141
142 ydtNode = ydtNode.getFirstChild();
143 validateLeafContents(ydtNode, "name", "ab");
144 ydtNode = ydtNode.getNextSibling();
145 validateLeafContents(ydtNode, "departmentId", "xy");
146
147 ydtNode = ydtNode.getParent().getParent();
148 ydtNode = ydtNode.getNextSibling();
149 validateNodeContents(ydtNode, "purchasingsupervisor", MERGE);
150 ydtNode = ydtNode.getFirstChild();
151 validateNodeContents(ydtNode, "supervisor", MERGE);
152
153 ydtNode = ydtNode.getFirstChild();
154 validateLeafContents(ydtNode, "purchasing-specialist", "abc");
155 ydtNode = ydtNode.getNextSibling();
156 validateLeafContents(ydtNode, "support", "xyz");
157
158 ydtNode = ydtNode.getParent().getParent();
159
160 ydtNode = ydtNode.getNextSibling();
161 validateNodeContents(ydtNode, "warehousesupervisor", MERGE);
162 ydtNode = ydtNode.getFirstChild();
163 validateLeafListContents(ydtNode, "supervisor", valueSet);
164
165 ydtNode = ydtNode.getParent();
166
167 ydtNode = ydtNode.getNextSibling();
168 validateNodeContents(ydtNode, "tradingsupervisor", MERGE);
169 ydtNode = ydtNode.getFirstChild();
170 validateLeafContents(ydtNode, "supervisor", "abc");
171
172 ydtNode = ydtNode.getParent();
173
174 ydtNode = ydtNode.getNextSibling();
175 validateNodeContents(ydtNode, "employeeid", MERGE);
176 ydtNode = ydtNode.getFirstChild();
177 validateLeafListContents(ydtNode, "employeeid", valueSet);
178 }
179}