5ad474a9a3455872452005179973f618426bf29c
[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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyAugment;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugment;
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.InstanceIdentifier.AugmentationIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.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<TreeLeafOnlyUsesAugment> BA_TREE_LEAF_ONLY_USES = BA_TOP_LEVEL_LIST.augmentation(TreeLeafOnlyUsesAugment.class);
28     private static final InstanceIdentifier<TreeComplexUsesAugment> BA_TREE_COMPLEX_USES = BA_TOP_LEVEL_LIST.augmentation(TreeComplexUsesAugment.class);
29     private static final QName SIMPLE_VALUE_QNAME = QName.create(TreeComplexUsesAugment.QNAME, "simple-value");
30
31
32     private RuntimeGeneratedMappingServiceImpl mappingService;
33     private BindingToNormalizedNodeCodec codec;
34
35     @Override
36     protected void setupWithSchema(final SchemaContext context) {
37         mappingService = new RuntimeGeneratedMappingServiceImpl(ClassPool.getDefault());
38         codec = new BindingToNormalizedNodeCodec(mappingService);
39         mappingService.onGlobalContextUpdated(context);
40         codec.onGlobalContextUpdated(context);
41     };
42
43     @Test
44     public void testComplexAugmentationSerialization() {
45
46         PathArgument lastArg = codec.toNormalized(BA_TREE_COMPLEX_USES).getLastPathArgument();
47         assertTrue(lastArg instanceof AugmentationIdentifier);
48     }
49
50
51     @Test
52     public void testLeafOnlyAugmentationSerialization() {
53
54         PathArgument leafOnlyLastArg = codec.toNormalized(BA_TREE_LEAF_ONLY).getLastPathArgument();
55         assertTrue(leafOnlyLastArg instanceof AugmentationIdentifier);
56         assertTrue(((AugmentationIdentifier) leafOnlyLastArg).getPossibleChildNames().contains(SIMPLE_VALUE_QNAME));
57     }
58
59 }

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