Search in sources :

Example 1 with CSVMigrator

use of ai.grakn.migration.csv.CSVMigrator in project grakn by graknlabs.

the class CSVMigratorTest method whenDataIsMissing_ErrorIsNotThrownAndThoseLinesAreSkipped.

@Test
public void whenDataIsMissing_ErrorIsNotThrownAndThoseLinesAreSkipped() {
    load(factory, getFile("csv", "pets/schema.gql"));
    String template = getFileAsString("csv", "pets/template.gql");
    try (CSVMigrator m = new CSVMigrator(getFile("csv", "pets/data/pets.empty"))) {
        defaultMigrator.load(template, m.setNullString("").convert());
    }
    try (GraknTx graph = factory.open(GraknTxType.WRITE)) {
        // Re Open Transaction
        Stream<Entity> pets = graph.getEntityType("pet").instances();
        assertEquals(1, pets.count());
        Stream<Entity> cats = graph.getEntityType("cat").instances();
        assertEquals(1, cats.count());
        AttributeType<String> name = graph.getAttributeType("name");
        AttributeType<String> death = graph.getAttributeType("death");
        Entity fluffy = name.getAttribute("Fluffy").ownerInstances().iterator().next().asEntity();
        assertEquals(1, fluffy.attributes(death).count());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) MigratorTestUtils.getFileAsString(ai.grakn.test.migration.MigratorTestUtils.getFileAsString) Matchers.containsString(org.hamcrest.Matchers.containsString) CSVMigrator(ai.grakn.migration.csv.CSVMigrator) Test(org.junit.Test)

Aggregations

GraknTx (ai.grakn.GraknTx)1 Entity (ai.grakn.concept.Entity)1 CSVMigrator (ai.grakn.migration.csv.CSVMigrator)1 MigratorTestUtils.getFileAsString (ai.grakn.test.migration.MigratorTestUtils.getFileAsString)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1