sonu gupta | eff184b | 2016-11-24 12:43:49 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2016. Lorem ipsum dolor sit amet, consectetur adipiscing elit. |
| 3 | * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. |
| 4 | * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. |
| 5 | * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. |
| 6 | * Vestibulum commodo. Ut rhoncus gravida arcu. |
| 7 | */ |
| 8 | |
| 9 | package org.onosproject.yms.app.ydt; |
| 10 | |
| 11 | import org.junit.Test; |
| 12 | |
| 13 | import java.io.IOException; |
| 14 | import java.util.ArrayList; |
| 15 | import java.util.HashSet; |
| 16 | import java.util.List; |
| 17 | import java.util.Set; |
| 18 | |
| 19 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents; |
| 20 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafListContents; |
| 21 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents; |
| 22 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 23 | |
| 24 | public class EmptyLeafListTest { |
| 25 | |
| 26 | // Logger list is used for walker testing. |
| 27 | private final List<String> logger = new ArrayList<>(); |
| 28 | |
| 29 | private static final String[] EXPECTED = { |
| 30 | "Entry Node is empty.", |
| 31 | "Entry Node is EmptyLeafList.", |
| 32 | "Entry Node is l1.", |
| 33 | "Exit Node is l1.", |
| 34 | "Entry Node is l2.", |
| 35 | "Exit Node is l2.", |
| 36 | "Entry Node is l3.", |
| 37 | "Exit Node is l3.", |
| 38 | "Entry Node is list1.", |
| 39 | "Exit Node is list1.", |
| 40 | "Entry Node is list2.", |
| 41 | "Exit Node is list2.", |
| 42 | "Entry Node is list3.", |
| 43 | "Exit Node is list3.", |
| 44 | "Exit Node is EmptyLeafList.", |
| 45 | "Exit Node is empty." |
| 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * Creates and validates empty leaf list ydt. |
| 50 | */ |
| 51 | @Test |
| 52 | public void emptyListTest() throws IOException { |
| 53 | |
| 54 | //TODO need to be handled later |
| 55 | // YangRequestWorkBench ydtBuilder = emptyLeafListYdt(); |
| 56 | // validateTree(ydtBuilder); |
| 57 | // walkINTree(ydtBuilder, EXPECTED); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Validates the given built ydt. |
| 62 | */ |
| 63 | private void validateTree(YangRequestWorkBench ydtBuilder) { |
| 64 | |
| 65 | Set<String> valueSet = new HashSet(); |
| 66 | |
| 67 | // Assign root node to ydtNode for validating purpose. |
| 68 | YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode(); |
| 69 | // Logical root node does not have operation type |
| 70 | validateNodeContents(ydtNode, "empty", null); |
| 71 | ydtNode = ydtNode.getFirstChild(); |
| 72 | validateNodeContents(ydtNode, "EmptyLeafList", MERGE); |
| 73 | ydtNode = ydtNode.getFirstChild(); |
| 74 | validateLeafContents(ydtNode, "l1", null); |
| 75 | ydtNode = ydtNode.getNextSibling(); |
| 76 | validateLeafContents(ydtNode, "l2", null); |
| 77 | ydtNode = ydtNode.getNextSibling(); |
| 78 | validateLeafContents(ydtNode, "l3", null); |
| 79 | ydtNode = ydtNode.getNextSibling(); |
| 80 | |
| 81 | validateLeafListContents(ydtNode, "list1", valueSet); |
| 82 | ydtNode = ydtNode.getNextSibling(); |
| 83 | validateLeafListContents(ydtNode, "list2", valueSet); |
| 84 | ydtNode = ydtNode.getNextSibling(); |
| 85 | validateLeafListContents(ydtNode, "list3", valueSet); |
| 86 | } |
| 87 | } |