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());
}
});
}
Aggregations