sonu gupta | 1bb37b8 | 2016-11-11 16:51:18 +0530 | [diff] [blame^] | 1 | /* |
| 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. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yms.app.ydt; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.List; |
| 23 | |
| 24 | import static org.onosproject.yms.app.ydt.YdtTestUtils.helloOnos; |
| 25 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateLeafContents; |
| 26 | import static org.onosproject.yms.app.ydt.YdtTestUtils.validateNodeContents; |
| 27 | import static org.onosproject.yms.app.ydt.YdtTestUtils.walkINTree; |
| 28 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 29 | |
| 30 | public class RpcTest { |
| 31 | |
| 32 | // Logger list is used for walker testing. |
| 33 | private final List<String> logger = new ArrayList<>(); |
| 34 | |
| 35 | private static final String[] EXPECTED = { |
| 36 | "Entry Node is Hello-ONOS.", |
| 37 | "Entry Node is Hello_ONOS.", |
| 38 | "Entry Node is hello-world.", |
| 39 | "Entry Node is input.", |
| 40 | "Entry Node is name.", |
| 41 | "Exit Node is name.", |
| 42 | "Entry Node is surName.", |
| 43 | "Exit Node is surName.", |
| 44 | "Entry Node is stringList.", |
| 45 | "Entry Node is string1.", |
| 46 | "Exit Node is string1.", |
| 47 | "Entry Node is string2.", |
| 48 | "Exit Node is string2.", |
| 49 | "Exit Node is stringList.", |
| 50 | "Exit Node is input.", |
| 51 | "Exit Node is hello-world.", |
| 52 | "Exit Node is Hello_ONOS.", |
| 53 | "Exit Node is Hello-ONOS." |
| 54 | }; |
| 55 | |
| 56 | /** |
| 57 | * Creates and validates hello onos ydt. |
| 58 | */ |
| 59 | @Test |
| 60 | public void rpc1Test() { |
| 61 | YangRequestWorkBench ydtBuilder = helloOnos(); |
| 62 | validateTree(ydtBuilder); |
| 63 | // walker test |
| 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, "Hello-ONOS", null); |
| 76 | ydtNode = ydtNode.getFirstChild(); |
| 77 | validateNodeContents(ydtNode, "Hello_ONOS", MERGE); |
| 78 | ydtNode = ydtNode.getFirstChild(); |
| 79 | validateNodeContents(ydtNode, "hello-world", MERGE); |
| 80 | ydtNode = ydtNode.getFirstChild(); |
| 81 | validateNodeContents(ydtNode, "input", MERGE); |
| 82 | ydtNode = ydtNode.getFirstChild(); |
| 83 | validateLeafContents(ydtNode, "name", "onos"); |
| 84 | ydtNode = ydtNode.getNextSibling(); |
| 85 | validateLeafContents(ydtNode, "surName", "yang"); |
| 86 | ydtNode = ydtNode.getNextSibling(); |
| 87 | validateNodeContents(ydtNode, "stringList", MERGE); |
| 88 | ydtNode = ydtNode.getFirstChild(); |
| 89 | validateLeafContents(ydtNode, "string1", "ON"); |
| 90 | ydtNode = ydtNode.getNextSibling(); |
| 91 | validateLeafContents(ydtNode, "string2", "LAB"); |
| 92 | } |
| 93 | } |