Search in sources :

Example 91 with Entity

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));
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Casting(ai.grakn.kb.internal.structure.Casting) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 92 with Entity

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())));
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) RelationshipImpl(ai.grakn.kb.internal.concept.RelationshipImpl) Test(org.junit.Test)

Example 93 with Entity

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);
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) Relationship(ai.grakn.concept.Relationship) Label(ai.grakn.concept.Label) Test(org.junit.Test)

Example 94 with Entity

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);
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

Example 95 with Entity

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());
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) 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