Search in sources :

Example 41 with EntityType

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

the class GraknTxPutPropertyTest method whenCallingPutEntityTypeWithAnExistingEntityTypeLabel_ItReturnsThatType.

@Property
public void whenCallingPutEntityTypeWithAnExistingEntityTypeLabel_ItReturnsThatType(@Open GraknTx graph, @FromTx EntityType entityType) {
    EntityType newType = graph.putEntityType(entityType.getLabel());
    assertEquals(entityType, newType);
}
Also used : EntityType(ai.grakn.concept.EntityType) Property(com.pholser.junit.quickcheck.Property)

Example 42 with EntityType

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

the class ValidatorTest method whenCommittingRelationWithoutSpecifyingSchema_ThrowOnCommit.

@Test
public void whenCommittingRelationWithoutSpecifyingSchema_ThrowOnCommit() {
    EntityType fakeType = tx.putEntityType("Fake Concept");
    RelationshipType relationshipType = tx.putRelationshipType("kicks");
    Role kicker = tx.putRole("kicker");
    Role kickee = tx.putRole("kickee");
    Thing kyle = fakeType.addEntity();
    Thing icke = fakeType.addEntity();
    relationshipType.addRelationship().addRolePlayer(kicker, kyle).addRolePlayer(kickee, icke);
    String error1 = ErrorMessage.VALIDATION_CASTING.getMessage(kyle.type().getLabel(), kyle.getId(), kicker.getLabel());
    String error2 = ErrorMessage.VALIDATION_CASTING.getMessage(icke.type().getLabel(), icke.getId(), kickee.getLabel());
    expectedException.expect(InvalidKBException.class);
    expectedException.expectMessage(allOf(containsString(error1), containsString(error2)));
    tx.commit();
}
Also used : EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Matchers.containsString(org.hamcrest.Matchers.containsString) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 43 with EntityType

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

the class EntityTypeTest method whenGettingTheSuperTypeOfType_ReturnSuperType.

@Test
public void whenGettingTheSuperTypeOfType_ReturnSuperType() {
    EntityType c1 = tx.putEntityType("c1");
    EntityType c2 = tx.putEntityType("c2").sup(c1);
    EntityType c3 = tx.putEntityType("c3").sup(c2);
    assertEquals(tx.admin().getMetaEntityType(), c1.sup());
    assertEquals(c1, c2.sup());
    assertEquals(c2, c3.sup());
}
Also used : EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 44 with EntityType

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

the class EntityTypeTest method whenDeletingTypeWithEntities_Throw.

@Test
public void whenDeletingTypeWithEntities_Throw() {
    EntityType entityTypeA = tx.putEntityType("entityTypeA");
    EntityType entityTypeB = tx.putEntityType("entityTypeB");
    entityTypeB.addEntity();
    entityTypeA.delete();
    assertNull(tx.getEntityType("entityTypeA"));
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.cannotBeDeleted(entityTypeB).getMessage());
    entityTypeB.delete();
}
Also used : EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 45 with EntityType

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

the class EntityTypeTest method whenCyclicSuperTypes_Throw.

@Test
public void whenCyclicSuperTypes_Throw() {
    EntityType entityType1 = tx.putEntityType("Entity1");
    EntityType entityType2 = tx.putEntityType("Entity2");
    EntityType entityType3 = tx.putEntityType("Entity3");
    entityType1.sup(entityType2);
    entityType2.sup(entityType3);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.loopCreated(entityType3, entityType1).getMessage());
    entityType3.sup(entityType1);
}
Also used : EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Aggregations

EntityType (ai.grakn.concept.EntityType)168 Test (org.junit.Test)141 Role (ai.grakn.concept.Role)83 RelationshipType (ai.grakn.concept.RelationshipType)82 Entity (ai.grakn.concept.Entity)74 GraknTx (ai.grakn.GraknTx)45 Relationship (ai.grakn.concept.Relationship)21 Attribute (ai.grakn.concept.Attribute)19 AttributeType (ai.grakn.concept.AttributeType)17 ConceptId (ai.grakn.concept.ConceptId)17 Label (ai.grakn.concept.Label)17 Set (java.util.Set)16 HashSet (java.util.HashSet)15 Thing (ai.grakn.concept.Thing)14 GraknTxType (ai.grakn.GraknTxType)8 ArrayList (java.util.ArrayList)8 GraknSession (ai.grakn.GraknSession)7 Concept (ai.grakn.concept.Concept)7 HashMap (java.util.HashMap)7 Before (org.junit.Before)7