@Override protected void setUp() throws Exception { parser = new FormatOptionsKvpParser(); }
private Hints getQueryHints(String viewParams) { if (viewParams != null && !viewParams.isEmpty()) { FormatOptionsKvpParser parser = new FormatOptionsKvpParser(); Map<String, String> params; try { params = (Map<String, String>) parser.parse(viewParams); return new Hints(Hints.VIRTUAL_TABLE_PARAMETERS, params); } catch (Exception e) { throw new RestException("Invalid viewparams", HttpStatus.INTERNAL_SERVER_ERROR); } } return null; }
@Override public Operation operationDispatched(Request request, Operation operation) { String sim = Optional.ofNullable(request.getRawKvp().get(KVP)) .map(String.class::cast) .orElse(null); if (sim == null) { return operation; } Map<String, Object> simOpts; if (sim.contains(";")) { try { simOpts = (Map<String, Object>) new FormatOptionsKvpParser().parse(sim.toString()); } catch (Exception e) { throw new RuntimeException( "Illegal syntax for simulate options: simulate=<key>:<val>[;<key>:<val>]*", e); } } else { simOpts = Collections.emptyMap(); } throw new HttpErrorCodeException(202, toJSON(operation, simOpts)) .setContentType("application/json"); }
static void assertMapsEqual(Map<String, Object> expected, Map<String, Object> actual) throws Exception { for (Map.Entry<String, Object> entry : expected.entrySet()) { if (entry.getKey().equalsIgnoreCase("format_options")) { FormatOptionsKvpParser parser = new FormatOptionsKvpParser(); Map expectedFormatOptions = (Map) parser.parse((String) entry.getValue()); Map actualFormatOptions = (Map) parser.parse((String) actual.get(entry.getKey())); for (Object o : expectedFormatOptions.entrySet()) { Map.Entry formatOption = (Map.Entry) o; assertEquals( formatOption.getValue(), actualFormatOptions.get(formatOption.getKey())); } for (Object key : actualFormatOptions.keySet()) { assertTrue( "found unexpected key '" + key + "' in format options", expectedFormatOptions.containsKey(key)); } // special treatment for the format options } else { assertEquals(entry.getValue(), actual.get(entry.getKey())); } } for (String key : actual.keySet()) { assertTrue(expected.containsKey(key)); } }