public InvalidQueryDiagnosedException(OperationContext context, InvalidQueryException cause) { super( context, cause, Diagnosis. create(). statusCode(Status.BAD_REQUEST). diagnostic("Invalid query: %s",cause.getMessage()). mandatory(true)); }
@Test public void testGetDescription$failureRequest$invalidValue() throws Exception { Name<?> id = NamingScheme.getDefault().name("Test"); Query query = QueryBuilder. newInstance(). withParameter(QueryableResourceHandler.FAILURE, "not a boolean"). build(); try { QuerySupport.getDescription(id, query); fail("Should not accept queries with the failure parameter"); } catch (InvalidQueryException e) { assertThat(e.getQuery(),equalTo(query)); assertThat(e.getCause(),instanceOf(ObjectTransformationException.class)); } }
try { if(failure.rawValueAs(Boolean.class)) { throw new InvalidQueryException("Failure requested", query); throw new InvalidQueryException("Could not understand: '"+failure.rawValue()+"' is not a valid boolean value for parameter '"+QueryableResourceHandler.FAILURE+"'",e,query);
@Test public void testGetDescription$failureRequest$happyPath() throws Exception { Name<?> id = NamingScheme.getDefault().name("Test"); Query query = QueryBuilder. newInstance(). withParameter(QueryableResourceHandler.FAILURE, "true"). build(); try { QuerySupport.getDescription(id, query); fail("Should not accept queries with the failure parameter set to true"); } catch (InvalidQueryException e) { assertThat(e.getQuery(),equalTo(query)); assertThat(e.getCause(),nullValue()); } }