public void testBuildBadQuery() { PathQueryBuilder pqb = new PathQueryBuilder(); try { pqb.buildQuery(invalidXML, schemaUrl, bags); fail( "Build query did not throw an exception - despite being given bad input - got this:" + pqb.getQuery()); } catch (AssertionFailedError e) { throw e; } catch (BadRequestException e) { assertEquals( "cvc-complex-type.4: Attribute 'view' must appear on element 'query'.", e.getMessage()); } catch (Throwable t) { fail("Unexpected error when building a query from bad xml" + t.getMessage()); } try { pqb.buildQuery(badQuery, schemaUrl, bags); fail( "Build query did not throw an exception - despite being given bad input - got this:" + pqb.getQuery()); } catch (AssertionFailedError e) { throw e; } catch (BadRequestException e) { assertEquals( "XML is well formatted but query contains errors: Multiple root classes in query: Employee and Department.", e.getMessage()); } catch (Throwable t) { fail("Unexpected error when building a query from bad xml" + t.getMessage()); } try { pqb.buildQuery(bagXML, schemaUrl, bags); fail( "Build query did not throw an exception - despite being given bad input - got this:" + pqb.getQuery()); } catch (AssertionFailedError e) { throw e; } catch (BadRequestException e) { assertEquals( "The query XML is well formatted but you do not have access to the following " + "mentioned lists: [Decent Human Beings] query: <query model=\"testmodel\" " + "view=\"Employee.age Employee.name\"><constraint path=\"Employee\" " + "op=\"IN\" value=\"Decent Human Beings\" /></query>", e.getMessage()); } catch (Throwable t) { fail("Unexpected error when building a query from bad xml" + t.getMessage()); } }
public void testBuildGoodQuery() { PathQueryBuilder pqb = new PathQueryBuilder(); pqb.buildQuery(goodXML, schemaUrl, bags); assertEquals(expectedGoodQuery.toString(), pqb.getQuery().toString()); }