List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:de.codecentric.boot.admin.AdminApplicationTest.java
@Test public void testReverseProxy() { String apiBaseUrl = "http://localhost:" + port + "/api/applications"; Application application = Application.create("TestApp") .withHealthUrl("http://localhost:" + port + "/health").withManagementUrl("http://localhost:" + port) .build();/*from ww w .j a v a 2s . co m*/ ResponseEntity<Application> entity = new TestRestTemplate().postForEntity(apiBaseUrl, application, Application.class); @SuppressWarnings("rawtypes") ResponseEntity<Map> app = new TestRestTemplate().getForEntity(apiBaseUrl + "/" + entity.getBody().getId(), Map.class); assertEquals(HttpStatus.OK, app.getStatusCode()); assertEquals("TestApp", app.getBody().get("name")); @SuppressWarnings("rawtypes") ResponseEntity<Map> info = new TestRestTemplate() .getForEntity(apiBaseUrl + "/" + entity.getBody().getId() + "/info", Map.class); assertEquals(HttpStatus.OK, info.getStatusCode()); @SuppressWarnings("rawtypes") ResponseEntity<Map> health = new TestRestTemplate() .getForEntity(apiBaseUrl + "/" + entity.getBody().getId() + "/health", Map.class); assertEquals(HttpStatus.OK, health.getStatusCode()); }
From source file:io.jmnarloch.spring.boot.rxjava.async.SingleDeferredResultTest.java
@Test public void shouldRetrieveJsonSerializedPojoValue() { // when//www .j a v a 2 s . com ResponseEntity<EventDto> response = restTemplate.getForEntity(path("/event"), EventDto.class); // then assertNotNull(response); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals("Spring.io", response.getBody().getName()); }
From source file:io.kahu.hawaii.rest.DefaultResponseManagerTest.java
@Test public void assureThatForbiddenStatusIsSetForAuthenticationException() throws Exception { ResponseEntity<?> response = responseManager.toResponse(new AuthenticationException()); assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK))); verify(logManager)//from www . ja v a2 s . c o m .logIncomingCallEnd(Mockito.argThat(new TestInstanceOfMatcher<>(AuthenticationException.class))); }
From source file:org.zaizi.SensefyResourceApplicationTests.java
@Test public void testKeywordSearchAnauthorized() { RestTemplate template = new TestRestTemplate(); // keywordSearch ResponseEntity<String> response = template.getForEntity(baseTestServerUrl() + "keywordSearch", String.class); Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); }
From source file:com.company.eleave.leave.rest.TestAnnualBalanceLeaveController.java
@Test public void testGetAllLeaves() { //given/*w ww.ja v a 2 s.c o m*/ AnnualBalanceLeave firstAnnualBalanceLeave = new AnnualBalanceLeave(); AnnualBalanceLeave secondAnnualBalanceLeave = new AnnualBalanceLeave(); ArrayList<AnnualBalanceLeave> allLeaves = Lists.newArrayList(firstAnnualBalanceLeave, secondAnnualBalanceLeave); Mockito.when(annualBalanceServiceMock.getAllLeaves()).thenReturn(allLeaves); Mockito.when(mapperMock.toDto(firstAnnualBalanceLeave)).thenReturn(new AnnualBalanceLeaveDTO()); Mockito.when(mapperMock.toDto(secondAnnualBalanceLeave)).thenReturn(new AnnualBalanceLeaveDTO()); //when ResponseEntity<List<AnnualBalanceLeaveDTO>> result = testedObject.getAllLeaves(); //then Assert.assertEquals(HttpStatus.OK, result.getStatusCode()); Assert.assertEquals(2, result.getBody().size()); }
From source file:de.pentasys.playground.springbootexample.NoManagementSampleActuatorApplicationTests.java
@Test public void testMetricsNotAvailable() throws Exception { testHome(); // makes sure some requests have been made @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("admin", getPassword()) .getForEntity("http://localhost:" + this.port + "/metrics", Map.class); assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); }
From source file:org.cloudfoundry.identity.uaa.integration.VmcScimUserEndpointIntegrationTests.java
@Test public void deleteUserFails() throws Exception { RestOperations client = serverRunning.getRestTemplate(); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = deleteUser(client, joe.getId(), joe.getVersion()); assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode()); @SuppressWarnings("unchecked") Map<String, String> error = response.getBody(); // System.err.println(error); assertEquals("access_denied", error.get("error")); }
From source file:org.hypernovae.entapps.actuator.ui.SampleActuatorUiApplicationTests.java
@Test public void testError() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/error", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("<html>")); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("<body>")); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("Please contact the operator with the above information")); }
From source file:org.opencredo.couchdb.CouchDbIntegrationTest.java
/** * This methods ensures that the database is running. Otherwise, the test is ignored. * //from w w w. j a v a 2s.c o m * @throws URISyntaxException */ private void assumeDatabaseIsUpAndRunning() throws URISyntaxException { try { if (restTemplate == null) { synchronized (this) { if (restTemplate == null) { credentials = CouchDbUtils.extractUsernamePassword(databaseUrl()); if (credentials.length == 0) restTemplate = new BasicAuthRestTemplate(); else restTemplate = new BasicAuthRestTemplate(credentials[0], credentials[1], databaseUrl()); } } } ResponseEntity<String> responseEntity = restTemplate.getForEntity(couchDbUrl, String.class); assumeTrue(responseEntity.getStatusCode().equals(OK)); log.debug("CouchDB is running on " + couchDbUrl + " with status " + responseEntity.getStatusCode()); } catch (RestClientException e) { log.debug("CouchDB is not running on " + couchDbUrl); assumeNoException(e); } }
From source file:org.zalando.github.spring.MembersTemplate.java
@Override public boolean isMemberOfOrganization(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 w ww . j a va 2 s . co m ResponseEntity<Void> responseEntity = getRestOperations() .getForEntity(buildUri("/orgs/{organization}/members/{username}", uriVariables), Void.class); status = responseEntity.getStatusCode(); } catch (HttpClientErrorException e) { // skip } return HttpStatus.NO_CONTENT.equals(status) ? true : false; }