sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.yms.app.ydt; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | import java.io.IOException; |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.List; |
| 24 | |
| 25 | import static org.onosproject.yms.app.ydt.YdtTestUtils.foodArenaYdt; |
| 26 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents; |
| 27 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents; |
| 28 | import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree; |
| 29 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 30 | |
| 31 | public class FoodArenaTest { |
| 32 | |
| 33 | // Logger list is used for walker testing. |
| 34 | private final List<String> logger = new ArrayList<>(); |
| 35 | |
| 36 | private static final String[] EXPECTED = { |
| 37 | "Entry Node is foodarena.", |
| 38 | "Entry Node is food.", |
| 39 | "Entry Node is food.", |
| 40 | "Entry Node is chocolate.", |
| 41 | "Exit Node is chocolate.", |
| 42 | "Exit Node is food.", |
| 43 | "Exit Node is food.", |
| 44 | "Exit Node is foodarena." |
| 45 | }; |
| 46 | |
| 47 | /** |
| 48 | * Creates and validates food arena ydt. |
| 49 | */ |
| 50 | @Test |
| 51 | public void foodArenaTest() throws IOException { |
| 52 | |
| 53 | YangRequestWorkBench ydtBuilder = foodArenaYdt(); |
| 54 | validateTree(ydtBuilder); |
| 55 | walkINTree(ydtBuilder, EXPECTED); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Validates the given built ydt. |
| 60 | */ |
| 61 | private void validateTree(YangRequestWorkBench ydtBuilder) { |
| 62 | // Assign root node to ydtNode for validating purpose. |
| 63 | YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode(); |
| 64 | // Logical root node does not have operation type |
| 65 | validateNodeContents(ydtNode, "foodarena", null); |
| 66 | ydtNode = ydtNode.getFirstChild(); |
| 67 | validateNodeContents(ydtNode, "food", MERGE); |
| 68 | ydtNode = ydtNode.getFirstChild(); |
| 69 | validateNodeContents(ydtNode, "food", MERGE); |
| 70 | ydtNode = ydtNode.getFirstChild(); |
| 71 | validateLeafContents(ydtNode, "chocolate", "dark"); |
| 72 | } |
| 73 | } |