+ @Test
+ public void testNestedUnionResolving2() {
+ Module testModule = TestUtils.findModule(modules, "types1");
+
+ LeafSchemaNode testleaf = (LeafSchemaNode) testModule
+ .getDataChildByName("custom-union-leaf");
+
+ ExtendedType testleafType = (ExtendedType) testleaf.getType();
+ QName testleafTypeQName = testleafType.getQName();
+ assertEquals(URI.create("urn:simple.container.demo.test"),
+ testleafTypeQName.getNamespace());
+ assertEquals(TestUtils.createDate("2013-02-27"),
+ testleafTypeQName.getRevision());
+ assertEquals("t3", testleafTypeQName.getPrefix());
+ assertEquals("union1", testleafTypeQName.getLocalName());
+
+ ExtendedType union2 = (ExtendedType) testleafType.getBaseType();
+ QName union2QName = union2.getQName();
+ assertEquals(URI.create("urn:simple.container.demo.test"),
+ union2QName.getNamespace());
+ assertEquals(TestUtils.createDate("2013-02-27"),
+ union2QName.getRevision());
+ assertEquals("t3", union2QName.getPrefix());
+ assertEquals("union2", union2QName.getLocalName());
+
+ UnionType union2Base = (UnionType) union2.getBaseType();
+ List<TypeDefinition<?>> unionTypes = union2Base.getTypes();
+ assertEquals(2, unionTypes.size());
+ assertTrue(unionTypes.get(0) instanceof Int32);
+ assertTrue(unionTypes.get(1) instanceof ExtendedType);
+
+ ExtendedType nestedUnion2 = (ExtendedType) unionTypes.get(1);
+ QName nestedUnion2QName = nestedUnion2.getQName();
+ assertEquals(URI.create("urn:simple.types.data.demo"),
+ nestedUnion2QName.getNamespace());
+ assertEquals(TestUtils.createDate("2013-02-27"),
+ nestedUnion2QName.getRevision());
+ assertEquals("t2", nestedUnion2QName.getPrefix());
+ assertEquals("nested-union2", nestedUnion2QName.getLocalName());
+
+ UnionType nestedUnion2Base = (UnionType) nestedUnion2.getBaseType();
+ List<TypeDefinition<?>> nestedUnion2Types = nestedUnion2Base.getTypes();
+ assertEquals(2, nestedUnion2Types.size());
+ assertTrue(nestedUnion2Types.get(0) instanceof StringType);
+ assertTrue(nestedUnion2Types.get(1) instanceof ExtendedType);
+
+ ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1);
+ QName myUnionExtQName = myUnionExt.getQName();
+ assertEquals(URI.create("urn:simple.types.data.demo"),
+ myUnionExtQName.getNamespace());
+ assertEquals(TestUtils.createDate("2013-02-27"),
+ myUnionExtQName.getRevision());
+ assertEquals("t2", myUnionExtQName.getPrefix());
+ assertEquals("my-union-ext", myUnionExtQName.getLocalName());
+
+ ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType();
+ QName myUnionQName = myUnion.getQName();
+ assertEquals(URI.create("urn:simple.types.data.demo"),
+ myUnionQName.getNamespace());
+ assertEquals(TestUtils.createDate("2013-02-27"),
+ myUnionQName.getRevision());
+ assertEquals("t2", myUnionQName.getPrefix());
+ assertEquals("my-union", myUnionQName.getLocalName());
+
+ UnionType myUnionBase = (UnionType) myUnion.getBaseType();
+ List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
+ assertEquals(2, myUnionBaseTypes.size());
+ assertTrue(myUnionBaseTypes.get(0) instanceof Int16);
+ assertTrue(myUnionBaseTypes.get(1) instanceof Int32);
+ Int16 int16 = (Int16) myUnionBaseTypes.get(0);
+ List<RangeConstraint> ranges = int16.getRangeStatements();
+ assertEquals(1, ranges.size());
+ RangeConstraint range = ranges.get(0);
+ assertEquals(1L, range.getMin());
+ assertEquals(100L, range.getMax());
+ }
+
+ @Test
+ public void testRefine() {
+ Module testModule = TestUtils.findModule(modules, "types2");
+
+ ContainerSchemaNode peer = (ContainerSchemaNode) testModule
+ .getDataChildByName("peer");
+ ContainerSchemaNode destination = (ContainerSchemaNode) peer
+ .getDataChildByName("destination");
+ Set<UsesNode> usesNodes = destination.getUses();
+ assertEquals(1, usesNodes.size());
+ UsesNode usesNode = usesNodes.iterator().next();
+ Map<SchemaPath, SchemaNode> refines = usesNode.getRefines();
+ assertEquals(2, refines.size());
+
+ for (Map.Entry<SchemaPath, SchemaNode> entry : refines.entrySet()) {
+ SchemaNode value = entry.getValue();
+
+ if (value instanceof LeafSchemaNode) {
+ LeafSchemaNode refineLeaf = (LeafSchemaNode) value;
+ assertNotNull(refineLeaf);
+ } else {
+ ContainerSchemaNode refineContainer = (ContainerSchemaNode) value;
+ Set<MustDefinition> mustConstraints = refineContainer
+ .getConstraints().getMustConstraints();
+ assertEquals(1, mustConstraints.size());
+ MustDefinition must = mustConstraints.iterator().next();
+ assertEquals("must-condition", must.toString());
+ assertEquals("An error message test", must.getErrorMessage());
+ assertEquals(("An error app tag test"), must.getErrorAppTag());