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