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:de.zib.gndms.gndmc.dspace.Test.SubspaceClientTest.java

@Test(groups = { "subspaceServiceTest" }, dependsOnMethods = { "testCreateSliceKind" })
public void testDeleteSubspace() {
    final ResponseEntity<Specifier<Facets>> responseEntity = subspaceClient.deleteSubspace(subspaceId, admindn);
    Assert.assertNotNull(responseEntity);
    Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);

    final TaskClient client = new TaskClient(serviceUrl);
    client.setRestTemplate(restTemplate);

    // wait for task to finish
    TaskStatus taskStatus = AbstractTaskFlowExecClient.waitForFinishOrFail(responseEntity.getBody(), client,
            100, admindn, "DELETESUBSPACEWID");
    Assert.assertNotNull(taskStatus);/*w  w  w.  j  ava2  s. c  o m*/
    Assert.assertEquals(taskStatus.getStatus(), TaskStatus.Status.FINISHED);
    Assert.assertEquals(taskStatus.getMaxProgress(), taskStatus.getProgress());
    Assert.assertEquals(taskStatus.getStatus(), TaskStatus.Status.FINISHED);
}

From source file:org.venice.piazza.servicecontroller.messaging.handlers.UpdateServiceHandlerTest.java

@Test
/**/*from  w  w w  . jav  a 2 s  .  c  om*/
 * Test that the handle method returns null
 */
public void testHandleJobRequestNull() {
    PiazzaJobType jobRequest = null;
    ResponseEntity<String> result = usHandler.handle(jobRequest);
    assertEquals("The response to a null JobRequest update should be null", result.getStatusCode(),
            HttpStatus.BAD_REQUEST);
}

From source file:com.cloudbees.jenkins.plugins.demo.actuator.ManagementPortSampleActuatorApplicationTests.java

@Test
public void testMetrics() throws Exception {
    testHome(); // makes sure some requests have been made
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.managementPort + "/metrics", Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
}

From source file:org.trustedanalytics.user.orgs.SpacesIT.java

@Test
public void getSpacesForSpecificOrg_shouldAskCloudfoundryForSpaces() {

    final String ORG = "6b436ee1-de3c-4996-b312-bacd54ef301a";
    Map<String, Object> pathVars = new HashMap<>();
    pathVars.put("org", ORG);

    Page<CcSpace> SPACES_FROM_CF = new Page<>();
    SPACES_FROM_CF.setResources(SpacesTestsResources.getSpacesReturnedByCf().getSpaces());
    final String EXPECTED_SPACES = SpacesTestsResources.getSpacesExpectedToBeReturnedBySc();

    Observable<CcSpace> toReturn = Observable.from(SpacesTestsResources.getSpacesReturnedByCf().getSpaces());
    when(ccClient.getSpaces(UUID.fromString(ORG))).thenReturn(toReturn);

    TestRestTemplate testRestTemplate = new TestRestTemplate();
    ResponseEntity<String> response = RestOperationsHelpers.getForEntityWithToken(testRestTemplate, TOKEN,
            BASE_URL + SpacesController.GET_SPACES_OF_ORG_URL, pathVars);

    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
    assertThat(response.getBody(), equalTo(EXPECTED_SPACES));
}

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

@Test
public void testGetDrugNotFound() {
    when(entityManager.find(Drug.class, 1L)).thenReturn(null);
    ResponseEntity<DrugResource> drugResourceResponseEntity = drugController.get(1L);
    assertThat(HttpStatus.NOT_FOUND, is(drugResourceResponseEntity.getStatusCode()));
    assertThat(drugResourceResponseEntity.getBody(), is(nullValue()));
}

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

@Test
public void testGetLeavesForEmployeeSuccessfuly() {
    //given/*from   w  w  w.j a  va2 s. c  o  m*/
    Mockito.when(employeeServiceMock.getById(EMPLOYEE_ID)).thenReturn(new Employee());
    Mockito.when(annualBalanceServiceMock.getLeavesForUser(EMPLOYEE_ID))
            .thenReturn(Lists.newArrayList(new AnnualBalanceLeave(), new AnnualBalanceLeave()));

    //when
    ResponseEntity<List<AnnualBalanceLeaveDTO>> result = testedObject.getLeavesForEmployee(EMPLOYEE_ID);

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

From source file:io.jmnarloch.spring.boot.rxjava.async.SingleDeferredResultTest.java

@Test
public void shouldRetrieveSingleValueWithStatusCode() {

    // when/* w  w  w.j  av a  2 s . c om*/
    ResponseEntity<String> response = restTemplate.getForEntity(path("/singleWithResponse"), String.class);

    // then
    assertNotNull(response);
    assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
    assertEquals("single value", response.getBody());
}

From source file:com.insys.cfclient.nozzle.InfluxDBSender.java

@Async
public void sendBatch(List<String> messages) {
    log.debug("ENTER sendBatch");
    httpClient.setErrorHandler(new ResponseErrorHandler() {
        @Override/*from  www . ja va 2s  . com*/
        public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
            return clientHttpResponse.getRawStatusCode() > 399;
        }

        @Override
        public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {

        }
    });

    RetryTemplate retryable = new RetryTemplate();
    retryable.setBackOffPolicy(getBackOffPolicy());
    retryable.setRetryPolicy(new SimpleRetryPolicy(properties.getMaxRetries(),
            Collections.singletonMap(ResourceAccessException.class, true)));

    final AtomicInteger counter = new AtomicInteger(0);
    retryable.execute(retryContext -> {
        int count = counter.incrementAndGet();
        log.trace("Attempt {} to deliver this batch", count);
        final StringBuilder builder = new StringBuilder();
        messages.forEach(s -> builder.append(s).append("\n"));

        String body = builder.toString();

        RequestEntity<String> entity = new RequestEntity<>(body, HttpMethod.POST, getUri());

        ResponseEntity<String> response;

        response = httpClient.exchange(entity, String.class);

        if (response.getStatusCode() != HttpStatus.NO_CONTENT) {
            log.error("Failed to write logs to InfluxDB! Expected error code 204, got {}",
                    response.getStatusCodeValue());

            log.trace("Request Body: {}", body);
            log.trace("Response Body: {}", response.getBody());

        } else {
            log.debug("batch sent successfully!");
        }

        log.debug("EXIT sendBatch");

        return null;
    }, recoveryContext -> {
        log.trace("Failed after {} attempts!", counter.get());
        return null;
    });
}

From source file:com.github.ffremont.microservices.springboot.node.services.MsService.java

public byte[] getContentOfProperties(String msName) {
    MasterUrlBuilder builder = new MasterUrlBuilder(cluster, node, masterhost, masterPort, masterCR);
    builder.setUri(msName + "/properties");

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_PLAIN));
    HttpEntity<byte[]> entity = new HttpEntity<>(headers);

    ResponseEntity<byte[]> response = restTempate.exchange(builder.build(), HttpMethod.GET, entity,
            byte[].class);

    return HttpStatus.OK.equals(response.getStatusCode()) ? response.getBody() : null;
}

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

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