@Test
public void testComplexFeatureType() throws Exception {

    String res = "/test-data/complexFeature.xsd";
    URL resource = getClass().getResource(res);
    SchemaIndex schemaIndex = EmfAppSchemaReader.newInstance().parse(resource);
    
    AppSchemaFeatureTypeRegistry typeRegistry = new AppSchemaFeatureTypeRegistry();
    try {
        typeRegistry.addSchemas(schemaIndex);
        
        Name typeName = Types.typeName(NS_URI, "wq_plus_Type");
        AttributeType type = (AttributeType) typeRegistry.getAttributeType(typeName);
        Assert.assertTrue(type instanceof FeatureType);
        Assert.assertFalse(type instanceof SimpleFeatureType);
        Assert.assertEquals(typeName, type.getName());
        Assert.assertTrue(type.getUserData().get(XSDTypeDefinition.class) instanceof XSDComplexTypeDefinition);

        FeatureType wq_plus_Type = (FeatureType) type;

        // I do not think types have default geometries any more.
        // assertNotNull(wq_plus_Type.getDefaultGeometry());
        Assert.assertNotNull(wq_plus_Type.getSuper());
        typeName = Types.typeName(GML.NAMESPACE, GML.AbstractFeatureType.getLocalPart());
        Assert.assertEquals(typeName, wq_plus_Type.getSuper().getName());
        Assert.assertNotNull(wq_plus_Type.getDescriptors());
        Assert.assertEquals(8, ((ComplexFeatureTypeImpl) wq_plus_Type).getTypeDescriptors().size());

        Name name = Types.typeName(NS_URI, "wq_plus");
        AttributeDescriptor wqPlusDescriptor = typeRegistry.getDescriptor(name, null);
        Assert.assertNotNull(wqPlusDescriptor);
        Assert.assertEquals(name, wqPlusDescriptor.getName());
        Assert.assertSame(wq_plus_Type, wqPlusDescriptor.getType());
        Assert.assertTrue(wqPlusDescriptor.getUserData().get(XSDElementDeclaration.class) instanceof XSDElementDeclaration);

        typeName = Types.typeName(NS_URI, "measurementType");
        type = typeRegistry.getAttributeType(typeName);
        Assert.assertTrue(type instanceof ComplexType);
        Assert.assertFalse(type instanceof FeatureType);
        Assert.assertTrue(type.getUserData().get(XSDTypeDefinition.class) instanceof XSDComplexTypeDefinition);

        ComplexType measurementType = (ComplexType) type;
        Assert.assertEquals(typeName, measurementType.getName());
        Assert.assertTrue(measurementType.isIdentified());
        Assert.assertFalse(measurementType.isAbstract());
        Assert.assertEquals(2, measurementType.getDescriptors().size());

        name = Types.typeName(NS_URI, "measurement");
        AttributeDescriptor descriptor;
        descriptor = (AttributeDescriptor) Types.descriptor(wq_plus_Type, name);
        Assert.assertNotNull(descriptor);
        Assert.assertEquals(name, descriptor.getName());
        Assert.assertNotNull(descriptor.getType());
        Assert.assertSame(measurementType, descriptor.getType());
        Assert.assertEquals(0, descriptor.getMinOccurs());
        Assert.assertEquals(Integer.MAX_VALUE, descriptor.getMaxOccurs());
        Assert.assertTrue(descriptor.getUserData().get(XSDElementDeclaration.class) instanceof XSDElementDeclaration);

        name = Types.typeName(NS_URI, "result");
        descriptor = (AttributeDescriptor) Types.descriptor(measurementType, name);
        typeName = Types.typeName(XS.NAMESPACE, XS.FLOAT.getLocalPart());
        assertSimpleAttribute(descriptor, name, typeName, Float.class, 1, 1);

        name = Types.typeName(NS_URI, "determinand_description");
        descriptor = (AttributeDescriptor) Types.descriptor(measurementType, name);
        typeName = Types.typeName(XS.NAMESPACE, XS.STRING.getLocalPart());
        assertSimpleAttribute(descriptor, name, typeName, String.class, 1, 1);

        name = Types.typeName(NS_URI, "the_geom");
        descriptor = (AttributeDescriptor) Types.descriptor(wq_plus_Type, name);
        typeName = Types.typeName(GML.NAMESPACE, GML.PointPropertyType.getLocalPart());
        assertSimpleAttribute(descriptor, name, typeName, Point.class, 1, 1);

        name = Types.typeName(NS_URI, "sitename");
        descriptor = (AttributeDescriptor) Types.descriptor(wq_plus_Type, name);
        typeName = Types.typeName(XS.NAMESPACE, XS.STRING.getLocalPart());
        assertSimpleAttribute(descriptor, name, typeName, String.class, 1, Integer.MAX_VALUE);
    }
    finally {
        typeRegistry.disposeSchemaIndexes();
    }
}