ac7b87a9f58ec55128eb8aed96b77220772fcfed
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / test / java / org / opendaylight / controller / md / sal / dom / broker / impl / DataNormalizerTest.java
1 package org.opendaylight.controller.md.sal.dom.broker.impl;
2
3 import static org.junit.Assert.assertNotNull;
4
5 import org.junit.Test;
6 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
7 import org.opendaylight.controller.md.sal.dom.store.impl.TestModel;
8 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
9 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
10 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates;
11 import org.opendaylight.yangtools.yang.data.api.Node;
12 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
14 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
15 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17
18 public class DataNormalizerTest {
19
20     private static final Short OUTER_LIST_ID = (short)10;
21
22     private static final InstanceIdentifier OUTER_LIST_PATH_LEGACY = InstanceIdentifier.builder(TestModel.TEST_QNAME)
23             .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME,OUTER_LIST_ID).build();
24
25     private  static final InstanceIdentifier LEAF_TWO_PATH_LEGACY = InstanceIdentifier.builder(OUTER_LIST_PATH_LEGACY)
26             .node(TestModel.TWO_QNAME).build();
27
28     private static final ChoiceNode OUTER_CHOICE_ITEM = Builders.choiceBuilder()
29             .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_CHOICE_QNAME))
30             .withChild(ImmutableNodes.leafNode(TestModel.TWO_QNAME, "two"))
31             .withChild(ImmutableNodes.leafNode(TestModel.THREE_QNAME, "three"))
32             .build();
33
34     private static final MapEntryNode OUTER_LIST_WITHOUT_CHOICE = Builders.mapEntryBuilder()
35             .withNodeIdentifier(new NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME,OUTER_LIST_ID))
36             .withChild(ImmutableNodes.leafNode(TestModel.ID_QNAME, OUTER_LIST_ID))
37             .build();
38
39     private static final MapEntryNode OUTER_LIST_WITH_CHOICE = Builders.mapEntryBuilder()
40             .withNodeIdentifier(new NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME,OUTER_LIST_ID))
41             .withChild(ImmutableNodes.leafNode(TestModel.ID_QNAME, OUTER_LIST_ID))
42             .withChild(OUTER_CHOICE_ITEM)
43             .build();
44
45     @Test
46     public void test() {
47         SchemaContext testCtx = TestModel.createTestContext();
48         DataNormalizer normalizer = new DataNormalizer(testCtx);
49
50         InstanceIdentifier normalizedPath = normalizer.toNormalized(LEAF_TWO_PATH_LEGACY);
51
52         Node<?> outerListLegacy = DataNormalizer.toLegacy(OUTER_LIST_WITH_CHOICE);
53         assertNotNull(outerListLegacy);
54     }
55
56 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.