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