List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:sample.RestTests.java
@Test public void authenticateWithXAuthTokenWorks() { String auth = getAuth("user", "password"); HttpHeaders headers = getHttpHeaders(); headers.set(AUTHORIZATION, BASIC + auth); ResponseEntity<User> entity = getForUser(this.baseUrl + "/", headers, User.class); String token = entity.getHeaders().getFirst(X_AUTH_TOKEN); HttpHeaders authTokenHeader = new HttpHeaders(); authTokenHeader.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); authTokenHeader.set(X_AUTH_TOKEN, token); ResponseEntity<User> authTokenResponse = getForUser(this.baseUrl + "/", authTokenHeader, User.class); assertThat(authTokenResponse.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(authTokenResponse.getBody().getUsername()).isEqualTo("user"); }
From source file:hello.SayHelloApplicationTests.java
@Test public void shouldReturn200WhenSendingRequestToRoot() throws Exception { @SuppressWarnings("rawtypes") ResponseEntity<String> entity = this.testRestTemplate.getForEntity("http://localhost:" + this.port + "/", String.class); then(entity.getStatusCode()).isEqualTo(HttpStatus.OK); then(entity.getBody()).isEqualTo("Hi!"); }
From source file:sample.jersey.SampleJerseyApplicationTests.java
@Test public void validation() { ResponseEntity<String> entity = this.restTemplate.getForEntity("http://localhost:" + this.port + "/reverse", String.class); assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode()); }
From source file:com.opopov.cloud.image.service.ImageStitchingServiceImpl.java
private Optional<BufferedImage> decompressImage(ResponseEntity<byte[]> resp) { if (resp.getStatusCode() != HttpStatus.OK) { return Optional.empty(); }/*w w w . jav a2s . co m*/ byte[] compressedBytes = resp.getBody(); try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(compressedBytes)); return Optional.of(image); } catch (IOException e) { return Optional.empty(); } }
From source file:edu.infsci2560.LoginIT.java
@Test public void testLoginPage() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, new HttpEntity<>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("_csrf"); }
From source file:edu.infsci2560.LoginIT.java
@Test public void testLoginPageValid() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET, new HttpEntity<>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); PageHtmlValidator.validatePage(entity.getBody()); }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.SearchServiceHandler.java
/** * Handler for the RegisterServiceJob that was submitted. Stores the metadata in MongoDB (non-Javadoc) * // w w w. j ava 2 s . com * @see org.venice.piazza.servicecontroller.messaging.handlers.Handler#handle(model.job.PiazzaJobType) */ @Override public ResponseEntity<String> handle(PiazzaJobType jobRequest) { SearchServiceJob job = (SearchServiceJob) jobRequest; ResponseEntity<String> responseEntity; if ((job != null) && (job.data != null)) { // Get the criteria to use for the search SearchCriteria criteria = job.data; coreLogger.log("search " + " " + criteria.field + "->" + criteria.pattern, Severity.INFORMATIONAL); ResponseEntity<String> response = handle(criteria); responseEntity = new ResponseEntity<>(response.getBody(), response.getStatusCode()); } else { responseEntity = new ResponseEntity<>("Null request received.", HttpStatus.BAD_REQUEST); } return responseEntity; }
From source file:sample.resteasy.SampleResteasyApplicationTests.java
@Test public void synchronousRequest() { ResponseEntity<String> response = new TestRestTemplate().getForEntity("http://localhost:" + port + "/hello", String.class); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals("Hello World", response.getBody()); }
From source file:sample.web.ui.SampleWebUiApplicationTests.java
@Test public void testCss() throws Exception { ResponseEntity<String> entity = this.restTemplate .getForEntity("http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("body"); }
From source file:com.crazyacking.learn.spring.actuator.ManagementAddressActuatorApplicationTests.java
@Test public void testHome() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); }