use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class PropertyResolverTest method testLoadShiporder.
/**
* Test loading a simple XML file with one instance
*
* @throws Exception if an error occurs
*/
@Test
public void testLoadShiporder() throws Exception {
InstanceCollection instances = loadXMLInstances(getClass().getResource("/data/shiporder/shiporder.xsd").toURI(), getClass().getResource("/data/shiporder/shiporder.xml").toURI());
ResourceIterator<Instance> it = instances.iterator();
try {
assertTrue(it.hasNext());
Instance instance = it.next();
assertNotNull(instance);
@SuppressWarnings("unused") TypeDefinition test = instance.getDefinition().getChildren().iterator().next().asProperty().getParentType();
assertTrue(PropertyResolver.hasProperty(instance, "{http://www.example.com}orderperson"));
assertTrue(PropertyResolver.hasProperty(instance, "{http://www.example.com}shipto.{http://www.example.com}city"));
assertTrue(PropertyResolver.getQueryPath(instance, "{http://www.example.com}shipto.{http://www.example.com}city").contains("{http://www.example.com}shipto.{http://www.example.com}city"));
assertTrue(PropertyResolver.hasProperty(instance, "orderperson"));
assertTrue(PropertyResolver.hasProperty(instance, "shipto.city"));
assertTrue(PropertyResolver.hasProperty(instance, "shipto.{http://www.example.com}city"));
assertEquals(PropertyResolver.getValues(instance, "shipto.city").iterator().next(), "4000 Stavanger");
} finally {
it.close();
}
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class SimplePartitionerTest method testIterate.
private void testIterate(int num, int partSize) {
InstanceCollection c1 = createCollection(num);
assertEquals(num, c1.size());
try (ResourceIterator<InstanceCollection> it = new SimplePartitioner().partition(c1, partSize, SimpleLog.CONSOLE_LOG)) {
int count = 0;
while (it.hasNext()) {
InstanceCollection part = it.next();
try (ResourceIterator<Instance> partIt = part.iterator()) {
while (partIt.hasNext()) {
Instance instance = partIt.next();
assertNotNull(instance);
count++;
}
}
}
assertEquals(num, count);
}
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class SimplePartitionerTest method createCollection.
static InstanceCollection createCollection(int num) {
Collection<Instance> instances = new ArrayList<>();
for (int i = 0; i < num; i++) {
instances.add(new DefaultInstance(null, null));
}
InstanceCollection res = new DefaultInstanceCollection(instances);
return res;
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class CSVInstanceReaderTest method testReadSimple.
/**
* Test - read a sample csv schema and data.
*
* @throws Exception , if an error occurs
*/
@Test
public void testReadSimple() throws Exception {
String typeName = "location";
String[] properties = { "Name", "Xcoord", "Ycoord", "id" };
String[] dataFirstColumn = { "test", "12", "16", "1" };
int numberOfInstances = 2;
// read Schema ###
Schema schema = readCSVSchema("/data/test1.csv", typeName, "java.lang.String,java.lang.String,java.lang.String,java.lang.String", "Name,Xcoord,Ycoord,id", null, null, null);
// Test properties
TypeDefinition schemaType = schema.getType(QName.valueOf(typeName));
// Check every property for their existence
for (String propertyName : properties) {
assertEquals(propertyName, schemaType.getChild(QName.valueOf(propertyName)).getDisplayName());
}
// read Instances ###
InstanceCollection instances = readCSVInstances("/data/test1.csv", typeName, true, schema, null, null, null);
assertEquals(numberOfInstances, collectionSize(instances));
// get Type to check property definition (schema and instance
// combination)
TypeDefinition type = instances.iterator().next().getDefinition();
ChildDefinition<?> child = null;
assertEquals(typeName, type.getDisplayName());
for (int i = 0; i < properties.length; i++) {
child = type.getChild(QName.valueOf(properties[i]));
assertEquals(properties[i], child.getDisplayName());
}
// Check the values of the first (type) instance
Instance instance = instances.iterator().next();
Object[] value;
for (int i = 0; i < dataFirstColumn.length; i++) {
value = instance.getProperty(QName.valueOf(properties[i]));
assertEquals(dataFirstColumn[i], value[0]);
assertTrue(value[0] instanceof String);
}
}
use of eu.esdihumboldt.hale.common.instance.model.InstanceCollection in project hale by halestudio.
the class CSVInstanceReaderTest method testReadWithPointDecimal.
/**
* Test - read a sample csv schema and data with point as a decimal divisor
*
* @throws Exception , if an error occurs
*/
@Test
public void testReadWithPointDecimal() throws Exception {
String typeName = "Random";
String[] properties = { "A", "B", "C", "D", "E" };
Object[] dataFirstColumn = { new Integer(1), "A", new Float(32647968.61), new Float(5649088.376), "Linderbacher Straße" };
int numberOfInstances = 5;
// read Schema ###
Schema schema = readCSVSchema("/data/test3-pointdecimal.csv", typeName, "java.lang.Integer,java.lang.String,java.lang.Float,java.lang.Float,java.lang.String", "A,B,C,D,E", ";", null, null, ".");
// Test properties
TypeDefinition schemaType = schema.getType(QName.valueOf(typeName));
// Check every property for their existence
for (String propertyName : properties) {
assertEquals(propertyName, schemaType.getChild(QName.valueOf(propertyName)).getDisplayName());
}
// read Instances ###
InstanceCollection instances = readCSVInstances("/data/test3-pointdecimal.csv", typeName, true, schema, ";", null, null, ".");
assertEquals(numberOfInstances, collectionSize(instances));
// get Type to check property definition (schema and instance
// combination)
TypeDefinition type = instances.iterator().next().getDefinition();
ChildDefinition<?> child = null;
assertEquals(typeName, type.getDisplayName());
for (int i = 0; i < properties.length; i++) {
child = type.getChild(QName.valueOf(properties[i]));
assertEquals(properties[i], child.getDisplayName());
}
// Check the values of the first (type) instance
Instance instance = instances.iterator().next();
Object[] value;
for (int i = 0; i < dataFirstColumn.length; i++) {
value = instance.getProperty(QName.valueOf(properties[i]));
assertEquals(dataFirstColumn[i], value[0]);
}
}
Aggregations