Search in sources :

Example 1 with EntityImpl

use of ai.grakn.kb.internal.concept.EntityImpl in project grakn by graknlabs.

the class ValidateGlobalRulesTest method testValidatePlaysStructureUnique.

@Test
public void testValidatePlaysStructureUnique() {
    Role role1 = tx.putRole("role1");
    Role role2 = tx.putRole("role2");
    RelationshipType relationshipType = tx.putRelationshipType("rt").relates(role1).relates(role2);
    EntityType entityType = tx.putEntityType("et");
    ((EntityTypeImpl) entityType).plays(role1, true);
    ((EntityTypeImpl) entityType).plays(role2, false);
    Entity other1 = entityType.addEntity();
    Entity other2 = entityType.addEntity();
    EntityImpl entity = (EntityImpl) entityType.addEntity();
    RelationshipImpl relation1 = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role2, other1).addRolePlayer(role1, entity);
    // Valid with only a single relation
    relation1.reified().get().castingsRelation().forEach(rolePlayer -> assertTrue(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty()));
    RelationshipImpl relation2 = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role2, other2).addRolePlayer(role1, entity);
    // Invalid with multiple relations
    relation1.reified().get().castingsRelation().forEach(rolePlayer -> {
        if (rolePlayer.getRole().equals(role1)) {
            assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty());
        }
    });
    relation2.reified().get().castingsRelation().forEach(rolePlayer -> {
        if (rolePlayer.getRole().equals(role1)) {
            assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty());
        }
    });
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) EntityImpl(ai.grakn.kb.internal.concept.EntityImpl) RelationshipType(ai.grakn.concept.RelationshipType) EntityTypeImpl(ai.grakn.kb.internal.concept.EntityTypeImpl) RelationshipImpl(ai.grakn.kb.internal.concept.RelationshipImpl) Test(org.junit.Test)

Aggregations

Entity (ai.grakn.concept.Entity)1 EntityType (ai.grakn.concept.EntityType)1 RelationshipType (ai.grakn.concept.RelationshipType)1 Role (ai.grakn.concept.Role)1 EntityImpl (ai.grakn.kb.internal.concept.EntityImpl)1 EntityTypeImpl (ai.grakn.kb.internal.concept.EntityTypeImpl)1 RelationshipImpl (ai.grakn.kb.internal.concept.RelationshipImpl)1 Test (org.junit.Test)1