Search in sources :

Example 1 with XmlIndex

use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_definitive_attributegroup.

/**
 * Test reading a simple XML schema that uses an attribute group and an
 * attribute with xs:date type.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_definitive_attributegroup() throws Exception {
    URI location = getClass().getResource("/testdata/definitive/attributegroup.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    // ShirtType
    TypeDefinition type = schema.getType(new QName("ShirtType"));
    assertNotNull(type);
    // not there any more because it is flattened away
    // // IdentifierGroup
    // GroupPropertyDefinition group = type.getChild(new QName("IdentifierGroup")).asGroup();
    // assertNotNull(group);
    // // not a choice
    // assertFalse(group.getConstraint(ChoiceFlag.class).isEnabled());
    // id
    PropertyDefinition id = type.getChild(new QName("id")).asProperty();
    assertNotNull(id);
    // property type must be a simple type
    assertTrue(id.getPropertyType().getConstraint(HasValueFlag.class).isEnabled());
    // binding must be string
    assertEquals(String.class, id.getPropertyType().getConstraint(Binding.class).getBinding());
    // required
    Cardinality cc = id.getConstraint(Cardinality.class);
    assertEquals(1, cc.getMinOccurs());
    assertEquals(1, cc.getMaxOccurs());
    // version
    PropertyDefinition version = type.getChild(new QName("version")).asProperty();
    assertNotNull(version);
    // property type must be a simple type
    assertTrue(version.getPropertyType().getConstraint(HasValueFlag.class).isEnabled());
    // effDate
    PropertyDefinition effDate = type.getChild(new QName("effDate")).asProperty();
    assertNotNull(effDate);
    // binding must be compatible to Date
    assertTrue(Date.class.isAssignableFrom(effDate.getPropertyType().getConstraint(Binding.class).getBinding()));
}
Also used : Binding(eu.esdihumboldt.hale.common.schema.model.constraint.type.Binding) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Cardinality(eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) URI(java.net.URI) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) Date(java.util.Date) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 2 with XmlIndex

use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_unqualified.

/**
 * Test reading a simple XML schema that contains one big element and where
 * elementFormDefault/attributeFromDefault is set to unqualified and no
 * target namespace is set. Focuses on structure, simple type bindings and
 * cardinalities.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_unqualified() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-unqualified.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = XMLConstants.NULL_NS_URI;
    assertEquals(ns, schema.getNamespace());
    // shiporder element
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(1, elements.size());
    XmlElement shiporder = elements.iterator().next();
    // XXX use null namespace XXX not sure how to work with unqualified form
    // FIXME target namespace no effect?! should the target namespace always
    // be injected?
    testShiporderStructure(shiporder, ns);
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) Test(org.junit.Test)

Example 3 with XmlIndex

use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_definitive_chapter03.

/**
 * Test reading a simple XML schema that is split into several files. Tests
 * also the {@link XmlElements} and {@link MappingRelevantFlag} constraints
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_definitive_chapter03() throws Exception {
    URI location = getClass().getResource("/testdata/definitive/chapter03env.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    // envelope element
    XmlElement envelope = schema.getElements().get(new QName("http://example.org/ord", "envelope"));
    assertNotNull(envelope);
    TypeDefinition envType = envelope.getType();
    // mappable
    assertTrue(envType.getConstraint(MappingRelevantFlag.class).isEnabled());
    // XmlElements
    Collection<? extends XmlElement> elements = envType.getConstraint(XmlElements.class).getElements();
    assertEquals(1, elements.size());
    assertEquals(envelope, elements.iterator().next());
    // order
    PropertyDefinition order = envType.getChild(new QName("http://example.org/ord", "order")).asProperty();
    assertNotNull(order);
    TypeDefinition orderType = order.getPropertyType();
    // mappable
    assertTrue(orderType.getConstraint(MappingRelevantFlag.class).isEnabled());
    // number
    PropertyDefinition number = orderType.getChild(new QName("http://example.org/ord", "number")).asProperty();
    assertNotNull(number);
    // binding must be string
    assertEquals(String.class, number.getPropertyType().getConstraint(Binding.class).getBinding());
    // items
    PropertyDefinition items = orderType.getChild(new QName("http://example.org/ord", "items")).asProperty();
    assertNotNull(items);
    // not mappable
    assertFalse(items.getPropertyType().getConstraint(MappingRelevantFlag.class).isEnabled());
    // no elements
    assertTrue(items.getPropertyType().getConstraint(XmlElements.class).getElements().isEmpty());
    // SpecialOrderType
    // extension to OrderType, should be mappable using xsi:type
    TypeDefinition specialOrderType = schema.getType(new QName("http://example.org/ord", "SpecialOrderType"));
    assertNotNull(specialOrderType);
    // number of declared children
    assertEquals(1, specialOrderType.getDeclaredChildren().size());
    // number of children
    assertEquals(3, specialOrderType.getChildren().size());
    // mappable
    assertTrue(specialOrderType.getConstraint(MappableFlag.class).isEnabled());
    // no elements
    assertTrue(specialOrderType.getConstraint(XmlElements.class).getElements().isEmpty());
    // overall mappable types
    Collection<? extends TypeDefinition> mt = schema.getMappingRelevantTypes();
    // envelope, order, special order
    assertEquals(2, mt.size());
}
Also used : XmlElements(eu.esdihumboldt.hale.io.xsd.constraint.XmlElements) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 4 with XmlIndex

use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_types_cycle.

/**
 * Test reading a simple XML schema that uses several custom named types and
 * has a cycle.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_types_cycle() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-types-cycle.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = "http://www.example.com";
    assertEquals(ns, schema.getNamespace());
    // shiporder element
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(1, elements.size());
    XmlElement shiporder = elements.iterator().next();
    assertNotNull(shiporder);
    TypeDefinition type = shiporder.getType();
    assertEquals(5, type.getChildren().size());
    // contained shiporder element
    PropertyDefinition s2 = type.getChild(new QName(ns, "shiporder")).asProperty();
    assertNotNull(s2);
    assertEquals(type, s2.getPropertyType());
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 5 with XmlIndex

use of eu.esdihumboldt.hale.io.xsd.model.XmlIndex in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_types_reverse.

/**
 * Test reading a simple XML schema that uses several custom named types.
 * The types are referenced before they are declared.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_types_reverse() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-types-r.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    String ns = "http://www.example.com";
    assertEquals(ns, schema.getNamespace());
    // shiporder element
    Collection<XmlElement> elements = getElementsWithNS(ns, schema.getElements().values());
    assertEquals(1, elements.size());
    XmlElement shiporder = elements.iterator().next();
    testShiporderStructure(shiporder, ns);
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) Test(org.junit.Test)

Aggregations

XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)24 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)16 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)15 URI (java.net.URI)15 Test (org.junit.Test)13 QName (javax.xml.namespace.QName)11 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)8 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)7 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)6 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 SchemaSpace (eu.esdihumboldt.hale.common.schema.model.SchemaSpace)4 Cardinality (eu.esdihumboldt.hale.common.schema.model.constraint.property.Cardinality)4 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)2 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)2 XmlElements (eu.esdihumboldt.hale.io.xsd.constraint.XmlElements)2 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2