List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:net.eusashead.hateoas.response.impl.PutResponseBuilderImplTest.java
@Test public void testIsCreate() throws Exception { Entity entity = new Entity("foo"); Date now = new Date(1373571924000l); ResponseEntity<Void> response = builder.entity(entity).etag().lastModified(now).isCreate().build(); Assert.assertNotNull(response);/*from w ww . j av a2s . c om*/ Assert.assertEquals(HttpStatus.CREATED, response.getStatusCode()); Assert.assertNull(response.getBody()); Assert.assertNotNull(response.getHeaders().getETag()); Assert.assertEquals("W/\"b0c689597eb9dd62c0a1fb90a7c5c5a5\"", response.getHeaders().getETag()); Assert.assertEquals(now.getTime(), response.getHeaders().getLastModified()); }
From source file:org.zalando.github.spring.MembersTemplate.java
@Override public boolean isPublicMemberOfOrganization(String organization, String username) { Map<String, Object> uriVariables = new HashMap<>(); uriVariables.put("organization", organization); uriVariables.put("username", username); HttpStatus status = HttpStatus.NOT_FOUND; try {/*from ww w. ja v a2 s .c om*/ ResponseEntity<Void> responseEntity = getRestOperations().getForEntity( buildUri("/orgs/{organization}/public_members/{username}", uriVariables), Void.class); status = responseEntity.getStatusCode(); } catch (HttpClientErrorException e) { // skip } return HttpStatus.NO_CONTENT.equals(status) ? true : false; }
From source file:com.crazyacking.learn.spring.actuator.ManagementPortAndPathSampleActuatorApplicationTests.java
@Test public void testHealth() { ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) .getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); }
From source file:de.qaware.cloud.nativ.zwitscher.monitor.ZwitscherMonitorApplicationTests.java
@Test public void hystrixDashboardIsRunning() { ResponseEntity<String> responseEntity = testRestTemplate.getForEntity(HOST + DEFINED_PORT, String.class); assertNotNull("responseEntity is null", responseEntity); assertEquals("wrong status code", HttpStatus.OK, responseEntity.getStatusCode()); assertTrue(responseEntity.getBody().contains("Hystrix Dashboard")); }
From source file:org.cloudfoundry.identity.uaa.login.integration.AuthorizationCodeGrantIntegrationTests.java
@Test public void testSuccessfulAuthorizationCodeFlow() throws Exception { HttpHeaders headers = new HttpHeaders(); // TODO: should be able to handle just TEXT_HTML headers.setAccept(Arrays.asList(MediaType.TEXT_HTML, MediaType.ALL)); AuthorizationCodeResourceDetails resource = testAccounts.getDefaultAuthorizationCodeResource(); URI uri = serverRunning.buildUri("/oauth/authorize").queryParam("response_type", "code") .queryParam("state", "mystateid").queryParam("client_id", resource.getClientId()) .queryParam("redirect_uri", resource.getPreEstablishedRedirectUri()).build(); ResponseEntity<Void> result = serverRunning.getForResponse(uri.toString(), headers); assertEquals(HttpStatus.FOUND, result.getStatusCode()); String location = result.getHeaders().getLocation().toString(); if (result.getHeaders().containsKey("Set-Cookie")) { String cookie = result.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); }/*www . j av a2 s . com*/ ResponseEntity<String> response = serverRunning.getForString(location, headers); // should be directed to the login screen... String body = response.getBody(); assertTrue(body.contains("/login.do")); assertTrue(body.contains("username")); assertTrue(body.contains("password")); MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("username", testAccounts.getUserName()); formData.add("password", testAccounts.getPassword()); // Should be redirected to the original URL, but now authenticated result = serverRunning.postForResponse("/login.do", headers, formData); assertEquals(HttpStatus.FOUND, result.getStatusCode()); if (result.getHeaders().containsKey("Set-Cookie")) { String cookie = result.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); } response = serverRunning.getForString(result.getHeaders().getLocation().toString(), headers); if (response.getStatusCode() == HttpStatus.OK) { body = response.getBody(); // The grant access page should be returned assertTrue(body.contains("Application Authorization")); // Forms should have the right action assertTrue(body.matches("(?s).*\\saction=\"\\S*oauth/authorize\".*")); formData.clear(); formData.add("user_oauth_approval", "true"); result = serverRunning.postForResponse("/oauth/authorize", headers, formData); assertEquals(HttpStatus.FOUND, result.getStatusCode()); location = result.getHeaders().getLocation().toString(); } else { // Token cached so no need for second approval assertEquals(HttpStatus.FOUND, response.getStatusCode()); location = response.getHeaders().getLocation().toString(); } assertTrue("Wrong location: " + location, location.matches(resource.getPreEstablishedRedirectUri() + ".*code=.+")); assertFalse("Location should not contain cookie: " + location, location.matches(resource.getPreEstablishedRedirectUri() + ".*cookie=.+")); formData.clear(); formData.add("client_id", resource.getClientId()); formData.add("redirect_uri", resource.getPreEstablishedRedirectUri()); formData.add("grant_type", "authorization_code"); formData.add("code", location.split("code=")[1].split("&")[0]); HttpHeaders tokenHeaders = new HttpHeaders(); tokenHeaders.set("Authorization", testAccounts.getAuthorizationHeader(resource.getClientId(), resource.getClientSecret())); @SuppressWarnings("rawtypes") ResponseEntity<Map> tokenResponse = serverRunning.postForMap("/oauth/token", formData, tokenHeaders); assertEquals(HttpStatus.OK, tokenResponse.getStatusCode()); }
From source file:org.openbaton.nse.beans.connectivitymanageragent.ConnectivityManagerRequestor.java
public HttpStatus delQos(String hypervisorName, String qosId) { String url = configuration.getBaseUrl() + "/qoses/" + hypervisorName + "/" + qosId; HttpHeaders headers = new HttpHeaders(); HttpEntity<String> delentity = new HttpEntity<>(headers); ResponseEntity<String> delete = template.exchange(url, HttpMethod.DELETE, delentity, String.class); if (delete.getStatusCode().is5xxServerError()) { logger.debug("The port is still here, returned " + delete.getStatusCode() + " with body " + delete.getBody());/*from w w w. j av a2s .co m*/ return delete.getStatusCode(); } logger.debug("deleting qos " + qosId + " has returned " + delete.getStatusCode()); return delete.getStatusCode(); }
From source file:org.kurento.repository.test.OneRecordingServerTest.java
protected void uploadFileWithPOST(String uploadURL, File fileToUpload) throws FileNotFoundException, IOException { RestTemplate template = new RestTemplate(); ByteArrayOutputStream fileBytes = new ByteArrayOutputStream(); IOUtils.copy(new FileInputStream(fileToUpload), fileBytes); ResponseEntity<String> entity = template.postForEntity(uploadURL, fileBytes.toByteArray(), String.class); assertEquals("Returned response: " + entity.getBody(), HttpStatus.OK, entity.getStatusCode()); }
From source file:com.example.SampleWebFreeMarkerApplicationTests.java
@Test public void testFreeMarkerErrorTemplate() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<String> requestEntity = new HttpEntity<String>(headers); ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/" + contextPath + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(responseEntity.getBody()).contains("Something went wrong: 404 Not Found"); }
From source file:com.athina.queue.manager.entity.HttpJob.java
@Override public void run() { HttpHeaders httpHeaders = new HttpHeaders(); headers.forEach(httpHeaders::add);/*from w ww .ja va2 s . c o m*/ HttpEntity<String> request = new HttpEntity<>(body, httpHeaders); ResponseEntity<String> response = restTemplate.exchange(url.toString(), method, request, String.class); int code = response.getStatusCode().value(); String responseBody = response.getBody(); LOG.info("{}", new HttpAuditRecord(this, code, responseBody)); }
From source file:com.crazyacking.learn.spring.actuator.ManagementPortAndPathSampleActuatorApplicationTests.java
@Test public void testErrorPage() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/error", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); assertThat(body.get("status")).isEqualTo(999); }