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