/** * Create new HTTP request to the test server * * @param path the path to call * @return the created {@link HTTPRequest} */ protected final HTTPRequest request(String path) { return WS.url(this.serverURL + path); }
/** * assert that the response has a 2XX status code * * @param res the response to check */ protected final void assertOK(HttpResponse res) { Assert.assertTrue(String.format("Expected OK - was %s", WS.getStatus(res)), WS.isStatusOK(res)); }
private String getAuthToken(String token) { if(token == null || token.isEmpty()) { return null; } String path = this.protocol + "://" + this.server + "/api/auth"; String body = "{\"token\":\"" + token + "\"}"; HttpResponse response = WS.url(path).body(body).header("Content-Type", "application/json;charset=UTF-8").put(); int status = WS.getStatus(response); if(200 <= status && 300 > status) { String responseAsString = WS.getResponseAsString(response); if(responseAsString.startsWith("\"")) { responseAsString = responseAsString.substring(1); } if(responseAsString.endsWith("\"")) { responseAsString = responseAsString.substring(0, responseAsString.length() - 1); } return responseAsString; } else { this.logger.warn("Authentication with CloudConductor Server %s failed with status %s", this.server, status); } return null; } }
/** * assert that the response has the given status code * * @param res the response to check * @param status the status to check against */ protected final void assertStatus(HttpResponse res, Status status) { Assert.assertTrue(String.format("Expected %s - was %s", status.getStatusCode(), WS.getStatus(res)), WS.getStatus(res) == status.getStatusCode()); }
/** * Create new HTTP request to the test server * * @param path the path to call * @return the created {@link HTTPRequest} */ protected final HTTPRequest request(String path) { return WS.url(this.serverURL + path); }
@Override protected HttpResponse getResponse() { return WS.url(this.url).get(); }
@Override protected HTTPResponse getResponse() { return WS.url(this.url).get(); }
private String getAuthToken(String token) { if(token == null || token.isEmpty()) { return null; } String path = this.protocol + "://" + this.server + "/api/auth"; String body = "{\"token\":\"" + token + "\"}"; HTTPRequest httpRequest = WS.url(path).body(body).header("Content-Type", "application/json;charset=UTF-8"); try (HTTPResponse response = httpRequest.put()) { int status = response.getStatus(); if (200 <= status && 300 > status) { String responseAsString = response.getResponseAsString(); if (responseAsString.startsWith("\"")) { responseAsString = responseAsString.substring(1); } if (responseAsString.endsWith("\"")) { responseAsString = responseAsString.substring(0, responseAsString.length() - 1); } return responseAsString; } else { this.logger.warn("Authentication with CloudConductor Server {} failed with status {}", this.server, status); } } return null; } }
private String createTicket(Ticket ticket) { final String json; try { json = MapperFactory.createDefault().writeValueAsString(ticket.toJsonMap()); } catch (JsonProcessingException e) { throw new RuntimeException(e); } String url = "https://" + this.subdomain + ".zendesk.com/api/v2/tickets.json"; HTTPRequest req = WS.url(url).authBasic(this.agentMail + "/token", this.agentToken).contentType(MediaType.APPLICATION_JSON).body(json); try (HTTPResponse post = req.post()) { if (post.getStatus() != 201) { throw new InternalServerErrorException(); } return post.getResponseAsString(); } }
@Override protected HTTPResponse getResponse() { HTTPRequest req = WS.url(this.protocol + "://" + this.server + "/api/config/{template}/{svc}"); req.pathParam("template", this.template).pathParam("svc", DaemonStarter.getDaemonName()); req.accept("application/x-javaprops"); if(this.jwt != null) { req.authBearer(this.jwt); } return req.get(); }
@Override protected HttpResponse getResponse() { HTTPRequest req = WS.url(this.protocol + "://" + this.server + "/api/config/{template}/{svc}"); req.pathParam("template", this.template).pathParam("svc", DaemonStarter.getDaemonName()); req.accept("application/x-javaprops"); if(this.jwt != null) { req.authBearer(this.jwt); } return req.get(); }