+ @Test
+ public void testTypedefUnion() {
+ Set<Module> modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2);
+ assertEquals(2, modules.size());
+
+ Module testModule = findModule(modules, "types1");
+ assertNotNull(testModule);
+
+ LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("union-leaf");
+ ExtendedType testleafType = (ExtendedType)testleaf.getType();
+ assertEquals("my-union-ext", testleafType.getQName().getLocalName());
+
+ ExtendedType baseType = (ExtendedType)testleafType.getBaseType();
+ assertEquals("my-union", baseType.getQName().getLocalName());
+
+ UnionType unionBase = (UnionType) baseType.getBaseType();
+
+ List<TypeDefinition<?>> unionTypes = unionBase.getTypes();
+ Int16 unionType1 = (Int16)unionTypes.get(0);
+ List<RangeConstraint> ranges = unionType1.getRangeStatements();
+ assertEquals(1, ranges.size());
+ RangeConstraint range = ranges.get(0);
+ assertEquals(1L, range.getMin());
+ assertEquals(100L, range.getMax());
+
+ assertTrue(unionTypes.get(0) instanceof Int16);
+ assertTrue(unionTypes.get(1) instanceof Int32);
+ }
+
+ @Test
+ public void testNestedUnionResolving() {
+ Set<Module> modules = tested.parseYangModels(TEST_FILE1, TEST_FILE2);
+ assertEquals(2, modules.size());
+
+ Module testModule = findModule(modules, "types1");
+ assertNotNull(testModule);
+
+ LeafSchemaNode testleaf = (LeafSchemaNode)testModule.getDataChildByName("nested-union-leaf");
+
+ ExtendedType nestedUnion1 = (ExtendedType)testleaf.getType();
+ assertEquals("nested-union1", nestedUnion1.getQName().getLocalName());
+
+ ExtendedType nestedUnion2 = (ExtendedType)nestedUnion1.getBaseType();
+ assertEquals("nested-union2", nestedUnion2.getQName().getLocalName());
+
+ UnionType unionType1 = (UnionType)nestedUnion2.getBaseType();
+ List<TypeDefinition<?>> unionTypes = unionType1.getTypes();
+ assertEquals(2, unionTypes.size());
+ assertTrue(unionTypes.get(0) instanceof StringType);
+ assertTrue(unionTypes.get(1) instanceof ExtendedType);
+
+ ExtendedType extendedUnion = (ExtendedType)unionTypes.get(1);
+ ExtendedType extendedUnionBase = (ExtendedType)extendedUnion.getBaseType();
+ assertEquals("my-union", extendedUnionBase.getQName().getLocalName());
+
+ UnionType extendedTargetUnion = (UnionType)extendedUnionBase.getBaseType();
+ List<TypeDefinition<?>> extendedTargetTypes = extendedTargetUnion.getTypes();
+ assertTrue(extendedTargetTypes.get(0) instanceof Int16);
+ assertTrue(extendedTargetTypes.get(1) instanceof Int32);
+
+ Int16 int16 = (Int16) extendedTargetTypes.get(0);
+ List<RangeConstraint> ranges = int16.getRangeStatements();
+ assertEquals(1, ranges.size());
+ RangeConstraint range = ranges.get(0);
+ assertEquals(1L, range.getMin());
+ assertEquals(100L, range.getMax());
+ }
+
+ private Module findModule(Set<Module> modules, String moduleName) {
+ Module result = null;
+ for(Module module : modules) {
+ if(module.getName().equals(moduleName)) {
+ result = module;
+ break;
+ }
+ }
+ return result;
+ }
+