Search in sources :

Example 6 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier 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)

Example 7 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_shiporder_one.

/**
 * Test reading a simple XML schema that contains one big element. Focuses
 * on structure, simple type bindings and cardinalities.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_shiporder_one() throws Exception {
    URI location = getClass().getResource("/testdata/shiporder/shiporder-one.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)

Example 8 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier 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 9 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_definitive_choice.

/**
 * Test reading a simple XML schema with choices and complex types.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_definitive_choice() throws Exception {
    URI location = getClass().getResource("/testdata/definitive/choice_complex.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    // ItemsType
    TypeDefinition itemsType = schema.getType(new QName("ItemsType"));
    assertNotNull(itemsType);
    Collection<? extends ChildDefinition<?>> children = itemsType.getChildren();
    assertEquals(1, children.size());
    // choice
    GroupPropertyDefinition choice = children.iterator().next().asGroup();
    assertNotNull(choice);
    // cardinality
    Cardinality cc = choice.getConstraint(Cardinality.class);
    assertEquals(0, cc.getMinOccurs());
    assertEquals(Cardinality.UNBOUNDED, cc.getMaxOccurs());
    // choice flag
    assertTrue(choice.getConstraint(ChoiceFlag.class).isEnabled());
    // children
    assertEquals(3, choice.getDeclaredChildren().size());
    // shirt
    PropertyDefinition shirt = choice.getChild(new QName("shirt")).asProperty();
    assertNotNull(shirt);
    // hat
    PropertyDefinition hat = choice.getChild(new QName("hat")).asProperty();
    assertNotNull(hat);
    // umbrella
    PropertyDefinition umbrella = choice.getChild(new QName("umbrella")).asProperty();
    assertNotNull(umbrella);
// TODO extend with advanced complex type tests?
}
Also used : GroupPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition) 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) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 10 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier 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)

Aggregations

DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)73 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)34 URI (java.net.URI)30 Test (org.junit.Test)21 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)15 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)15 IOException (java.io.IOException)13 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)11 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)10 QName (javax.xml.namespace.QName)10 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)9 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)7 CSVSchemaReader (eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader)7 GmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)6 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)6 File (java.io.File)6