use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class TxCacheTest method whenCreatingRelations_EnsureRolePlayersAreCached.
@Test
public void whenCreatingRelations_EnsureRolePlayersAreCached() {
Role r1 = tx.putRole("r1");
Role r2 = tx.putRole("r2");
EntityType t1 = tx.putEntityType("t1").plays(r1).plays(r2);
RelationshipType rt1 = tx.putRelationshipType("rel1").relates(r1).relates(r2);
Entity e1 = t1.addEntity();
Entity e2 = t1.addEntity();
assertThat(tx.txCache().getModifiedCastings(), empty());
Set<Casting> castings = ((RelationshipImpl) rt1.addRelationship().addRolePlayer(r1, e1).addRolePlayer(r2, e2)).reified().get().castingsRelation().collect(toSet());
assertTrue(tx.txCache().getModifiedCastings().containsAll(castings));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class TxCacheTest method whenCreatingSuperTypes_EnsureLogContainsSubTypeCastings.
@Test
public void whenCreatingSuperTypes_EnsureLogContainsSubTypeCastings() {
Role r1 = tx.putRole("r1");
Role r2 = tx.putRole("r2");
EntityType t1 = tx.putEntityType("t1").plays(r1).plays(r2);
EntityType t2 = tx.putEntityType("t2");
RelationshipType rt1 = tx.putRelationshipType("rel1").relates(r1).relates(r2);
Entity i1 = t1.addEntity();
Entity i2 = t1.addEntity();
RelationshipImpl relation = (RelationshipImpl) rt1.addRelationship().addRolePlayer(r1, i1).addRolePlayer(r2, i2);
tx.commit();
tx = EmbeddedGraknSession.create(tx.keyspace(), Grakn.IN_MEMORY).open(GraknTxType.WRITE);
assertThat(tx.txCache().getModifiedCastings(), is(empty()));
t1.sup(t2);
assertTrue(tx.txCache().getModifiedCastings().containsAll(relation.reified().get().castingsRelation().collect(toSet())));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTest method checkKeyCreatesCorrectResourceStructure.
@Test
public void checkKeyCreatesCorrectResourceStructure() {
Label resourceLabel = Label.of("A Attribute Thing");
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType(resourceLabel, AttributeType.DataType.STRING);
entityType.key(attributeType);
Entity entity = entityType.addEntity();
Attribute attribute = attributeType.putAttribute("A attribute thing");
entity.attribute(attribute);
Relationship relationship = entity.relationships().iterator().next();
checkImplicitStructure(attributeType, relationship, entity, Schema.ImplicitType.KEY, Schema.ImplicitType.KEY_OWNER, Schema.ImplicitType.KEY_VALUE);
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTest method whenAddingResourceToEntityWithoutAllowingItBetweenTypes_Throw.
@Test
public void whenAddingResourceToEntityWithoutAllowingItBetweenTypes_Throw() {
EntityType entityType = tx.putEntityType("A Thing");
AttributeType<String> attributeType = tx.putAttributeType("A Attribute Thing", AttributeType.DataType.STRING);
Entity entity = entityType.addEntity();
Attribute attribute = attributeType.putAttribute("A attribute thing");
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(GraknTxOperationException.hasNotAllowed(entity, attribute).getMessage());
entity.attribute(attribute);
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class EntityTest method whenGettingTypeOfEntity_ReturnEntityType.
@Test
public void whenGettingTypeOfEntity_ReturnEntityType() {
EntityType entityType = tx.putEntityType("Entiy Type");
Entity entity = entityType.addEntity();
assertEquals(entityType, entity.type());
}
Aggregations