Vidyashree Rama | f463dc5 | 2016-10-06 12:46:33 +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.yob; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.BinarytestOpParam; |
| 21 | import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.binarytest.cont1.AugmentedCont1; |
| 22 | import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.binarytest.food.snack.Sportsarena; |
| 23 | import org.onosproject.yms.app.ydt.YangRequestWorkBench; |
| 24 | import org.onosproject.yms.app.ydt.YdtExtendedContext; |
| 25 | import org.onosproject.yms.ydt.YdtContext; |
| 26 | |
| 27 | import java.io.IOException; |
| 28 | |
| 29 | import static org.hamcrest.CoreMatchers.is; |
| 30 | import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | import static org.hamcrest.core.IsNull.notNullValue; |
| 32 | import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE; |
| 33 | |
| 34 | /** |
| 35 | * Test the YANG object building for the YANG data tree based on the binary. |
| 36 | */ |
| 37 | public class YobBinaryTest { |
| 38 | |
| 39 | private YobTestUtils utils = YobTestUtils.instance(); |
| 40 | |
| 41 | @Test |
| 42 | public void testBinaryInLeaf() throws IOException { |
| 43 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 44 | ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true); |
| 45 | ydtBuilder.addChild("binarytest", "ydt.binarytest"); |
| 46 | ydtBuilder.addChild("binaryList", null); |
| 47 | ydtBuilder.addLeaf("binary", null, "YmluYXJ5"); |
| 48 | ydtBuilder.traverseToParent(); |
| 49 | ydtBuilder.traverseToParent(); |
| 50 | ydtBuilder.traverseToParent(); |
| 51 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 52 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 53 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 54 | Object yangObject = builder.getYangObject( |
| 55 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 56 | assertThat(yangObject, notNullValue()); |
| 57 | BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject); |
| 58 | |
| 59 | byte[] binaryValue = binarytestOpParam.binaryList().get(0).binary(); |
| 60 | String value = new String(binaryValue); |
| 61 | assertThat(value, is("binary")); |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | public void testBinaryInTypedef() throws IOException { |
| 66 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 67 | ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true); |
| 68 | ydtBuilder.addChild("binarytest", "ydt.binarytest"); |
| 69 | ydtBuilder.addLeaf("name", null, "YmluYXJ5"); |
| 70 | ydtBuilder.traverseToParent(); |
| 71 | ydtBuilder.traverseToParent(); |
| 72 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 73 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 74 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 75 | Object yangObject = builder.getYangObject( |
| 76 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 77 | assertThat(yangObject, notNullValue()); |
| 78 | BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject); |
| 79 | |
| 80 | byte[] binaryValue = binarytestOpParam.name().binary(); |
| 81 | String value = new String(binaryValue); |
| 82 | assertThat(value, is("binary")); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void testBinaryInGrouping() throws IOException { |
| 87 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 88 | ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true); |
| 89 | ydtBuilder.addChild("binarytest", "ydt.binarytest"); |
| 90 | ydtBuilder.addChild("cont1", "ydt.binarytest"); |
| 91 | ydtBuilder.addLeaf("surname", null, "YmluYXJ5"); |
| 92 | ydtBuilder.traverseToParent(); |
| 93 | ydtBuilder.traverseToParent(); |
| 94 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 95 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 96 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 97 | Object yangObject = builder.getYangObject( |
| 98 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 99 | assertThat(yangObject, notNullValue()); |
| 100 | BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject); |
| 101 | |
| 102 | byte[] binaryValue = binarytestOpParam.cont1().surname(); |
| 103 | String value = new String(binaryValue); |
| 104 | assertThat(value, is("binary")); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void testBinaryInAugment() throws IOException { |
| 109 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 110 | ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true); |
| 111 | ydtBuilder.addChild("binarytest", "ydt.binarytest"); |
| 112 | ydtBuilder.addChild("cont1", "ydt.binarytest"); |
| 113 | ydtBuilder.addLeaf("lastname", null, "YmluYXJ5"); |
| 114 | ydtBuilder.traverseToParent(); |
| 115 | ydtBuilder.traverseToParent(); |
| 116 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 117 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 118 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 119 | Object yangObject = builder.getYangObject( |
| 120 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 121 | assertThat(yangObject, notNullValue()); |
| 122 | BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject); |
| 123 | |
| 124 | AugmentedCont1 augmentedCont1 = (AugmentedCont1) binarytestOpParam.cont1() |
| 125 | .yangAugmentedInfo(AugmentedCont1.class); |
| 126 | byte[] binaryValue = augmentedCont1.lastname(); |
| 127 | String value = new String(binaryValue); |
| 128 | assertThat(value, is("binary")); |
| 129 | } |
| 130 | |
| 131 | @Test |
| 132 | public void testBinaryInCase() throws IOException { |
| 133 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 134 | ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true); |
| 135 | ydtBuilder.addChild("binarytest", "ydt.binarytest"); |
| 136 | ydtBuilder.addChild("food", "ydt.binarytest"); |
| 137 | ydtBuilder.addLeaf("pretzel", null, "YmluYXJ5"); |
| 138 | ydtBuilder.traverseToParent(); |
| 139 | ydtBuilder.traverseToParent(); |
| 140 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 141 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 142 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 143 | Object yangObject = builder.getYangObject( |
| 144 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 145 | assertThat(yangObject, notNullValue()); |
| 146 | BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject); |
| 147 | Sportsarena sportsArena = ((Sportsarena) binarytestOpParam.food() |
| 148 | .snack()); |
| 149 | byte[] binaryValue = sportsArena.pretzel(); |
| 150 | String value = new String(binaryValue); |
| 151 | assertThat(value, is("binary")); |
| 152 | } |
| 153 | |
| 154 | @Test |
| 155 | public void testBinaryInUnion() throws IOException { |
| 156 | YangRequestWorkBench ydtBuilder = new YangRequestWorkBench( |
| 157 | ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true); |
| 158 | ydtBuilder.addChild("binarytest", "ydt.binarytest"); |
| 159 | ydtBuilder.addLeaf("middlename", null, "YmluYXJ5"); |
| 160 | ydtBuilder.traverseToParent(); |
| 161 | ydtBuilder.traverseToParent(); |
| 162 | YdtContext rootCtx = ydtBuilder.getRootNode(); |
| 163 | YdtContext childCtx = rootCtx.getFirstChild(); |
| 164 | DefaultYobBuilder builder = new DefaultYobBuilder(); |
| 165 | Object yangObject = builder.getYangObject( |
| 166 | (YdtExtendedContext) childCtx, utils.schemaRegistry()); |
| 167 | assertThat(yangObject, notNullValue()); |
| 168 | BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject); |
| 169 | |
| 170 | byte[] binaryValue = binarytestOpParam.middlename().binary(); |
| 171 | String value = new String(binaryValue); |
| 172 | assertThat(value, is("binary")); |
| 173 | } |
| 174 | } |