Search in sources :

Example 36 with ConceptId

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

the class IndexPostProcessorTest method whenPostProcessingIndices_EnsureFixingMethodIsCalled.

@Test
public void whenPostProcessingIndices_EnsureFixingMethodIsCalled() {
    // Setup mocks
    Keyspace keyspace = Keyspace.of("whatakeyspace");
    EmbeddedGraknTx<?> tx = mock(EmbeddedGraknTx.class);
    when(tx.duplicateResourcesExist(any(), any())).thenReturn(true);
    when(tx.keyspace()).thenReturn(keyspace);
    String index = "index1";
    Set<ConceptId> ids = Stream.of("a", "b", "c").map(ConceptId::of).collect(Collectors.toSet());
    // Call post processor
    indexPostProcessor.mergeDuplicateConcepts(tx, index, ids);
    // Check method calls
    verify(tx, Mockito.times(1)).fixDuplicateResources(index, ids);
}
Also used : Keyspace(ai.grakn.Keyspace) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 37 with ConceptId

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

the class RelatesProperty method mapToAtom.

@Override
public Atomic mapToAtom(VarPatternAdmin var, Set<VarPatternAdmin> vars, ReasonerQuery parent) {
    Var varName = var.var().asUserDefined();
    VarPatternAdmin roleVar = this.role();
    Var roleVariable = roleVar.var().asUserDefined();
    IdPredicate predicate = getIdPredicate(roleVariable, roleVar, vars, parent);
    ConceptId predicateId = predicate != null ? predicate.getPredicate() : null;
    return RelatesAtom.create(varName, roleVariable, predicateId, parent);
}
Also used : IdPredicate(ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate) ReasonerUtils.getIdPredicate(ai.grakn.graql.internal.reasoner.utils.ReasonerUtils.getIdPredicate) VarPatternAdmin(ai.grakn.graql.admin.VarPatternAdmin) Var(ai.grakn.graql.Var) ConceptId(ai.grakn.concept.ConceptId)

Example 38 with ConceptId

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

the class GrpcServerTest method whenGettingALabelForANonSchemaConcept_Throw.

@Test
public void whenGettingALabelForANonSchemaConcept_Throw() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isSchemaConcept()).thenReturn(false);
    when(concept.asSchemaConcept()).thenThrow(EXCEPTION);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.GET_LABEL));
        exception.expect(hasStatus(Status.UNKNOWN.withDescription(EXCEPTION_MESSAGE)));
        throw tx.receive().error();
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 39 with ConceptId

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

the class GrpcServerTest method whenGettingAConcept_ReturnTheConcept.

@Test
public void whenGettingAConcept_ReturnTheConcept() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(concept.getId()).thenReturn(id);
    when(concept.isRelationship()).thenReturn(true);
    when(tx.getConcept(id)).thenReturn(concept);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.getConceptRequest(id));
        GrpcConcept.OptionalConcept response = tx.receive().ok().getOptionalConcept();
        assertEquals(id.getValue(), response.getPresent().getId().getValue());
        assertEquals(BaseType.Relationship, response.getPresent().getBaseType());
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 40 with ConceptId

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

the class GrpcServerTest method whenGettingIsInferredProperty_IsInferredIsReturned.

@Test
public void whenGettingIsInferredProperty_IsInferredIsReturned() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isThing()).thenReturn(true);
    when(concept.asThing().isInferred()).thenReturn(false);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.IS_INFERRED));
        assertFalse(ConceptMethods.IS_INFERRED.get(conceptConverter, client, tx.receive().ok()));
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Aggregations

ConceptId (ai.grakn.concept.ConceptId)80 Test (org.junit.Test)55 Concept (ai.grakn.concept.Concept)23 Role (ai.grakn.concept.Role)22 RelationshipType (ai.grakn.concept.RelationshipType)19 GraknTx (ai.grakn.GraknTx)18 EntityType (ai.grakn.concept.EntityType)18 Label (ai.grakn.concept.Label)16 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)14 Var (ai.grakn.graql.Var)12 List (java.util.List)12 Entity (ai.grakn.concept.Entity)10 AttributeType (ai.grakn.concept.AttributeType)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 ClassRule (org.junit.ClassRule)9 GraknTxType (ai.grakn.GraknTxType)8 Keyspace (ai.grakn.Keyspace)8 IdPredicate (ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)8