blob: b7bcddb328b7fbd26960d6c54bde0d19fc9abfaa [file] [log] [blame]
sonu gupta1bb37b82016-11-11 16:51:18 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
sonu gupta1bb37b82016-11-11 16:51:18 +05303 *
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.io.IOException;
22import java.util.ArrayList;
23import java.util.List;
24
Sonu Gupta1f418aa2017-02-23 20:48:46 +053025import static org.junit.Assert.assertEquals;
26import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.DELETE_ONLY;
sonu gupta1bb37b82016-11-11 16:51:18 +053027import static org.onosproject.yms.app.ydt.YdtTestUtils.foodArenaYdt;
Sonu Gupta1f418aa2017-02-23 20:48:46 +053028import static org.onosproject.yms.app.ydt.YdtTestUtils.getYdtBuilder;
sonu gupta1bb37b82016-11-11 16:51:18 +053029import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents;
30import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents;
31import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree;
Sonu Gupta1f418aa2017-02-23 20:48:46 +053032import static org.onosproject.yms.ydt.YdtContextOperationType.DELETE;
sonu gupta1bb37b82016-11-11 16:51:18 +053033import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
Sonu Gupta1f418aa2017-02-23 20:48:46 +053034import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
sonu gupta1bb37b82016-11-11 16:51:18 +053035
36public class FoodArenaTest {
37
38 // Logger list is used for walker testing.
39 private final List<String> logger = new ArrayList<>();
40
41 private static final String[] EXPECTED = {
42 "Entry Node is foodarena.",
43 "Entry Node is food.",
44 "Entry Node is food.",
45 "Entry Node is chocolate.",
46 "Exit Node is chocolate.",
47 "Exit Node is food.",
48 "Exit Node is food.",
49 "Exit Node is foodarena."
50 };
51
52 /**
53 * Creates and validates food arena ydt.
54 */
55 @Test
56 public void foodArenaTest() throws IOException {
57
58 YangRequestWorkBench ydtBuilder = foodArenaYdt();
59 validateTree(ydtBuilder);
60 walkINTree(ydtBuilder, EXPECTED);
61 }
62
63 /**
Sonu Gupta1f418aa2017-02-23 20:48:46 +053064 * Creates and validates food arena ydt.
65 */
66 @Test
67 public void foodArenaDeleteOperationTest() throws IOException {
68
69 YangRequestWorkBench ydtBuilder;
70 ydtBuilder = getYdtBuilder("foodarena", "food", "ydt.food", NONE);
71 ydtBuilder.addChild("food", "ydt.food", DELETE);
72 YdtAppContext appRootNode = ydtBuilder.getAppRootNode();
Sean Condonfe6ceba2017-02-26 16:40:03 +000073 assertEquals(DELETE_ONLY, appRootNode.getFirstChild().getOperationType());
Sonu Gupta1f418aa2017-02-23 20:48:46 +053074 }
75
76 /**
sonu gupta1bb37b82016-11-11 16:51:18 +053077 * Validates the given built ydt.
78 */
79 private void validateTree(YangRequestWorkBench ydtBuilder) {
80 // Assign root node to ydtNode for validating purpose.
81 YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode();
82 // Logical root node does not have operation type
83 validateNodeContents(ydtNode, "foodarena", null);
84 ydtNode = ydtNode.getFirstChild();
85 validateNodeContents(ydtNode, "food", MERGE);
86 ydtNode = ydtNode.getFirstChild();
87 validateNodeContents(ydtNode, "food", MERGE);
88 ydtNode = ydtNode.getFirstChild();
89 validateLeafContents(ydtNode, "chocolate", "dark");
90 }
91}