Search in sources :

Example 1 with GraknTxOperationException

use of ai.grakn.exception.GraknTxOperationException in project grakn by graknlabs.

the class AttributeTypePropertyTest method whenPuttingAResourceAndMethodThrows_DoNotCreateTheResource.

@Property
public void whenPuttingAResourceAndMethodThrows_DoNotCreateTheResource(@NonMeta @NonAbstract AttributeType type, @From(ResourceValues.class) Object value) {
    Collection previousResources = (Collection) type.instances().collect(toSet());
    try {
        type.putAttribute(value);
        assumeTrue("Assumed putResource would throw", false);
    } catch (GraknTxOperationException e) {
    // This is expected to throw
    }
    Collection newResources = (Collection) type.instances().collect(toSet());
    assertEquals(previousResources.size(), newResources.size());
}
Also used : Collection(java.util.Collection) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) Property(com.pholser.junit.quickcheck.Property)

Example 2 with GraknTxOperationException

use of ai.grakn.exception.GraknTxOperationException in project grakn by graknlabs.

the class GraqlControllerInsertTest method POSTGraqlDefineNotValid_ResponseStatusCodeIs422.

@Test
public void POSTGraqlDefineNotValid_ResponseStatusCodeIs422() {
    GraknTxOperationException exception = GraknTxOperationException.invalidCasting(Object.class, Object.class);
    when(tx.graql().parser().parseQuery("define person plays movie;").execute()).thenThrow(exception);
    Response response = sendRequest("define person plays movie;");
    assertThat(response.statusCode(), equalTo(422));
}
Also used : Response(com.jayway.restassured.response.Response) GraqlControllerReadOnlyTest.jsonResponse(ai.grakn.engine.controller.GraqlControllerReadOnlyTest.jsonResponse) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) Test(org.junit.Test)

Example 3 with GraknTxOperationException

use of ai.grakn.exception.GraknTxOperationException in project grakn by graknlabs.

the class GraknTxTest method attemptingToUseClosedGraphFailingThenOpeningGraph_EnsureGraphIsUsable.

@Test
public void attemptingToUseClosedGraphFailingThenOpeningGraph_EnsureGraphIsUsable() throws InvalidKBException {
    GraknTx graph = Grakn.session(Grakn.IN_MEMORY, "testingagain").open(GraknTxType.WRITE);
    graph.close();
    boolean errorThrown = false;
    try {
        graph.putEntityType("A Thing");
    } catch (GraknTxOperationException e) {
        if (e.getMessage().equals(ErrorMessage.TX_CLOSED_ON_ACTION.getMessage("closed", graph.keyspace()))) {
            errorThrown = true;
        }
    }
    assertTrue("Graph not correctly closed", errorThrown);
    graph = Grakn.session(Grakn.IN_MEMORY, "testingagain").open(GraknTxType.WRITE);
    graph.putEntityType("A Thing");
}
Also used : GraknTx(ai.grakn.GraknTx) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) Test(org.junit.Test)

Example 4 with GraknTxOperationException

use of ai.grakn.exception.GraknTxOperationException in project grakn by graknlabs.

the class AttributeTest method whenCreatingResourceWithAnInvalidDataType_DoNotCreateTheResource.

// this is deliberately an incorrect type for the test
@SuppressWarnings("unchecked")
@Test
public void whenCreatingResourceWithAnInvalidDataType_DoNotCreateTheResource() {
    AttributeType longAttributeType = tx.putAttributeType("long", AttributeType.DataType.LONG);
    try {
        longAttributeType.putAttribute("Invalid Thing");
        fail("Expected to throw");
    } catch (GraknTxOperationException e) {
    // expected failure
    }
    Collection<Attribute> instances = (Collection<Attribute>) longAttributeType.instances().collect(toSet());
    assertThat(instances, empty());
}
Also used : Attribute(ai.grakn.concept.Attribute) AttributeType(ai.grakn.concept.AttributeType) Collection(java.util.Collection) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) Test(org.junit.Test)

Example 5 with GraknTxOperationException

use of ai.grakn.exception.GraknTxOperationException in project grakn by graknlabs.

the class GraqlControllerDeleteTest method DELETEGraqlDeleteNotValid_ResponseExceptionContainsValidationErrorMessage.

@Test
public void DELETEGraqlDeleteNotValid_ResponseExceptionContainsValidationErrorMessage() {
    GraknTxOperationException exception = GraknTxOperationException.cannotBeDeleted(mock(SchemaConcept.class));
    // Not allowed to delete roles with incoming edges
    when(tx.graql().parser().parseQuery("undefine production-being-directed sub work;").execute()).thenThrow(exception);
    Response response = sendRequest("undefine production-being-directed sub work;");
    assertThat(exception(response), containsString("cannot be deleted"));
}
Also used : Response(com.jayway.restassured.response.Response) GraknTxOperationException(ai.grakn.exception.GraknTxOperationException) SchemaConcept(ai.grakn.concept.SchemaConcept) Test(org.junit.Test)

Aggregations

GraknTxOperationException (ai.grakn.exception.GraknTxOperationException)8 Test (org.junit.Test)6 Response (com.jayway.restassured.response.Response)4 SchemaConcept (ai.grakn.concept.SchemaConcept)2 GraqlControllerReadOnlyTest.jsonResponse (ai.grakn.engine.controller.GraqlControllerReadOnlyTest.jsonResponse)2 Collection (java.util.Collection)2 GraknTx (ai.grakn.GraknTx)1 Attribute (ai.grakn.concept.Attribute)1 AttributeType (ai.grakn.concept.AttributeType)1 InvalidKBException (ai.grakn.exception.InvalidKBException)1 Property (com.pholser.junit.quickcheck.Property)1 ExecutionException (java.util.concurrent.ExecutionException)1 VerificationException (org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.VerificationException)1