Search in sources :

Example 56 with InstanceCollection

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();
    }
}
Also used : MutableInstance(eu.esdihumboldt.hale.common.instance.model.MutableInstance) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 57 with InstanceCollection

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);
    }
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection)

Example 58 with InstanceCollection

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;
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) DefaultInstance(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection) ArrayList(java.util.ArrayList) DefaultInstanceCollection(eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection)

Example 59 with InstanceCollection

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);
    }
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Example 60 with InstanceCollection

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]);
    }
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Test(org.junit.Test)

Aggregations

InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)151 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)131 Test (org.junit.Test)116 AbstractHandlerTest (eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)97 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)17 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)17 DefaultInstance (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstance)11 ArrayList (java.util.ArrayList)10 Geometry (com.vividsolutions.jts.geom.Geometry)9 MutableInstance (eu.esdihumboldt.hale.common.instance.model.MutableInstance)9 IOException (java.io.IOException)9 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)8 Polygon (com.vividsolutions.jts.geom.Polygon)8 QName (javax.xml.namespace.QName)8 Coordinate (com.vividsolutions.jts.geom.Coordinate)7 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)7 DefaultInstanceCollection (eu.esdihumboldt.hale.common.instance.model.impl.DefaultInstanceCollection)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)6 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)6 TypeFilter (eu.esdihumboldt.hale.common.instance.model.TypeFilter)6