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