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.Test; |
| 20 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ymsietfinettypes.Uri; |
| 21 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.YmsIetfNetwork; |
| 22 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.YmsIetfNetworkOpParam; |
| 23 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.DefaultNetworks; |
| 24 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.Networks; |
| 25 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.NodeId; |
| 26 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.networks.DefaultNetwork; |
| 27 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.networks.Network; |
| 28 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.networks.network.DefaultNode; |
| 29 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.networks.network.Node; |
| 30 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.networks.network.node.DefaultSupportingNode; |
| 31 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.networks.network.node.SupportingNode; |
| 32 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.from.another.file.rev20160826.ytbaugmentfromanotherfile.networks.network.node.AugmentedNdNode; |
| 33 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.from.another.file.rev20160826.ytbaugmentfromanotherfile.networks.network.node.DefaultAugmentedNdNode; |
| 34 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.from.another.file.rev20160826.ytbaugmentfromanotherfile.networks.network.node.augmentedndnode.DefaultTerminationPoint; |
| 35 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.from.another.file.rev20160826.ytbaugmentfromanotherfile.networks.network.node.augmentedndnode.TerminationPoint; |
| 36 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.from.another.file.rev20160826.ytbaugmentfromanotherfile.networks.network.node.augmentedndnode.terminationpoint.DefaultSupportingTerminationPoint; |
| 37 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.from.another.file.rev20160826.ytbaugmentfromanotherfile.networks.network.node.augmentedndnode.terminationpoint.SupportingTerminationPoint; |
| 38 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput.activatesoftwareimage.output.AugmentedRpcOutput; |
| 39 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput.activatesoftwareimage.output.DefaultAugmentedRpcOutput; |
| 40 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput.activatesoftwareimage.output.augmentedrpcoutput.Selection; |
| 41 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput.activatesoftwareimage.output.augmentedrpcoutput.selection.DefaultValueIn; |
| 42 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput.activatesoftwareimage.output.augmentedrpcoutput.selection.valuein.ValueIn; |
| 43 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput2.activatesoftwareimage.output.AugmentedInputOutput; |
| 44 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput2.activatesoftwareimage.output.DefaultAugmentedInputOutput; |
| 45 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput2.activatesoftwareimage.output.augmentedinputoutput.DefaultFriction; |
| 46 | import org.onosproject.yang.gen.v1.yms.test.ytb.augment.yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput2.activatesoftwareimage.output.augmentedinputoutput.Friction; |
| 47 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.YtbChoiceWithContainerAndLeafList; |
| 48 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.YtbChoiceWithContainerAndLeafListOpParam; |
| 49 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.ContentTest; |
| 50 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.CurrentValue; |
| 51 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.DefaultChoiceContainer; |
| 52 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.ChoiceContainer; |
| 53 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.DefaultPredict; |
| 54 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.Predict; |
| 55 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.DefaultReproduce; |
| 56 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.Reproduce; |
| 57 | import org.onosproject.yang.gen.v1.yms.test.ytb.choice.with.container.and.leaf.list.rev20160826.ytbchoicewithcontainerandleaflist.currentvalue.DefaultYtbAbsent; |
| 58 | import org.onosproject.yang.gen.v1.yms.test.ytb.rpc.response.with.advanced.input.and.output.rev20160826.ytbrpcresponsewithadvancedinputandoutput.activatesoftwareimage.ActivateSoftwareImageOutput; |
| 59 | import org.onosproject.yang.gen.v1.yms.test.ytb.rpc.response.with.advanced.input.and.output.rev20160826.ytbrpcresponsewithadvancedinputandoutput.activatesoftwareimage.DefaultActivateSoftwareImageOutput; |
| 60 | import org.onosproject.yang.gen.v1.yms.test.ytb.rpc.response.with.advanced.input.and.output.rev20160826.ytbrpcresponsewithadvancedinputandoutput.activatesoftwareimage.activatesoftwareimageoutput.DefaultOutputList; |
| 61 | import org.onosproject.yang.gen.v1.yms.test.ytb.rpc.response.with.advanced.input.and.output.rev20160826.ytbrpcresponsewithadvancedinputandoutput.activatesoftwareimage.activatesoftwareimageoutput.OutputList; |
| 62 | import org.onosproject.yang.gen.v1.yms.test.ytb.rpc.response.with.advanced.input.and.output.rev20160826.ytbrpcresponsewithadvancedinputandoutput.activatesoftwareimage.activatesoftwareimageoutput.outputlist.ContentInside; |
| 63 | import org.onosproject.yang.gen.v1.yms.test.ytb.rpc.response.with.advanced.input.and.output.rev20160826.ytbrpcresponsewithadvancedinputandoutput.activatesoftwareimage.activatesoftwareimageoutput.outputlist.DefaultContentInside; |
| 64 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.YtbSimpleAugment; |
| 65 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.YtbSimpleAugmentOpParam; |
| 66 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.ytbsimpleaugment.Cont1; |
| 67 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.ytbsimpleaugment.DefaultCont1; |
| 68 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.ytbsimpleaugment.cont1.DefaultCont2; |
| 69 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.ytbsimpleaugment.cont1.cont2.AugmentedCont2; |
| 70 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.ytbsimpleaugment.cont1.cont2.DefaultAugmentedCont2; |
| 71 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.Cont1s; |
| 72 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.DefaultCont1s; |
| 73 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.choice.yangautoprefixcase.rev20160826.YtbSimpleChoiceCase; |
| 74 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.choice.yangautoprefixcase.rev20160826.YtbSimpleChoiceCaseOpParam; |
| 75 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.choice.yangautoprefixcase.rev20160826.ytbsimplechoicecase.DefaultYtbFood; |
| 76 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.choice.yangautoprefixcase.rev20160826.ytbsimplechoicecase.YtbFood; |
| 77 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.choice.yangautoprefixcase.rev20160826.ytbsimplechoicecase.ytbfood.YtbSnack; |
| 78 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.choice.yangautoprefixcase.rev20160826.ytbsimplechoicecase.ytbfood.ytbsnack.DefaultYtbLateNight; |
| 79 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.rpc.response.rev20160826.ytbsimplerpcresponse.rpc.DefaultRpcOutput; |
| 80 | import org.onosproject.yang.gen.v1.yms.test.ytb.simple.rpc.response.rev20160826.ytbsimplerpcresponse.rpc.RpcOutput; |
| 81 | import org.onosproject.yms.app.ydt.YangRequestWorkBench; |
| 82 | import org.onosproject.yms.app.ydt.YdtExtendedBuilder; |
| 83 | import org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry; |
| 84 | import org.onosproject.yms.ydt.YdtContext; |
| 85 | |
| 86 | import java.math.BigInteger; |
| 87 | import java.util.ArrayList; |
| 88 | import java.util.HashSet; |
| 89 | import java.util.LinkedList; |
| 90 | import java.util.List; |
| 91 | import java.util.Set; |
| 92 | |
| 93 | import static org.hamcrest.MatcherAssert.assertThat; |
| 94 | import static org.hamcrest.core.Is.is; |
| 95 | import static org.hamcrest.core.IsNull.notNullValue; |
| 96 | import static org.onosproject.yms.ydt.YdtContextOperationType.NONE; |
| 97 | import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REPLY; |
| 98 | import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REQUEST; |
| 99 | import static org.onosproject.yms.ydt.YmsOperationType.QUERY_CONFIG_REPLY; |
| 100 | import static org.onosproject.yms.ydt.YmsOperationType.RPC_REQUEST; |
| 101 | |
| 102 | /** |
| 103 | * Unit test cases for YANG tree builder for context switch for augment, RPC |
| 104 | * and case. |
| 105 | */ |
| 106 | public class YtbContextSwitchTest extends YtbErrMsgAndConstants { |
| 107 | |
| 108 | private static final String RPC_ADV_NAME = "RPCAdvanced"; |
| 109 | private static final String RPC_ADV_NAMESPACE = "RPCAdvancedSpace"; |
| 110 | private static final String RPC_ADV_IO = |
| 111 | "YtbRpcResponseWithAdvancedInputAndOutput"; |
| 112 | private static final String ACT_IMG = "activate-software-image"; |
| 113 | private static final String INPUT = "input"; |
| 114 | private static final String FINAL = "final"; |
| 115 | private static final String AUG_NW_REF_1 = "network-ref-aug1"; |
| 116 | private static final String AUG_NODE_REF_1 = "node-ref-aug1"; |
| 117 | private static final String AUG_TP_REF_1 = "tp-ref-aug-1"; |
| 118 | private static final String AUG_TP_ID_1 = "tp-id-aug-1"; |
| 119 | private static final String AUG_NW_REF_B1 = "network-ref-augb1"; |
| 120 | private static final String AUG_NODE_REF_B1 = "node-ref-augb1"; |
| 121 | private static final String AUG_TP_REF_B1 = "tp-ref-aug-b1"; |
| 122 | private static final String AUG_TP_ID_B1 = "tp-id-aug-1b"; |
| 123 | private static final String NW_REF = "network-ref"; |
| 124 | private static final String NODE_REF = "node-ref"; |
| 125 | private static final String NW_REF_2 = "network-ref2"; |
| 126 | private static final String NODE_REF_3 = "node-ref3"; |
| 127 | private static final String NW_REF_B = "network-ref-b"; |
| 128 | private static final String NODE_REF_B = "node-ref-b"; |
| 129 | private static final String NW_REF_2B = "network-ref2-b"; |
| 130 | private static final String NODE_REF_2B = "node-ref2-b"; |
| 131 | private static final String NODE_REF_3B = "node-ref3-b"; |
| 132 | private static final String CHOC = "choc"; |
| 133 | private static final String CHOICE_CASE = "YtbSimpleChoiceCase"; |
| 134 | private static final String FOOD = "YtbFood"; |
| 135 | private static final String CHOCOLATE = "chocolate"; |
| 136 | private static final String VAL = "val"; |
| 137 | private static final String IND = "ind"; |
| 138 | private static final String CHOICE_ROOT_NAME = "choiceContainerRootName"; |
| 139 | private static final String CHOICE_ROOT_NAMESPACE = |
| 140 | "choiceContainerRootNamespace"; |
| 141 | private static final String ROOT = "root"; |
| 142 | private static final String CHOICE_CONT = |
| 143 | "YtbChoiceWithContainerAndLeafList"; |
| 144 | private static final String CONT_CHOICE = "choice-container"; |
| 145 | private static final String REPRODUCE = "reproduce"; |
| 146 | private static final String NINETY = "90"; |
| 147 | private static final String HUNDRED = "100"; |
| 148 | private static final String RPC_RT_NAME = "rpcRootName"; |
| 149 | private static final String RPC_RT_NAMESPACE = "rpcRootNameSpace"; |
| 150 | private static final String OUTPUT_LEAF = "output-leaf"; |
| 151 | private static final String FIVE_HUNDRED = "500"; |
| 152 | private static final String OUTPUT_LIST = "output-list"; |
| 153 | private static final String LIST_KEY = "list-key"; |
| 154 | private static final String BIN_VAL_1 = "AAE="; |
| 155 | private static final String CONT_INSIDE = "content_inside"; |
| 156 | private static final String BIN_VAL_2 = "CAk="; |
| 157 | private static final String AVAILABLE = "available"; |
| 158 | private static final String EIGHTY_NINE = "89"; |
| 159 | private static final String NINETY_EIGHT = "98"; |
| 160 | private static final String BIN_VAL_3 = "AAA="; |
| 161 | private static final String SIM_AUG = "simpleAugment"; |
| 162 | private static final String SIM_AUG_NAMESPACE = "simpleAugmentSpace"; |
| 163 | private static final String SIMPLE_AUG = "YtbSimpleAugment"; |
| 164 | private static final String CONT1 = "cont1"; |
| 165 | private static final String CONT2 = "cont2"; |
| 166 | private static final String LEAF4 = "leaf4"; |
| 167 | private static final String CONT1S = "cont1s"; |
| 168 | private static final String INTER_AUG = "inter-file-augment"; |
| 169 | private static final String INTER_AUG_NAMESPACE = |
| 170 | "inter-file-augment-space"; |
| 171 | private static final String IETF_NW = "yms-ietf-network"; |
| 172 | private static final String NWS = "networks"; |
| 173 | private static final String NW = "network"; |
| 174 | private static final String NODE = "node"; |
| 175 | private static final String NODE_ID = "node-id"; |
| 176 | private static final String TERM_POINT = "termination-point"; |
| 177 | private static final String TP_ID = "tp-id"; |
| 178 | private static final String SUP_TERM_POINT = "supporting-termination-point"; |
| 179 | private static final String TP_REF = "tp-ref"; |
| 180 | private static final String SUP_NODE = "supporting-node"; |
| 181 | private static final String KIN1 = "kin1"; |
| 182 | private static final String KIN2 = "kin2"; |
| 183 | private static final String VAL_IN = "value-in"; |
| 184 | private static final String KINETIC = "kinetic"; |
| 185 | private static final String FRICTION = "friction"; |
| 186 | private static final String SPEED = "speed"; |
| 187 | private static final String THOUSAND = "1000"; |
| 188 | |
| 189 | /** |
| 190 | * Creates object as like an application for RPC with list. |
| 191 | * |
| 192 | * @return object of RPC |
| 193 | */ |
| 194 | private List<OutputList> createApplicationBuiltObjectForRpc() { |
| 195 | |
| 196 | // Creates a empty container inside without leaf for list1. |
| 197 | ContentInside inside1 = new DefaultContentInside.ContentInsideBuilder() |
| 198 | .build(); |
| 199 | |
| 200 | // Creates a leaf list-key which is a leaf ref. |
| 201 | byte[] listKey1 = new byte[]{0, 1}; |
| 202 | |
| 203 | // Creates the list content 1. |
| 204 | OutputList output1 = new DefaultOutputList.OutputListBuilder() |
| 205 | .listKey(listKey1).contentInside(inside1).build(); |
| 206 | |
| 207 | // Creates a list of leaf for available. |
| 208 | List<Short> avail = new ArrayList<>(); |
| 209 | avail.add((short) 89); |
| 210 | avail.add((short) 98); |
| 211 | |
| 212 | // Adds the leaf list in the inside container. |
| 213 | ContentInside inside2 = new DefaultContentInside.ContentInsideBuilder() |
| 214 | .available(avail).build(); |
| 215 | |
| 216 | // Creates a leaf, list-key which is a leaf ref. |
| 217 | byte[] listKey2 = new byte[]{8, 9}; |
| 218 | |
| 219 | // Creates the list content 2. |
| 220 | OutputList outputList2 = new DefaultOutputList.OutputListBuilder() |
| 221 | .listKey(listKey2).contentInside(inside2).build(); |
| 222 | |
| 223 | // Creates only leaf, list-key which is a leaf ref. |
| 224 | byte[] arr3 = new byte[]{0, 0}; |
| 225 | |
| 226 | // Creates the list content 3. |
| 227 | OutputList outputList3 = new DefaultOutputList.OutputListBuilder() |
| 228 | .listKey(arr3).build(); |
| 229 | |
| 230 | // Adds all the list contents in array list and gives returns it. |
| 231 | List<OutputList> outputLists = new ArrayList<>(); |
| 232 | outputLists.add(output1); |
| 233 | outputLists.add(outputList2); |
| 234 | outputLists.add(outputList3); |
| 235 | return outputLists; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Builds YANG request work bench for RPC with container input. |
| 240 | * |
| 241 | * @param registry schema registry |
| 242 | * @return YANG request work bench |
| 243 | */ |
| 244 | private YangRequestWorkBench buildYangRequestWorkBenchForRpc( |
| 245 | DefaultYangSchemaRegistry registry) { |
| 246 | |
| 247 | // Creates a request work bench and adds the input child into it. |
| 248 | YangRequestWorkBench workBench = new YangRequestWorkBench( |
| 249 | RPC_ADV_NAME, RPC_ADV_NAMESPACE, RPC_REQUEST, |
| 250 | registry, true); |
| 251 | Set<String> valueList = new HashSet<>(); |
| 252 | valueList.add("800"); |
| 253 | valueList.add("900"); |
| 254 | workBench.addChild(RPC_ADV_IO, null, NONE); |
| 255 | workBench.addChild(ACT_IMG, null, NONE); |
| 256 | workBench.addChild(INPUT, null, NONE); |
| 257 | workBench.addChild(FINAL, null, NONE); |
| 258 | workBench.addLeaf("value", null, valueList); |
| 259 | return workBench; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Creates an application object for inter file augment. |
| 264 | * |
| 265 | * @return application object |
| 266 | */ |
| 267 | private Object createObjectForInterFileAugment() { |
| 268 | |
| 269 | // Creates leaf value for network-ref. |
| 270 | Uri nwkRef = new Uri(AUG_NW_REF_1); |
| 271 | Uri nwkRef2 = new Uri("network-ref-aug2"); |
| 272 | |
| 273 | // Creates leaf value for node-ref |
| 274 | Uri nodeRef = new Uri(AUG_NODE_REF_1); |
| 275 | NodeId nodeId = new NodeId(nodeRef); |
| 276 | |
| 277 | Uri nodeRef2 = new Uri("node-ref-aug2"); |
| 278 | NodeId nodeId2 = new NodeId(nodeRef2); |
| 279 | |
| 280 | // Creates support termination list with the above two contents. |
| 281 | SupportingTerminationPoint point1 = |
| 282 | new DefaultSupportingTerminationPoint |
| 283 | .SupportingTerminationPointBuilder() |
| 284 | .networkRef(nwkRef).nodeRef(nodeId) |
| 285 | .tpRef(AUG_TP_REF_1).build(); |
| 286 | SupportingTerminationPoint point2 = |
| 287 | new DefaultSupportingTerminationPoint |
| 288 | .SupportingTerminationPointBuilder() |
| 289 | .networkRef(nwkRef2).nodeRef(nodeId2) |
| 290 | .tpRef("tp-ref-aug-2").build(); |
| 291 | |
| 292 | List<SupportingTerminationPoint> pointList = new ArrayList<>(); |
| 293 | pointList.add(point1); |
| 294 | pointList.add(point2); |
| 295 | |
| 296 | // Adds the list created to the termination point content1. |
| 297 | TerminationPoint tPoint1 = new DefaultTerminationPoint |
| 298 | .TerminationPointBuilder() |
| 299 | .supportingTerminationPoint(pointList) |
| 300 | .tpId(AUG_TP_ID_1).build(); |
| 301 | |
| 302 | // Creates leaf value for network-ref. |
| 303 | Uri nwkRef3 = new Uri(AUG_NW_REF_B1); |
| 304 | Uri nwkRef4 = new Uri("network-ref-augb2"); |
| 305 | |
| 306 | // Creates leaf value for node-ref |
| 307 | Uri nodeRef3 = new Uri(AUG_NODE_REF_B1); |
| 308 | NodeId nodeId3 = new NodeId(nodeRef3); |
| 309 | |
| 310 | Uri nodeRef4 = new Uri("node-ref-augb2"); |
| 311 | NodeId nodeId4 = new NodeId(nodeRef4); |
| 312 | |
| 313 | // Creates support termination list with the above two contents. |
| 314 | SupportingTerminationPoint point3 = |
| 315 | new DefaultSupportingTerminationPoint |
| 316 | .SupportingTerminationPointBuilder() |
| 317 | .networkRef(nwkRef3).nodeRef(nodeId3) |
| 318 | .tpRef(AUG_TP_REF_B1).build(); |
| 319 | SupportingTerminationPoint point4 = |
| 320 | new DefaultSupportingTerminationPoint |
| 321 | .SupportingTerminationPointBuilder() |
| 322 | .networkRef(nwkRef4).nodeRef(nodeId4) |
| 323 | .tpRef("tp-ref-aug-b2").build(); |
| 324 | |
| 325 | List<SupportingTerminationPoint> pointList2 = new ArrayList<>(); |
| 326 | pointList2.add(point3); |
| 327 | pointList2.add(point4); |
| 328 | |
| 329 | // Adds the list created to the termination point content2. |
| 330 | TerminationPoint tPoint2 = new DefaultTerminationPoint |
| 331 | .TerminationPointBuilder() |
| 332 | .supportingTerminationPoint(pointList2) |
| 333 | .tpId(AUG_TP_ID_B1).build(); |
| 334 | |
| 335 | List<TerminationPoint> terminationPointList = new ArrayList<>(); |
| 336 | terminationPointList.add(tPoint1); |
| 337 | terminationPointList.add(tPoint2); |
| 338 | |
| 339 | // Adds all the above contents to the augment. |
| 340 | AugmentedNdNode augment = new DefaultAugmentedNdNode |
| 341 | .AugmentedNdNodeBuilder() |
| 342 | .terminationPoint(terminationPointList) |
| 343 | .build(); |
| 344 | |
| 345 | // Creates leaf value for network-ref in augmented node(ietf-network). |
| 346 | Uri nwRef5 = new Uri(NW_REF); |
| 347 | |
| 348 | //Creates leaf value for node-ref in augmented node(ietf-network). |
| 349 | Uri nodeRef5 = new Uri(NODE_REF); |
| 350 | NodeId nodeId5 = new NodeId(nodeRef5); |
| 351 | |
| 352 | // Creates supporting node list content 1 with above contents. |
| 353 | SupportingNode supNode1 = new DefaultSupportingNode |
| 354 | .SupportingNodeBuilder().nodeRef(nodeId5) |
| 355 | .networkRef(nwRef5).build(); |
| 356 | |
| 357 | // Creates leaf value for network-ref in augmented node(ietf-network). |
| 358 | Uri nwRef6 = new Uri(NW_REF_2); |
| 359 | |
| 360 | //Creates leaf value for node-ref in augmented node(ietf-network). |
| 361 | Uri nodeRef6 = new Uri("node-ref2"); |
| 362 | NodeId nodeId6 = new NodeId(nodeRef6); |
| 363 | |
| 364 | // Creates supporting node list content 2 with above contents. |
| 365 | SupportingNode supNode2 = new DefaultSupportingNode |
| 366 | .SupportingNodeBuilder() |
| 367 | .nodeRef(nodeId6) |
| 368 | .networkRef(nwRef6).build(); |
| 369 | |
| 370 | List<SupportingNode> supNodeList = new ArrayList<>(); |
| 371 | supNodeList.add(supNode1); |
| 372 | supNodeList.add(supNode2); |
| 373 | |
| 374 | // Creates leaf value for node-id in augmented node(ietf-network). |
| 375 | Uri nodeId1 = new Uri(NODE_REF_3); |
| 376 | NodeId nodeIdForId = new NodeId(nodeId1); |
| 377 | |
| 378 | // Creates node list with content 1 by adding augment also. |
| 379 | DefaultNode.NodeBuilder nodeBuilder = new DefaultNode.NodeBuilder(); |
| 380 | nodeBuilder.addYangAugmentedInfo( |
| 381 | augment, AugmentedNdNode.class); |
| 382 | nodeBuilder.supportingNode(supNodeList); |
| 383 | nodeBuilder.nodeId(nodeIdForId); |
| 384 | Node node1 = nodeBuilder.build(); |
| 385 | |
| 386 | // Creates an augment node without any values set to it. |
| 387 | AugmentedNdNode augmentedNdNode2 = new DefaultAugmentedNdNode |
| 388 | .AugmentedNdNodeBuilder().build(); |
| 389 | |
| 390 | // Creates leaf value for network-ref in augmented node(ietf-network). |
| 391 | Uri nwRef7 = new Uri(NW_REF_B); |
| 392 | |
| 393 | //Creates leaf value for node-ref in augmented node(ietf-network). |
| 394 | Uri nodeRef7 = new Uri(NODE_REF_B); |
| 395 | NodeId nodeId7 = new NodeId(nodeRef7); |
| 396 | |
| 397 | // Creates supporting node list content 1 with above contents. |
| 398 | SupportingNode supNode3 = new DefaultSupportingNode |
| 399 | .SupportingNodeBuilder().nodeRef(nodeId7) |
| 400 | .networkRef(nwRef7).build(); |
| 401 | |
| 402 | // Creates leaf value for network-ref in augmented node(ietf-network). |
| 403 | Uri nwRef8 = new Uri(NW_REF_2B); |
| 404 | |
| 405 | //Creates leaf value for node-ref in augmented node(ietf-network). |
| 406 | Uri nodeRef8 = new Uri(NODE_REF_2B); |
| 407 | NodeId nodeId8 = new NodeId(nodeRef8); |
| 408 | |
| 409 | // Creates supporting node list content 1 with above contents. |
| 410 | SupportingNode supNode4 = new DefaultSupportingNode |
| 411 | .SupportingNodeBuilder() |
| 412 | .nodeRef(nodeId8) |
| 413 | .networkRef(nwRef8).build(); |
| 414 | |
| 415 | List<SupportingNode> supNodeList2 = new ArrayList<>(); |
| 416 | supNodeList2.add(supNode3); |
| 417 | supNodeList2.add(supNode4); |
| 418 | |
| 419 | // Creates leaf value for node-id in augmented node(ietf-network). |
| 420 | Uri nodeIdLeaf = new Uri(NODE_REF_3B); |
| 421 | NodeId nodeIdForId2 = new NodeId(nodeIdLeaf); |
| 422 | |
| 423 | // Creates node list with content 2 by adding empty augment also. |
| 424 | DefaultNode.NodeBuilder nodeBuilder2 = new DefaultNode.NodeBuilder(); |
| 425 | nodeBuilder2.addYangAugmentedInfo( |
| 426 | augmentedNdNode2, AugmentedNdNode.class); |
| 427 | nodeBuilder2.supportingNode(supNodeList2); |
| 428 | nodeBuilder2.nodeId(nodeIdForId2); |
| 429 | Node node2 = nodeBuilder2.build(); |
| 430 | |
| 431 | // Adds both nodes into the list. |
| 432 | List<Node> nodeList = new LinkedList<>(); |
| 433 | nodeList.add(node1); |
| 434 | nodeList.add(node2); |
| 435 | |
| 436 | // Adds the list into the network list. |
| 437 | Network nwkList = new DefaultNetwork.NetworkBuilder() |
| 438 | .node(nodeList).build(); |
| 439 | |
| 440 | List<Network> networkList = new ArrayList<>(); |
| 441 | networkList.add(nwkList); |
| 442 | |
| 443 | // Adds the network list into networks container. |
| 444 | Networks contNetworks = new DefaultNetworks.NetworksBuilder() |
| 445 | .network(networkList).build(); |
| 446 | |
| 447 | // Adds the container into the module. |
| 448 | YmsIetfNetwork opParam = new YmsIetfNetworkOpParam |
| 449 | .YmsIetfNetworkBuilder() |
| 450 | .networks(contNetworks).build(); |
| 451 | return opParam; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Processes a simple choice case and builds the YDT. |
| 456 | */ |
| 457 | @Test |
| 458 | public void processSimpleChoiceCase() { |
| 459 | |
| 460 | schemaProvider.processSchemaRegistry(null); |
| 461 | DefaultYangSchemaRegistry registry = schemaProvider |
| 462 | .getDefaultYangSchemaRegistry(); |
| 463 | |
| 464 | // As an application, creates the object. |
| 465 | |
| 466 | // Creates a choice snack with the case late night. |
| 467 | YtbSnack lateNight = new DefaultYtbLateNight.YtbLateNightBuilder() |
| 468 | .chocolate(CHOC).build(); |
| 469 | |
| 470 | // Creates container food with the created case. |
| 471 | YtbFood food = new DefaultYtbFood.YtbFoodBuilder() |
| 472 | .ytbSnack(lateNight).build(); |
| 473 | |
| 474 | // Creates module with the container food. |
| 475 | YtbSimpleChoiceCase choiceCase = new YtbSimpleChoiceCaseOpParam |
| 476 | .YtbSimpleChoiceCaseBuilder().ytbFood(food).build(); |
| 477 | |
| 478 | // As YSB or YAB protocol, sets the value for YTB. |
| 479 | List<Object> objectList = new ArrayList<>(); |
| 480 | objectList.add(choiceCase); |
| 481 | |
| 482 | // Builds YANG tree in YTB. |
| 483 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 484 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 485 | objectList, ROOT_NAME, ROOT_NAME_SPACE, |
| 486 | EDIT_CONFIG_REPLY, registry); |
| 487 | |
| 488 | // Receives YDT context and check the tree that is built. |
| 489 | YdtContext rootNode = ydtBuilder.getRootNode(); |
| 490 | |
| 491 | // Gets the first module from logical root node. |
| 492 | YdtContext module = rootNode.getFirstChild(); |
| 493 | assertThat(getInCrtName(MODULE, CHOICE_CASE), module.getName(), |
| 494 | is(CHOICE_CASE)); |
| 495 | |
| 496 | // Gets the container food from module. |
| 497 | YdtContext container = module.getFirstChild(); |
| 498 | assertThat(getInCrtName(CONTAINER, FOOD), container.getName(), |
| 499 | is(FOOD)); |
| 500 | |
| 501 | // Gets the case-leaf from container |
| 502 | YdtContext caseNode = container.getFirstChild(); |
| 503 | assertThat(getInCrtName(LEAF, CHOCOLATE), caseNode.getName(), |
| 504 | is(CHOCOLATE)); |
| 505 | assertThat(getInCrtLeafValue(CHOCOLATE, CHOC), caseNode.getValue(), |
| 506 | is(CHOC)); |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Processes module with two choices and a choice having node and a |
| 511 | * leaf-list. |
| 512 | */ |
| 513 | @Test |
| 514 | public void processChoiceWithNodeAndLeafList() { |
| 515 | |
| 516 | schemaProvider.processSchemaRegistry(null); |
| 517 | DefaultYangSchemaRegistry registry = schemaProvider |
| 518 | .getDefaultYangSchemaRegistry(); |
| 519 | |
| 520 | // As an application, creates the object. |
| 521 | |
| 522 | // Creates reproduce container for list predict-1. |
| 523 | Reproduce reproduce1 = new DefaultReproduce.ReproduceBuilder() |
| 524 | .yangAutoPrefixCatch((short) 90).build(); |
| 525 | |
| 526 | // Assigns predict-1 with the container. |
| 527 | Predict predict1 = new DefaultPredict.PredictBuilder() |
| 528 | .reproduce(reproduce1).build(); |
| 529 | |
| 530 | // Creates reproduce container for list predict-2. |
| 531 | Reproduce reproduce2 = new DefaultReproduce.ReproduceBuilder() |
| 532 | .yangAutoPrefixCatch((short) 100).build(); |
| 533 | |
| 534 | // Assigns predict-2 with the container. |
| 535 | Predict predict2 = new DefaultPredict.PredictBuilder() |
| 536 | .reproduce(reproduce2).build(); |
| 537 | |
| 538 | List<Predict> predictList = new ArrayList<>(); |
| 539 | predictList.add(predict1); |
| 540 | predictList.add(predict2); |
| 541 | |
| 542 | // Case container is added to the choice content-test. |
| 543 | ChoiceContainer containerCase = new org.onosproject.yang.gen.v1.yms |
| 544 | .test.ytb.choice.with.container.and.leaf.list.rev20160826 |
| 545 | .ytbchoicewithcontainerandleaflist.contenttest.choicecontainer |
| 546 | .DefaultChoiceContainer.ChoiceContainerBuilder() |
| 547 | .predict(predictList).build(); |
| 548 | |
| 549 | // Case container is added to the choice content-test. |
| 550 | ContentTest contentTest = new DefaultChoiceContainer |
| 551 | .ChoiceContainerBuilder().choiceContainer(containerCase).build(); |
| 552 | |
| 553 | // Creates string list for leaf-list final. |
| 554 | List<String> stringList = new ArrayList<>(); |
| 555 | stringList.add(VAL); |
| 556 | stringList.add(IND); |
| 557 | |
| 558 | // For choice current value, the leaf list gets added as case. |
| 559 | CurrentValue currentValue = new DefaultYtbAbsent.YtbAbsentBuilder() |
| 560 | .yangAutoPrefixFinal(stringList).build(); |
| 561 | |
| 562 | // Adds choice as child to the module. |
| 563 | YtbChoiceWithContainerAndLeafList choiceWithContainerAndLeafList = |
| 564 | new YtbChoiceWithContainerAndLeafListOpParam |
| 565 | .YtbChoiceWithContainerAndLeafListBuilder() |
| 566 | .contentTest(contentTest).currentValue(currentValue) |
| 567 | .build(); |
| 568 | |
| 569 | // As YSB or YAB protocol, sets the value for YTB. |
| 570 | List<Object> objectList = new ArrayList<>(); |
| 571 | objectList.add(choiceWithContainerAndLeafList); |
| 572 | |
| 573 | // Builds YANG tree in YTB. |
| 574 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 575 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 576 | objectList, CHOICE_ROOT_NAME, CHOICE_ROOT_NAMESPACE, |
| 577 | QUERY_CONFIG_REPLY, registry); |
| 578 | |
| 579 | // Receives YDT context and check the tree that is built. |
| 580 | YdtContext context = ydtBuilder.getRootNode(); |
| 581 | assertThat(getInCrtName(ROOT, CHOICE_ROOT_NAME), context.getName(), |
| 582 | is(CHOICE_ROOT_NAME)); |
| 583 | assertThat(getInCrtName(ROOT, CHOICE_ROOT_NAMESPACE), context.getNamespace(), |
| 584 | is(CHOICE_ROOT_NAMESPACE)); |
| 585 | |
| 586 | // Gets the first module from logical root node. |
| 587 | YdtContext module = context.getFirstChild(); |
| 588 | assertThat(getInCrtName(MODULE, CHOICE_CONT), module.getName(), |
| 589 | is(CHOICE_CONT)); |
| 590 | |
| 591 | // Gets the first choice content under the module, as container. |
| 592 | YdtContext choice1 = module.getFirstChild(); |
| 593 | assertThat(getInCrtName(CONTAINER, CONT_CHOICE), choice1.getName(), |
| 594 | is(CONT_CHOICE)); |
| 595 | |
| 596 | // Gets the first content in the list predict. |
| 597 | YdtContext list1 = choice1.getFirstChild(); |
| 598 | assertThat(getInCrtName(LIST, PREDICT), list1.getName(), is(PREDICT)); |
| 599 | |
| 600 | // Gets the container and its child leaf in the list predict. |
| 601 | YdtContext container1 = list1.getFirstChild(); |
| 602 | assertThat(getInCrtName(CONTAINER, REPRODUCE), container1.getName(), |
| 603 | is(REPRODUCE)); |
| 604 | YdtContext leaf1 = container1.getFirstChild(); |
| 605 | assertThat(getInCrtName(LEAF, CATCH), leaf1.getName(), is(CATCH)); |
| 606 | assertThat(getInCrtLeafValue(CATCH, NINETY), leaf1.getValue(), |
| 607 | is(NINETY)); |
| 608 | |
| 609 | // Gets the second content in the list predict. |
| 610 | YdtContext list2 = list1.getNextSibling(); |
| 611 | assertThat(getInCrtName(LIST, PREDICT), list2.getName(), is(PREDICT)); |
| 612 | |
| 613 | // Gets the container and its child leaf in the list predict. |
| 614 | YdtContext container2 = list2.getFirstChild(); |
| 615 | assertThat(getInCrtName(CONTAINER, REPRODUCE), container2.getName(), |
| 616 | is(REPRODUCE)); |
| 617 | YdtContext leaf2 = container2.getFirstChild(); |
| 618 | assertThat(getInCrtName(LEAF, CATCH), leaf2.getName(), is(CATCH)); |
| 619 | assertThat(getInCrtLeafValue(CATCH, HUNDRED), leaf2.getValue(), |
| 620 | is(HUNDRED)); |
| 621 | |
| 622 | // Gets the second choice content under the module, as leaf-list. |
| 623 | YdtContext choice2 = choice1.getNextSibling(); |
| 624 | assertThat(getInCrtName(LEAF_LIST, FINAL), choice2.getName(), |
| 625 | is(FINAL)); |
| 626 | Set value2 = choice2.getValueSet(); |
| 627 | assertThat(getInCrtLeafListValue(FINAL, VAL), value2.contains(VAL), |
| 628 | is(true)); |
| 629 | assertThat(getInCrtLeafListValue(FINAL, IND), value2.contains(IND), |
| 630 | is(true)); |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Processes RPC response of a simple output with only a leaf content |
| 635 | * inside. |
| 636 | */ |
| 637 | @Test |
| 638 | public void processSimpleRpcResponse() { |
| 639 | schemaProvider.processSchemaRegistry(null); |
| 640 | DefaultYangSchemaRegistry registry = schemaProvider |
| 641 | .getDefaultYangSchemaRegistry(); |
| 642 | |
| 643 | // As an application, creates the object. |
| 644 | RpcOutput output = new DefaultRpcOutput.RpcOutputBuilder() |
| 645 | .outputLeaf(500).build(); |
| 646 | |
| 647 | // Creates request work bench of rpc. |
| 648 | YangRequestWorkBench workBench = new YangRequestWorkBench( |
| 649 | RPC_RT_NAME, RPC_RT_NAMESPACE, RPC_REQUEST, registry, true); |
| 650 | workBench.addChild(RPC_NAME, null, NONE); |
| 651 | workBench.addChild(RPC, null, NONE); |
| 652 | workBench.addChild(INPUT, null, NONE); |
| 653 | |
| 654 | // Builds YANG tree in YTB. |
| 655 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 656 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtForRpcResponse( |
| 657 | output, workBench); |
| 658 | |
| 659 | // Receives YDT context and check the tree that is built. |
| 660 | YdtContext context = ydtBuilder.getRootNode(); |
| 661 | assertThat(getInCrtName(ROOT, RPC_RT_NAME), context.getName(), |
| 662 | is(RPC_RT_NAME)); |
| 663 | assertThat(getInCrtName(ROOT, RPC_RT_NAMESPACE), context.getNamespace(), |
| 664 | is(RPC_RT_NAMESPACE)); |
| 665 | |
| 666 | // Gets the first module from logical root node. |
| 667 | YdtContext module = context.getFirstChild(); |
| 668 | assertThat(getInCrtName(MODULE, RPC_NAME), module.getName(), |
| 669 | is(RPC_NAME)); |
| 670 | |
| 671 | // Gets the rpc node from the module. |
| 672 | YdtContext rpc = module.getFirstChild(); |
| 673 | assertThat(getInCrtName(RPC, RPC), rpc.getName(), is(RPC)); |
| 674 | |
| 675 | // Gets the output node from the module. |
| 676 | // TODO: Change assert after YANG utils is merged. |
| 677 | YdtContext rpcOutput = rpc.getFirstChild(); |
| 678 | //assertThat(rpcOutputNode.getName(), is("output")); |
| 679 | |
| 680 | YdtContext outputLeaf = rpcOutput.getFirstChild(); |
| 681 | assertThat(getInCrtName(LEAF, OUTPUT_LEAF), outputLeaf.getName(), |
| 682 | is(OUTPUT_LEAF)); |
| 683 | assertThat(getInCrtLeafValue(OUTPUT_LEAF, FIVE_HUNDRED), |
| 684 | outputLeaf.getValue(), is(FIVE_HUNDRED)); |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * Processes RPC response of an output defined with list. |
| 689 | */ |
| 690 | @Test |
| 691 | public void processRpcResponseForAdvInputOutput() { |
| 692 | schemaProvider.processSchemaRegistry(null); |
| 693 | DefaultYangSchemaRegistry registry = schemaProvider |
| 694 | .getDefaultYangSchemaRegistry(); |
| 695 | |
| 696 | // As an application, creates the object. |
| 697 | List<OutputList> list = createApplicationBuiltObjectForRpc(); |
| 698 | ActivateSoftwareImageOutput output = |
| 699 | new DefaultActivateSoftwareImageOutput |
| 700 | .ActivateSoftwareImageOutputBuilder() |
| 701 | .outputList(list).build(); |
| 702 | |
| 703 | // Creates request work bench of rpc. |
| 704 | YangRequestWorkBench workBench = buildYangRequestWorkBenchForRpc( |
| 705 | registry); |
| 706 | |
| 707 | // Builds YANG tree in YTB. |
| 708 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 709 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtForRpcResponse( |
| 710 | output, workBench); |
| 711 | |
| 712 | // Receives YDT context and check the tree that is built. |
| 713 | YdtContext context = ydtBuilder.getRootNode(); |
| 714 | assertThat(getInCrtName(ROOT, RPC_ADV_NAME), context.getName(), |
| 715 | is(RPC_ADV_NAME)); |
| 716 | assertThat(getInCrtName(ROOT, RPC_ADV_NAMESPACE), context.getNamespace(), |
| 717 | is(RPC_ADV_NAMESPACE)); |
| 718 | |
| 719 | // Gets the first module from logical root node. |
| 720 | YdtContext module = context.getFirstChild(); |
| 721 | assertThat(getInCrtName(MODULE, RPC_ADV_IO), module.getName(), |
| 722 | is(RPC_ADV_IO)); |
| 723 | |
| 724 | // Gets the rpc node from module. |
| 725 | YdtContext rpc = module.getFirstChild(); |
| 726 | assertThat(getInCrtName(RPC, ACT_IMG), rpc.getName(), is(ACT_IMG)); |
| 727 | |
| 728 | // Gets the output node from the module. |
| 729 | // TODO: Change assert after YANG utils is merged. |
| 730 | YdtContext rpcOutput = rpc.getFirstChild(); |
| 731 | //assertThat(rpcOutputNode.getName(), is("output")); |
| 732 | |
| 733 | // Gets the list content 1 as the node from output. |
| 734 | YdtContext outputList1 = rpcOutput.getFirstChild(); |
| 735 | assertThat(getInCrtName(LIST, OUTPUT_LIST), outputList1.getName(), |
| 736 | is(OUTPUT_LIST)); |
| 737 | |
| 738 | // Gets the leaf key-list from list content1. |
| 739 | YdtContext keyList1 = outputList1.getFirstChild(); |
| 740 | assertThat(getInCrtName(LEAF, LIST_KEY), keyList1.getName(), |
| 741 | is(LIST_KEY)); |
| 742 | assertThat(getInCrtLeafValue(LIST_KEY, BIN_VAL_1), keyList1.getValue(), |
| 743 | is(BIN_VAL_1)); |
| 744 | |
| 745 | // Gets the content inside container from list content 1. |
| 746 | YdtContext cont1 = keyList1.getNextSibling(); |
| 747 | assertThat(getInCrtName(CONTAINER, CONT_INSIDE), cont1.getName(), |
| 748 | is(CONT_INSIDE)); |
| 749 | |
| 750 | // Gets the list content 2 as the node from output. |
| 751 | YdtContext outputList2 = outputList1.getNextSibling(); |
| 752 | assertThat(getInCrtName(LIST, OUTPUT_LIST), outputList2.getName(), |
| 753 | is(OUTPUT_LIST)); |
| 754 | |
| 755 | // Gets the leaf-list key-list from list content2. |
| 756 | YdtContext keyList2 = outputList2.getFirstChild(); |
| 757 | assertThat(getInCrtName(LEAF, LIST_KEY), keyList2.getName(), |
| 758 | is(LIST_KEY)); |
| 759 | assertThat(getInCrtLeafValue(LIST_KEY, BIN_VAL_2), keyList2.getValue(), |
| 760 | is(BIN_VAL_2)); |
| 761 | |
| 762 | // Gets the content inside container from list content 2. |
| 763 | YdtContext cont2 = keyList2.getNextSibling(); |
| 764 | assertThat(getInCrtName(CONTAINER, CONT_INSIDE), cont2.getName(), |
| 765 | is(CONT_INSIDE)); |
| 766 | |
| 767 | // Gets the leaf-list available inside container. |
| 768 | YdtContext availLeafList = cont2.getFirstChild(); |
| 769 | assertThat(getInCrtName(LEAF_LIST, AVAILABLE), availLeafList.getName(), |
| 770 | is(AVAILABLE)); |
| 771 | Set value1 = availLeafList.getValueSet(); |
| 772 | assertThat(getInCrtLeafListValue(AVAILABLE, EIGHTY_NINE), |
| 773 | value1.contains(EIGHTY_NINE), is(true)); |
| 774 | assertThat(getInCrtLeafListValue(AVAILABLE, NINETY_EIGHT), |
| 775 | value1.contains(NINETY_EIGHT), is(true)); |
| 776 | |
| 777 | // Gets the list content 3. |
| 778 | YdtContext outputList3 = outputList2.getNextSibling(); |
| 779 | assertThat(getInCrtName(LIST, OUTPUT_LIST), outputList3.getName(), |
| 780 | is(OUTPUT_LIST)); |
| 781 | |
| 782 | // Gets the leaf list-key in content 3 of list. |
| 783 | YdtContext keyList3 = outputList3.getFirstChild(); |
| 784 | assertThat(getInCrtName(LEAF, LIST_KEY), keyList3.getName(), |
| 785 | is(LIST_KEY)); |
| 786 | assertThat(getInCrtLeafValue(LIST_KEY, BIN_VAL_3), keyList3.getValue(), |
| 787 | is(BIN_VAL_3)); |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * Processes simple self augment file with leaf and container inside |
| 792 | * augment. |
| 793 | */ |
| 794 | @Test |
| 795 | public void processSimpleAugment() { |
| 796 | schemaProvider.processSchemaRegistry(null); |
| 797 | DefaultYangSchemaRegistry registry = schemaProvider |
| 798 | .getDefaultYangSchemaRegistry(); |
| 799 | |
| 800 | // As an application, creates the object. |
| 801 | |
| 802 | // Creates container cont1s with the leaf. |
| 803 | org.onosproject.yang.gen.v1.yms.test.ytb.simple.augment.rev20160826 |
| 804 | .ytbsimpleaugment.cont1.cont2.augmentedcont2.cont1s |
| 805 | .Cont1s cont1s1 = new org.onosproject.yang.gen.v1.yms.test |
| 806 | .ytb.simple.augment.rev20160826.ytbsimpleaugment.cont1.cont2 |
| 807 | .augmentedcont2.cont1s.DefaultCont1s.Cont1sBuilder().build(); |
| 808 | |
| 809 | // Appends the created container into another container. |
| 810 | Cont1s cont1s = new DefaultCont1s.Cont1sBuilder() |
| 811 | .cont1s(cont1s1).build(); |
| 812 | |
| 813 | // Creates augment with the container and leaf. |
| 814 | AugmentedCont2 augment = new DefaultAugmentedCont2 |
| 815 | .AugmentedCont2Builder().cont1s(cont1s).leaf4(500).build(); |
| 816 | |
| 817 | // Creates for the node which will be getting augmented. |
| 818 | // Creates cont2 where content will be augmented into. |
| 819 | DefaultCont2.Cont2Builder augCont2 = new DefaultCont2 |
| 820 | .Cont2Builder(); |
| 821 | augCont2.addYangAugmentedInfo(augment, AugmentedCont2.class); |
| 822 | |
| 823 | // Creates cont1 where cont2 is added. |
| 824 | Cont1 cont1 = new DefaultCont1.Cont1Builder() |
| 825 | .cont2(augCont2.build()).build(); |
| 826 | |
| 827 | // Creates module with the nodes inside. |
| 828 | YtbSimpleAugment simpleAugment = new YtbSimpleAugmentOpParam |
| 829 | .YtbSimpleAugmentBuilder().cont1(cont1).build(); |
| 830 | |
| 831 | // As YSB or YAB protocol, sets the value for YTB. |
| 832 | List<Object> objectList = new ArrayList<>(); |
| 833 | objectList.add(simpleAugment); |
| 834 | |
| 835 | // Builds YANG tree in YTB. |
| 836 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 837 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 838 | objectList, SIM_AUG, SIM_AUG_NAMESPACE, |
| 839 | EDIT_CONFIG_REQUEST, registry); |
| 840 | |
| 841 | // Receives YDT context and check the tree that is built. |
| 842 | YdtContext context = ydtBuilder.getRootNode(); |
| 843 | assertThat(getInCrtName(ROOT, SIM_AUG), context.getName(), is(SIM_AUG)); |
| 844 | assertThat(getInCrtName(ROOT, SIM_AUG_NAMESPACE), |
| 845 | context.getNamespace(), is(SIM_AUG_NAMESPACE)); |
| 846 | |
| 847 | // Gets the first module from logical root node. |
| 848 | YdtContext module = context.getFirstChild(); |
| 849 | assertThat(getInCrtName(MODULE, SIMPLE_AUG), module.getName(), |
| 850 | is(SIMPLE_AUG)); |
| 851 | |
| 852 | // Gets the cont1 under module. |
| 853 | YdtContext container1 = module.getFirstChild(); |
| 854 | assertThat(getInCrtName(CONTAINER, CONT1), container1.getName(), |
| 855 | is(CONT1)); |
| 856 | |
| 857 | // Gets the cont2 under cont1. |
| 858 | YdtContext container2 = container1.getFirstChild(); |
| 859 | assertThat(getInCrtName(CONTAINER, CONT2), container2.getName(), |
| 860 | is(CONT2)); |
| 861 | |
| 862 | // Gets the leaf4 which was augmented under cont2. |
| 863 | YdtContext leaf4 = container2.getFirstChild(); |
| 864 | assertThat(getInCrtName(LEAF, LEAF4), leaf4.getName(), is(LEAF4)); |
| 865 | assertThat(getInCrtLeafValue(LEAF4, FIVE_HUNDRED), leaf4.getValue(), |
| 866 | is(FIVE_HUNDRED)); |
| 867 | |
| 868 | // Gets the cont1s which was augmented under cont2. |
| 869 | YdtContext container1s = leaf4.getNextSibling(); |
| 870 | assertThat(getInCrtName(CONTAINER, CONT1S), container1s.getName(), |
| 871 | is(CONT1S)); |
| 872 | |
| 873 | // Gets the cont2s which was augmented under cont1s. |
| 874 | YdtContext container2s = container1s.getFirstChild(); |
| 875 | assertThat(getInCrtName(CONTAINER, CONT1S), container2s.getName(), |
| 876 | is(CONT1S)); |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Processes inter file augment with augmented node as list and the |
| 881 | * augment having list. |
| 882 | */ |
| 883 | @Test |
| 884 | public void processInterFileAugment() { |
| 885 | schemaProvider.processSchemaRegistry(null); |
| 886 | DefaultYangSchemaRegistry registry = schemaProvider |
| 887 | .getDefaultYangSchemaRegistry(); |
| 888 | |
| 889 | // As an application, creates the object. |
| 890 | Object opParam = createObjectForInterFileAugment(); |
| 891 | |
| 892 | // As YSB or YAB protocol, sets the value for YTB. |
| 893 | List<Object> objectList = new ArrayList<>(); |
| 894 | objectList.add(opParam); |
| 895 | |
| 896 | // Builds YANG tree in YTB. |
| 897 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 898 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtBuilderForYo( |
| 899 | objectList, INTER_AUG, INTER_AUG_NAMESPACE, |
| 900 | EDIT_CONFIG_REQUEST, registry); |
| 901 | |
| 902 | // Receives YDT context and check the tree that is built. |
| 903 | YdtContext context = ydtBuilder.getRootNode(); |
| 904 | assertThat(getInCrtName(ROOT, INTER_AUG), context.getName(), |
| 905 | is(INTER_AUG)); |
| 906 | assertThat(getInCrtName(ROOT, INTER_AUG_NAMESPACE), context.getNamespace(), |
| 907 | is(INTER_AUG_NAMESPACE)); |
| 908 | |
| 909 | // Checks the first module from logical root node. |
| 910 | YdtContext module = context.getFirstChild(); |
| 911 | assertThat(getInCrtName(MODULE, IETF_NW), module.getName(), |
| 912 | is(IETF_NW)); |
| 913 | |
| 914 | // Checks the container networks from module. |
| 915 | YdtContext nwksCont = module.getFirstChild(); |
| 916 | assertThat(getInCrtName(CONTAINER, NWS), nwksCont.getName(), is(NWS)); |
| 917 | |
| 918 | // Checks the list network from container networks. |
| 919 | YdtContext nwrkList = nwksCont.getFirstChild(); |
| 920 | assertThat(getInCrtName(LIST, NW), nwrkList.getName(), is(NW)); |
| 921 | |
| 922 | // Checks the node list content 1 under network list. |
| 923 | YdtContext node1 = nwrkList.getFirstChild(); |
| 924 | assertThat(getInCrtName(LIST, NODE), node1.getName(), is(NODE)); |
| 925 | |
| 926 | // Checks the node-id leaf for list content 1. |
| 927 | YdtContext nodeId1 = node1.getFirstChild(); |
| 928 | assertThat(getInCrtName(LEAF, NODE_ID), nodeId1.getName(), is(NODE_ID)); |
| 929 | assertThat(getInCrtLeafValue(NODE_ID, NODE_REF_3), nodeId1.getValue(), |
| 930 | is(NODE_REF_3)); |
| 931 | |
| 932 | // Checks termination list 1 under node 1, from augment. |
| 933 | YdtContext terList1 = nodeId1.getNextSibling(); |
| 934 | assertThat(getInCrtName(LIST, TERM_POINT), terList1.getName(), |
| 935 | is(TERM_POINT)); |
| 936 | |
| 937 | // Checks tp-id leaf from termination list content 1. |
| 938 | YdtContext tpId1 = terList1.getFirstChild(); |
| 939 | assertThat(getInCrtName(LEAF, TP_ID), tpId1.getName(), is(TP_ID)); |
| 940 | assertThat(getInCrtLeafValue(TP_ID, AUG_TP_ID_1), tpId1.getValue(), |
| 941 | is(AUG_TP_ID_1)); |
| 942 | |
| 943 | // Checks supporting term point list content1 from term list content 1. |
| 944 | YdtContext supTerm1 = tpId1.getNextSibling(); |
| 945 | assertThat(getInCrtName(LIST, SUP_TERM_POINT), supTerm1.getName(), |
| 946 | is(SUP_TERM_POINT)); |
| 947 | |
| 948 | YdtContext nwkRefSupTerm1 = supTerm1.getFirstChild(); |
| 949 | assertThat(getInCrtName(LEAF, NW_REF), nwkRefSupTerm1.getName(), |
| 950 | is(NW_REF)); |
| 951 | assertThat(getInCrtLeafValue(NW_REF, AUG_NW_REF_1), |
| 952 | nwkRefSupTerm1.getValue(), is(AUG_NW_REF_1)); |
| 953 | |
| 954 | YdtContext nodeRefSupTerm1 = nwkRefSupTerm1.getNextSibling(); |
| 955 | assertThat(getInCrtName(LEAF, NODE_REF), nodeRefSupTerm1.getName(), |
| 956 | is(NODE_REF)); |
| 957 | assertThat(getInCrtLeafValue(NODE_REF, AUG_NODE_REF_1), |
| 958 | nodeRefSupTerm1.getValue(), is(AUG_NODE_REF_1)); |
| 959 | |
| 960 | YdtContext tpRefSupTerm1 = nodeRefSupTerm1.getNextSibling(); |
| 961 | assertThat(getInCrtName(LEAF, TP_REF), tpRefSupTerm1.getName(), |
| 962 | is(TP_REF)); |
| 963 | assertThat(getInCrtLeafValue(TP_REF, AUG_TP_REF_1), |
| 964 | tpRefSupTerm1.getValue(), is(AUG_TP_REF_1)); |
| 965 | |
| 966 | // Checks termination list 2 under node 1, from augment. |
| 967 | YdtContext terminationList2 = terList1.getNextSibling(); |
| 968 | assertThat(getInCrtName(LIST, TERM_POINT), terminationList2.getName(), |
| 969 | is(TERM_POINT)); |
| 970 | |
| 971 | YdtContext terList2 = terminationList2.getFirstChild(); |
| 972 | assertThat(getInCrtName(LEAF, TP_ID), terList2.getName(), is(TP_ID)); |
| 973 | assertThat(getInCrtLeafValue(TP_ID, AUG_TP_ID_B1), terList2.getValue(), |
| 974 | is(AUG_TP_ID_B1)); |
| 975 | |
| 976 | // Checks supporting term point list content1 from term list content 2. |
| 977 | YdtContext supTerm2 = terList2.getNextSibling(); |
| 978 | assertThat(getInCrtName(LIST, SUP_TERM_POINT), supTerm2.getName(), |
| 979 | is(SUP_TERM_POINT)); |
| 980 | |
| 981 | YdtContext nwkRefSupTerm2 = supTerm2.getFirstChild(); |
| 982 | assertThat(getInCrtName(LEAF, NW_REF), nwkRefSupTerm2.getName(), |
| 983 | is(NW_REF)); |
| 984 | assertThat(getInCrtLeafValue(NW_REF, AUG_NW_REF_B1), |
| 985 | nwkRefSupTerm2.getValue(), is(AUG_NW_REF_B1)); |
| 986 | |
| 987 | YdtContext nodeRefSupTerm2 = nwkRefSupTerm2.getNextSibling(); |
| 988 | assertThat(getInCrtName(LEAF, NODE_REF), nodeRefSupTerm2.getName(), |
| 989 | is(NODE_REF)); |
| 990 | assertThat(getInCrtLeafValue(NODE_REF, AUG_NODE_REF_B1), |
| 991 | nodeRefSupTerm2.getValue(), is(AUG_NODE_REF_B1)); |
| 992 | |
| 993 | YdtContext tpRefSupTerm2 = nodeRefSupTerm2.getNextSibling(); |
| 994 | assertThat(getInCrtName(LEAF, TP_REF), tpRefSupTerm2.getName(), |
| 995 | is(TP_REF)); |
| 996 | assertThat(getInCrtLeafValue(TP_REF, AUG_TP_REF_B1), |
| 997 | tpRefSupTerm2.getValue(), is(AUG_TP_REF_B1)); |
| 998 | |
| 999 | // Checks the content of the supporting node list content 1 in node 1. |
| 1000 | YdtContext supNode1 = terminationList2.getNextSibling(); |
| 1001 | assertThat(getInCrtName(LIST, SUP_NODE), supNode1.getName(), |
| 1002 | is(SUP_NODE)); |
| 1003 | |
| 1004 | YdtContext nwkRefSupNode1 = supNode1.getFirstChild(); |
| 1005 | assertThat(getInCrtName(LEAF, NW_REF), nwkRefSupNode1.getName(), |
| 1006 | is(NW_REF)); |
| 1007 | assertThat(getInCrtLeafValue(NW_REF, NW_REF), nwkRefSupNode1.getValue(), |
| 1008 | is(NW_REF)); |
| 1009 | |
| 1010 | YdtContext nodeRefSupNode1 = nwkRefSupNode1.getNextSibling(); |
| 1011 | assertThat(getInCrtName(LEAF, NODE_REF), nodeRefSupNode1.getName(), |
| 1012 | is(NODE_REF)); |
| 1013 | assertThat(getInCrtLeafValue(NODE_REF, NW_REF), |
| 1014 | nwkRefSupNode1.getValue(), is(NW_REF)); |
| 1015 | |
| 1016 | // Checks the content of the supporting node list content 2 in node 1. |
| 1017 | YdtContext supNode2 = supNode1.getNextSibling(); |
| 1018 | assertThat(getInCrtName(LIST, SUP_NODE), supNode2.getName(), |
| 1019 | is(SUP_NODE)); |
| 1020 | |
| 1021 | YdtContext nwkRefSupNode2 = supNode2.getFirstChild(); |
| 1022 | assertThat(getInCrtName(LEAF, NW_REF), nwkRefSupNode2.getName(), |
| 1023 | is(NW_REF)); |
| 1024 | assertThat(getInCrtLeafValue(NW_REF, NW_REF_2), |
| 1025 | nwkRefSupNode2.getValue(), is(NW_REF_2)); |
| 1026 | |
| 1027 | YdtContext nodeRefSupNode2 = nwkRefSupNode2.getNextSibling(); |
| 1028 | assertThat(getInCrtName(LEAF, NODE_REF), nodeRefSupNode2.getName(), |
| 1029 | is(NODE_REF)); |
| 1030 | assertThat(getInCrtLeafValue(NODE_REF, NW_REF_2), |
| 1031 | nwkRefSupNode2.getValue(), is(NW_REF_2)); |
| 1032 | |
| 1033 | // Checks the node list content 2 under network list. |
| 1034 | YdtContext node2 = node1.getNextSibling(); |
| 1035 | assertThat(getInCrtName(LIST, NODE), node2.getName(), is(NODE)); |
| 1036 | |
| 1037 | // Checks the node-id leaf for list content 2. |
| 1038 | YdtContext nodeId2 = node2.getFirstChild(); |
| 1039 | assertThat(getInCrtName(LEAF, NODE_ID), nodeId2.getName(), is(NODE_ID)); |
| 1040 | assertThat(getInCrtLeafValue(NODE_ID, NODE_REF_3B), nodeId2.getValue(), |
| 1041 | is(NODE_REF_3B)); |
| 1042 | |
| 1043 | // Checks supporting term point list content1 from term list content 2. |
| 1044 | YdtContext supNode3 = nodeId2.getNextSibling(); |
| 1045 | assertThat(getInCrtName(LIST, SUP_NODE), supNode3.getName(), |
| 1046 | is(SUP_NODE)); |
| 1047 | |
| 1048 | YdtContext nwkRefSupNode3 = supNode3.getFirstChild(); |
| 1049 | assertThat(getInCrtName(LEAF, NW_REF), nwkRefSupNode3.getName(), |
| 1050 | is(NW_REF)); |
| 1051 | assertThat(getInCrtLeafValue(NW_REF, NW_REF_B), |
| 1052 | nwkRefSupNode3.getValue(), is(NW_REF_B)); |
| 1053 | |
| 1054 | YdtContext nodeRefSupNode3 = nwkRefSupNode3.getNextSibling(); |
| 1055 | assertThat(getInCrtName(LEAF, NODE_REF), nodeRefSupNode3.getName(), |
| 1056 | is(NODE_REF)); |
| 1057 | assertThat(getInCrtLeafValue(NODE_REF, NODE_REF_B), |
| 1058 | nodeRefSupNode3.getValue(), is(NODE_REF_B)); |
| 1059 | |
| 1060 | // Checks supporting term point list content2 from term list content 2. |
| 1061 | YdtContext supNode4 = supNode3.getNextSibling(); |
| 1062 | assertThat(getInCrtName(LIST, SUP_NODE), supNode4.getName(), |
| 1063 | is(SUP_NODE)); |
| 1064 | |
| 1065 | YdtContext nwkRefSupNode4 = supNode4.getFirstChild(); |
| 1066 | assertThat(getInCrtName(LEAF, NW_REF), nwkRefSupNode4.getName(), |
| 1067 | is(NW_REF)); |
| 1068 | assertThat(getInCrtLeafValue(NW_REF, NW_REF_2B), |
| 1069 | nwkRefSupNode4.getValue(), is(NW_REF_2B)); |
| 1070 | |
| 1071 | YdtContext nodeRefSupNode4 = nwkRefSupNode4.getNextSibling(); |
| 1072 | assertThat(getInCrtName(LEAF, NODE_REF), nodeRefSupNode4.getName(), |
| 1073 | is(NODE_REF)); |
| 1074 | assertThat(getInCrtLeafValue(NODE_REF, NODE_REF_2B), |
| 1075 | nodeRefSupNode4.getValue(), is(NODE_REF_2B)); |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * Processes inter file augment with rpc output as its target node. |
| 1080 | */ |
| 1081 | @Test |
| 1082 | public void processInterFileAugmentWithRpcInputAsTarget() { |
| 1083 | schemaProvider.processSchemaRegistry(null); |
| 1084 | DefaultYangSchemaRegistry registry = schemaProvider |
| 1085 | .getDefaultYangSchemaRegistry(); |
| 1086 | |
| 1087 | // Builds RPC request tree in YDT. |
| 1088 | YangRequestWorkBench workBench = |
| 1089 | buildYangRequestWorkBenchForRpc(registry); |
| 1090 | |
| 1091 | // Creates augment code object. |
| 1092 | |
| 1093 | // Creates the list of value in, case value in. |
| 1094 | ValueIn valuein1 = new org.onosproject.yang.gen.v1.yms.test.ytb.augment |
| 1095 | .yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput |
| 1096 | .activatesoftwareimage.output.augmentedrpcoutput.selection |
| 1097 | .valuein.DefaultValueIn.ValueInBuilder().kinetic(KIN1) |
| 1098 | .build(); |
| 1099 | ValueIn valuein2 = new org.onosproject.yang.gen.v1.yms.test.ytb.augment |
| 1100 | .yangautoprefixfor.rpc.input.rev20160826.ytbaugmentforrpcinput |
| 1101 | .activatesoftwareimage.output.augmentedrpcoutput.selection |
| 1102 | .valuein.DefaultValueIn.ValueInBuilder().kinetic(KIN2) |
| 1103 | .build(); |
| 1104 | |
| 1105 | List<ValueIn> valueInList = new ArrayList<>(); |
| 1106 | valueInList.add(valuein1); |
| 1107 | valueInList.add(valuein2); |
| 1108 | |
| 1109 | // Adds the case value into the choice interface. |
| 1110 | Selection selection = new DefaultValueIn.ValueInBuilder() |
| 1111 | .valueIn(valueInList).build(); |
| 1112 | |
| 1113 | // Augment is created for the object. |
| 1114 | AugmentedRpcOutput augmentRpcOutput = new DefaultAugmentedRpcOutput |
| 1115 | .AugmentedRpcOutputBuilder().selection(selection).build(); |
| 1116 | |
| 1117 | // Create two list object of friction. |
| 1118 | Friction friction1 = new DefaultFriction.FrictionBuilder() |
| 1119 | .speed(BigInteger.valueOf(500)).build(); |
| 1120 | Friction friction2 = new DefaultFriction.FrictionBuilder() |
| 1121 | .speed(BigInteger.valueOf(1000)).build(); |
| 1122 | |
| 1123 | List<Friction> fricList = new ArrayList<>(); |
| 1124 | fricList.add(friction1); |
| 1125 | fricList.add(friction2); |
| 1126 | |
| 1127 | // Create augment with the friction object created. |
| 1128 | AugmentedInputOutput augmentedIO = new DefaultAugmentedInputOutput |
| 1129 | .AugmentedInputOutputBuilder().friction(fricList).build(); |
| 1130 | |
| 1131 | // Creates RPC object. |
| 1132 | List<OutputList> outputLists = createApplicationBuiltObjectForRpc(); |
| 1133 | |
| 1134 | // Adds the augment and the rps output values into the output. |
| 1135 | DefaultActivateSoftwareImageOutput |
| 1136 | .ActivateSoftwareImageOutputBuilder output = |
| 1137 | new DefaultActivateSoftwareImageOutput |
| 1138 | .ActivateSoftwareImageOutputBuilder(); |
| 1139 | output.addYangAugmentedInfo(augmentRpcOutput, AugmentedRpcOutput.class); |
| 1140 | output.addYangAugmentedInfo(augmentedIO, AugmentedInputOutput.class); |
| 1141 | output.outputList(outputLists); |
| 1142 | |
| 1143 | // Builds YANG tree in YTB. |
| 1144 | DefaultYangTreeBuilder treeBuilder = new DefaultYangTreeBuilder(); |
| 1145 | YdtExtendedBuilder ydtBuilder = treeBuilder.getYdtForRpcResponse( |
| 1146 | output, workBench); |
| 1147 | |
| 1148 | // Receives YDT context and check the tree that is built. |
| 1149 | YdtContext context = ydtBuilder.getRootNode(); |
| 1150 | assertThat(getInCrtName(ROOT, RPC_ADV_NAME), context.getName(), |
| 1151 | is(RPC_ADV_NAME)); |
| 1152 | assertThat(getInCrtName(ROOT, RPC_ADV_NAMESPACE), |
| 1153 | context.getNamespace(), is(RPC_ADV_NAMESPACE)); |
| 1154 | |
| 1155 | // Checks the first module from logical root node. |
| 1156 | YdtContext module = context.getFirstChild(); |
| 1157 | assertThat(getInCrtName(MODULE, RPC_ADV_IO), module.getName(), |
| 1158 | is(RPC_ADV_IO)); |
| 1159 | |
| 1160 | // Gets the rpc under module. |
| 1161 | YdtContext rpc = module.getFirstChild(); |
| 1162 | assertThat(getInCrtName(RPC, ACT_IMG), rpc.getName(), is(ACT_IMG)); |
| 1163 | |
| 1164 | // Gets the output value under rpc. |
| 1165 | // TODO: Change assert after YANG utils is merged. |
| 1166 | YdtContext rpcOutputNode = rpc.getFirstChild(); |
| 1167 | //assertThat(rpcOutputNode.getName(), is("output")); |
| 1168 | |
| 1169 | YdtContext firstNode = rpcOutputNode.getFirstChild(); |
| 1170 | assertThat(firstNode, notNullValue()); |
| 1171 | |
| 1172 | YdtContext secondNode = firstNode.getNextSibling(); |
| 1173 | assertThat(secondNode, notNullValue()); |
| 1174 | |
| 1175 | YdtContext thirdNode = secondNode.getNextSibling(); |
| 1176 | assertThat(thirdNode, notNullValue()); |
| 1177 | |
| 1178 | YdtContext fourthNode = thirdNode.getNextSibling(); |
| 1179 | assertThat(fourthNode, notNullValue()); |
| 1180 | |
| 1181 | // Gets the list content 1 as the node from output. |
| 1182 | YdtContext outputList1 = fourthNode.getNextSibling(); |
| 1183 | assertThat(getInCrtName(LIST, OUTPUT_LIST), outputList1.getName(), |
| 1184 | is(OUTPUT_LIST)); |
| 1185 | |
| 1186 | // Gets the leaf key-list from list content1. |
| 1187 | YdtContext keyList1 = outputList1.getFirstChild(); |
| 1188 | assertThat(getInCrtName(LEAF, LIST_KEY), keyList1.getName(), |
| 1189 | is(LIST_KEY)); |
| 1190 | assertThat(getInCrtLeafValue(LIST_KEY, BIN_VAL_1), keyList1.getValue(), |
| 1191 | is(BIN_VAL_1)); |
| 1192 | |
| 1193 | // Gets the content inside container from list content 1. |
| 1194 | YdtContext cont1 = keyList1.getNextSibling(); |
| 1195 | assertThat(getInCrtName(CONTAINER, CONT_INSIDE), cont1.getName(), |
| 1196 | is(CONT_INSIDE)); |
| 1197 | |
| 1198 | // Gets the list content 2 as the node from output. |
| 1199 | YdtContext outputList2 = outputList1.getNextSibling(); |
| 1200 | assertThat(getInCrtName(LIST, OUTPUT_LIST), outputList2.getName(), |
| 1201 | is(OUTPUT_LIST)); |
| 1202 | |
| 1203 | // Gets the leaf-list key-list from list content2. |
| 1204 | YdtContext keyList2 = outputList2.getFirstChild(); |
| 1205 | assertThat(getInCrtName(LEAF, LIST_KEY), keyList2.getName(), |
| 1206 | is(LIST_KEY)); |
| 1207 | assertThat(getInCrtLeafValue(LIST_KEY, BIN_VAL_2), keyList2.getValue(), |
| 1208 | is(BIN_VAL_2)); |
| 1209 | |
| 1210 | // Gets the content inside container from list content 2. |
| 1211 | YdtContext cont2 = keyList2.getNextSibling(); |
| 1212 | assertThat(getInCrtName(CONTAINER, CONT_INSIDE), cont2.getName(), |
| 1213 | is(CONT_INSIDE)); |
| 1214 | |
| 1215 | // Gets the leaf-list available inside container. |
| 1216 | YdtContext availLeafList = cont2.getFirstChild(); |
| 1217 | assertThat(getInCrtName(LEAF_LIST, AVAILABLE), availLeafList.getName(), |
| 1218 | is(AVAILABLE)); |
| 1219 | Set value1 = availLeafList.getValueSet(); |
| 1220 | assertThat(getInCrtLeafListValue(AVAILABLE, EIGHTY_NINE), |
| 1221 | value1.contains(EIGHTY_NINE), is(true)); |
| 1222 | assertThat(getInCrtLeafListValue(AVAILABLE, NINETY_EIGHT), |
| 1223 | value1.contains(NINETY_EIGHT), is(true)); |
| 1224 | |
| 1225 | // Gets the list content 3. |
| 1226 | YdtContext outputList3 = outputList2.getNextSibling(); |
| 1227 | assertThat(getInCrtName(LIST, OUTPUT_LIST), outputList3.getName(), |
| 1228 | is(OUTPUT_LIST)); |
| 1229 | |
| 1230 | // Gets the leaf list-key in content 3 of list. |
| 1231 | YdtContext keyList3 = outputList3.getFirstChild(); |
| 1232 | assertThat(getInCrtName(LEAF, LIST_KEY), keyList3.getName(), |
| 1233 | is(LIST_KEY)); |
| 1234 | assertThat(getInCrtLeafValue(LIST_KEY, BIN_VAL_3), keyList3.getValue(), |
| 1235 | is(BIN_VAL_3)); |
| 1236 | } |
| 1237 | } |