BUG-1092: adjust to YangInstanceIdentifier
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / BindingNormalizedCodecTest.java
1 package org.opendaylight.controller.md.sal.binding.impl.test;
2
3 import static org.junit.Assert.assertTrue;
4 import javassist.ClassPool;
5
6 import org.junit.Test;
7 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
8 import org.opendaylight.controller.md.sal.binding.test.AbstractSchemaAwareTest;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyAugment;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
14 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20
21 public class BindingNormalizedCodecTest extends AbstractSchemaAwareTest {
22
23     private static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
24     private static final InstanceIdentifier<TopLevelList> BA_TOP_LEVEL_LIST = InstanceIdentifier
25             .builder(Top.class).child(TopLevelList.class, TOP_FOO_KEY).toInstance();
26     private static final InstanceIdentifier<TreeLeafOnlyAugment> BA_TREE_LEAF_ONLY = BA_TOP_LEVEL_LIST.augmentation(TreeLeafOnlyAugment.class);
27     private static final InstanceIdentifier<TreeComplexUsesAugment> BA_TREE_COMPLEX_USES = BA_TOP_LEVEL_LIST.augmentation(TreeComplexUsesAugment.class);
28     private static final QName SIMPLE_VALUE_QNAME = QName.create(TreeComplexUsesAugment.QNAME, "simple-value");
29
30
31     private RuntimeGeneratedMappingServiceImpl mappingService;
32     private BindingToNormalizedNodeCodec codec;
33
34     @Override
35     protected void setupWithSchema(final SchemaContext context) {
36         mappingService = new RuntimeGeneratedMappingServiceImpl(ClassPool.getDefault());
37         codec = new BindingToNormalizedNodeCodec(mappingService);
38         mappingService.onGlobalContextUpdated(context);
39         codec.onGlobalContextUpdated(context);
40     };
41
42     @Test
43     public void testComplexAugmentationSerialization() {
44
45         PathArgument lastArg = codec.toNormalized(BA_TREE_COMPLEX_USES).getLastPathArgument();
46         assertTrue(lastArg instanceof AugmentationIdentifier);
47     }
48
49
50     @Test
51     public void testLeafOnlyAugmentationSerialization() {
52
53         PathArgument leafOnlyLastArg = codec.toNormalized(BA_TREE_LEAF_ONLY).getLastPathArgument();
54         assertTrue(leafOnlyLastArg instanceof AugmentationIdentifier);
55         assertTrue(((AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
56     }
57
58 }

©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.