sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 1 | /* |
Ray Milkey | 2d572dd | 2017-04-14 10:01:24 -0700 | [diff] [blame^] | 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. |
sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame] | 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.HashSet; |
| 24 | import java.util.List; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents; |
| 28 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafListContents; |
| 29 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents; |
| 30 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 31 | |
| 32 | public class EmptyLeafListTest { |
| 33 | |
| 34 | // Logger list is used for walker testing. |
| 35 | private final List<String> logger = new ArrayList<>(); |
| 36 | |
| 37 | private static final String[] EXPECTED = { |
| 38 | "Entry Node is empty.", |
| 39 | "Entry Node is EmptyLeafList.", |
| 40 | "Entry Node is l1.", |
| 41 | "Exit Node is l1.", |
| 42 | "Entry Node is l2.", |
| 43 | "Exit Node is l2.", |
| 44 | "Entry Node is l3.", |
| 45 | "Exit Node is l3.", |
| 46 | "Entry Node is list1.", |
| 47 | "Exit Node is list1.", |
| 48 | "Entry Node is list2.", |
| 49 | "Exit Node is list2.", |
| 50 | "Entry Node is list3.", |
| 51 | "Exit Node is list3.", |
| 52 | "Exit Node is EmptyLeafList.", |
| 53 | "Exit Node is empty." |
| 54 | }; |
| 55 | |
| 56 | /** |
| 57 | * Creates and validates empty leaf list ydt. |
| 58 | */ |
| 59 | @Test |
| 60 | public void emptyListTest() throws IOException { |
| 61 | |
| 62 | //TODO need to be handled later |
| 63 | // YangRequestWorkBench ydtBuilder = emptyLeafListYdt(); |
| 64 | // validateTree(ydtBuilder); |
| 65 | // walkINTree(ydtBuilder, EXPECTED); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Validates the given built ydt. |
| 70 | */ |
| 71 | private void validateTree(YangRequestWorkBench ydtBuilder) { |
| 72 | |
| 73 | Set<String> valueSet = new HashSet(); |
| 74 | |
| 75 | // Assign root node to ydtNode for validating purpose. |
| 76 | YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode(); |
| 77 | // Logical root node does not have operation type |
| 78 | validateNodeContents(ydtNode, "empty", null); |
| 79 | ydtNode = ydtNode.getFirstChild(); |
| 80 | validateNodeContents(ydtNode, "EmptyLeafList", MERGE); |
| 81 | ydtNode = ydtNode.getFirstChild(); |
| 82 | validateLeafContents(ydtNode, "l1", null); |
| 83 | ydtNode = ydtNode.getNextSibling(); |
| 84 | validateLeafContents(ydtNode, "l2", null); |
| 85 | ydtNode = ydtNode.getNextSibling(); |
| 86 | validateLeafContents(ydtNode, "l3", null); |
| 87 | ydtNode = ydtNode.getNextSibling(); |
| 88 | |
| 89 | validateLeafListContents(ydtNode, "list1", valueSet); |
| 90 | ydtNode = ydtNode.getNextSibling(); |
| 91 | validateLeafListContents(ydtNode, "list2", valueSet); |
| 92 | ydtNode = ydtNode.getNextSibling(); |
| 93 | validateLeafListContents(ydtNode, "list3", valueSet); |
| 94 | } |
| 95 | } |