sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 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 | |
Sonu Gupta | 1f418aa | 2017-02-23 20:48:46 +0530 | [diff] [blame] | 25 | import static org.junit.Assert.assertEquals; |
| 26 | import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.DELETE_ONLY; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 27 | import static org.onosproject.yms.app.ydt.YdtTestUtils.foodArenaYdt; |
Sonu Gupta | 1f418aa | 2017-02-23 20:48:46 +0530 | [diff] [blame] | 28 | import static org.onosproject.yms.app.ydt.YdtTestUtils.getYdtBuilder; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 29 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents; |
| 30 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents; |
| 31 | import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree; |
Sonu Gupta | 1f418aa | 2017-02-23 20:48:46 +0530 | [diff] [blame] | 32 | import static org.onosproject.yms.ydt.YdtContextOperationType.DELETE; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 33 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
Sonu Gupta | 1f418aa | 2017-02-23 20:48:46 +0530 | [diff] [blame] | 34 | import static org.onosproject.yms.ydt.YdtContextOperationType.NONE; |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 35 | |
| 36 | public 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 Gupta | 1f418aa | 2017-02-23 20:48:46 +0530 | [diff] [blame] | 64 | * 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 Condon | fe6ceba | 2017-02-26 16:40:03 +0000 | [diff] [blame] | 73 | assertEquals(DELETE_ONLY, appRootNode.getFirstChild().getOperationType()); |
Sonu Gupta | 1f418aa | 2017-02-23 20:48:46 +0530 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame] | 77 | * 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 | } |