Search in sources :

Example 91 with Role

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

the class ConceptPropertyTest method assumeDeletable.

private static void assumeDeletable(GraknTx graph, Concept concept) {
    // TODO: A better way to handle these assumptions?
    if (concept.isSchemaConcept()) {
        SchemaConcept schemaConcept = concept.asSchemaConcept();
        assumeThat(schemaConcept.subs().collect(toSet()), contains(schemaConcept));
        if (schemaConcept.isType()) {
            Type type = schemaConcept.asType();
            assumeThat(type.instances().collect(toSet()), empty());
            assumeThat(type.getRulesOfHypothesis().collect(toSet()), empty());
            assumeThat(type.getRulesOfConclusion().collect(toSet()), empty());
        }
        if (schemaConcept.isRole()) {
            Role role = schemaConcept.asRole();
            assumeThat(role.playedByTypes().collect(toSet()), empty());
            assumeThat(role.relationshipTypes().collect(toSet()), empty());
            Stream<Relationship> allRelations = graph.admin().getMetaRelationType().instances();
            Set<Role> allRolesPlayed = allRelations.flatMap(relation -> relation.allRolePlayers().keySet().stream()).collect(toSet());
            assumeThat(allRolesPlayed, not(hasItem(role)));
        } else if (schemaConcept.isRelationshipType()) {
            assumeThat(schemaConcept.asRelationshipType().relates().collect(toSet()), empty());
        }
    }
}
Also used : Role(ai.grakn.concept.Role) FromTx(ai.grakn.generator.FromTxGenerator.FromTx) Assume.assumeThat(org.junit.Assume.assumeThat) Matchers.isA(org.hamcrest.Matchers.isA) Methods.mockParamsOf(ai.grakn.generator.Methods.mockParamsOf) Role(ai.grakn.concept.Role) Assume.assumeFalse(org.junit.Assume.assumeFalse) Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) MethodOf(ai.grakn.generator.Methods.MethodOf) RunWith(org.junit.runner.RunWith) Matchers.not(org.hamcrest.Matchers.not) Type(ai.grakn.concept.Type) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Open(ai.grakn.generator.GraknTxs.Open) NonMeta(ai.grakn.generator.AbstractSchemaConceptGenerator.NonMeta) JUnitQuickcheck(com.pholser.junit.quickcheck.runner.JUnitQuickcheck) GraknTx(ai.grakn.GraknTx) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ConceptId(ai.grakn.concept.ConceptId) Relationship(ai.grakn.concept.Relationship) ExpectedException(org.junit.rules.ExpectedException) Method(java.lang.reflect.Method) Collectors.toSet(java.util.stream.Collectors.toSet) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) ErrorMessage(ai.grakn.util.ErrorMessage) Matchers.empty(org.hamcrest.Matchers.empty) Property(com.pholser.junit.quickcheck.Property) Set(java.util.Set) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) InvocationTargetException(java.lang.reflect.InvocationTargetException) Rule(org.junit.Rule) Stream(java.util.stream.Stream) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Ignore(org.junit.Ignore) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) GraknTxs.allConceptsFrom(ai.grakn.generator.GraknTxs.allConceptsFrom) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) Type(ai.grakn.concept.Type) Relationship(ai.grakn.concept.Relationship) SchemaConcept(ai.grakn.concept.SchemaConcept)

Example 92 with Role

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

the class GraknTxPropertyTest method whenCallingGetConceptWithAnIncorrectGeneric_ItThrows.

@Property
public void whenCallingGetConceptWithAnIncorrectGeneric_ItThrows(@Open GraknTx graph, @FromTx Concept concept) {
    assumeFalse(concept.isRole());
    ConceptId id = concept.getId();
    exception.expect(ClassCastException.class);
    // We have to assign the result for the cast to happen
    // noinspection unused
    Role role = graph.getConcept(id);
}
Also used : Role(ai.grakn.concept.Role) ConceptId(ai.grakn.concept.ConceptId) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Property(com.pholser.junit.quickcheck.Property)

Example 93 with Role

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

the class RelationshipTypePropertyTest method whenRelatingARole_TheDirectSubTypeRelatedRolesAreUnchanged.

@Property
public void whenRelatingARole_TheDirectSubTypeRelatedRolesAreUnchanged(@NonMeta RelationshipType subType, @FromTx Role role) {
    RelationshipType superType = subType.sup();
    assumeFalse(isMetaLabel(superType.getLabel()));
    Set<Role> previousHasRoles = subType.relates().collect(toSet());
    superType.relates(role);
    Set<Role> newHasRoles = subType.relates().collect(toSet());
    assertEquals(previousHasRoles, newHasRoles);
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Property(com.pholser.junit.quickcheck.Property)

Example 94 with Role

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

the class RelationshipTypePropertyTest method whenDeletingARelatedRole_TheDirectSubTypeRelatedRolesAreUnchanged.

@Property
public void whenDeletingARelatedRole_TheDirectSubTypeRelatedRolesAreUnchanged(@NonMeta RelationshipType subType, @FromTx Role role) {
    RelationshipType superType = subType.sup();
    assumeFalse(isMetaLabel(superType.getLabel()));
    Set<Role> previousHasRoles = subType.relates().collect(toSet());
    superType.deleteRelates(role);
    Set<Role> newHasRoles = subType.relates().collect(toSet());
    assertEquals(previousHasRoles, newHasRoles);
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Property(com.pholser.junit.quickcheck.Property)

Example 95 with Role

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

the class RelationshipTypePropertyTest method whenRelatingARole_TheDirectSuperTypeRelatedRolesAreUnchanged.

@Property
public void whenRelatingARole_TheDirectSuperTypeRelatedRolesAreUnchanged(@NonMeta RelationshipType subType, @FromTx Role role) {
    RelationshipType superType = subType.sup();
    Set<Role> previousHasRoles = superType.relates().collect(toSet());
    subType.relates(role);
    Set<Role> newHasRoles = superType.relates().collect(toSet());
    assertEquals(previousHasRoles, newHasRoles);
}
Also used : Role(ai.grakn.concept.Role) RelationshipType(ai.grakn.concept.RelationshipType) Property(com.pholser.junit.quickcheck.Property)

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