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());
}
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());
}
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());
}
}
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();
}
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();
}
Aggregations