List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:dk.nsi.haiba.epimibaimporter.status.StatusReporterTest.java
@Test public void willReturn500whenHAIBADBisDown() throws Exception { Mockito.when(haibaJdbcTemplate.queryForObject("SELECT headerid from Data_Header LIMIT 1", Long.class)) .thenThrow(Exception.class); final ResponseEntity<String> response = reporter.reportStatus(); assertEquals(500, response.getStatusCode().value()); assertTrue(response.getBody().contains("HAIBA Database is _NOT_ running correctly")); }
From source file:org.cloudfoundry.identity.batch.integration.BatchEndpointIntegrationTests.java
/** * tests a unauthorized flow of the <code>/batch</code> endpoint *//*from ww w.jav a 2 s .co m*/ @Test public void testUnauthorized() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Basic %s", new String(Base64.encode("batch:bogus".getBytes())))); ResponseEntity<String> response = serverRunning.getForString("/batch/", headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); String map = response.getBody(); // System.err.println(map); assertTrue(map.contains("{\"error\"")); }
From source file:com.crazyacking.learn.spring.actuator.ManagementPathSampleActuatorApplicationTests.java
@Test public void testHomeIsSecure() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); assertThat(body.get("error")).isEqualTo("Unauthorized"); assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); }
From source file:org.trustedanalytics.routermetrics.LoadMetricsIT.java
@Test public void callLoadPerSecEndpoint_noInputRequired_shouldReturnLoadData() { String url = BASE_URL + MetricsController.LOAD_PER_SEC_URL; LoadPerSecRecord[] RECORDS_TO_BE_RETURNED = { new LoadPerSecRecord(new Date(), 0.1), new LoadPerSecRecord(new Date(), 0.2) }; when(loadStore.read()).thenReturn(Arrays.asList(RECORDS_TO_BE_RETURNED)); TestRestTemplate testRestTemplate = new TestRestTemplate(); ResponseEntity<LoadPerSecRecord[]> response = testRestTemplate.getForEntity(url, LoadPerSecRecord[].class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); assertThat(response.getBody(), equalTo(RECORDS_TO_BE_RETURNED)); }
From source file:tds.assessment.web.endpoints.AccommodationControllerTest.java
@Test public void shouldReturnAccommodationsByAssessmentKey() { Accommodation accommodation = new Accommodation.Builder().build(); when(accommodationsService.findAccommodationsByAssessmentKey("clientName", "key")) .thenReturn(Collections.singletonList(accommodation)); ResponseEntity<List<Accommodation>> response = controller.findAccommodations("clientName", "key", null); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody()).containsOnly(accommodation); }
From source file:edu.infsci2560.LoginIT.java
@Test public void testLogin() throws Exception { ResponseEntity<String> entity = LoginHelper.login(this.restTemplate, "/login", "user", "password"); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/"); assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); }
From source file:net.eusashead.hateoas.response.impl.DeleteResponseBuilderImplTest.java
@Test public void testBuild() throws Exception { ResponseEntity<Void> response = builder.build(); Assert.assertNotNull(response);// w ww . ja v a 2 s. co m Assert.assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); Assert.assertNull(response.getBody()); Assert.assertNull(response.getHeaders().getLocation()); Assert.assertNull(response.getHeaders().getETag()); Assert.assertEquals(-1l, response.getHeaders().getLastModified()); Assert.assertNull(response.getHeaders().getCacheControl()); Assert.assertEquals(-1l, response.getHeaders().getExpires()); Assert.assertEquals(-1l, response.getHeaders().getDate()); }
From source file:org.cloudfoundry.identity.uaa.integration.VarzEndpointIntegrationTests.java
/** * tests a unauthorized flow of the <code>/varz</code> endpoint */// w w w. java 2 s .c o m @Test public void testUnauthorized() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", String.format("Basic %s", new String(Base64.encode("varz:bogus".getBytes())))); ResponseEntity<String> response = serverRunning.getForString("/varz", headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); String map = response.getBody(); // System.err.println(map); assertTrue(map.contains("{\"error\"")); }
From source file:com.carlomicieli.jtrains.infrastructure.web.ResponsesTests.java
@Test public void shouldCreateResponsesForCreated() { ResponseEntity<Void> resp = Responses.created(new Link("http://localhost", "self")); assertThat(resp).isNotNull();// w w w . j a va 2 s.c om assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.CREATED); assertThat(resp.getHeaders()).containsEntry("Location", Arrays.asList("http://localhost")); }
From source file:de.codecentric.boot.admin.services.SpringBootAdminRegistrator.java
/** * Registers the client application at spring-boot-admin-server. * @return true if successful//from www . j a v a2 s . co m */ public boolean register() { Application app = createApplication(); String adminUrl = adminProps.getUrl() + '/' + adminProps.getContextPath(); try { ResponseEntity<Application> response = template.postForEntity(adminUrl, app, Application.class); if (response.getStatusCode().equals(HttpStatus.CREATED)) { LOGGER.debug("Application registered itself as {}", response.getBody()); return true; } else if (response.getStatusCode().equals(HttpStatus.CONFLICT)) { LOGGER.warn("Application failed to registered itself as {} because of conflict in registry.", app); } else { LOGGER.warn("Application failed to registered itself as {}. Response: {}", app, response.toString()); } } catch (Exception ex) { LOGGER.warn("Failed to register application as {} at spring-boot-admin ({}): {}", app, adminUrl, ex.getMessage()); } return false; }