import static org.opendaylight.mdsal.binding.generator.impl.SupportTestUtil.containsAttributes;
import static org.opendaylight.mdsal.binding.generator.impl.SupportTestUtil.containsMethods;
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
-import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.Type;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class BitAndUnionTOEnclosingTest {
- private final static List<File> testModels = new ArrayList<>();
private static List<Type> genTypes = null;
private static GeneratedType parentContainer = null;
- public static void parseResources() throws IOException, SourceException, ReactorException {
-
- final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
+ @BeforeClass
+ public static void loadTestResources() {
+ final SchemaContext context = YangParserTestUtils.parseYangResource("/bit_and_union.yang");
assertNotNull(context);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
genTypes = bindingGen.generateTypes(context);
for (Type type : genTypes) {
}
}
- @BeforeClass
- public static void loadTestResources() throws IOException, URISyntaxException, SourceException, ReactorException {
- final File listModelFile = new File(ExtendedTypedefTest.class.getResource("/bit_and_union.yang").toURI());
- testModels.add(listModelFile);
- parseResources();
- }
-
@Test
public void testNestedTypesInLeaf() {
GeneratedTransferObject lfLeaf = null;
if (genType.getName().equals("Lf")) {
lfLeaf = (GeneratedTransferObject) genType;
lfLeafCounter++;
- } else if (genType.getName().equals("Lf1")) {
+ } else if (genType.getName().equals("Lf$1")) {
lf1Leaf = (GeneratedTransferObject) genType;
lf1LeafCounter++;
- } else if (genType.getName().equals("Lf2")) {
+ } else if (genType.getName().equals("Lf$2")) {
lf2Leaf = (GeneratedTransferObject) genType;
lf2LeafCounter++;
}
assertEquals("Lf TO has incorrect number of occurences.", 1, lfLeafCounter);
assertEquals("Lf has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
- lfLeaf.getPackageName());
+ lfLeaf.getIdentifier().immediatelyEnclosingClass().get().toString());
- assertEquals("Lf generated TO has incorrect number of properties", 3, lfLeaf.getProperties().size());
+ assertEquals("Lf generated TO has incorrect number of properties", 2, lfLeaf.getProperties().size());
containsAttributes(lfLeaf, true, true, true, new NameTypePattern("string", "String"));
- containsAttributes(lfLeaf, true, false, true, new NameTypePattern("lf1", "Lf1"));
+ containsAttributes(lfLeaf, true, false, true, new NameTypePattern("lf$1", "Lf$1"));
// nested types in leaf, contains Lf1?
- assertNotNull("Lf1 TO wasn't found.", lf1Leaf);
- assertEquals("Lf1 TO has incorrect number of occurences.", 1, lf1LeafCounter);
- assertEquals("Lf1 has incorrect package name.",
+ assertNotNull("Lf$1 TO wasn't found.", lf1Leaf);
+ assertEquals("Lf$1 TO has incorrect number of occurences.", 1, lf1LeafCounter);
+ assertEquals("Lf$1 has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
- lf1Leaf.getPackageName());
+ lf1Leaf.getIdentifier().immediatelyEnclosingClass().get().toString());
assertEquals("Lf generated TO has incorrect number of properties", 4, lf1Leaf.getProperties().size());
containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("uint32", "Long"));
containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("int8", "Byte"));
containsAttributes(lf1Leaf, true, true, true, new NameTypePattern("string", "String"));
- containsAttributes(lf1Leaf, true, false, true, new NameTypePattern("lf2", "Lf2"));
+ containsAttributes(lf1Leaf, true, false, true, new NameTypePattern("lf$2", "Lf$2"));
// nested types in leaf, contains Lf2?
- assertNotNull("Lf2 TO wasn't found.", lf2Leaf);
- assertEquals("Lf2 TO has incorrect number of occurences.", 1, lf2LeafCounter);
- assertEquals("Lf2 has incorrect package name.",
+ assertNotNull("Lf$2 TO wasn't found.", lf2Leaf);
+ assertEquals("Lf$2 TO has incorrect number of occurences.", 1, lf2LeafCounter);
+ assertEquals("Lf$2 has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
- lf2Leaf.getPackageName());
+ lf2Leaf.getIdentifier().immediatelyEnclosingClass().get().toString());
assertEquals("Lf generated TO has incorrect number of properties", 2, lf2Leaf.getProperties().size());
containsAttributes(lf2Leaf, true, true, true, new NameTypePattern("string", "String"));
for (Type type : genTypes) {
if (type instanceof GeneratedType) {
GeneratedType genType = (GeneratedType) type;
- if (genType.getName().equals("TypeUnion") && (genType instanceof GeneratedTransferObject)) {
+ if (genType.getName().equals("TypeUnion") && genType instanceof GeneratedTransferObject) {
typeUnionTypedef = (GeneratedTransferObject) genType;
typeUnionTypedefCounter++;
}
assertEquals("TypeUnion has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnionTypedef.getPackageName());
- assertEquals("TypeUnion generated TO has incorrect number of properties", 3, typeUnionTypedef.getProperties()
+ assertEquals("TypeUnion generated TO has incorrect number of properties", 2, typeUnionTypedef.getProperties()
.size());
containsAttributes(typeUnionTypedef, true, true, true, new NameTypePattern("string", "String"));
- containsAttributes(typeUnionTypedef, true, false, true, new NameTypePattern("typeUnion1", "TypeUnion1"));
+ containsAttributes(typeUnionTypedef, true, false, true, new NameTypePattern("typeUnion$1", "TypeUnion$1"));
List<GeneratedType> nestedUnions = typeUnionTypedef.getEnclosedTypes();
assertEquals("Incorrect number of nested unions", 2, nestedUnions.size());
int typeUnion2Counter = 0;
for (GeneratedType genType : nestedUnions) {
if (genType instanceof GeneratedTransferObject) {
- if (genType.getName().equals("TypeUnion1")) {
+ if (genType.getName().equals("TypeUnion$1")) {
typeUnion1 = (GeneratedTransferObject) genType;
typeUnion1Counter++;
- } else if (genType.getName().equals("TypeUnion2")) {
+ } else if (genType.getName().equals("TypeUnion$2")) {
typeUnion2 = (GeneratedTransferObject) genType;
typeUnion2Counter++;
}
}
}
- assertNotNull("TypeUnion1 TO wasn't found.", typeUnion1);
- assertEquals("TypeUnion1 TO has incorrect number of occurences.", 1, typeUnion1Counter);
+ assertNotNull("TypeUnion$1 TO wasn't found.", typeUnion1);
+ assertEquals("TypeUnion$1 TO has incorrect number of occurences.", 1, typeUnion1Counter);
- assertEquals("TypeUnion1 has incorrect package name.",
+ assertEquals("TypeUnion$1 has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnion1.getPackageName());
- assertEquals("TypeUnion1 generated TO has incorrect number of properties", 4, typeUnion1.getProperties().size());
+ assertEquals("TypeUnion1 generated TO has incorrect number of properties", 4,
+ typeUnion1.getProperties().size());
containsAttributes(typeUnion1, true, true, true, new NameTypePattern("uint32", "Long"));
containsAttributes(typeUnion1, true, true, true, new NameTypePattern("int8", "Byte"));
containsAttributes(typeUnion1, true, true, true, new NameTypePattern("string", "String"));
- containsAttributes(typeUnion1, true, false, true, new NameTypePattern("typeUnion2", "TypeUnion2"));
+ containsAttributes(typeUnion1, true, false, true, new NameTypePattern("typeUnion$2", "TypeUnion$2"));
- assertNotNull("TypeUnion2 TO wasn't found.", typeUnion2);
- assertEquals("TypeUnion2 TO has incorrect number of occurences.", 1, typeUnion2Counter);
+ assertNotNull("TypeUnion$2 TO wasn't found.", typeUnion2);
+ assertEquals("TypeUnion$2 TO has incorrect number of occurences.", 1, typeUnion2Counter);
- assertEquals("TypeUnion2 has incorrect package name.",
+ assertEquals("TypeUnion$2 has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626", typeUnion2.getPackageName());
- assertEquals("TypeUnion2 generated TO has incorrect number of properties", 2, typeUnion2.getProperties().size());
+ assertEquals("TypeUnion2 generated TO has incorrect number of properties", 2,
+ typeUnion2.getProperties().size());
containsAttributes(typeUnion2, true, true, true, new NameTypePattern("string", "String"));
containsAttributes(typeUnion2, true, true, true, new NameTypePattern("uint64", "BigInteger"));
assertEquals("BitLeaf has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
- bitLeaf.getPackageName());
+ bitLeaf.getIdentifier().immediatelyEnclosingClass().get().toString());
assertEquals("UnionLeaf has incorrect package name.",
"org.opendaylight.yang.gen.v1.urn.bit.union.in.leaf.rev130626.ParentContainer",
- bitLeaf.getPackageName());
+ unionLeaf.getIdentifier().immediatelyEnclosingClass().get().toString());
List<GeneratedProperty> propertiesBitLeaf = bitLeaf.getProperties();
GeneratedProperty firstBitProperty = null;