List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:org.openbaton.nfvo.vnfm_reg.impl.sender.RestVnfmSender.java
private String get(String path, String url) { HttpEntity<String> requestEntity = new HttpEntity<>("", headers); ResponseEntity<String> responseEntity = rest.exchange(url + path, HttpMethod.GET, requestEntity, String.class); this.setStatus(responseEntity.getStatusCode()); return responseEntity.getBody(); }
From source file:com.ginema.ApplicationTests.java
@Test public void homePageProtected() { ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + "/ginema-server/", String.class); assertEquals(HttpStatus.FOUND, response.getStatusCode()); }
From source file:fleetmgt.ApiControllerTest.java
@Test public void shouldReturnFleetCalculation() throws Exception { //given// w w w . j av a2s . c om final FleetConstraints fleetConstraints = new FleetConstraints(new int[] { 15, 10 }, 12, 5); // when: final ResponseEntity<Map> response = testRestTemplate.exchange("/fleet-calculation", HttpMethod.POST, new HttpEntity<>(fleetConstraints), Map.class); // then: assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody()).containsKey("fleet_engineers"); assertThat(response.getBody()).containsKey("fleet_manager_location"); }
From source file:net.eusashead.hateoas.response.impl.OptionsResponseBuilderImplTest.java
@Test public void testAllHeaders() throws Exception { Entity entity = new Entity("foo"); ResponseEntity<Entity> response = builder.entity(entity).allow(HttpMethod.GET, HttpMethod.PUT).build(); Assert.assertNotNull(response);// ww w . ja v a 2 s . c om Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); Assert.assertEquals(entity, response.getBody()); Assert.assertNotNull(response.getHeaders().getAllow()); Set<HttpMethod> allow = new HashSet<HttpMethod>(); allow.addAll(Arrays.asList(HttpMethod.GET, HttpMethod.PUT)); Assert.assertEquals(allow, response.getHeaders().getAllow()); }
From source file:org.cloudfoundry.identity.uaa.integration.ClientInfoEndpointIntegrationTests.java
@Test public void testUnauthenticated() throws Exception { HttpHeaders headers = new HttpHeaders(); ResourceOwnerPasswordResourceDetails app = testAccounts.getDefaultResourceOwnerPasswordResource(); headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), "bogus")); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.getForObject("/clientinfo", Map.class, headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); assertEquals("unauthorized", response.getBody().get("error")); }
From source file:org.openbaton.nfvo.vnfm_reg.impl.sender.RestVnfmSender.java
private void delete(String path, String url) { HttpEntity<String> requestEntity = new HttpEntity<>("", headers); ResponseEntity<String> responseEntity = rest.exchange(url + path, HttpMethod.DELETE, requestEntity, String.class); this.setStatus(responseEntity.getStatusCode()); }
From source file:com.manh.cp.fw.swagger.SwaggerConfigTest.java
@Test public void simple_controller() { RestTemplate restTemplate = new RestTemplate(); ResponseEntity<String> jsonResponseEntity = restTemplate .getForEntity("http://localhost:" + localPort + "/v2/api-docs", String.class); assertThat(jsonResponseEntity.getStatusCode(), equalTo(HttpStatus.OK)); String json = jsonResponseEntity.getBody(); assertThat(json, isJson());/*from w w w . j av a2s . c o m*/ assertThat(json, hasJsonPath("$.paths.*", hasSize(1))); }
From source file:com.redhat.fisdemoaggregator.ApplicationTest.java
@Test public void balanceTest() throws Exception { String responseMsg = "Tested!"; camelContext.getRouteDefinition("gatewaybalance").adviceWith(camelContext, new AdviceWithRouteBuilder() { @Override//from w w w. j av a2s . c om public void configure() throws Exception { interceptSendToEndpoint("http*").skipSendToOriginalEndpoint().setBody(constant(responseMsg)); } }); ResponseEntity<String> balanceResponse = restTemplate .getForEntity("/demos/sourcegateway/balance/123456?moneysource=bitcoin", String.class); assertThat(balanceResponse.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(balanceResponse.getBody()).isEqualTo("\"" + responseMsg + "\""); balanceResponse = restTemplate.getForEntity("/demos/sourcegateway/balance/123456", String.class); assertThat(balanceResponse.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(balanceResponse.getBody()).isEqualTo("\"" + responseMsg + "\""); }
From source file:comsat.sample.ui.SampleGroovyTemplateApplicationTests.java
@Test public void testCreateValidation() throws Exception { MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.set("text", ""); map.set("summary", ""); ResponseEntity<String> entity = new TestRestTemplate().postForEntity("http://localhost:" + this.port, map, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body ('required' validation error doesn't match):\n" + entity.getBody(), entity.getBody().contains("is required")); }
From source file:org.aksw.gerbil.datasets.datahub.DatahubNIFLoader.java
private void getNIFDataSetsMetaInformation(List<String> nifDataSets) { datasets = Maps.newHashMap();/*from w w w .j av a 2 s .c o m*/ String nifCorpusMetaInfURL = GerbilConfiguration.getInstance() .getString(DATAHUB_NIF_CORPUS_META_INF_URL_PROPERTY_NAME); if (nifCorpusMetaInfURL == null) { LOGGER.error("Couldn't load the needed property \"{}\". Aborting.", DATAHUB_NIF_CORPUS_META_INF_URL_PROPERTY_NAME); return; } // go through all datasets tagged with nif for (String d : nifDataSets) { ResponseEntity<Dataset.Response> entity = rt.getForEntity(nifCorpusMetaInfURL + d, Dataset.Response.class); if (entity.getStatusCode().equals(HttpStatus.OK)) { Dataset.Response body = entity.getBody(); List<Resource> resources = body.getResult().getResources(); // go through the downloadable Resources for (Resource r : resources) { String url = r.getUrl(); LOGGER.debug("checking {}", url); HttpHeaders headers = rt.headForHeaders(url); long contentLength = headers.getContentLength(); LOGGER.debug("{} bytes", contentLength); // FIXME - put the magic number in application.properties // add if less than 20mb ends with ttl (turtle) but not with dataid.ttl (we aint gonna need it yet) if (contentLength < 20_000_000 && url.endsWith(".ttl") && !url.endsWith("dataid.ttl")) { LOGGER.debug("{}: {} has less than 20mb and is turtle > add to Dataset", d, url); datasets.put(d, url); } } } } }