use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class GrpcServerTest method whenGettingIsImplicitProperty_IsImplicitIsReturned.
@Test
public void whenGettingIsImplicitProperty_IsImplicitIsReturned() throws InterruptedException {
ConceptId id = ConceptId.of("V123456");
Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
when(tx.getConcept(id)).thenReturn(concept);
when(concept.isSchemaConcept()).thenReturn(true);
when(concept.asSchemaConcept().isImplicit()).thenReturn(true);
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.READ));
tx.receive().ok();
tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.IS_IMPLICIT));
assertTrue(ConceptMethods.IS_IMPLICIT.get(conceptConverter, client, tx.receive().ok()));
}
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class GrpcServerTest method whenRemovingRolePlayer_RolePlayerIsRemoved.
@Test
public void whenRemovingRolePlayer_RolePlayerIsRemoved() throws InterruptedException {
ConceptId conceptId = ConceptId.of("V123456");
ConceptId roleId = ConceptId.of("ROLE");
ConceptId playerId = ConceptId.of("PLAYER");
Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
when(tx.getConcept(conceptId)).thenReturn(concept);
when(concept.isRelationship()).thenReturn(true);
Role role = mock(Role.class, RETURNS_DEEP_STUBS);
when(tx.getConcept(roleId)).thenReturn(role);
when(role.isRole()).thenReturn(true);
when(role.asRole()).thenReturn(role);
when(role.getId()).thenReturn(roleId);
Entity player = mock(Entity.class, RETURNS_DEEP_STUBS);
when(tx.getConcept(playerId)).thenReturn(player);
when(player.isEntity()).thenReturn(true);
when(player.asEntity()).thenReturn(player);
when(player.isThing()).thenReturn(true);
when(player.asThing()).thenReturn(player);
when(player.getId()).thenReturn(playerId);
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.READ));
tx.receive().ok();
ConceptMethod<Void> conceptMethod = ConceptMethods.removeRolePlayer(RolePlayer.create(role, player));
tx.send(GrpcUtil.runConceptMethodRequest(conceptId, conceptMethod));
tx.receive().ok();
verify(concept.asRelationship()).removeRolePlayer(role, player);
}
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class XMLMigratorTest method clearGraph.
@After
public void clearGraph() {
try (GraknTx graph = session.open(GraknTxType.WRITE)) {
AttributeType<String> nameType = graph.getAttributeType("name");
nameType.instances().forEach(Concept::delete);
EntityType thingType = graph.getEntityType("thingy");
thingType.instances().forEach(Concept::delete);
graph.commit();
}
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class GrpcServerIT method whenGettingAConcept_TheInformationOnTheConceptIsCorrect.
@Test
public void whenGettingAConcept_TheInformationOnTheConceptIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x")).get();
for (Answer answer : query) {
Concept remoteConcept = answer.get("x");
Concept localConcept = localTx.getConcept(remoteConcept.getId());
assertEquals(localConcept.isAttribute(), remoteConcept.isAttribute());
assertEquals(localConcept.isAttributeType(), remoteConcept.isAttributeType());
assertEquals(localConcept.isEntity(), remoteConcept.isEntity());
assertEquals(localConcept.isEntityType(), remoteConcept.isEntityType());
assertEquals(localConcept.isRelationship(), remoteConcept.isRelationship());
assertEquals(localConcept.isRelationshipType(), remoteConcept.isRelationshipType());
assertEquals(localConcept.isRole(), remoteConcept.isRole());
assertEquals(localConcept.isRule(), remoteConcept.isRule());
assertEquals(localConcept.isSchemaConcept(), remoteConcept.isSchemaConcept());
assertEquals(localConcept.isThing(), remoteConcept.isThing());
assertEquals(localConcept.isType(), remoteConcept.isType());
assertEquals(localConcept.getId(), remoteConcept.getId());
assertEquals(localConcept.isDeleted(), remoteConcept.isDeleted());
assertEquals(localConcept.keyspace(), remoteConcept.keyspace());
}
}
}
use of ai.grakn.concept.Concept in project grakn by graknlabs.
the class ReasonerQueryImpl method getRoleSubstitution.
public Answer getRoleSubstitution() {
Map<Var, Concept> roleSub = new HashMap<>();
getAtoms(RelationshipAtom.class).flatMap(RelationshipAtom::getRolePredicates).forEach(p -> {
Concept concept = tx().getConcept(p.getPredicate());
if (concept == null)
throw GraqlQueryException.idNotFound(p.getPredicate());
roleSub.put(p.getVarName(), concept);
});
return new QueryAnswer(roleSub);
}
Aggregations