@Test public void shouldThrowAppropriateException() { try { db.execute( "RETURN rand()/0" ).next(); } catch ( QueryExecutionException ex ) { assertThat( ex.getCause(), instanceOf( QueryExecutionKernelException.class ) ); assertThat( ex.getCause().getCause(), instanceOf( ArithmeticException.class ) ); } }
@Test public void shouldRefuseToCreateIndexWithNoStructure() throws Exception { // when try { execute("CALL apoc.index.addAllNodes('empty', {})"); fail("expected exception"); } // then catch (QueryExecutionException e) { Throwable cause = e.getCause(); for (Throwable next = cause.getCause(); next != null; ) { cause = next; next = cause.getCause(); } assertThat(cause, instanceOf(IllegalArgumentException.class)); assertEquals("No structure given.", cause.getMessage()); } }
@Test public void testValidateTrue() throws Exception { try { db.execute("CALL apoc.util.validate(true,'message %d',[42])").close(); fail("should have failed"); } catch(QueryExecutionException qee) { assertEquals("Failed to invoke procedure `apoc.util.validate`: Caused by: java.lang.RuntimeException: message 42",qee.getCause().getCause().getMessage()); } }
private Throwable findRecognizableCause(QueryExecutionException qee) { Throwable cause = qee.getCause(); while ( cause.getCause() != null ) { cause = cause.getCause(); } return cause; }