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:org.zaizi.SensefyResourceApplicationTests.java

@Test
public void testRootPathAnauthorized() {
    RestTemplate template = new TestRestTemplate();
    ResponseEntity<String> response = template.getForEntity(baseTestServerUrl(), String.class);
    Assert.assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
}

From source file:sample.tomcat.X509ApplicationTests.java

@Test(expected = ResourceAccessException.class)
public void testUnauthenticatedHello() throws Exception {
    RestTemplate template = new TestRestTemplate();
    ResponseEntity<String> httpsEntity = template.getForEntity("https://localhost:" + this.port + "/hello",
            String.class);
    assertEquals(HttpStatus.OK, httpsEntity.getStatusCode());
    assertEquals("hello", httpsEntity.getBody());
}

From source file:com.ginema.ApplicationTests.java

@Test
public void authorizationRedirects() {
    ResponseEntity<String> response = template
            .getForEntity("http://localhost:" + port + "/ginema-server/authorize", String.class);
    assertEquals(HttpStatus.FOUND, response.getStatusCode());
    String location = response.getHeaders().getFirst("Location");
    assertTrue("Wrong header: " + location,
            location.startsWith("http://localhost:" + port + "/ginema-server/login"));
}

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

public void verifyGoodTwitterConnectionSettings() throws IOException {
    Properties credentials = new Properties();
    try (InputStream is = getClass().getResourceAsStream("/valid-twitter-keys.properties")) {
        credentials.load(is);/* w ww .  j  av  a2  s.c o m*/
    }

    ResponseEntity<Verifier.Result> response = post("/api/v1/connectors/twitter/verifier/connectivity",
            credentials, Verifier.Result.class);
    assertThat(response.getStatusCode()).as("component list status code").isEqualTo(HttpStatus.OK);
    Verifier.Result result = response.getBody();
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(Verifier.Result.Status.OK);
    assertThat(result.getErrors()).isEmpty();
}

From source file:de.pentasys.playground.springbootexample.UnsecureManagementSampleActuatorApplicationTests.java

@Test
public void testMetrics() throws Exception {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = new TestRestTemplate()
            .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
}

From source file:org.aksw.gerbil.datasets.datahub.DatahubNIFLoader.java

private List<String> getNIFDataSets() {
    List<String> result = Lists.newArrayList();

    String taggedCorpusURL = GerbilConfiguration.getInstance().getString(DATAHUB_TAG_INF_URL_PROPERTY_NAME);
    if (taggedCorpusURL == null) {
        LOGGER.error("Couldn't load the needed property \"{}\". Aborting.", DATAHUB_TAG_INF_URL_PROPERTY_NAME);
    } else {// w w  w  .  jav  a2  s.co  m
        Set<String> requestResult, taggedCorpora = null;
        String[] body;
        for (int i = 0; i < neededTags.length; ++i) {
            try {
                ResponseEntity<String[]> forEntity = rt.getForEntity(taggedCorpusURL + neededTags[i],
                        String[].class);
                if (forEntity.getStatusCode().equals(HttpStatus.OK)) {
                    body = forEntity.getBody();
                    if (taggedCorpora == null) {
                        taggedCorpora = Sets.newHashSet(body);
                        LOGGER.debug("corpora with \"{}\" tag {}", neededTags[i], taggedCorpora);
                    } else {
                        requestResult = Sets.newHashSet(body);
                        LOGGER.debug("corpora with \"{}\" tag {}", neededTags[i], requestResult);
                        taggedCorpora = Sets.intersection(taggedCorpora, requestResult);
                    }
                } else {
                    LOGGER.warn("Couldn't get any datasets with the {} tag from DataHubIO. Status: ",
                            neededTags[i], forEntity.getStatusCode());
                }
            } catch (Exception e) {
                LOGGER.warn("Couldn't get any datasets with the {} tag from DataHubIO. Exception: {}",
                        neededTags[i], e);
            }
        }
    }
    return result;
}

From source file:sample.actuator.EndpointsPropertiesSampleActuatorApplicationTests.java

@Test
public void testCustomContextPath() throws Exception {
    ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
            .getForEntity("http://localhost:" + this.port + "/admin/health", String.class);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertTrue("Wrong body: " + entity.getBody(), entity.getBody().contains("\"status\":\"UP\""));
    System.err.println(entity.getBody());
    assertTrue("Wrong body: " + entity.getBody(), entity.getBody().contains("\"hello\":\"world\""));
}

From source file:com.borabora.ui.secure.SampleSecureApplicationTests.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.OK, entity.getStatusCode());
    assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(),
            entity.getBody().contains("<title>Login"));
}

From source file:com.crazyacking.learn.spring.actuator.ShutdownSampleActuatorApplicationTests.java

@Test
@DirtiesContext//from w  ww.j  ava2 s.  c  o m
public void testShutdown() {
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
            .postForEntity("/actuator/shutdown", null, Map.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    @SuppressWarnings("unchecked")
    Map<String, Object> body = entity.getBody();
    assertThat(((String) body.get("message"))).contains("Shutting down");
}

From source file:it.reply.orchestrator.service.CloudProviderRankerServiceImpl.java

@Override
public List<RankedCloudProvider> getProviderRanking(CloudProviderRankerRequest cloudProviderRankerRequest) {

    HttpEntity<CloudProviderRankerRequest> entity = new HttpEntity<CloudProviderRankerRequest>(
            cloudProviderRankerRequest);

    ResponseEntity<List<RankedCloudProvider>> response = restTemplate.exchange(url, HttpMethod.POST, entity,
            new ParameterizedTypeReference<List<RankedCloudProvider>>() {
            });//from ww w .j ava 2  s . co m
    if (response.getStatusCode().is2xxSuccessful()) {
        return response.getBody();
    }

    throw new DeploymentException(
            "Error retrieving cloud provider ranking data for request <" + cloudProviderRankerRequest + ">");
}