2e8b046fa46f5d0d6aaba02eca6e09aaa9817078
[yangtools.git] / integration-test / yang-runtime-tests / src / test / java / org / opendaylight / yangtools / it / yang / runtime / tests / RuntimeCodecAugmentationWithGroupingsAndCasesTest.java
1 package org.opendaylight.yangtools.it.yang.runtime.tests;
2
3 import static junit.framework.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5
6 import java.util.AbstractMap.SimpleEntry;
7 import java.util.Map.Entry;
8
9 import javassist.ClassPool;
10
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.RpcContextRef;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.test.regression.augmentation.base.rev140424.Choices;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.test.regression.augmentation.base.rev140424.grouping.GroupingDataBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.test.regression.augmentation.ext.rev140424.choices.augmentable.choice.ext.with.grouping.augmentations.ExtWithGroupingAugmentations;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.test.regression.augmentation.ext.rev140424.choices.augmentable.choice.ext.with.grouping.augmentations.ExtWithGroupingAugmentationsBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.test.regression.augmentation.ext.rev140424.choices.augmentable.choice.ext.with.grouping.augmentations.ext.with.grouping.augmentations.InUsesAugment;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.test.regression.augmentation.ext.rev140424.choices.augmentable.choice.ext.with.grouping.augmentations.ext.with.grouping.augmentations.InUsesAugmentBuilder;
20 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
21 import org.opendaylight.yangtools.sal.binding.generator.impl.RuntimeGeneratedMappingServiceImpl;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
24 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
25 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27
28 import com.google.common.base.Optional;
29
30 public class RuntimeCodecAugmentationWithGroupingsAndCasesTest {
31
32     private static final InstanceIdentifier<ExtWithGroupingAugmentations> GROUPING_AUGMENTATIONS_PATH = InstanceIdentifier
33             .builder(Choices.class).child(ExtWithGroupingAugmentations.class).build();
34
35     private ModuleInfoBackedContext moduleInfoContext;
36
37     private Optional<SchemaContext> schemaContext;
38
39     private RuntimeGeneratedMappingServiceImpl mappingService;
40
41
42     @Before
43     public void setUp() throws Exception {
44         YangModuleInfo yangExtInfo = BindingReflections.getModuleInfo(RpcContextRef.class);
45         YangModuleInfo baseModuleInfo = BindingReflections.getModuleInfo(Choices.class);
46         YangModuleInfo augmentationModuleInfo = BindingReflections.getModuleInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.yang.test.regression.augmentation.ext.rev140424.choices.augmentable.choice.ext.with.grouping.augmentations.ExtWithGroupingAugmentations.class);
47
48         moduleInfoContext = ModuleInfoBackedContext.create();
49         moduleInfoContext.registerModuleInfo(yangExtInfo);
50         moduleInfoContext.registerModuleInfo(baseModuleInfo);
51         moduleInfoContext.registerModuleInfo(augmentationModuleInfo);
52
53         schemaContext = moduleInfoContext.tryToCreateSchemaContext();
54         assertNotNull(schemaContext);
55         assertTrue(schemaContext.isPresent());
56
57         mappingService = new RuntimeGeneratedMappingServiceImpl(ClassPool.getDefault(), moduleInfoContext);
58         mappingService.onGlobalContextUpdated(schemaContext.get());
59
60     }
61
62     @Test
63     public void testSerialization() {
64
65         ExtWithGroupingAugmentations caseData = new ExtWithGroupingAugmentationsBuilder() //
66                 .setGroupingData(new GroupingDataBuilder() //
67                         .addAugmentation(InUsesAugment.class, new InUsesAugmentBuilder() //
68                                 .setExtAumentation("InUses") //
69                                 .build()) //
70                         .build()) //
71                 .build();
72
73         Entry<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode> result = mappingService
74                 .toDataDom(new SimpleEntry(GROUPING_AUGMENTATIONS_PATH, caseData));
75         assertNotNull(result);
76     }
77 }