f595dc5b8b5f801ef9283b7464262759658c7382
[mdsal.git] / binding / mdsal-binding-dom-codec / src / test / java / org / opendaylight / yangtools / binding / data / codec / test / NormalizedNodeSerializeDeserializeTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  *  and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.binding.data.codec.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.top;
12 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.topLevelList;
13 import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.augmentationBuilder;
14 import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.choiceBuilder;
15 import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.containerBuilder;
16 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode;
17 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry;
18 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
19 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
20
21 import com.google.common.collect.Sets;
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27 import javassist.ClassPool;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TopChoiceAugment1;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TopChoiceAugment1Builder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TopChoiceAugment2;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TopChoiceAugment2Builder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeLeafOnlyAugment;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeLeafOnlyAugmentBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.AugmentChoice1;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.augment.choice1.Case1Builder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.augment.choice1.case1.augment.choice2.Case11Builder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.top.augment.choice1.case1.augment.choice2.case11.Case11ChoiceCaseContainerBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.ChoiceContainer;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.ChoiceContainerBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TopBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.choice.identifier.ExtendedBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.choice.identifier.extended.ExtendedIdBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedList;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListKey;
53 import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
54 import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
55 import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils;
56 import org.opendaylight.yangtools.yang.binding.DataObject;
57 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
58 import org.opendaylight.yangtools.yang.common.QName;
59 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
60 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
61 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
62 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
63 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
64 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder;
65 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
66 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
67 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
68 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
69 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
70 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
71
72 public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingRuntimeTest{
73
74     public static final String TOP_LEVEL_LIST_FOO_KEY_VALUE = "foo";
75     public static final TopLevelListKey TOP_LEVEL_LIST_FOO_KEY = new TopLevelListKey(TOP_LEVEL_LIST_FOO_KEY_VALUE);
76
77     public static final QName TOP_QNAME = Top.QNAME;
78     public static final QName TOP_LEVEL_LIST_QNAME = QName.create(TOP_QNAME, "top-level-list");
79     public static final QName TOP_LEVEL_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
80     public static final QName TOP_LEVEL_LEAF_LIST_QNAME = QName.create(TOP_QNAME, "top-level-leaf-list");
81     public static final QName NESTED_LIST_QNAME = QName.create(TOP_QNAME, "nested-list");
82     public static final QName NESTED_LIST_KEY_QNAME = QName.create(TOP_QNAME, "name");
83     public static final QName CHOICE_CONTAINER_QNAME = ChoiceContainer.QNAME;
84     public static final QName CHOICE_IDENTIFIER_QNAME = QName.create(CHOICE_CONTAINER_QNAME, "identifier");
85     public static final QName CHOICE_IDENTIFIER_ID_QNAME = QName.create(CHOICE_CONTAINER_QNAME, "id");
86     public static final QName SIMPLE_ID_QNAME = QName.create(CHOICE_CONTAINER_QNAME, "simple-id");
87     public static final QName EXTENDED_ID_QNAME = QName.create(CHOICE_CONTAINER_QNAME, "extended-id");
88     private static final QName SIMPLE_VALUE_QNAME = QName.create(TreeComplexUsesAugment.QNAME, "simple-value");
89
90     private static final InstanceIdentifier<TopLevelList> BA_TOP_LEVEL_LIST = InstanceIdentifier
91             .builder(Top.class).child(TopLevelList.class, TOP_LEVEL_LIST_FOO_KEY).build();
92     private static final InstanceIdentifier<TreeLeafOnlyAugment> BA_TREE_LEAF_ONLY =
93             BA_TOP_LEVEL_LIST.augmentation(TreeLeafOnlyAugment.class);
94     private static final InstanceIdentifier<TreeComplexUsesAugment> BA_TREE_COMPLEX_USES =
95             BA_TOP_LEVEL_LIST.augmentation(TreeComplexUsesAugment.class);
96
97     public static final YangInstanceIdentifier BI_TOP_PATH = YangInstanceIdentifier.of(TOP_QNAME);
98     public static final YangInstanceIdentifier BI_TOP_LEVEL_LIST_PATH = BI_TOP_PATH.node(TOP_LEVEL_LIST_QNAME);
99     public static final YangInstanceIdentifier BI_TOP_LEVEL_LIST_FOO_PATH = BI_TOP_LEVEL_LIST_PATH
100             .node(new YangInstanceIdentifier.NodeIdentifierWithPredicates(TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE));
101     public static final YangInstanceIdentifier BI_CHOICE_CONTAINER_PATH = YangInstanceIdentifier.of(CHOICE_CONTAINER_QNAME);
102
103     private BindingNormalizedNodeCodecRegistry registry;
104
105     @Override
106     @Before
107     public void setup() {
108         super.setup();
109         final JavassistUtils utils = JavassistUtils.forClassPool(ClassPool.getDefault());
110         registry = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(utils));
111         registry.onBindingRuntimeContextUpdated(getRuntimeContext());
112     }
113
114     @Test
115     public void containerToNormalized() {
116         final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
117                 registry.toNormalizedNode(InstanceIdentifier.create(Top.class), top());
118         final ContainerNode topNormalized = ImmutableContainerNodeBuilder.create()
119                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
120                 .withChild(mapNodeBuilder(TOP_LEVEL_LIST_QNAME).build()).build();
121         assertEquals(topNormalized, entry.getValue());
122     }
123
124     @Test
125     public void containerFromNormalized() {
126         final ContainerNode topNormalized = ImmutableContainerNodeBuilder.create()
127                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
128                 .withChild(mapNodeBuilder(TOP_LEVEL_LIST_QNAME).build()).build();
129         final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topNormalized);
130         assertEquals(top(), entry.getValue());
131     }
132
133     @Test
134     public void listWithKeysToNormalized() {
135         final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
136                 registry.toNormalizedNode(BA_TOP_LEVEL_LIST, topLevelList(TOP_LEVEL_LIST_FOO_KEY));
137         final MapEntryNode topLevelListNormalized = ImmutableMapEntryNodeBuilder.create()
138                 .withNodeIdentifier(
139                         new YangInstanceIdentifier.NodeIdentifierWithPredicates(
140                                 TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
141                 .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
142                 .build();
143         assertEquals(topLevelListNormalized, entry.getValue());
144     }
145
146     @Test
147     public void listWithKeysFromNormalized() {
148         final MapEntryNode topLevelListNormalized = ImmutableMapEntryNodeBuilder.create()
149                 .withNodeIdentifier(
150                         new YangInstanceIdentifier.NodeIdentifierWithPredicates(
151                                 TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
152                 .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
153                 .build();
154         final Map.Entry<InstanceIdentifier<?>, DataObject> entry =
155                 registry.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH, topLevelListNormalized);
156         assertEquals(topLevelList(TOP_LEVEL_LIST_FOO_KEY), entry.getValue());
157     }
158
159     @Test
160     public void leafOnlyAugmentationToNormalized() {
161         final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
162                 registry.toNormalizedNode(BA_TREE_LEAF_ONLY, new TreeLeafOnlyAugmentBuilder().setSimpleValue("simpleValue").build());
163         final Set<QName> augmentationChildren = new HashSet<>();
164         augmentationChildren.add(SIMPLE_VALUE_QNAME);
165         final AugmentationNode augmentationNode = ImmutableAugmentationNodeBuilder.create()
166                 .withNodeIdentifier(new YangInstanceIdentifier.AugmentationIdentifier(augmentationChildren))
167                 .withChild(leafNode(SIMPLE_VALUE_QNAME, "simpleValue"))
168                 .build();
169         assertEquals(augmentationNode, entry.getValue());
170     }
171
172     @Test
173     public void leafOnlyAugmentationFromNormalized() {
174         final Set<QName> augmentationChildren = new HashSet<>();
175         augmentationChildren.add(SIMPLE_VALUE_QNAME);
176         final AugmentationNode augmentationNode = ImmutableAugmentationNodeBuilder.create()
177                 .withNodeIdentifier(new YangInstanceIdentifier.AugmentationIdentifier(augmentationChildren))
178                 .withChild(leafNode(SIMPLE_VALUE_QNAME, "simpleValue"))
179                 .build();
180         final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH.node(
181                 new YangInstanceIdentifier.AugmentationIdentifier(augmentationChildren)), augmentationNode);
182         assertEquals(new TreeLeafOnlyAugmentBuilder().setSimpleValue("simpleValue").build(), entry.getValue());
183     }
184
185     @Test
186     public void leafListToNormalized() {
187         final List<String> topLevelLeafList = new ArrayList<>();
188         topLevelLeafList.add("foo");
189         final Top top = new TopBuilder().setTopLevelLeafList(topLevelLeafList).build();
190
191         final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
192                 registry.toNormalizedNode(InstanceIdentifier.create(Top.class), top);
193         final ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
194                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
195                 .withChild(ImmutableLeafSetNodeBuilder.create()
196                         .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_LEVEL_LEAF_LIST_QNAME))
197                         .withChild(
198                                 ImmutableLeafSetEntryNodeBuilder.create()
199                                         .withNodeIdentifier(new YangInstanceIdentifier.NodeWithValue(TOP_LEVEL_LEAF_LIST_QNAME, "foo"))
200                                         .withValue("foo")
201                                         .build())
202                         .build())
203                 .build();
204         assertEquals(containerNode, entry.getValue());
205     }
206
207     @Test
208     public void leafListFromNormalized() {
209         final ContainerNode topWithLeafList = ImmutableContainerNodeBuilder.create()
210                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
211                 .withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_LEVEL_LEAF_LIST_QNAME))
212                         .withChild(ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
213                                 new YangInstanceIdentifier.NodeWithValue(TOP_LEVEL_LEAF_LIST_QNAME, "foo")).withValue("foo").build()).build())
214                 .build();
215         final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_PATH, topWithLeafList);
216         final List<String> topLevelLeafList = new ArrayList<>();
217         topLevelLeafList.add("foo");
218         final Top top = new TopBuilder().setTopLevelLeafList(topLevelLeafList).build();
219         assertEquals(top, entry.getValue());
220     }
221
222     @Test
223     public void choiceToNormalized() {
224         final ChoiceContainer choiceContainerBA = new ChoiceContainerBuilder().setIdentifier(new ExtendedBuilder().setExtendedId(
225                 new ExtendedIdBuilder().setId("identifier_value").build()).build()).build();
226         final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry =
227                 registry.toNormalizedNode(InstanceIdentifier.create(ChoiceContainer.class), choiceContainerBA);
228         final ContainerNode choiceContainer = ImmutableContainerNodeBuilder.create()
229                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_CONTAINER_QNAME))
230                 .withChild(ImmutableChoiceNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_IDENTIFIER_QNAME))
231                         .withChild(ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(EXTENDED_ID_QNAME))
232                                 .withChild(leafNode(CHOICE_IDENTIFIER_ID_QNAME, "identifier_value")).build()).build())
233                 .build();
234         assertEquals(choiceContainer, entry.getValue());
235     }
236
237     @Test
238     public void choiceFromNormalized() {
239         final ContainerNode choiceContainerBI = ImmutableContainerNodeBuilder.create()
240                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_CONTAINER_QNAME))
241                 .withChild(ImmutableChoiceNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_IDENTIFIER_QNAME))
242                         .withChild(ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(EXTENDED_ID_QNAME))
243                                 .withChild(leafNode(CHOICE_IDENTIFIER_ID_QNAME, "identifier_value")).build()).build())
244                 .build();
245         final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_CHOICE_CONTAINER_PATH, choiceContainerBI);
246         final ChoiceContainer choiceContainerBA = new ChoiceContainerBuilder().setIdentifier(new ExtendedBuilder().setExtendedId(
247                 new ExtendedIdBuilder().setId("identifier_value").build()).build()).build();
248         assertEquals(choiceContainerBA, entry.getValue());
249     }
250
251     @Test
252     public void orderedLisToNormalized() {
253         final InstanceIdentifier<TopLevelList> ii = BA_TOP_LEVEL_LIST;
254         final List<NestedList> nestedLists = new ArrayList<>();
255         nestedLists.add(new NestedListBuilder().setKey(new NestedListKey("foo")).build());
256         nestedLists.add(new NestedListBuilder().setKey(new NestedListKey("bar")).build());
257         final TopLevelList topLevelList = new TopLevelListBuilder().setKey(TOP_LEVEL_LIST_FOO_KEY).setNestedList(nestedLists).build();
258         final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = registry.toNormalizedNode(ii, topLevelList);
259         final MapEntryNode foo = mapEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
260                 TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
261                 .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
262                 .withChild(
263                         ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME))
264                                 .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "foo"))
265                                 .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "bar")).build()).build();
266         assertEquals(foo, entry.getValue());
267     }
268
269     @Test
270     public void orderedLisFromNormalized() {
271         final MapEntryNode foo = mapEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(
272                 TOP_LEVEL_LIST_QNAME, TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
273                 .withChild(leafNode(TOP_LEVEL_LIST_KEY_QNAME, TOP_LEVEL_LIST_FOO_KEY_VALUE))
274                 .withChild(
275                         ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME))
276                                 .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "foo"))
277                                 .withChild(mapEntry(NESTED_LIST_QNAME, NESTED_LIST_KEY_QNAME, "bar")).build()).build();
278         final InstanceIdentifier<TopLevelList> ii = BA_TOP_LEVEL_LIST;
279
280         final Map.Entry<InstanceIdentifier<?>, DataObject> entry = registry.fromNormalizedNode(BI_TOP_LEVEL_LIST_FOO_PATH, foo);
281         final List<NestedList> nestedLists = new ArrayList<>();
282         nestedLists.add(new NestedListBuilder().setKey(new NestedListKey("foo")).build());
283         nestedLists.add(new NestedListBuilder().setKey(new NestedListKey("bar")).build());
284         final TopLevelList topLevelList = new TopLevelListBuilder().setKey(TOP_LEVEL_LIST_FOO_KEY).setNestedList(nestedLists).build();
285         assertEquals(topLevelList, entry.getValue());
286     }
287
288     @Test
289     public void augmentMultipleChoices() {
290         final QName augmentChoice1QName = AugmentChoice1.QNAME;
291         final QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
292         final QName containerQName = QName.create(augmentChoice1QName, "case11-choice-case-container");
293         final QName leafQName = QName.create(augmentChoice1QName, "case11-choice-case-leaf");
294
295         final YangInstanceIdentifier.AugmentationIdentifier aug1Id =
296                 new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(augmentChoice1QName));
297         final YangInstanceIdentifier.AugmentationIdentifier aug2Id =
298                 new YangInstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(augmentChoice2QName));
299         final YangInstanceIdentifier.NodeIdentifier augmentChoice1Id =
300                 new YangInstanceIdentifier.NodeIdentifier(augmentChoice1QName);
301         final YangInstanceIdentifier.NodeIdentifier augmentChoice2Id =
302                 new YangInstanceIdentifier.NodeIdentifier(augmentChoice2QName);
303         final YangInstanceIdentifier.NodeIdentifier containerId =
304                 new YangInstanceIdentifier.NodeIdentifier(containerQName);
305
306         final TopBuilder tBuilder = new TopBuilder();
307         final TopChoiceAugment1Builder tca1Builder = new TopChoiceAugment1Builder();
308         final Case1Builder c1Builder = new Case1Builder();
309         final TopChoiceAugment2Builder tca2Builder = new TopChoiceAugment2Builder();
310         final Case11Builder c11Builder = new Case11Builder();
311         final Case11ChoiceCaseContainerBuilder cccc1Builder = new Case11ChoiceCaseContainerBuilder();
312         cccc1Builder.setCase11ChoiceCaseLeaf("leaf-value");
313         c11Builder.setCase11ChoiceCaseContainer(cccc1Builder.build());
314         tca2Builder.setAugmentChoice2(c11Builder.build());
315         c1Builder.addAugmentation(TopChoiceAugment2.class, tca2Builder.build());
316         tca1Builder.setAugmentChoice1(c1Builder.build());
317         tBuilder.addAugmentation(TopChoiceAugment1.class, tca1Builder.build());
318         final Top top = tBuilder.build();
319
320         final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> biResult =
321                 registry.toNormalizedNode(InstanceIdentifier.create(Top.class), top);
322
323         final NormalizedNode<?, ?> topNormalized =
324                 containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_QNAME))
325                 .withChild(augmentationBuilder().withNodeIdentifier(aug1Id)
326                         .withChild(choiceBuilder().withNodeIdentifier(augmentChoice1Id)
327                                 .withChild(augmentationBuilder().withNodeIdentifier(aug2Id)
328                                         .withChild(choiceBuilder().withNodeIdentifier(augmentChoice2Id)
329                                                 .withChild(containerBuilder().withNodeIdentifier(containerId)
330                                                         .withChild(leafNode(leafQName, "leaf-value"))
331                                                         .build())
332                                                 .build())
333                                         .build())
334                                 .build())
335                         .build()).build();
336
337         assertEquals(BI_TOP_PATH, biResult.getKey());
338         assertEquals(topNormalized, biResult.getValue());
339
340         final Map.Entry<InstanceIdentifier<?>, DataObject> baResult = registry.fromNormalizedNode(BI_TOP_PATH, topNormalized);
341
342         assertEquals(InstanceIdentifier.create(Top.class), baResult.getKey());
343         assertEquals(top, baResult.getValue());
344     }
345 }