1 package org.opendaylight.yangtools.it.yang.runtime.tests;
3 import static junit.framework.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
6 import java.util.AbstractMap.SimpleEntry;
7 import java.util.Map.Entry;
9 import javassist.ClassPool;
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;
28 import com.google.common.base.Optional;
30 public class RuntimeCodecAugmentationWithGroupingsAndCasesTest {
32 private static final InstanceIdentifier<ExtWithGroupingAugmentations> GROUPING_AUGMENTATIONS_PATH = InstanceIdentifier
33 .builder(Choices.class).child(ExtWithGroupingAugmentations.class).build();
35 private ModuleInfoBackedContext moduleInfoContext;
37 private Optional<SchemaContext> schemaContext;
39 private RuntimeGeneratedMappingServiceImpl mappingService;
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);
48 moduleInfoContext = ModuleInfoBackedContext.create();
49 moduleInfoContext.registerModuleInfo(yangExtInfo);
50 moduleInfoContext.registerModuleInfo(baseModuleInfo);
51 moduleInfoContext.registerModuleInfo(augmentationModuleInfo);
53 schemaContext = moduleInfoContext.tryToCreateSchemaContext();
54 assertNotNull(schemaContext);
55 assertTrue(schemaContext.isPresent());
57 mappingService = new RuntimeGeneratedMappingServiceImpl(ClassPool.getDefault(), moduleInfoContext);
58 mappingService.onGlobalContextUpdated(schemaContext.get());
63 public void testSerialization() {
65 ExtWithGroupingAugmentations caseData = new ExtWithGroupingAugmentationsBuilder() //
66 .setGroupingData(new GroupingDataBuilder() //
67 .addAugmentation(InUsesAugment.class, new InUsesAugmentBuilder() //
68 .setExtAumentation("InUses") //
73 Entry<org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, CompositeNode> result = mappingService
74 .toDataDom(new SimpleEntry(GROUPING_AUGMENTATIONS_PATH, caseData));
75 assertNotNull(result);