public static int statusCode(Response response) { return response.getStatusCode(); }
public static int statusCode(Response response) { return response.getStatusCode(); }
Response response = RestUtil.sendHttpGet(contentType, url.toString(), responseLog); if (response.getStatusCode() == 200) { LOGGER.debug("Call passed with status code '" + response.getStatusCode() + "'. "); } else { LOGGER.error("Call failed with status code '" + response.getStatusCode() + "'. ");
/** * get Push Service Response * * @param contentType String * @param request String * @param url String * @param responseLog boolean * @return JsonObject */ public static JsonObject getPushServiceResponse(String contentType, String request, String url, boolean responseLog) { try { LOGGER.info("Request url: " + url); Response response = RestUtil.sendHttpPost(contentType, request, url.toString(), responseLog); if (response.getStatusCode() == 200) { LOGGER.debug("Call passed with status code '" + response.getStatusCode() + "'. "); JsonParser parser = new JsonParser(); return parser.parse(response.asString()).getAsJsonObject(); } else { LOGGER.error("Call failed with status code '" + response.getStatusCode() + "'. "); } } catch (Exception e) { LOGGER.error("getPushServiceResponse failure", e); } return null; }
/** * call Push Service * * @param contentType String * @param parameters Map String, ? * @param url String * @param responseLog boolean * @return JsonObject */ public static JsonObject callPushService(String contentType, Map<String, ?> parameters, String url, boolean responseLog) { try { LOGGER.info("Request url: " + url); Response response = RestUtil.sendHttpPost(contentType, parameters, url.toString(), responseLog); if (response.getStatusCode() == 200) { LOGGER.debug("Call passed with status code '" + response.getStatusCode() + "'. "); JsonParser parser = new JsonParser(); return parser.parse(response.asString()).getAsJsonObject(); } else { LOGGER.error("Call failed with status code '" + response.getStatusCode() + "'. "); } } catch (Exception e) { LOGGER.error("callPushService failure", e); } return null; }
/** * get Push Service Response * * @param contentType String * @param request String * @param url String * @param responseLog boolean * @return JsonObject */ public static JsonObject getPushServiceResponse(String contentType, String request, String url, boolean responseLog) { try { LOGGER.info("Request url: " + url); Response response = RestUtil.sendHttpPost(contentType, request, url.toString(), responseLog); if (response.getStatusCode() == 200) { LOGGER.debug("Call passed with status code '" + response.getStatusCode() + "'. "); JsonParser parser = new JsonParser(); return parser.parse(response.asString()).getAsJsonObject(); } else { LOGGER.error("Call failed with status code '" + response.getStatusCode() + "'. "); } } catch (Exception e) { LOGGER.error("getPushServiceResponse failure", e); } return null; }
Response response = RestUtil.sendHttpGet(contentType, url.toString(), responseLog); if (response.getStatusCode() == 200) { LOGGER.debug("Call passed with status code '" + response.getStatusCode() + "'. "); } else { LOGGER.error("Call failed with status code '" + response.getStatusCode() + "'. ");
/** * call Push Service * * @param contentType String * @param parameters Map String, ? * @param url String * @param responseLog boolean * @return JsonObject */ public static JsonObject callPushService(String contentType, Map<String, ?> parameters, String url, boolean responseLog) { try { LOGGER.info("Request url: " + url); Response response = RestUtil.sendHttpPost(contentType, parameters, url.toString(), responseLog); if (response.getStatusCode() == 200) { LOGGER.debug("Call passed with status code '" + response.getStatusCode() + "'. "); JsonParser parser = new JsonParser(); return parser.parse(response.asString()).getAsJsonObject(); } else { LOGGER.error("Call failed with status code '" + response.getStatusCode() + "'. "); } } catch (Exception e) { LOGGER.error("callPushService failure", e); } return null; }
@Nullable public String getProperty(@Nonnull String key) { Response response = systemPropertiesTester.get(new PropertyRequest.Builder(key) .expectStatus(okOrNotFound()) .build()); return response.getStatusCode() == Status.OK.getStatusCode() ? response.as(BaseRestEntity.class).getString(VALUE_PROPERTY) : null; }
/** * Clone an already existing response. * * @return Builder. */ public ResponseBuilder clone(Response response) { if (isRestAssuredResponse(response)) { final RestAssuredResponseImpl raResponse = raResponse(response); restAssuredResponse.setContent(raResponse.getContent()); restAssuredResponse.setHasExpectations(raResponse.getHasExpectations()); restAssuredResponse.setDefaultContentType(raResponse.getDefaultContentType()); restAssuredResponse.setDecoderConfig(raResponse.getDecoderConfig()); restAssuredResponse.setSessionIdName(raResponse.getSessionIdName()); restAssuredResponse.setConnectionManager(raResponse.getConnectionManager()); restAssuredResponse.setConfig(raResponse.getConfig()); restAssuredResponse.setRpr(raResponse.getRpr()); restAssuredResponse.setLogRepository(raResponse.getLogRepository()); restAssuredResponse.setFilterContextProperties(raResponse.getFilterContextProperties()); } else { restAssuredResponse.setContent(response.asInputStream()); } restAssuredResponse.setContentType(response.getContentType()); restAssuredResponse.setCookies(response.getDetailedCookies()); restAssuredResponse.setResponseHeaders(response.getHeaders()); restAssuredResponse.setStatusCode(response.getStatusCode()); restAssuredResponse.setStatusLine(response.getStatusLine()); return this; }
.contentType(mimeType) .post(container); if (response.getStatusCode() != HttpStatus.SC_CREATED) { System.err.println(SETUP_ERROR); System.err.println("POST failed with status code: " + response.getStatusCode()); System.err.println(); return;
.body(model, new RdfObjectMapper()) .post(this.container); if (postResponse.getStatusCode() != HttpStatus.SC_CREATED) { System.err.println(SETUP_ERROR); System.err.println("POST failed with status code: " + postResponse.getStatusCode()); System.err.println(); return;
@Test @RunAsClient @InSequence(16) public void testApplicationMetadataOkJson() { Header wantJson = new Header("Accept", APPLICATION_JSON); Response response = given().header(wantJson).options("/metrics/application"); int code = response.getStatusCode(); assertTrue(code == 200 || code == 204); }
public void shouldListDefinitions(List<String> names, // Class clazz, // Function<List<String>, Map<String, ? extends Definition>> provider, // DefinitionType wantedType, // String expectedType) throws IOException { // given BDDMockito.given(delegate.getDefinitionsMapByType(clazz)) // .willReturn(provider.apply(names)); // when final Response response = when().get(getVersionPrefix() + "/definitions/" + wantedType).andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(names.size(), actual.size()); actual.forEach(d -> { assertEquals(expectedType, d.getType()); assertTrue(names.contains(d.getName().substring("mock ".length()))); // it's expected }); }
protected Response expectPut4xxStatus(String invalidProp) { // Get the resource. String resourceUri = getResourceUri(); Response getResponse = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .get(resourceUri); String eTag = getResponse.getHeader(ETAG); Model m = getResponse.as(Model.class, new RdfObjectMapper(resourceUri)); modifyProperty(m, resourceUri, invalidProp); Response putResponse = buildBaseRequestSpecification() .contentType(TEXT_TURTLE) .header(IF_MATCH, eTag) .body(m, new RdfObjectMapper(resourceUri)) .when() .put(resourceUri); if (isSuccessful().matches(putResponse.getStatusCode())) { throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(), "Skipping test because PUT request was successful.", skipLog); } assertThat(putResponse.statusCode(), is4xxRange()); return putResponse; }
public void shouldFilterComponentsByTypologyAndExecutionEngine(ConnectorTypology wantedTypology, ExecutionEngine executionEngine, int expectedResults) throws IOException { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when().get(getVersionPrefix() + "/definitions/components?typology=" + wantedTypology + "&executionEngine=" + executionEngine.name()).andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(expectedResults, actual.size()); assertEquals(expectedResults, actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.name())) .filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count()); }
public void shouldFilterComponentsByExecutionEngine(ExecutionEngine executionEngine, int expectedResults) throws IOException { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when() .get(getVersionPrefix() + "/definitions/components?executionEngine=" + executionEngine.name()).andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(expectedResults, actual.size()); assertEquals(expectedResults, actual.stream().filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count()); }
public void shouldFilterComponentsByTypology(ConnectorTypology wantedTypology, int expectedResults) throws IOException { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when().get(getVersionPrefix() + "/definitions/components?typology=" + wantedTypology.name()) .andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(expectedResults, actual.size()); assertEquals(expectedResults, actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.name())) // it's // a // source .count()); }
public void shouldFilterComponentsByTag(String tag, int expectedResults) throws JsonParseException, JsonMappingException, IOException { Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when().get(getVersionPrefix() + "/definitions/" + COMPONENT + "?tag=" + tag).andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(expectedResults, actual.size()); }
@Test public void shouldNotFilterTypology() throws Exception { // given Map<String, ComponentDefinition> definitions = getComponentsDefinitions(); BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) // .willReturn(definitions); // when final Response response = when().get(getVersionPrefix() + "/definitions/components").andReturn(); // then assertEquals(OK.value(), response.getStatusCode()); List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() { }); assertEquals(14, actual.size()); }