Example usage for org.springframework.http ResponseEntity getStatusCode

List of usage examples for org.springframework.http ResponseEntity getStatusCode

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity getStatusCode.

Prototype

public HttpStatus getStatusCode() 

Source Link

Document

Return the HTTP status code of the response.

Usage

From source file:com.company.eleave.leave.rest.TestLeaveTypeController.java

@Test
public void testGetAll() {
    //given//from ww w  .ja  v  a  2  s . co m
    Mockito.when(leaveTypeServiceMock.getAll())
            .thenReturn(Lists.newArrayList(new LeaveType(), new LeaveType()));

    //when
    ResponseEntity<List<LeaveTypeDTO>> result = testedObject.getAll();

    //then
    Assert.assertEquals(HttpStatus.OK, result.getStatusCode());
    Assert.assertEquals(2, result.getBody().size());
}

From source file:io.kahu.hawaii.rest.DefaultResponseManagerTest.java

@Test
public void assurteThatResponseContainsJSONArrayWithJsonObject() throws Exception {

    ResponseEntity<?> response = responseManager.toResponse(new ObjectExample("piet", "puk"));
    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));

    JSONObject json = new JSONObject(response.getBody().toString());

    JSONArray content = json.getJSONArray("data");
    assertThat(content.length(), is(equalTo(1)));

    assertThat(content.getJSONObject(0).getString("firstname"), is(equalTo("piet")));
    assertThat(content.getJSONObject(0).getString("lastname"), is(equalTo("puk")));

}

From source file:sample.actuator.EndpointsPropertiesSampleActuatorApplicationTests.java

@Test
public void testCustomErrorPath() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
            .getForEntity("http://localhost:" + this.port + "/oops", Map.class);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertEquals("None", body.get("error"));
    assertEquals(999, body.get("status"));
}

From source file:com.nicusa.controller.DrugControllerTest.java

@Test
public void testGetDrugFound() {
    Drug persistedDrug = new Drug();
    persistedDrug.setId(1L);/*from www.  j a v  a2  s . c o m*/
    DrugResource drugResource = new DrugResource();
    when(entityManager.find(Drug.class, 1L)).thenReturn(persistedDrug);
    when(drugAssembler.toResource(persistedDrug)).thenReturn(drugResource);
    ResponseEntity<DrugResource> drugResourceResponseEntity = drugController.get(1L);
    assertThat(HttpStatus.OK, is(drugResourceResponseEntity.getStatusCode()));
    assertThat(drugResourceResponseEntity.getBody(), is(drugResource));
}

From source file:io.kahu.hawaii.rest.DefaultResponseManagerTest.java

@Test
public void assureThatUnauthorizedStatusIsSetForAuthorisationException() throws Exception {
    ResponseEntity<?> response = responseManager.toResponse(new AuthorisationException("Some Message"));
    assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK)));
    verify(logManager).logIncomingCallEnd(200, "Some Message");
}

From source file:org.akaademiwolof.ConfigurationTests.java

@Test
public void shouldReturn200WhenSendingRequestToController() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.restTemplate.getForEntity(
            "http://localhost:" + this.port + "/akademiWlof/gaggantikaay/baat?name=bijji", Map.class);
    System.out.print(entity.getStatusCode());
    //assertThat(entity.getStatusCode().equals(HttpStatus.OK));
}

From source file:io.syndesis.runtime.BaseITCase.java

private <T> ResponseEntity<T> processResponse(HttpStatus expectedStatus, ResponseEntity<T> response) {
    if (expectedStatus != null) {
        assertThat(response.getStatusCode()).as("status code").isEqualTo(expectedStatus);
    }//from  w ww. jav a  2 s .co  m
    return response;
}

From source file:com.interop.webapp.WebAppTests.java

@Test
public void testHome() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port,
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
    assertTrue("Wrong location:\n" + entity.getHeaders(),
            entity.getHeaders().getLocation().toString().endsWith(port + "/login"));
}

From source file:comsat.sample.ui.method.SampleMethodSecurityApplicationTests.java

@Test
public void testManagementAuthorizedAccess() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
            .getForEntity("http://localhost:" + this.port + "/beans", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}