protected void doBooleanLinksOnly(BooleanQueryResultFormat format, boolean input, List<String> links) throws IOException, QueryResultHandlerException, QueryResultParseException, UnsupportedQueryResultFormatException, QueryEvaluationException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); BooleanQueryResultWriter writer = QueryResultIO.createBooleanWriter(format, out); writer.handleLinks(links); writer.handleBoolean(input); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); boolean output = QueryResultIO.parseBoolean(in, format); assertEquals(output, input); }
protected void doBooleanLinks(BooleanQueryResultFormat format, boolean input, List<String> links) throws IOException, QueryResultHandlerException, QueryResultParseException, UnsupportedQueryResultFormatException, QueryEvaluationException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); BooleanQueryResultWriter writer = QueryResultIO.createBooleanWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(links); writer.handleBoolean(input); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); boolean output = QueryResultIO.parseBoolean(in, format); assertEquals(output, input); }
protected void doInvalidBooleanAfterStartQueryResult(BooleanQueryResultFormat format, boolean input, List<String> links) throws IOException, QueryResultHandlerException, QueryResultParseException, UnsupportedQueryResultFormatException, QueryEvaluationException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); BooleanQueryResultWriter writer = QueryResultIO.createBooleanWriter(format, out); writer.handleLinks(links); // Determine whether this writer also supports startQueryResult, if not, // this test is irrelevant as it will fail early boolean supported = true; try { writer.startQueryResult(Arrays.asList("foo")); } catch (UnsupportedOperationException uoe) { // Boolean writers are allowed to throw this for startQueryResult supported = false; } if (supported) { try { // After calling startQueryResult, we should not be able to call // handleBoolean without an exception occuring writer.handleBoolean(input); fail("Did not find expected exception"); } catch (QueryResultHandlerException e) { // Expected } } }
protected void doBooleanLinksAndStylesheetAndNamespaces(BooleanQueryResultFormat format, boolean input, List<String> links, String stylesheetUrl, Map<String, String> namespaces) throws IOException, QueryResultHandlerException, QueryResultParseException, UnsupportedQueryResultFormatException, QueryEvaluationException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); BooleanQueryResultWriter writer = QueryResultIO.createBooleanWriter(format, out); for (String nextPrefix : namespaces.keySet()) { writer.handleNamespace(nextPrefix, namespaces.get(nextPrefix)); } writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); writer.handleBoolean(input); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); boolean output = QueryResultIO.parseBoolean(in, format); assertEquals(output, input); }
protected void doBooleanLinksAndStylesheet(BooleanQueryResultFormat format, boolean input, List<String> links, String stylesheetUrl) throws IOException, QueryResultHandlerException, QueryResultParseException, UnsupportedQueryResultFormatException, QueryEvaluationException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); BooleanQueryResultWriter writer = QueryResultIO.createBooleanWriter(format, out); writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); writer.handleBoolean(input); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); boolean output = QueryResultIO.parseBoolean(in, format); assertEquals(output, input); }