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