/** * For each supplied regexp, fail unless content contains at * least one line that matches. * Regexps are automatically prefixed/suffixed with .* so as * to have match partial lines. */ public RequestExecutor assertContentRegexp(String... regexp) { return assertContentRegexp(true,regexp); } /**
/** * Wrap supplied HTTP request */ public Request buildOtherRequest(HttpRequestBase r) { return new Request(r); }
public void setAttribute(String name, Object object) { this.putAttribute(name, object); }
/** * Executes a {@link QueryTestCase} by sending the * {@link QueryTestCase#getContent() query} as an POST request to the * <code>{@link #endpointPath}/{@link QueryTestCase#getServicePath()}</Code>. * @param path the path to perform the field query. "/query" is added to the * parsed value * @param test the field query test * @return the result executor used for the test * @throws IOException on any exception while connecting to the entityhub * @throws JSONException if the returned results are not valid JSON */ protected RequestExecutor executeQuery(QueryTestCase test) throws IOException, JSONException { Request request = builder.buildPostRequest(endpointPath+test.getServicePath()); for(Entry<String,String> header : test.getHeaders().entrySet()){ request.withHeader(header.getKey(), header.getValue()); } request.withContent(test.getContent()); RequestExecutor re = executor.execute(request); assertQueryResults(re, test); return re; } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/** * Retry Condition c until it returns true or timeout. See {@link Condition} * for isTrue semantics. */ public RetryLoop(Condition c, int timeoutSeconds, int intervalBetweenTriesMsec) { timeout = System.currentTimeMillis() + timeoutSeconds * 1000L; while (System.currentTimeMillis() < timeout) { try { if (c.isTrue()) { return; } } catch (AssertionError ae) { // Retry JUnit tests failing in the condition as well reportException(ae); } catch (Exception e) { reportException(e); } try { Thread.sleep(intervalBetweenTriesMsec); } catch (InterruptedException ignore) { } } onTimeout(); fail("RetryLoop failed, condition is false after " + timeoutSeconds + " seconds: " + c.getDescription()); }
protected Request buildMultipartRequest(String path,MultipartEntity multiPart) { HttpPost httpPost = new HttpPost(builder.buildUrl(path)); httpPost.setEntity(multiPart); /** * In case of Multipart requests, we must __NOT__ set the content-type header to multipart/form-data. * If we do it, we have a 400 response (bad request). */ return this.builder.buildOtherRequest(httpPost); }
/** * Create the job and check for its status until it is complete * * @param request * @throws Exception */ protected void executeAndPingSingleJob(Request request) throws Exception{ log.info("Executing: {}", request.getRequest().getURI()); String location = createJob(request); log.info("Job location is {}", location); // Get the result and ping the jId pingSingleJob(location); }
/** * For each supplied string, fail unless content contains it */ public RequestExecutor assertContentContains(String... expected) throws ParseException { assertNotNull(this.toString(), response); for (String exp : expected) { if (!contentString.contains(exp)) { fail(this + ": content does not contain '" + exp + "', content=\n" + contentString); } } return this; }
@After public void closeExecutor(){ executor.close(); }
public void generateDocumentation(RequestDocumentor documentor, String... metadata) throws IOException { documentor.generateDocumentation(this, metadata); }
public Request withEntity(HttpEntity e) { getHttpEntityEnclosingRequestBase().setEntity(e); return this; }
public Request withContent(String content) throws UnsupportedEncodingException { return withEntity(new StringEntity(content, "UTF-8")); } /**
public void close() { clear(); try { httpClient.close(); } catch (IOException e) { log.error("Error while closing Http Client", e); } } }
public ServletContextMock() { this.attributeMap.put(BundleContext.class.getName(), new BundleContextMock()); }
/** * Verify that response matches supplied status */ public RequestExecutor assertStatus(int expected) { assertNotNull(this.toString(), response); int status = response.getStatusLine().getStatusCode(); assertEquals(this + ": expecting status " + expected + " (content: "+contentString+")", expected, status); return this; }
@After public void closeExecutor(){ executor.close(); }
/** * Verify that response matches supplied charset */ public RequestExecutor assertCharset(String expected) { assertNotNull(this.toString(), response); if (entity == null) { fail(this + ": no entity in response, cannot check content type"); } assertEquals(this + ": expecting charset " + expected, expected, charset == null ? null : charset.name()); return this; }
/** * Verify that response matches supplied content type */ public RequestExecutor assertContentType(String expected) { assertNotNull(this.toString(), response); if (entity == null) { fail(this + ": no entity in response, cannot check content type"); } // And check for match assertEquals(this + ": expecting content type " + expected, expected, contentType.getMimeType()); return this; } /**