use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.
the class XLSReaderTest method readXLSInstances.
private InstanceCollection readXLSInstances(String sourceLocation, int sheetIndex, String typeName, boolean skipFirst, Schema sourceSchema) throws Exception {
InstanceReader instanceReader = new XLSInstanceReader();
instanceReader.setSource(new DefaultInputSupplier(getClass().getResource(sourceLocation).toURI()));
instanceReader.setParameter(InstanceTableIOConstants.SHEET_INDEX, Value.of(sheetIndex));
instanceReader.setParameter(CommonSchemaConstants.PARAM_TYPENAME, Value.of(typeName));
instanceReader.setParameter(CommonSchemaConstants.PARAM_SKIP_FIRST_LINE, Value.of(skipFirst));
instanceReader.setSourceSchema(sourceSchema);
// Test instances
IOReport report = instanceReader.execute(null);
assertTrue("Data import was not successfull.", report.isSuccess());
return instanceReader.getInstances();
}
use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.
the class XmlSchemaReaderTest method testRead_definitive_annotated.
/**
* Test reading a simple XML schema with an annotated element.
*
* @throws Exception if reading the schema fails
*/
@Test
public void testRead_definitive_annotated() throws Exception {
URI location = getClass().getResource("/testdata/definitive/documentation_ex.xsd").toURI();
LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
XmlIndex schema = (XmlIndex) readSchema(input);
// product element
XmlElement product = schema.getElements().get(new QName("product"));
assertNotNull(product);
assertTrue(product.getDescription().contains("This element represents a product."));
}
use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.
the class XmlSchemaReaderTest method testRead_definitive_substitution.
/**
* Test reading a simple XML schema containing substitution groups.
*
* @throws Exception if reading the schema fails
*/
@Test
public void testRead_definitive_substitution() throws Exception {
URI location = getClass().getResource("/testdata/definitive/substgroups.xsd").toURI();
LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
XmlIndex schema = (XmlIndex) readSchema(input);
// shirt element
XmlElement shirt = schema.getElements().get(new QName("shirt"));
assertNotNull(shirt);
assertEquals(new QName("product"), shirt.getSubstitutionGroup());
// TODO extend
}
use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.
the class XmlSchemaReaderTest method testRead_shiporder_types.
/**
* Test reading a simple XML schema that uses several custom named types
*
* @throws Exception if reading the schema fails
*/
@Test
public void testRead_shiporder_types() throws Exception {
URI location = getClass().getResource("/testdata/shiporder/shiporder-types.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);
}
use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.
the class XmlSchemaReaderTest method testRead_definitive_groups.
/**
* Test reading a simple XML schema containing groups and group references.
*
* @throws Exception if reading the schema fails
*/
@Test
public void testRead_definitive_groups() throws Exception {
URI location = getClass().getResource("/testdata/definitive/groups.xsd").toURI();
LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
XmlIndex schema = (XmlIndex) readSchema(input);
// ShirtType
TypeDefinition shirtType = schema.getType(new QName("ShirtType"));
assertNotNull(shirtType);
assertEquals(5, shirtType.getChildren().size());
Iterator<? extends ChildDefinition<?>> it = shirtType.getChildren().iterator();
// ProductPropertyGroup
GroupPropertyDefinition prodGroup = it.next().asGroup();
// cardinality
Cardinality cc = prodGroup.getConstraint(Cardinality.class);
assertEquals(0, cc.getMinOccurs());
assertEquals(1, cc.getMaxOccurs());
// name
assertEquals("ProductPropertyGroup", prodGroup.getName().getLocalPart());
assertEquals(4, prodGroup.getDeclaredChildren().size());
Iterator<? extends ChildDefinition<?>> itProd = prodGroup.getDeclaredChildren().iterator();
// not there any more because it is flattened away
// // DescriptionGroup
// GroupPropertyDefinition descGroup = itProd.next().asGroup();
// assertNotNull(descGroup);
// // cardinality
// cc = descGroup.getConstraint(Cardinality.class);
// assertEquals(1, cc.getMinOccurs());
// assertEquals(1, cc.getMaxOccurs());
//
// assertEquals(2, descGroup.getDeclaredChildren().size());
// Iterator<? extends ChildDefinition<?>> itDesc = descGroup.getDeclaredChildren().iterator();
// description
PropertyDefinition description = itProd.next().asProperty();
assertNotNull(description);
assertEquals("description", description.getName().getLocalPart());
// comment
PropertyDefinition comment = itProd.next().asProperty();
assertNotNull(comment);
assertEquals("comment", comment.getName().getLocalPart());
// number
PropertyDefinition number = itProd.next().asProperty();
assertNotNull(number);
assertEquals("number", number.getName().getLocalPart());
// name
PropertyDefinition name = itProd.next().asProperty();
assertNotNull(name);
assertEquals("name", name.getName().getLocalPart());
// size
PropertyDefinition size = it.next().asProperty();
assertNotNull(size);
assertEquals("size", size.getName().getLocalPart());
}
Aggregations