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 static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.OTHER_EDIT; |
| 14 | import static org.onosproject.yms.app.ydt.YdtTestConstants.AUGNS; |
| 15 | import static org.onosproject.yms.app.ydt.YdtTestConstants.AUGSE; |
| 16 | import static org.onosproject.yms.app.ydt.YdtTestUtils.augmentSequenceYdt; |
| 17 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppLogicalNodeContents; |
| 18 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppModuleNodeContents; |
| 19 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateAppNodeContents; |
| 20 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents; |
| 21 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents; |
| 22 | import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree; |
| 23 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 24 | |
| 25 | public class AugmentSequenceTest { |
| 26 | |
| 27 | private static final String[] EXPECTED = { |
| 28 | "Entry Node is augment.", |
| 29 | "Entry Node is augmentSequence.", |
| 30 | "Entry Node is l1.", |
| 31 | "Entry Node is leaf1.", |
| 32 | "Exit Node is leaf1.", |
| 33 | |
| 34 | "Entry Node is c1.", |
| 35 | "Entry Node is leaf2.", |
| 36 | "Exit Node is leaf2.", |
| 37 | "Exit Node is c1.", |
| 38 | |
| 39 | "Entry Node is c2.", |
| 40 | "Entry Node is leaf2.", |
| 41 | "Exit Node is leaf2.", |
| 42 | "Exit Node is c2.", |
| 43 | |
| 44 | "Exit Node is l1.", |
| 45 | "Exit Node is augmentSequence.", |
| 46 | "Exit Node is augment.", |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * Creates and validates sequence of augment in ydt. |
| 51 | */ |
| 52 | @Test |
| 53 | public void augmentTest() { |
| 54 | YangRequestWorkBench ydtBuilder = augmentSequenceYdt(); |
| 55 | validateTree(ydtBuilder); |
| 56 | validateAppTree(ydtBuilder); |
| 57 | walkINTree(ydtBuilder, EXPECTED); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Validates the given built ydt. |
| 62 | */ |
| 63 | private void validateTree(YangRequestWorkBench ydtBuilder) { |
| 64 | |
| 65 | // Assign root node to ydtNode for validating purpose. |
| 66 | YdtNode ydtNode = (YdtNode) ydtBuilder.getRootNode(); |
| 67 | // Logical root node does not have operation type |
| 68 | validateNodeContents(ydtNode, "augment", null); |
| 69 | ydtNode = ydtNode.getFirstChild(); |
| 70 | validateNodeContents(ydtNode, "augmentSequence", MERGE); |
| 71 | ydtNode = ydtNode.getFirstChild(); |
| 72 | validateNodeContents(ydtNode, "l1", MERGE); |
| 73 | ydtNode = ydtNode.getFirstChild(); |
| 74 | |
| 75 | validateLeafContents(ydtNode, "leaf1", "1"); |
| 76 | ydtNode = ydtNode.getNextSibling(); |
| 77 | |
| 78 | //Augmenting leaf2 |
| 79 | validateNodeContents(ydtNode, "c1", MERGE); |
| 80 | ydtNode = ydtNode.getFirstChild(); |
| 81 | validateLeafContents(ydtNode, "leaf2", "2"); |
| 82 | ydtNode = ydtNode.getParent(); |
| 83 | ydtNode = ydtNode.getNextSibling(); |
| 84 | |
| 85 | //Augmenting leaf3 |
| 86 | validateNodeContents(ydtNode, "c2", MERGE); |
| 87 | ydtNode = ydtNode.getFirstChild(); |
| 88 | validateLeafContents(ydtNode, "leaf2", "3"); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Validates the given built ydt application tree. |
| 93 | */ |
| 94 | private void validateAppTree(YangRequestWorkBench ydtBuilder) { |
| 95 | |
| 96 | // Assign root node to ydtNode for validating purpose. |
| 97 | YdtAppContext ydtAppContext = ydtBuilder.getAppRootNode(); |
| 98 | // Logical root node does not have operation type |
| 99 | validateAppLogicalNodeContents(ydtAppContext); |
| 100 | ydtAppContext = ydtAppContext.getFirstChild(); |
| 101 | validateAppModuleNodeContents(ydtAppContext, "augmentSequence", |
| 102 | OTHER_EDIT); |
| 103 | ydtAppContext = ydtAppContext.getFirstChild(); |
| 104 | |
| 105 | //Inside list checking the first augmented leaf |
| 106 | validateAppNodeContents(ydtAppContext, AUGSE, AUGNS, OTHER_EDIT); |
| 107 | } |
| 108 | } |