janani b | 9069eb4 | 2016-11-24 17:50:08 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
janani b | 9069eb4 | 2016-11-24 17:50:08 +0530 | [diff] [blame] | 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.ytb; |
| 18 | |
| 19 | import org.junit.Rule; |
| 20 | import org.junit.Test; |
| 21 | import org.junit.rules.ExpectedException; |
| 22 | import org.onosproject.yang.gen.v1.yms.test.ytb.derived.type.with.bits.and.binary.rev20160826.YtbDerivedTypeWithBitsAndBinary; |
| 23 | import org.onosproject.yang.gen.v1.yms.test.ytb.derived.type.with.bits.and.binary.rev20160826.YtbDerivedTypeWithBitsAndBinaryOpParam; |
| 24 | import org.onosproject.yang.gen.v1.yms.test.ytb.derived.type.with.bits.and.binary.rev20160826.ytbderivedtypewithbitsandbinary.Derivedbinarya; |
| 25 | import org.onosproject.yang.gen.v1.yms.test.ytb.derived.type.with.bits.and.binary.rev20160826.ytbderivedtypewithbitsandbinary.Derivedbinaryb; |
| 26 | import org.onosproject.yang.gen.v1.yms.test.ytb.derived.type.with.bits.and.binary.rev20160826.ytbderivedtypewithbitsandbinary.Derivedbitsa; |
| 27 | import org.onosproject.yang.gen.v1.yms.test.ytb.derived.type.with.bits.and.binary.rev20160826.ytbderivedtypewithbitsandbinary.Derivedbitsb; |
| 28 | import org.onosproject.yang.gen.v1.yms.test.ytb.derived.type.with.bits.and.binary.rev20160826.ytbderivedtypewithbitsandbinary.ForunionUnion; |
| 29 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.container.rev20160826.YtbModuleWithContainer; |
| 30 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.container.rev20160826.YtbModuleWithContainerOpParam; |
| 31 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.container.rev20160826.ytbmodulewithcontainer.DefaultSched; |
| 32 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.container.rev20160826.ytbmodulewithcontainer.Sched; |
| 33 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaf.ietfschedule.rev20160826.YtbIetfSchedule; |
| 34 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaf.ietfschedule.rev20160826.YtbIetfSchedule.OnosYangOpType; |
| 35 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaf.ietfschedule.rev20160826.YtbIetfScheduleOpParam; |
| 36 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaf.ietfschedule.rev20160826.ytbietfschedule.Enum1Enum; |
| 37 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaf.ietfschedule.rev20160826.ytbietfschedule.Enum2Enum; |
| 38 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaflist.rev20160826.YtbModuleWithLeafList; |
| 39 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.leaflist.rev20160826.YtbModuleWithLeafListOpParam; |
| 40 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.yangautoprefixlist.rev20160826.YtbModuleWithList; |
| 41 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.yangautoprefixlist.rev20160826.YtbModuleWithListOpParam; |
| 42 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.yangautoprefixlist.rev20160826.ytbmodulewithlist.DefaultYtblistlist; |
| 43 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.yangautoprefixlist.rev20160826.ytbmodulewithlist.Find; |
| 44 | import org.onosproject.yang.gen.v1.yms.test.ytb.module.with.yangautoprefixlist.rev20160826.ytbmodulewithlist.Ytblistlist; |
| 45 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.module.a.rev20160826.YtbMultiModulea; |
| 46 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.module.a.rev20160826.YtbMultiModuleaOpParam; |
| 47 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.module.a.rev20160826.ytbmultimodulea.DefaultYtbmultilist; |
| 48 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.module.a.rev20160826.ytbmultimodulea.Ytbmultilist; |
| 49 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.module.b.rev20160826.YtbMultiModuleb; |
| 50 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.module.b.rev20160826.YtbMultiModulebOpParam; |
| 51 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.module.b.rev20160826.ytbmultimoduleb.DefaultYtbmultilistb; |
| 52 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.module.b.rev20160826.ytbmultimoduleb.Ytbmultilistb; |
| 53 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.notification.with.container.rev20160826.ytbmultinotificationwithcontainer.DefaultFortesta; |
| 54 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.notification.with.container.rev20160826.ytbmultinotificationwithcontainer.Fortesta; |
| 55 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.notification.with.container.rev20160826.ytbmultinotificationwithcontainer.YtbMultiNotificationWithContainerEvent; |
| 56 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.notification.with.container.rev20160826.ytbmultinotificationwithcontainer.YtbMultiNotificationWithContainerEventSubject; |
| 57 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.notification.with.container.rev20160826.ytbmultinotificationwithcontainer.fortesta.DefaultYtbnot; |
| 58 | import org.onosproject.yang.gen.v1.yms.test.ytb.multi.notification.with.container.rev20160826.ytbmultinotificationwithcontainer.fortesta.Ytbnot; |
| 59 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.YtbTreeBuilderForListHavingList; |
| 60 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.YtbTreeBuilderForListHavingListOpParam; |
| 61 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.ytbtreebuilderforlisthavinglist.Carrier; |
| 62 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.ytbtreebuilderforlisthavinglist.DefaultCarrier; |
| 63 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.DefaultMultiplexes; |
| 64 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.Multiplexes; |
| 65 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.multiplexes.ApplicationAreas; |
| 66 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.multiplexes.DefaultApplicationAreas; |
| 67 | import org.onosproject.yang.gen.v1.yms.test.ytb.tree.builder.yangautoprefixfor.yangautoprefixlist.having.yangautoprefixlist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.multiplexes.TypesEnum; |
| 68 | import org.onosproject.yms.app.ydt.YdtExtendedBuilder; |
| 69 | import org.onosproject.yms.app.ydt.YdtNode; |
| 70 | import org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry; |
| 71 | import org.onosproject.yms.ydt.YdtBuilder; |
| 72 | import org.onosproject.yms.ydt.YdtContext; |
| 73 | import org.onosproject.yms.ydt.YdtContextOperationType; |
| 74 | |
| 75 | import java.math.BigDecimal; |
| 76 | import java.math.BigInteger; |
| 77 | import java.util.ArrayList; |
| 78 | import java.util.BitSet; |
| 79 | import java.util.List; |
| 80 | import java.util.Set; |
| 81 | |
| 82 | import static org.hamcrest.MatcherAssert.assertThat; |
| 83 | import static org.hamcrest.core.Is.is; |
| 84 | import static org.hamcrest.core.IsNull.nullValue; |
| 85 | import static org.onosproject.yms.ydt.YdtContextOperationType.CREATE; |
| 86 | import static org.onosproject.yms.ydt.YdtContextOperationType.DELETE; |
| 87 | import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE; |
| 88 | import static org.onosproject.yms.ydt.YdtContextOperationType.NONE; |
| 89 | import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REQUEST; |
| 90 | import static org.onosproject.yms.ydt.YmsOperationType.QUERY_CONFIG_REQUEST; |
| 91 | import static org.onosproject.yms.ydt.YmsOperationType.QUERY_REQUEST; |
| 92 | |
| 93 | /** |
| 94 | * Unit test cases for YANG tree builder with different YANG object |
| 95 | * configuration. |
| 96 | */ |
| 97 | public class DefaultYangTreeBuilderTest extends YtbErrMsgAndConstants { |
| 98 | |
| 99 | private static final String ONE = "1"; |
| 100 | private static final String TWO = "2"; |
| 101 | private static final String THREE = "3"; |
| 102 | private static final String FOUR = "4"; |
| 103 | private static final String FIVE = "5"; |
| 104 | private static final String SIX = "6"; |
| 105 | private static final String NINE = "9"; |
| 106 | private static final String IETF_SCHEDULE = "YtbIetfSchedule"; |
| 107 | private static final String TIME = "time"; |
| 108 | private static final String MOD_LEAF_LIST = "YtbModuleWithLeafList"; |
| 109 | private static final String ENUM_1 = "enum1"; |
| 110 | private static final String ENUM_2 = "enum2"; |
| 111 | private static final String HUNDRED_100 = "hundred-100"; |
| 112 | private static final String TEN_10 = "ten-10"; |
| 113 | private static final String THOUSAND_1000 = "thousand-1000"; |
| 114 | private static final String MOD_CONT = "YtbModuleWithContainer"; |
| 115 | private static final String SCHED = "sched"; |
| 116 | private static final String PREDICT_VAL = "98989"; |
| 117 | private static final String MOD_LIST = "YtbModuleWithList"; |
| 118 | private static final String LIST_LIST = "ytblistlist"; |
| 119 | private static final String PREDICTION = "prediction"; |
| 120 | private static final String TRUE = "true"; |
| 121 | private static final String FALSE = "false"; |
| 122 | private static final String MUL_NOTIFY = |
| 123 | "YtbMultiNotificationWithContainer"; |
| 124 | private static final String NOTIFICATION = "notification"; |
| 125 | private static final String NOTIFY = "fortesta"; |
| 126 | private static final String YTB_NOTIFY_CONT = "ytbnot"; |
| 127 | private static final String NOTIFY_LEAF = "notileaf"; |
| 128 | private static final String ANT = "ant"; |
| 129 | private static final String ANIMAL = "animal"; |
| 130 | private static final String BIRD = "bird"; |
| 131 | private static final String BALL = "ball"; |
| 132 | private static final String BAT = "bat"; |
| 133 | private static final String MUL_MOD_A = "YtbMultiModulea"; |
| 134 | private static final String MUL_LIST_A = "ytbmultilist"; |
| 135 | private static final String CHECK = "check"; |
| 136 | private static final String MUL_MOD_B = "YtbMultiModuleb"; |
| 137 | private static final String MUL_LIST_B = "ytbmultilistb"; |
| 138 | private static final String CHECKIN = "checkin"; |
| 139 | private static final String LIST_WITH_LIST = |
| 140 | "YtbTreeBuilderForListHavingList"; |
| 141 | private static final String CONT_CARRIER = "carrier"; |
| 142 | private static final String LIST_MULTIPLEXES = "multiplexes"; |
| 143 | private static final String TYPES = "types"; |
| 144 | private static final String TIME_DIVISION = "time-division"; |
| 145 | private static final String APP_AREA_LIST = "application-areas"; |
| 146 | private static final String DEST_AREA = "destination-areas"; |
| 147 | private static final String FREQUENCY_DIV = "frequency-division"; |
| 148 | private static final String MOD_BIT_BIN = "YtbDerivedTypeWithBitsAndBinary"; |
| 149 | private static final String FOR_BINARY = "forbinary"; |
| 150 | private static final String BIN_VAL_1 = "BQUF"; |
| 151 | private static final String FOR_BITS = "forbits"; |
| 152 | private static final String FOR_BINARY_LIST = "forbinarylist"; |
| 153 | private static final String BIN_VAL_2 = "CQkA"; |
| 154 | private static final String BIN_VAL_3 = "DAYA"; |
| 155 | private static final String BIN_VAL_4 = "EB0Z"; |
| 156 | private static final String FOR_BITS_LIST = "forbitslist"; |
| 157 | private static final String FOR_UNION = "forunion"; |
| 158 | private static final String BIN_VAL_5 = "AAAA"; |
| 159 | private static final String BIT_VAL_1 = "leaf1 leaf2"; |
| 160 | private static final String BIN_VAL_6 = "AQYD"; |
| 161 | private static final String BIN_VAL_7 = "AgcE"; |
| 162 | private static final String BIN_VAL_8 = "BQYB"; |
| 163 | private static final String BIN_VAL_9 = "AwgE"; |
| 164 | private static final String BIN_VAL_10 = "AQAA"; |
| 165 | private static final String BIN_VAL_11 = "AAAB"; |
| 166 | private static final String BIN_VAL_12 = "BwcH"; |
| 167 | private static final String BIN_VAL_13 = "AAE="; |
| 168 | private static final String BIT_VAL_2 = "index signature"; |
| 169 | private static final String BIT_VAL_3 = "index"; |
| 170 | private static final String BIT_VAL_4 = "index name"; |
| 171 | private static final String BIT_VAL_5 = "index name signature"; |
| 172 | |
| 173 | @Rule |
| 174 | public ExpectedException thrown = ExpectedException.none(); |
| 175 | |
| 176 | private static String emptyObjErrMsg(String objName) { |
| 177 | return "The " + objName + " given for tree creation cannot be null"; |
| 178 | } |
| 179 | |
| 180 | private static BigDecimal getBigDeci(int bigDecimal) { |
| 181 | return BigDecimal.valueOf(bigDecimal); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Processes an empty object list to the YTB and checks that the |
| 186 | * exception is thrown. |
| 187 | */ |
| 188 | @Test |
| 189 | public void processInvalidListInput() { |
| 190 | thrown.expect(YtbException.class); |
| 191 | thrown.expectMessage(emptyObjErrMsg("object list")); |
| 192 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 193 | treeBuilder.getYdtBuilderForYo(null, ROOT_NAME, ROOT_NAME_SPACE, |
| 194 | EDIT_CONFIG_REQUEST, null); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Processes an empty notification object to the YTB and checks that the |
| 199 | * exception is thrown. |
| 200 | */ |
| 201 | @Test |
| 202 | public void processInvalidInputForNotification() { |
| 203 | thrown.expect(YtbException.class); |
| 204 | thrown.expectMessage(emptyObjErrMsg("event object")); |
| 205 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 206 | treeBuilder.getYdtForNotification(null, ROOT_NAME, null); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Processes an empty rpc output object to the YTB and checks that the |
| 211 | * exception is thrown. |
| 212 | */ |
| 213 | @Test |
| 214 | public void processInvalidInputForRpc() { |
| 215 | thrown.expect(YtbException.class); |
| 216 | thrown.expectMessage(emptyObjErrMsg("output object")); |
| 217 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 218 | treeBuilder.getYdtForRpcResponse(null, null); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Processes a YAB/YSB request to YTB with a leaf value being filled in |
| 223 | * the app object. Checks the constructed YDT tree for module and leaf |
| 224 | * and its value. |
| 225 | */ |
| 226 | @Test |
| 227 | public void processModuleAndLeaf() { |
| 228 | |
| 229 | schemaProvider.processSchemaRegistry(null); |
| 230 | DefaultYangSchemaRegistry registry = schemaProvider |
| 231 | .getDefaultYangSchemaRegistry(); |
| 232 | |
| 233 | // As an application, creates the object. |
| 234 | YtbIetfSchedule schedule = new YtbIetfScheduleOpParam |
| 235 | .YtbIetfScheduleBuilder() |
| 236 | .time((byte) 9) |
| 237 | .yangYtbIetfScheduleOpType(OnosYangOpType.MERGE) |
| 238 | .build(); |
| 239 | |
| 240 | // As YSB or YAB protocol sets the value for YTB. |
| 241 | List<Object> objectList = new ArrayList<>(); |
| 242 | objectList.add(schedule); |
| 243 | |
| 244 | // Builds YANG tree in YTB. |
| 245 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 246 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 247 | objectList, ROOT_NAME, ROOT_NAME_SPACE, |
| 248 | EDIT_CONFIG_REQUEST, registry); |
| 249 | |
| 250 | // Receives YDT context and checks the tree that is built. |
| 251 | YdtContext context = ydtBuilder.getRootNode(); |
| 252 | |
| 253 | // Gets the first module from logical root node. |
| 254 | YdtContext module = context.getFirstChild(); |
| 255 | YdtContextOperationType opType = ((YdtNode) module) |
| 256 | .getYdtContextOperationType(); |
| 257 | assertThat(getInCrtName(MODULE, IETF_SCHEDULE), |
| 258 | module.getName(), is(IETF_SCHEDULE)); |
| 259 | assertThat(getInCrtOpType(MODULE, IETF_SCHEDULE), |
| 260 | opType, is(MERGE)); |
| 261 | |
| 262 | // Gets the first leaf from module IetfSchedule. |
| 263 | YdtContext leafContext = module.getFirstChild(); |
| 264 | assertThat(getInCrtName(LEAF, TIME), |
| 265 | leafContext.getName(), is(TIME)); |
| 266 | assertThat(getInCrtLeafValue(TIME, NINE), |
| 267 | leafContext.getValue(), is(NINE)); |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Processes a YAB/YSB request to YTB with a leaf-list value being filled |
| 272 | * in the app object. Checks the constructed YDT tree for module and |
| 273 | * leaf-list and its value. |
| 274 | */ |
| 275 | @Test |
| 276 | public void processModuleAndLeafList() { |
| 277 | |
| 278 | schemaProvider.processSchemaRegistry(null); |
| 279 | DefaultYangSchemaRegistry registry = schemaProvider |
| 280 | .getDefaultYangSchemaRegistry(); |
| 281 | |
| 282 | // As an application, creates the object. |
| 283 | |
| 284 | // Creates list of type long for setting the leaf-list. |
| 285 | List<Long> longList = new ArrayList<>(); |
| 286 | longList.add((long) 1); |
| 287 | longList.add((long) 2); |
| 288 | longList.add((long) 3); |
| 289 | |
| 290 | YtbModuleWithLeafList leafListModule = new YtbModuleWithLeafListOpParam |
| 291 | .YtbModuleWithLeafListBuilder().time(longList).build(); |
| 292 | |
| 293 | // As YSB or YAB protocol sets the value for YTB. |
| 294 | List<Object> objectList = new ArrayList<>(); |
| 295 | objectList.add(leafListModule); |
| 296 | |
| 297 | // Builds YANG tree in YTB. |
| 298 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 299 | YdtBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 300 | objectList, ROOT_NAME, ROOT_NAME_SPACE, QUERY_REQUEST, registry); |
| 301 | |
| 302 | // Receives YDT context and check the tree that is built. |
| 303 | YdtContext context = ydtBuilder.getRootNode(); |
| 304 | |
| 305 | // Gets the first module from logical root node. |
| 306 | YdtContext module = context.getFirstChild(); |
| 307 | YdtContextOperationType opType = ((YdtNode) module) |
| 308 | .getYdtContextOperationType(); |
| 309 | assertThat(getInCrtName(MODULE, MOD_LEAF_LIST), |
| 310 | module.getName(), is(MOD_LEAF_LIST)); |
| 311 | assertThat(getInCrtOpType(MODULE, MOD_LEAF_LIST), opType, nullValue()); |
| 312 | |
| 313 | // Gets the first leaf-list from module. |
| 314 | YdtContext leafList = module.getFirstChild(); |
| 315 | assertThat(getInCrtName(LEAF_LIST, TIME), leafList.getName(), |
| 316 | is(TIME)); |
| 317 | Set<String> value = leafList.getValueSet(); |
| 318 | assertThat(getInCrtLeafListValue(TIME, ONE), |
| 319 | value.contains(ONE), is(true)); |
| 320 | assertThat(getInCrtLeafListValue(TIME, TWO), |
| 321 | value.contains(TWO), is(true)); |
| 322 | assertThat(getInCrtLeafListValue(TIME, THREE), |
| 323 | value.contains(THREE), is(true)); |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Processes leaf and leaf-list with type enum under module. Checks the |
| 328 | * constructed YDT tree has YANG enum value. |
| 329 | */ |
| 330 | @Test |
| 331 | public void processWithTypeEnum() { |
| 332 | |
| 333 | schemaProvider.processSchemaRegistry(null); |
| 334 | DefaultYangSchemaRegistry registry = schemaProvider |
| 335 | .getDefaultYangSchemaRegistry(); |
| 336 | |
| 337 | // As an application, creates the object. |
| 338 | |
| 339 | // Creates enum list for setting the leaf-list. |
| 340 | List<Enum2Enum> enumList = new ArrayList<>(); |
| 341 | enumList.add(Enum2Enum.HUNDRED_100); |
| 342 | enumList.add(Enum2Enum.TEN_10); |
| 343 | enumList.add(Enum2Enum.THOUSAND_1000); |
| 344 | |
| 345 | YtbIetfSchedule schedule = new YtbIetfScheduleOpParam |
| 346 | .YtbIetfScheduleBuilder() |
| 347 | .time((byte) 9) |
| 348 | .yangYtbIetfScheduleOpType(OnosYangOpType.MERGE) |
| 349 | .enum1(Enum1Enum.HUNDRED) |
| 350 | .enum2(enumList) |
| 351 | .build(); |
| 352 | |
| 353 | |
| 354 | // As YSB or YAB protocol sets the value for YTB. |
| 355 | List<Object> objectList = new ArrayList<>(); |
| 356 | objectList.add(schedule); |
| 357 | |
| 358 | // Builds YANG tree in YTB. |
| 359 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 360 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 361 | objectList, ROOT_NAME, ROOT_NAME_SPACE, |
| 362 | EDIT_CONFIG_REQUEST, registry); |
| 363 | |
| 364 | // Receives YDT context and check the tree that is built. |
| 365 | YdtContext context = ydtBuilder.getRootNode(); |
| 366 | |
| 367 | // Gets the first module from logical root node. |
| 368 | YdtContext module = context.getFirstChild(); |
| 369 | YdtContextOperationType opType = |
| 370 | ((YdtNode) module).getYdtContextOperationType(); |
| 371 | assertThat(getInCrtName(MODULE, IETF_SCHEDULE), |
| 372 | module.getName(), is(IETF_SCHEDULE)); |
| 373 | assertThat(getInCrtOpType(MODULE, IETF_SCHEDULE), opType, is(MERGE)); |
| 374 | |
| 375 | // Checks the leaf and leaf-list values. |
| 376 | YdtContext timeLeaf = module.getFirstChild(); |
| 377 | assertThat(getInCrtName(LEAF, TIME), timeLeaf.getName(), is(TIME)); |
| 378 | assertThat(getInCrtLeafValue(TIME, NINE), |
| 379 | timeLeaf.getValue(), is(NINE)); |
| 380 | |
| 381 | YdtContext enum1Leaf = timeLeaf.getNextSibling(); |
| 382 | assertThat(getInCrtName(LEAF, ENUM_1), enum1Leaf.getName(), is(ENUM_1)); |
| 383 | assertThat(getInCrtLeafValue(ENUM_1, HUNDRED), |
| 384 | enum1Leaf.getValue(), is(HUNDRED)); |
| 385 | |
| 386 | YdtContext enum2LeafList = enum1Leaf.getNextSibling(); |
| 387 | assertThat(getInCrtName(LEAF_LIST, ENUM_2), |
| 388 | enum2LeafList.getName(), is(ENUM_2)); |
| 389 | Set<String> valueSet = enum2LeafList.getValueSet(); |
| 390 | assertThat(getInCrtLeafListValue(ENUM_2, HUNDRED_100), |
| 391 | valueSet.contains(HUNDRED_100), is(true)); |
| 392 | assertThat(getInCrtLeafListValue(ENUM_2, TEN_10), |
| 393 | valueSet.contains(TEN_10), is(true)); |
| 394 | assertThat(getInCrtLeafListValue(ENUM_2, THOUSAND_1000), |
| 395 | valueSet.contains(THOUSAND_1000), is(true)); |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Processes a YAB/YSB request to YTB with a container having leaf value |
| 400 | * being filled in the app object. Checks the constructed YDT tree for |
| 401 | * module and container and leaf. |
| 402 | */ |
| 403 | @Test |
| 404 | public void processModuleWithContainer() { |
| 405 | |
| 406 | schemaProvider.processSchemaRegistry(null); |
| 407 | DefaultYangSchemaRegistry registry = schemaProvider |
| 408 | .getDefaultYangSchemaRegistry(); |
| 409 | |
| 410 | // As an application, creates the object. |
| 411 | |
| 412 | // Creates container object with leaf of decimal type. |
| 413 | Sched sched = new DefaultSched.SchedBuilder() |
| 414 | .predict(getBigDeci(98989)) |
| 415 | .yangSchedOpType( |
| 416 | YtbModuleWithContainerOpParam.OnosYangOpType.DELETE) |
| 417 | .build(); |
| 418 | // Creates module object with the container. |
| 419 | YtbModuleWithContainer contModule = new YtbModuleWithContainerOpParam |
| 420 | .YtbModuleWithContainerBuilder() |
| 421 | .sched(sched) |
| 422 | .yangYtbModuleWithContainerOpType( |
| 423 | YtbModuleWithContainerOpParam.OnosYangOpType.CREATE) |
| 424 | .build(); |
| 425 | |
| 426 | // As YSB or YAB protocol sets the value for YTB. |
| 427 | List<Object> objectList = new ArrayList<>(); |
| 428 | objectList.add(contModule); |
| 429 | |
| 430 | // Builds YANG tree in YTB. |
| 431 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 432 | YdtBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 433 | objectList, ROOT_NAME, ROOT_NAME_SPACE, |
| 434 | QUERY_CONFIG_REQUEST, registry); |
| 435 | |
| 436 | // Receives YDT context and check the tree that is built. |
| 437 | YdtContext context = ydtBuilder.getRootNode(); |
| 438 | |
| 439 | // Gets the first module from logical root node. |
| 440 | YdtContext module = context.getFirstChild(); |
| 441 | YdtContextOperationType opType = ((YdtNode) module) |
| 442 | .getYdtContextOperationType(); |
| 443 | |
| 444 | assertThat(getInCrtName(MODULE, MOD_CONT), |
| 445 | module.getName(), is(MOD_CONT)); |
| 446 | assertThat(getInCrtOpType(MODULE, MOD_CONT), opType, is(CREATE)); |
| 447 | |
| 448 | // Get the container from module. |
| 449 | YdtContext container = module.getFirstChild(); |
| 450 | YdtContextOperationType opTypeOfCont = ((YdtNode) container) |
| 451 | .getYdtContextOperationType(); |
| 452 | |
| 453 | assertThat(getInCrtName(CONTAINER, SCHED), |
| 454 | container.getName(), is("sched")); |
| 455 | assertThat(getInCrtOpType(CONTAINER, SCHED), opTypeOfCont, is(DELETE)); |
| 456 | |
| 457 | // Gets leaf from container. |
| 458 | YdtContext leafContext = container.getFirstChild(); |
| 459 | assertThat(getInCrtName(LEAF, PREDICT), |
| 460 | leafContext.getName(), is(PREDICT)); |
| 461 | assertThat(getInCrtLeafValue(PREDICT, PREDICT_VAL), |
| 462 | leafContext.getValue(), is(PREDICT_VAL)); |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Processes a YAB/YSB request to YTB with a list having leaf-list value |
| 467 | * being filled in the app object. Checks the constructed YDT tree for |
| 468 | * module and list and leaf-list. |
| 469 | */ |
| 470 | @Test |
| 471 | public void processModuleWithList() { |
| 472 | |
| 473 | schemaProvider.processSchemaRegistry(null); |
| 474 | DefaultYangSchemaRegistry registry = schemaProvider |
| 475 | .getDefaultYangSchemaRegistry(); |
| 476 | |
| 477 | // As an application, creates the object. |
| 478 | |
| 479 | // Creates multi typedef values. |
| 480 | Find find1 = new Find(true); |
| 481 | Find find2 = new Find(false); |
| 482 | Find find3 = new Find(true); |
| 483 | Find find4 = new Find(false); |
| 484 | |
| 485 | // Creates two lists, with the typedef values added. |
| 486 | List<Find> findList1 = new ArrayList<>(); |
| 487 | List<Find> findList2 = new ArrayList<>(); |
| 488 | findList1.add(find1); |
| 489 | findList1.add(find2); |
| 490 | findList2.add(find3); |
| 491 | findList2.add(find4); |
| 492 | |
| 493 | // Creates two list contents. |
| 494 | Ytblistlist list1 = new DefaultYtblistlist |
| 495 | .YtblistlistBuilder().prediction(findList1).build(); |
| 496 | Ytblistlist list2 = new DefaultYtblistlist |
| 497 | .YtblistlistBuilder().prediction(findList2).build(); |
| 498 | |
| 499 | List<Ytblistlist> ytbList = new ArrayList<>(); |
| 500 | ytbList.add(list1); |
| 501 | ytbList.add(list2); |
| 502 | |
| 503 | // Creates module having list. |
| 504 | YtbModuleWithList listModule = new YtbModuleWithListOpParam |
| 505 | .YtbModuleWithListBuilder().ytblistlist(ytbList).build(); |
| 506 | |
| 507 | // As YSB or YAB protocol sets the value for YTB. |
| 508 | List<Object> objectList = new ArrayList<>(); |
| 509 | objectList.add(listModule); |
| 510 | |
| 511 | // Builds YANG tree in YTB. |
| 512 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 513 | YdtBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 514 | objectList, ROOT_NAME, ROOT_NAME_SPACE, |
| 515 | EDIT_CONFIG_REQUEST, registry); |
| 516 | |
| 517 | // Receives YDT context and check the tree that is built. |
| 518 | YdtContext context = ydtBuilder.getRootNode(); |
| 519 | |
| 520 | // Gets the first module from logical root node. |
| 521 | YdtContext module = context.getFirstChild(); |
| 522 | YdtContextOperationType opType = ((YdtNode) module) |
| 523 | .getYdtContextOperationType(); |
| 524 | |
| 525 | assertThat(getInCrtName(MODULE, MOD_LIST), |
| 526 | module.getName(), is(MOD_LIST)); |
| 527 | assertThat(getInCrtOpType(MODULE, MOD_LIST), opType, nullValue()); |
| 528 | |
| 529 | // Gets the first list from module YtbModuleWithList. |
| 530 | YdtContext firstList = module.getFirstChild(); |
| 531 | YdtContextOperationType listOpType = ((YdtNode) firstList) |
| 532 | .getYdtContextOperationType(); |
| 533 | // Checks the contents in the list. |
| 534 | assertThat(getInCrtName(LIST, LIST_LIST), |
| 535 | firstList.getName(), is(LIST_LIST)); |
| 536 | assertThat(getInCrtOpType(LIST, LIST_LIST), listOpType, nullValue()); |
| 537 | |
| 538 | // Gets the contents of the leaf-list in the first list content. |
| 539 | YdtContext leafListInList1 = firstList.getFirstChild(); |
| 540 | |
| 541 | // Evaluates the leaf-list values. |
| 542 | Set leafListValue1 = leafListInList1.getValueSet(); |
| 543 | assertThat(getInCrtName(LEAF_LIST, PREDICTION), |
| 544 | leafListInList1.getName(), is(PREDICTION)); |
| 545 | assertThat(getInCrtLeafListValue(PREDICTION, TRUE), |
| 546 | leafListValue1.contains(TRUE), is(true)); |
| 547 | assertThat(getInCrtLeafListValue(PREDICTION, FALSE), |
| 548 | leafListValue1.contains(FALSE), is(true)); |
| 549 | |
| 550 | // Gets the second list from module YtbModuleWithList. |
| 551 | YdtContext secondList = firstList.getNextSibling(); |
| 552 | |
| 553 | // Gets the contents of the leaf-list in the second list content. |
| 554 | YdtContext leafListInList2 = secondList.getFirstChild(); |
| 555 | // Evaluates the leaf-list values. |
| 556 | Set leafListValue2 = leafListInList2.getValueSet(); |
| 557 | assertThat(getInCrtName(LEAF_LIST, PREDICTION), |
| 558 | leafListInList2.getName(), is(PREDICTION)); |
| 559 | assertThat(getInCrtLeafListValue(PREDICTION, TRUE), |
| 560 | leafListValue2.contains(TRUE), is(true)); |
| 561 | assertThat(getInCrtLeafListValue(PREDICTION, FALSE), |
| 562 | leafListValue2.contains(FALSE), is(true)); |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * Processes multi notification under module when request comes for one |
| 567 | * notification event in module. |
| 568 | */ |
| 569 | @Test |
| 570 | public void processMultiNotificationWithContainer() { |
| 571 | |
| 572 | schemaProvider.processSchemaRegistry(null); |
| 573 | DefaultYangSchemaRegistry registry = schemaProvider |
| 574 | .getDefaultYangSchemaRegistry(); |
| 575 | |
| 576 | // As an application, creates the object. |
| 577 | |
| 578 | // Sets the bit value. |
| 579 | BitSet bitleaf = new BitSet(); |
| 580 | bitleaf.set(0); |
| 581 | bitleaf.set(1); |
| 582 | |
| 583 | // Creates container with the leaf. |
| 584 | Ytbnot ytbnot = new DefaultYtbnot.YtbnotBuilder().notileaf(bitleaf) |
| 585 | .build(); |
| 586 | // Creates notification with container. |
| 587 | Fortesta testa = new DefaultFortesta.FortestaBuilder() |
| 588 | .ytbnot(ytbnot).build(); |
| 589 | // Invokes event subject class with notification. |
| 590 | YtbMultiNotificationWithContainerEventSubject eventSubject = new |
| 591 | YtbMultiNotificationWithContainerEventSubject(); |
| 592 | eventSubject.fortesta(testa); |
| 593 | // Invokes event class with the event type and the event subject obj. |
| 594 | YtbMultiNotificationWithContainerEvent event = |
| 595 | new YtbMultiNotificationWithContainerEvent( |
| 596 | YtbMultiNotificationWithContainerEvent.Type.FORTESTA, |
| 597 | eventSubject); |
| 598 | |
| 599 | // Builds YANG tree in YTB. |
| 600 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 601 | YdtContext ydtContext = treeBuilder.getYdtForNotification( |
| 602 | event, ROOT_NAME, registry); |
| 603 | |
| 604 | // Gets the first module from logical root node. |
| 605 | YdtContext context = ydtContext.getFirstChild(); |
| 606 | YdtContextOperationType opType = ((YdtNode) context) |
| 607 | .getYdtContextOperationType(); |
| 608 | |
| 609 | assertThat(getInCrtName(MODULE, MUL_NOTIFY), context.getName(), |
| 610 | is(MUL_NOTIFY)); |
| 611 | assertThat(getInCrtOpType(MODULE, MUL_NOTIFY), opType, is(NONE)); |
| 612 | |
| 613 | // Gets the notification under module. |
| 614 | YdtContext notify = context.getFirstChild(); |
| 615 | YdtContextOperationType notifyOpType = ((YdtNode) notify) |
| 616 | .getYdtContextOperationType(); |
| 617 | |
| 618 | // Checks the contents in the first notification. |
| 619 | assertThat(getInCrtName(NOTIFICATION, NOTIFY), notify.getName(), |
| 620 | is(NOTIFY)); |
| 621 | assertThat(getInCrtOpType(NOTIFICATION, NOTIFY), notifyOpType, |
| 622 | is(NONE)); |
| 623 | |
| 624 | // Gets the container in notification |
| 625 | YdtContext container = notify.getFirstChild(); |
| 626 | assertThat(getInCrtName(CONTAINER, YTB_NOTIFY_CONT), |
| 627 | container.getName(), is(YTB_NOTIFY_CONT)); |
| 628 | |
| 629 | // Evaluates the leaf values. |
| 630 | YdtContext leafInCont = container.getFirstChild(); |
| 631 | assertThat(getInCrtName(LEAF, NOTIFY_LEAF), leafInCont.getName(), |
| 632 | is(NOTIFY_LEAF)); |
| 633 | assertThat(getInCrtLeafValue(NOTIFY_LEAF, BIT_VAL_1), |
| 634 | leafInCont.getValue(), is(BIT_VAL_1)); |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Processes multi module with list in both the modules and checks the |
| 639 | * YANG data tree building. |
| 640 | */ |
| 641 | @Test |
| 642 | public void processMultiModule() { |
| 643 | |
| 644 | schemaProvider.processSchemaRegistry(null); |
| 645 | DefaultYangSchemaRegistry registry = schemaProvider |
| 646 | .getDefaultYangSchemaRegistry(); |
| 647 | |
| 648 | // As an application, creates the object. |
| 649 | |
| 650 | // Creates list of big integer for leaf-list under list1. |
| 651 | List<BigInteger> bigIntegerList = new ArrayList<>(); |
| 652 | bigIntegerList.add(BigInteger.valueOf(1)); |
| 653 | bigIntegerList.add(BigInteger.valueOf(2)); |
| 654 | bigIntegerList.add(BigInteger.valueOf(3)); |
| 655 | // Creates list of big integer for leaf-list under list2. |
| 656 | List<BigInteger> bigIntegerList1 = new ArrayList<>(); |
| 657 | bigIntegerList1.add(BigInteger.valueOf(4)); |
| 658 | bigIntegerList1.add(BigInteger.valueOf(5)); |
| 659 | bigIntegerList1.add(BigInteger.valueOf(6)); |
| 660 | |
| 661 | // Creates two list contents. |
| 662 | Ytbmultilist listContent1 = new DefaultYtbmultilist |
| 663 | .YtbmultilistBuilder().check(bigIntegerList).build(); |
| 664 | Ytbmultilist listContent2 = new DefaultYtbmultilist |
| 665 | .YtbmultilistBuilder().check(bigIntegerList1).build(); |
| 666 | |
| 667 | List<Ytbmultilist> ytbmultilists = new ArrayList<>(); |
| 668 | ytbmultilists.add(listContent1); |
| 669 | ytbmultilists.add(listContent2); |
| 670 | |
| 671 | // Creates module-a with two list contents created. |
| 672 | YtbMultiModulea modulea = new YtbMultiModuleaOpParam |
| 673 | .YtbMultiModuleaBuilder().ytbmultilist(ytbmultilists).build(); |
| 674 | |
| 675 | // Creates list of string for leaf-list under list1. |
| 676 | List<String> stringList = new ArrayList<>(); |
| 677 | stringList.add(ANT); |
| 678 | stringList.add(ANIMAL); |
| 679 | stringList.add(BIRD); |
| 680 | |
| 681 | // Creates list of string for leaf-list under list2. |
| 682 | List<String> stringList1 = new ArrayList<>(); |
| 683 | stringList1.add(CATCH); |
| 684 | stringList1.add(BALL); |
| 685 | stringList1.add(BAT); |
| 686 | |
| 687 | // Creates two list contents. |
| 688 | Ytbmultilistb listContent3 = new DefaultYtbmultilistb |
| 689 | .YtbmultilistbBuilder().checkin(stringList).build(); |
| 690 | Ytbmultilistb listContent4 = new DefaultYtbmultilistb |
| 691 | .YtbmultilistbBuilder().checkin(stringList1).build(); |
| 692 | |
| 693 | List<Ytbmultilistb> ytbMultiListb = new ArrayList<>(); |
| 694 | ytbMultiListb.add(listContent3); |
| 695 | ytbMultiListb.add(listContent4); |
| 696 | |
| 697 | // Creates module-b with two list contents created. |
| 698 | YtbMultiModuleb moduleb = new YtbMultiModulebOpParam |
| 699 | .YtbMultiModulebBuilder().ytbmultilistb(ytbMultiListb).build(); |
| 700 | |
| 701 | // As YSB or YAB protocol sets the value for YTB. |
| 702 | List<Object> listOfModules = new ArrayList<>(); |
| 703 | listOfModules.add(modulea); |
| 704 | listOfModules.add(moduleb); |
| 705 | |
| 706 | // Builds YANG tree in YTB. |
| 707 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 708 | YdtBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 709 | listOfModules, ROOT_NAME, ROOT_NAME_SPACE, |
| 710 | EDIT_CONFIG_REQUEST, registry); |
| 711 | |
| 712 | // Receives YDT context and check the tree that is built. |
| 713 | YdtContext context = ydtBuilder.getRootNode(); |
| 714 | |
| 715 | // Checks module-a under root node. |
| 716 | YdtContext moduleA = context.getFirstChild(); |
| 717 | assertThat(getInCrtName(MODULE, MUL_MOD_A), moduleA.getName(), |
| 718 | is(MUL_MOD_A)); |
| 719 | |
| 720 | // Checks list-a in module-a and its respective leaf-list. |
| 721 | YdtContext list1InModuleA = moduleA.getFirstChild(); |
| 722 | assertThat(getInCrtName(LIST, MUL_LIST_A), list1InModuleA.getName(), |
| 723 | is(MUL_LIST_A)); |
| 724 | |
| 725 | YdtContext leafListA = list1InModuleA.getFirstChild(); |
| 726 | assertThat(getInCrtName(LEAF_LIST, CHECK), leafListA.getName(), |
| 727 | is(CHECK)); |
| 728 | |
| 729 | Set<String> valueA = leafListA.getValueSet(); |
| 730 | assertThat(getInCrtLeafListValue(CHECK, ONE), valueA.contains(ONE), |
| 731 | is(true)); |
| 732 | assertThat(getInCrtLeafListValue(CHECK, TWO), valueA.contains(TWO), |
| 733 | is(true)); |
| 734 | assertThat(getInCrtLeafListValue(CHECK, THREE), valueA.contains(THREE), |
| 735 | is(true)); |
| 736 | |
| 737 | // Checks list-b in module-a and its respective leaf-list. |
| 738 | YdtContext list2InModuleA = list1InModuleA.getNextSibling(); |
| 739 | assertThat(getInCrtName(LIST, MUL_LIST_A), list2InModuleA.getName(), |
| 740 | is(MUL_LIST_A)); |
| 741 | |
| 742 | YdtContext leafListB = list2InModuleA.getFirstChild(); |
| 743 | assertThat(getInCrtName(LEAF_LIST, CHECK), leafListB.getName(), |
| 744 | is(CHECK)); |
| 745 | |
| 746 | Set<String> valueB = leafListB.getValueSet(); |
| 747 | assertThat(getInCrtLeafListValue(CHECK, FOUR), valueB.contains(FOUR), |
| 748 | is(true)); |
| 749 | assertThat(getInCrtLeafListValue(CHECK, FIVE), valueB.contains(FIVE), |
| 750 | is(true)); |
| 751 | assertThat(getInCrtLeafListValue(CHECK, SIX), valueB.contains(SIX), |
| 752 | is(true)); |
| 753 | |
| 754 | // Checks module-b under root node. |
| 755 | YdtContext moduleB = moduleA.getNextSibling(); |
| 756 | assertThat(getInCrtName(MODULE, MUL_MOD_B), moduleB.getName(), |
| 757 | is(MUL_MOD_B)); |
| 758 | |
| 759 | // Checks list-a in module-b and its respective leaf-list. |
| 760 | YdtContext list1InModuleB = moduleB.getFirstChild(); |
| 761 | assertThat(getInCrtName(LIST, MUL_LIST_B), list1InModuleB.getName(), |
| 762 | is(MUL_LIST_B)); |
| 763 | |
| 764 | YdtContext leafListC = list1InModuleB.getFirstChild(); |
| 765 | assertThat(getInCrtName(LEAF_LIST, CHECKIN), leafListC.getName(), |
| 766 | is(CHECKIN)); |
| 767 | |
| 768 | Set<String> valueC = leafListC.getValueSet(); |
| 769 | assertThat(getInCrtLeafListValue(CHECKIN, ANT), valueC.contains(ANT), |
| 770 | is(true)); |
| 771 | assertThat(getInCrtLeafListValue(CHECKIN, ANIMAL), |
| 772 | valueC.contains(ANIMAL), is(true)); |
| 773 | assertThat(getInCrtLeafListValue(CHECKIN, BIRD), |
| 774 | valueC.contains(BIRD), is(true)); |
| 775 | |
| 776 | // Checks list-b in module-b and its respective leaf-list. |
| 777 | YdtContext list2InModuleB = list1InModuleB.getNextSibling(); |
| 778 | assertThat(getInCrtName(LIST, MUL_LIST_B), list2InModuleB.getName(), |
| 779 | is(MUL_LIST_B)); |
| 780 | |
| 781 | YdtContext leafListD = list2InModuleB.getFirstChild(); |
| 782 | assertThat(getInCrtName(LEAF_LIST, CHECKIN), leafListD.getName(), |
| 783 | is(CHECKIN)); |
| 784 | |
| 785 | Set<String> valueD = leafListD.getValueSet(); |
| 786 | assertThat(getInCrtLeafListValue(CHECKIN, CATCH), |
| 787 | valueD.contains(CATCH), is(true)); |
| 788 | assertThat(getInCrtLeafListValue(CHECKIN, BALL), |
| 789 | valueD.contains(BALL), is(true)); |
| 790 | assertThat(getInCrtLeafListValue(CHECKIN, BAT), |
| 791 | valueD.contains(BAT), is(true)); |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * Processes tree building when a list node is having list inside it. |
| 796 | */ |
| 797 | @Test |
| 798 | public void processTreeBuilderForListHavingList() { |
| 799 | |
| 800 | schemaProvider.processSchemaRegistry(null); |
| 801 | DefaultYangSchemaRegistry registry = schemaProvider |
| 802 | .getDefaultYangSchemaRegistry(); |
| 803 | |
| 804 | // As an application, creates the object. |
| 805 | |
| 806 | // Creates two binary leaf-lists for two list app areas. |
| 807 | List<byte[]> destArea1 = new ArrayList<>(); |
| 808 | byte[] arr = new byte[]{1, 6, 3}; |
| 809 | byte[] arr1 = new byte[]{2, 7, 4}; |
| 810 | destArea1.add(arr); |
| 811 | destArea1.add(arr1); |
| 812 | |
| 813 | List<byte[]> destArea2 = new ArrayList<>(); |
| 814 | byte[] arr2 = new byte[]{3, 8, 4}; |
| 815 | byte[] arr3 = new byte[]{5, 6, 1}; |
| 816 | destArea2.add(arr2); |
| 817 | destArea2.add(arr3); |
| 818 | |
| 819 | // Creates two app areas list. |
| 820 | ApplicationAreas appArea1 = new DefaultApplicationAreas |
| 821 | .ApplicationAreasBuilder().destinationAreas(destArea1).build(); |
| 822 | ApplicationAreas appArea2 = new DefaultApplicationAreas |
| 823 | .ApplicationAreasBuilder().destinationAreas(destArea2).build(); |
| 824 | |
| 825 | List<ApplicationAreas> applicationAreasList = new ArrayList<>(); |
| 826 | applicationAreasList.add(appArea1); |
| 827 | applicationAreasList.add(appArea2); |
| 828 | |
| 829 | // Adds two lists under the multiplex list for content 1. |
| 830 | Multiplexes mpx1 = new DefaultMultiplexes.MultiplexesBuilder() |
| 831 | .types(TypesEnum.TIME_DIVISION) |
| 832 | .applicationAreas(applicationAreasList).build(); |
| 833 | |
| 834 | // Creates two binary leaf-lists for two list app areas. |
| 835 | List<byte[]> destArea3 = new ArrayList<>(); |
| 836 | byte[] arrB = new byte[]{0, 0, 1}; |
| 837 | byte[] arr1B = new byte[]{1, 0, 0}; |
| 838 | destArea3.add(arrB); |
| 839 | destArea3.add(arr1B); |
| 840 | |
| 841 | List<byte[]> destArea4 = new ArrayList<>(); |
| 842 | byte[] arr2B = new byte[]{7, 7, 7}; |
| 843 | byte[] arr3B = new byte[]{0, 1}; |
| 844 | destArea4.add(arr2B); |
| 845 | destArea4.add(arr3B); |
| 846 | |
| 847 | // Creates two app areas list. |
| 848 | ApplicationAreas appArea3 = new DefaultApplicationAreas |
| 849 | .ApplicationAreasBuilder().destinationAreas(destArea3).build(); |
| 850 | ApplicationAreas appArea4 = new DefaultApplicationAreas |
| 851 | .ApplicationAreasBuilder().destinationAreas(destArea4).build(); |
| 852 | |
| 853 | List<ApplicationAreas> applicationAreasListB = new ArrayList<>(); |
| 854 | applicationAreasListB.add(appArea3); |
| 855 | applicationAreasListB.add(appArea4); |
| 856 | |
| 857 | // Adds two lists under the multiplex list for content 2. |
| 858 | Multiplexes mpx2 = new DefaultMultiplexes.MultiplexesBuilder() |
| 859 | .types(TypesEnum.FREQUENCY_DIVISION) |
| 860 | .applicationAreas(applicationAreasListB).build(); |
| 861 | |
| 862 | List<Multiplexes> multiplexList = new ArrayList<>(); |
| 863 | multiplexList.add(mpx1); |
| 864 | multiplexList.add(mpx2); |
| 865 | |
| 866 | // Sets it in the container carrier. |
| 867 | Carrier carrier = new DefaultCarrier.CarrierBuilder() |
| 868 | .multiplexes(multiplexList).build(); |
| 869 | |
| 870 | YtbTreeBuilderForListHavingList listWithList = new |
| 871 | YtbTreeBuilderForListHavingListOpParam |
| 872 | .YtbTreeBuilderForListHavingListBuilder() |
| 873 | .carrier(carrier).build(); |
| 874 | |
| 875 | // As YSB or YAB protocol sets the value for YTB. |
| 876 | List<Object> objectList = new ArrayList<>(); |
| 877 | objectList.add(listWithList); |
| 878 | |
| 879 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 880 | YdtBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 881 | objectList, ROOT_NAME, ROOT_NAME_SPACE, |
| 882 | QUERY_CONFIG_REQUEST, registry); |
| 883 | |
| 884 | // Receives YDT context and check the tree that is built. |
| 885 | YdtContext context = ydtBuilder.getRootNode(); |
| 886 | |
| 887 | // Gets the first module from logical root node. |
| 888 | YdtContext module = context.getFirstChild(); |
| 889 | assertThat(getInCrtName(LIST, LIST_WITH_LIST), module.getName(), |
| 890 | is(LIST_WITH_LIST)); |
| 891 | |
| 892 | // Checks the container node under module node. |
| 893 | YdtContext container = module.getFirstChild(); |
| 894 | assertThat(getInCrtName(CONTAINER, CONT_CARRIER), container.getName(), |
| 895 | is(CONT_CARRIER)); |
| 896 | |
| 897 | // Checks the list node with content 1 of multiplex. |
| 898 | YdtContext mtx1 = container.getFirstChild(); |
| 899 | assertThat(getInCrtName(LIST, LIST_MULTIPLEXES), mtx1.getName(), |
| 900 | is(LIST_MULTIPLEXES)); |
| 901 | |
| 902 | // Checks enum leaf under multiplex of content1. |
| 903 | YdtContext enumLeaf1 = mtx1.getFirstChild(); |
| 904 | assertThat(getInCrtName(LEAF, TYPES), enumLeaf1.getName(), is(TYPES)); |
| 905 | assertThat(getInCrtLeafValue(TYPES, TIME_DIVISION), |
| 906 | enumLeaf1.getValue(), is(TIME_DIVISION)); |
| 907 | |
| 908 | // Checks list app area content 1 under multiplex content 1. |
| 909 | YdtContext appAreaList1 = enumLeaf1.getNextSibling(); |
| 910 | assertThat(getInCrtName(LIST, APP_AREA_LIST), appAreaList1.getName(), |
| 911 | is(APP_AREA_LIST)); |
| 912 | |
| 913 | YdtContext leafList1 = appAreaList1.getFirstChild(); |
| 914 | assertThat(getInCrtName(LEAF_LIST, DEST_AREA), leafList1.getName(), |
| 915 | is(DEST_AREA)); |
| 916 | Set value1 = leafList1.getValueSet(); |
| 917 | assertThat(getInCrtLeafListValue(DEST_AREA, BIN_VAL_6), |
| 918 | value1.contains(BIN_VAL_6), is(true)); |
| 919 | assertThat(getInCrtLeafListValue(DEST_AREA, BIN_VAL_7), |
| 920 | value1.contains(BIN_VAL_7), is(true)); |
| 921 | |
| 922 | // Checks list app area content 2 under multiplex content 1. |
| 923 | YdtContext appAreaList2 = appAreaList1.getNextSibling(); |
| 924 | assertThat(getInCrtName(LIST, APP_AREA_LIST), appAreaList2.getName(), |
| 925 | is(APP_AREA_LIST)); |
| 926 | |
| 927 | YdtContext leafList2 = appAreaList2.getFirstChild(); |
| 928 | assertThat(getInCrtName(LEAF_LIST, DEST_AREA), leafList2.getName(), |
| 929 | is(DEST_AREA)); |
| 930 | Set value2 = leafList2.getValueSet(); |
| 931 | assertThat(getInCrtLeafListValue(DEST_AREA, BIN_VAL_8), |
| 932 | value2.contains(BIN_VAL_8), is(true)); |
| 933 | assertThat(getInCrtLeafListValue(DEST_AREA, BIN_VAL_9), |
| 934 | value2.contains(BIN_VAL_9), is(true)); |
| 935 | |
| 936 | // Checks the list node with content 2 of multiplex. |
| 937 | YdtContext mtx2 = mtx1.getNextSibling(); |
| 938 | assertThat(getInCrtName(LIST, LIST_MULTIPLEXES), mtx2.getName(), |
| 939 | is(LIST_MULTIPLEXES)); |
| 940 | |
| 941 | // Checks enum leaf under multiplex of content2. |
| 942 | YdtContext enumLeaf2 = mtx2.getFirstChild(); |
| 943 | assertThat(getInCrtName(LEAF, TYPES), enumLeaf2.getName(), is(TYPES)); |
| 944 | assertThat(getInCrtLeafValue(TYPES, FREQUENCY_DIV), |
| 945 | enumLeaf2.getValue(), is(FREQUENCY_DIV)); |
| 946 | |
| 947 | // Checks list app area content 1 under multiplex content 2. |
| 948 | YdtContext appAreaList3 = enumLeaf2.getNextSibling(); |
| 949 | assertThat(getInCrtName(LIST, APP_AREA_LIST), appAreaList3.getName(), |
| 950 | is(APP_AREA_LIST)); |
| 951 | |
| 952 | YdtContext leafList3 = appAreaList3.getFirstChild(); |
| 953 | assertThat(getInCrtName(LEAF_LIST, DEST_AREA), leafList3.getName(), |
| 954 | is(DEST_AREA)); |
| 955 | Set value3 = leafList3.getValueSet(); |
| 956 | assertThat(getInCrtLeafListValue(DEST_AREA, BIN_VAL_10), |
| 957 | value3.contains(BIN_VAL_10), is(true)); |
| 958 | assertThat(getInCrtLeafListValue(DEST_AREA, BIN_VAL_11), |
| 959 | value3.contains(BIN_VAL_11), is(true)); |
| 960 | |
| 961 | // Checks list app area content 2 under multiplex content 2. |
| 962 | YdtContext appAreaList4 = appAreaList3.getNextSibling(); |
| 963 | assertThat(getInCrtName(LIST, APP_AREA_LIST), appAreaList4.getName(), |
| 964 | is(APP_AREA_LIST)); |
| 965 | |
| 966 | YdtContext leafList4 = appAreaList4.getFirstChild(); |
| 967 | assertThat(getInCrtName(LEAF_LIST, DEST_AREA), leafList4.getName(), |
| 968 | is(DEST_AREA)); |
| 969 | Set value4 = leafList4.getValueSet(); |
| 970 | assertThat(getInCrtLeafListValue(DEST_AREA, BIN_VAL_12), |
| 971 | value4.contains(BIN_VAL_12), is(true)); |
| 972 | assertThat(getInCrtLeafListValue(DEST_AREA, BIN_VAL_13), |
| 973 | value4.contains(BIN_VAL_13), is(true)); |
| 974 | } |
| 975 | |
| 976 | /** |
| 977 | * Processes tree building from the derived type of leaf and leaf-list |
| 978 | * having binary and bits . |
| 979 | */ |
| 980 | @Test |
| 981 | public void processTreeBuilderForBinaryAndBits() { |
| 982 | schemaProvider.processSchemaRegistry(null); |
| 983 | DefaultYangSchemaRegistry registry = schemaProvider |
| 984 | .getDefaultYangSchemaRegistry(); |
| 985 | |
| 986 | // As an application, creates the object. |
| 987 | |
| 988 | // Creates a byte array for binary leaf. |
| 989 | byte[] binLeaf = new byte[]{5, 5, 5}; |
| 990 | |
| 991 | // Assigns the value in the chained loop of typedef. |
| 992 | Derivedbinaryb derBinb = new Derivedbinaryb(binLeaf); |
| 993 | Derivedbinarya derBina = new Derivedbinarya(derBinb); |
| 994 | |
| 995 | // Creates bit set for bit leaf. |
| 996 | BitSet bitLeaf = new BitSet(); |
| 997 | bitLeaf.set(1); |
| 998 | bitLeaf.set(100); |
| 999 | |
| 1000 | // Assigns the value in the chained loop of typedef. |
| 1001 | Derivedbitsb derBitb = new Derivedbitsb(bitLeaf); |
| 1002 | Derivedbitsa derBita = new Derivedbitsa(derBitb); |
| 1003 | |
| 1004 | // Creates a byte array list for binary leaf-list. |
| 1005 | byte[] binList1 = new byte[]{9, 9, 0}; |
| 1006 | byte[] binList2 = new byte[]{12, 6, 0}; |
| 1007 | byte[] binList3 = new byte[]{16, 29, 25}; |
| 1008 | |
| 1009 | // Assigns the value in the chained loop of typedef. |
| 1010 | Derivedbinaryb derBinBList1 = new Derivedbinaryb(binList1); |
| 1011 | Derivedbinaryb derBinBList2 = new Derivedbinaryb(binList2); |
| 1012 | Derivedbinaryb derBinBList3 = new Derivedbinaryb(binList3); |
| 1013 | |
| 1014 | Derivedbinarya derBinAList1 = new Derivedbinarya(derBinBList1); |
| 1015 | Derivedbinarya derBinAList2 = new Derivedbinarya(derBinBList2); |
| 1016 | Derivedbinarya derBinAList3 = new Derivedbinarya(derBinBList3); |
| 1017 | |
| 1018 | List<Derivedbinarya> binAlist = new ArrayList<>(); |
| 1019 | binAlist.add(derBinAList1); |
| 1020 | binAlist.add(derBinAList2); |
| 1021 | binAlist.add(derBinAList3); |
| 1022 | |
| 1023 | // Creates a bit set list for bit leaf-list. |
| 1024 | BitSet bitList1 = new BitSet(); |
| 1025 | bitList1.set(1); |
| 1026 | BitSet bitList2 = new BitSet(); |
| 1027 | bitList2.set(1); |
| 1028 | bitList2.set(10); |
| 1029 | BitSet bitList3 = new BitSet(); |
| 1030 | bitList3.set(1); |
| 1031 | bitList3.set(10); |
| 1032 | bitList3.set(100); |
| 1033 | |
| 1034 | // Assigns the value in the chained loop of typedef. |
| 1035 | Derivedbitsb bitBlist1 = new Derivedbitsb(bitList1); |
| 1036 | Derivedbitsb bitBlist2 = new Derivedbitsb(bitList2); |
| 1037 | Derivedbitsb bitBlist3 = new Derivedbitsb(bitList3); |
| 1038 | |
| 1039 | Derivedbitsa bitAlist1 = new Derivedbitsa(bitBlist1); |
| 1040 | Derivedbitsa bitAlist2 = new Derivedbitsa(bitBlist2); |
| 1041 | Derivedbitsa bitAlist3 = new Derivedbitsa(bitBlist3); |
| 1042 | |
| 1043 | List<Derivedbitsa> bitAlist = new ArrayList<>(); |
| 1044 | bitAlist.add(bitAlist1); |
| 1045 | bitAlist.add(bitAlist2); |
| 1046 | bitAlist.add(bitAlist3); |
| 1047 | |
| 1048 | // Creates a module by assigning all the leaf and leaf-list. |
| 1049 | YtbDerivedTypeWithBitsAndBinary bitsAndBinary = new |
| 1050 | YtbDerivedTypeWithBitsAndBinaryOpParam |
| 1051 | .YtbDerivedTypeWithBitsAndBinaryBuilder() |
| 1052 | .forbinary(derBina).forbits(derBita) |
| 1053 | .forbinarylist(binAlist) |
| 1054 | .forbitslist(bitAlist).build(); |
| 1055 | |
| 1056 | // As YSB or YAB protocol, sets the value for YTB. |
| 1057 | List<Object> objectList = new ArrayList<>(); |
| 1058 | objectList.add(bitsAndBinary); |
| 1059 | |
| 1060 | // Builds YANG tree in YTB. |
| 1061 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 1062 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 1063 | objectList, ROOT_NAME, ROOT_NAME_SPACE, |
| 1064 | EDIT_CONFIG_REQUEST, registry); |
| 1065 | |
| 1066 | // Receives YDT context and check the tree that is built. |
| 1067 | YdtContext context = ydtBuilder.getRootNode(); |
| 1068 | |
| 1069 | // Gets the first module from logical root node. |
| 1070 | YdtContext module = context.getFirstChild(); |
| 1071 | assertThat(getInCrtName(MODULE, MOD_BIT_BIN), module.getName(), |
| 1072 | is(MOD_BIT_BIN)); |
| 1073 | |
| 1074 | // Checks the leaf for binary. |
| 1075 | YdtContext binaryLeaf = module.getFirstChild(); |
| 1076 | assertThat(getInCrtName(LEAF, FOR_BINARY), binaryLeaf.getName(), |
| 1077 | is(FOR_BINARY)); |
| 1078 | assertThat(getInCrtLeafValue(FOR_BINARY, BIN_VAL_1), |
| 1079 | binaryLeaf.getValue(), is(BIN_VAL_1)); |
| 1080 | |
| 1081 | // Checks the leaf for bits. |
| 1082 | YdtContext bitsLeaf = binaryLeaf.getNextSibling(); |
| 1083 | assertThat(getInCrtName(LEAF, FOR_BITS), bitsLeaf.getName(), |
| 1084 | is(FOR_BITS)); |
| 1085 | assertThat(getInCrtLeafValue(FOR_BITS, BIT_VAL_2), |
| 1086 | bitsLeaf.getValue(), is(BIT_VAL_2)); |
| 1087 | |
| 1088 | // Checks the leaf-list for binary. |
| 1089 | YdtContext binaryLeafList = bitsLeaf.getNextSibling(); |
| 1090 | assertThat(getInCrtName(LEAF_LIST, FOR_BINARY_LIST), |
| 1091 | binaryLeafList.getName(), is(FOR_BINARY_LIST)); |
| 1092 | |
| 1093 | Set value2 = binaryLeafList.getValueSet(); |
| 1094 | assertThat(getInCrtLeafListValue(FOR_BINARY_LIST, BIN_VAL_2), |
| 1095 | value2.contains(BIN_VAL_2), is(true)); |
| 1096 | assertThat(getInCrtLeafListValue(FOR_BINARY_LIST, BIN_VAL_3), |
| 1097 | value2.contains(BIN_VAL_3), is(true)); |
| 1098 | assertThat(getInCrtLeafListValue(FOR_BINARY_LIST, BIN_VAL_4), |
| 1099 | value2.contains(BIN_VAL_4), is(true)); |
| 1100 | |
| 1101 | // Checks the leaf-list for bits. |
| 1102 | YdtContext bitsLeafList = binaryLeafList.getNextSibling(); |
| 1103 | assertThat(getInCrtName(LEAF_LIST, FOR_BITS_LIST), |
| 1104 | bitsLeafList.getName(), is(FOR_BITS_LIST)); |
| 1105 | Set value3 = bitsLeafList.getValueSet(); |
| 1106 | assertThat(getInCrtLeafListValue(FOR_BITS_LIST, BIT_VAL_3), |
| 1107 | value3.contains(BIT_VAL_3), is(true)); |
| 1108 | assertThat(getInCrtLeafListValue(FOR_BITS_LIST, BIT_VAL_4), |
| 1109 | value3.contains(BIT_VAL_4), is(true)); |
| 1110 | assertThat(getInCrtLeafListValue(FOR_BITS_LIST, BIT_VAL_5), |
| 1111 | value3.contains(BIT_VAL_5), is(true)); |
| 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * Processes tree building for the union type. |
| 1116 | */ |
| 1117 | @Test |
| 1118 | public void processYtbUnionType() { |
| 1119 | schemaProvider.processSchemaRegistry(null); |
| 1120 | DefaultYangSchemaRegistry registry = schemaProvider |
| 1121 | .getDefaultYangSchemaRegistry(); |
| 1122 | |
| 1123 | // As an application, creates the object. |
| 1124 | |
| 1125 | // Creates union with binary type. |
| 1126 | byte[] binary = new byte[]{0, 0, 0}; |
| 1127 | ForunionUnion union = new ForunionUnion(binary); |
| 1128 | |
| 1129 | // Creates module with union. |
| 1130 | YtbDerivedTypeWithBitsAndBinary unionType = new |
| 1131 | YtbDerivedTypeWithBitsAndBinaryOpParam |
| 1132 | .YtbDerivedTypeWithBitsAndBinaryBuilder() |
| 1133 | .forunion(union) |
| 1134 | .build(); |
| 1135 | |
| 1136 | // As YSB or YAB protocol, sets the value for YTB. |
| 1137 | List<Object> objectList = new ArrayList<>(); |
| 1138 | objectList.add(unionType); |
| 1139 | |
| 1140 | // Builds YANG tree in YTB. |
| 1141 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 1142 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 1143 | objectList, ROOT_NAME, ROOT_NAME_SPACE, |
| 1144 | EDIT_CONFIG_REQUEST, registry); |
| 1145 | |
| 1146 | // Receives YDT context and check the tree that is built. |
| 1147 | YdtContext rootNode = ydtBuilder.getRootNode(); |
| 1148 | YdtContext module = rootNode.getFirstChild(); |
| 1149 | YdtContext unionChild = module.getFirstChild(); |
| 1150 | assertThat(getInCrtName(LEAF, FOR_UNION), unionChild.getName(), |
| 1151 | is(FOR_UNION)); |
| 1152 | assertThat(getInCrtLeafValue(FOR_UNION, BIN_VAL_5), |
| 1153 | unionChild.getValue(), is(BIN_VAL_5)); |
| 1154 | } |
| 1155 | } |