use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class ValidatorTest method whenARoleInARelationIsNotPlayed_TheGraphIsValid.
@Test
public void whenARoleInARelationIsNotPlayed_TheGraphIsValid() {
Role role1 = tx.putRole("role-1");
Role role2 = tx.putRole("role-2");
RelationshipType relationshipType = tx.putRelationshipType("my-relation").relates(role1).relates(role2);
Thing thing = tx.putEntityType("my-entity").plays(role1).addEntity();
relationshipType.addRelationship().addRolePlayer(role1, thing);
tx.commit();
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class ValidatorTest method whenARoleInARelationIsPlayedAZillionTimes_TheGraphIsValid.
@Test
public void whenARoleInARelationIsPlayedAZillionTimes_TheGraphIsValid() {
Role role1 = tx.putRole("role-1");
Role role2 = tx.putRole("role-2");
RelationshipType relationshipType = tx.putRelationshipType("my-relationship").relates(role1).relates(role2);
EntityType entityType = tx.putEntityType("my-entity").plays(role1);
Relationship relationship = relationshipType.addRelationship();
Set<Thing> things = new HashSet<>();
int oneZillion = 100;
for (int i = 0; i < oneZillion; i++) {
Thing thing = entityType.addEntity();
things.add(thing);
relationship.addRolePlayer(role1, thing);
}
assertEquals(things, relationship.rolePlayers(role1).collect(toSet()));
tx.commit();
}
use of ai.grakn.concept.Thing 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();
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingInstances_GetTheExpectedResult.
@Test
public void whenCallingInstances_GetTheExpectedResult() {
Thing a = RemoteConcepts.createRelationship(tx, A);
Thing b = RemoteConcepts.createRelationship(tx, B);
Thing c = RemoteConcepts.createRelationship(tx, C);
mockConceptMethod(ConceptMethods.GET_INSTANCES, Stream.of(a, b, c));
assertThat(relationshipType.instances().collect(toSet()), containsInAnyOrder(a, b, c));
}
use of ai.grakn.concept.Thing in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingAddRolePlayer_ExecuteAConceptMethod.
@Test
public void whenCallingAddRolePlayer_ExecuteAConceptMethod() {
Role role = RemoteConcepts.createRole(tx, A);
Thing thing = RemoteConcepts.createEntity(tx, B);
assertEquals(relationship, relationship.addRolePlayer(role, thing));
verifyConceptMethodCalled(ConceptMethods.setRolePlayer(RolePlayer.create(role, thing)));
}
Aggregations