Search in sources :

Example 11 with Role

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

the class RoleTest method whenDeletingRoleTypeWithTypesWhichCanPlayIt_Throw.

@Test
public void whenDeletingRoleTypeWithTypesWhichCanPlayIt_Throw() {
    Role foundType = tx.getRole("My Role");
    assertNotNull(foundType);
    foundType.delete();
    assertNull(tx.getRole("My Role"));
    Role role = tx.putRole("New Role Type");
    tx.putEntityType("Entity Type").plays(role);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.cannotBeDeleted(role).getMessage());
    role.delete();
}
Also used : Role(ai.grakn.concept.Role) Test(org.junit.Test)

Example 12 with Role

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

the class RoleTest method whenAddingRoleTypeToMultipleRelationTypes_EnsureItLinkedToBothRelationTypes.

@Test
public void whenAddingRoleTypeToMultipleRelationTypes_EnsureItLinkedToBothRelationTypes() throws InvalidKBException {
    Role roleA = tx.putRole("roleA");
    Role roleB = tx.putRole("roleB");
    relationshipType.relates(roleA).relates(role);
    RelationshipType relationshipType2 = tx.putRelationshipType("relationshipType2").relates(roleB).relates(role);
    tx.commit();
    assertThat(roleA.relationshipTypes().collect(toSet()), containsInAnyOrder(relationshipType));
    assertThat(roleB.relationshipTypes().collect(toSet()), containsInAnyOrder(relationshipType2));
    assertThat(role.relationshipTypes().collect(toSet()), containsInAnyOrder(relationshipType, relationshipType2));
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 13 with Role

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

the class RoleTest method whenDeletingRoleTypeWithRelationTypes_Throw.

@Test
public void whenDeletingRoleTypeWithRelationTypes_Throw() {
    Role role2 = tx.putRole("New Role Type");
    tx.putRelationshipType("Thing").relates(role2).relates(role);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.cannotBeDeleted(role2).getMessage());
    role2.delete();
}
Also used : Role(ai.grakn.concept.Role) Test(org.junit.Test)

Example 14 with Role

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

the class RoleTest method whenDeletingRoleTypeWithRolePlayers_Throw.

@Test
public void whenDeletingRoleTypeWithRolePlayers_Throw() {
    Role roleA = tx.putRole("roleA");
    Role roleB = tx.putRole("roleB");
    RelationshipType relationshipType = tx.putRelationshipType("relationTypes").relates(roleA).relates(roleB);
    EntityType entityType = tx.putEntityType("entityType").plays(roleA).plays(roleB);
    Entity a = entityType.addEntity();
    Entity b = entityType.addEntity();
    relationshipType.addRelationship().addRolePlayer(roleA, a).addRolePlayer(roleB, b);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.cannotBeDeleted(roleA).getMessage());
    roleA.delete();
}
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 15 with Role

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

the class SchemaMutationTest method whenAddingPlaysUsingBatchGraph_Throw.

@Test
public void whenAddingPlaysUsingBatchGraph_Throw() {
    String roleTypeId = "role-thing";
    String entityTypeId = "entityType";
    tx.putRole(roleTypeId);
    tx.putEntityType(entityTypeId);
    EmbeddedGraknTx<?> graknGraphBatch = batchTx();
    Role role = graknGraphBatch.getRole(roleTypeId);
    EntityType entityType = graknGraphBatch.getEntityType(entityTypeId);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.schemaMutation().getMessage());
    entityType.plays(role);
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Aggregations

Role (ai.grakn.concept.Role)189 Test (org.junit.Test)124 RelationshipType (ai.grakn.concept.RelationshipType)114 EntityType (ai.grakn.concept.EntityType)92 Entity (ai.grakn.concept.Entity)55 GraknTx (ai.grakn.GraknTx)48 Relationship (ai.grakn.concept.Relationship)37 Set (java.util.Set)36 ConceptId (ai.grakn.concept.ConceptId)33 Label (ai.grakn.concept.Label)33 Thing (ai.grakn.concept.Thing)32 HashSet (java.util.HashSet)31 Var (ai.grakn.graql.Var)25 AttributeType (ai.grakn.concept.AttributeType)21 Concept (ai.grakn.concept.Concept)20 Schema (ai.grakn.util.Schema)17 Collectors (java.util.stream.Collectors)17 Attribute (ai.grakn.concept.Attribute)16 SchemaConcept (ai.grakn.concept.SchemaConcept)16 Type (ai.grakn.concept.Type)16