Search in sources :

Example 81 with Entity

use of ai.grakn.concept.Entity in project grakn by graknlabs.

the class EntityTypePropertyTest method whenAddingAnEntity_TheDirectTypeOfTheEntityIsTheTypeItWasCreatedFrom.

@Property
public void whenAddingAnEntity_TheDirectTypeOfTheEntityIsTheTypeItWasCreatedFrom(@NonMeta @NonAbstract EntityType type) {
    Entity entity = type.addEntity();
    assertEquals(type, entity.type());
}
Also used : Entity(ai.grakn.concept.Entity) Property(com.pholser.junit.quickcheck.Property)

Example 82 with Entity

use of ai.grakn.concept.Entity in project grakn by graknlabs.

the class CSVMigratorTest method multipleEntitiesInOneFileTest.

// Ignored because this feature is not yet supported
@Ignore
@Test
public void multipleEntitiesInOneFileTest() throws IOException {
    load(factory, getFile("csv", "single-file/schema.gql"));
    // Re Open Transaction
    GraknTx graph = factory.open(GraknTxType.WRITE);
    assertNotNull(graph.getEntityType("make"));
    String template = getFileAsString("csv", "single-file/template.gql");
    declareAndLoad(template, "single-file/data/cars.csv", defaultMigrator);
    // test
    Stream<Entity> makes = graph.getEntityType("make").instances();
    assertEquals(3, makes.count());
    Stream<Entity> models = graph.getEntityType("model").instances();
    assertEquals(4, models.count());
    // test empty value not created
    AttributeType description = graph.getAttributeType("description");
    Entity venture = graph.getConcept(ConceptId.of("Venture"));
    assertEquals(1, venture.attributes(description).count());
    Entity ventureLarge = graph.getConcept(ConceptId.of("Venture Large"));
    assertEquals(0, ventureLarge.attributes(description).count());
}
Also used : GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) AttributeType(ai.grakn.concept.AttributeType) MigratorTestUtils.getFileAsString(ai.grakn.test.migration.MigratorTestUtils.getFileAsString) Matchers.containsString(org.hamcrest.Matchers.containsString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 83 with Entity

use of ai.grakn.concept.Entity 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)

Example 84 with Entity

use of ai.grakn.concept.Entity in project grakn by graknlabs.

the class ValidatorTest method whenCommittingWithRoleTypeHierarchyAndInstancesCannotPlayRolesExplicitly_Throw2.

@Test
public void whenCommittingWithRoleTypeHierarchyAndInstancesCannotPlayRolesExplicitly_Throw2() throws InvalidKBException {
    Role parent = tx.putRole("parent");
    Role child = tx.putRole("child");
    EntityType person = tx.putEntityType("person").plays(child);
    RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(child);
    Entity x = person.addEntity();
    Entity y = person.addEntity();
    parenthood.addRelationship().addRolePlayer(parent, x).addRolePlayer(child, y);
    expectedException.expect(InvalidKBException.class);
    expectedException.expectMessage(ErrorMessage.VALIDATION_CASTING.getMessage(person.getLabel(), x.getId(), parent.getLabel()));
    tx.commit();
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 85 with Entity

use of ai.grakn.concept.Entity in project grakn by graknlabs.

the class ValidatorTest method whenCommittingWithRoleTypeHierarchy_EnsureInstancesCanPlayRelevantRoles2.

@Test
public void whenCommittingWithRoleTypeHierarchy_EnsureInstancesCanPlayRelevantRoles2() throws InvalidKBException {
    Role parent = tx.putRole("parent");
    Role child = tx.putRole("child");
    EntityType person = tx.putEntityType("person").plays(parent).plays(child);
    EntityType company = tx.putEntityType("company").plays(parent);
    RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(child);
    Entity x = company.addEntity();
    Entity y = person.addEntity();
    parenthood.addRelationship().addRolePlayer(parent, x).addRolePlayer(child, y);
    tx.commit();
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Aggregations

Entity (ai.grakn.concept.Entity)99 Test (org.junit.Test)81 EntityType (ai.grakn.concept.EntityType)74 Role (ai.grakn.concept.Role)53 RelationshipType (ai.grakn.concept.RelationshipType)50 GraknTx (ai.grakn.GraknTx)44 Attribute (ai.grakn.concept.Attribute)18 Set (java.util.Set)16 Relationship (ai.grakn.concept.Relationship)14 Label (ai.grakn.concept.Label)11 ConceptId (ai.grakn.concept.ConceptId)10 HashSet (java.util.HashSet)10 ArrayList (java.util.ArrayList)8 AttributeType (ai.grakn.concept.AttributeType)7 List (java.util.List)7 GraknSession (ai.grakn.GraknSession)6 Before (org.junit.Before)6 GraknTxType (ai.grakn.GraknTxType)5 Concept (ai.grakn.concept.Concept)5 GraqlQueryException (ai.grakn.exception.GraqlQueryException)5