Search in sources :

Example 6 with Thing

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();
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 7 with Thing

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();
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Relationship(ai.grakn.concept.Relationship) RelationshipType(ai.grakn.concept.RelationshipType) Thing(ai.grakn.concept.Thing) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Thing

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();
}
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 9 with Thing

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));
}
Also used : Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Example 10 with Thing

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)));
}
Also used : Role(ai.grakn.concept.Role) Thing(ai.grakn.concept.Thing) Test(org.junit.Test)

Aggregations

Thing (ai.grakn.concept.Thing)47 Role (ai.grakn.concept.Role)30 Test (org.junit.Test)29 RelationshipType (ai.grakn.concept.RelationshipType)17 EntityType (ai.grakn.concept.EntityType)14 Relationship (ai.grakn.concept.Relationship)12 HashSet (java.util.HashSet)9 Set (java.util.Set)9 GraknTx (ai.grakn.GraknTx)7 Attribute (ai.grakn.concept.Attribute)7 ConceptId (ai.grakn.concept.ConceptId)7 AttributeType (ai.grakn.concept.AttributeType)6 Concept (ai.grakn.concept.Concept)6 Entity (ai.grakn.concept.Entity)6 Collectors (java.util.stream.Collectors)5 Label (ai.grakn.concept.Label)4 Schema (ai.grakn.util.Schema)4 Collection (java.util.Collection)4 Map (java.util.Map)4 GraknSession (ai.grakn.GraknSession)3