Example usage for org.springframework.http HttpHeaders setAccept

List of usage examples for org.springframework.http HttpHeaders setAccept

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders setAccept.

Prototype

public void setAccept(List<MediaType> acceptableMediaTypes) 

Source Link

Document

Set the list of acceptable MediaType media types , as specified by the Accept header.

Usage

From source file:com.opensearchserver.hadse.index.IndexTest.java

@Test
public void t02_createDefaultIndex() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    RestTemplate template = new RestTemplate();

    ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.PUT, null,
            String.class);

    assertEquals(HttpStatus.CREATED, entity.getStatusCode());
}

From source file:com.opensearchserver.hadse.index.IndexTest.java

@Test
public void t03_exists() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    RestTemplate template = new RestTemplate();

    ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.GET, null,
            String.class);

    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
}

From source file:com.alcatel.hello.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:comsat.sample.actuator.ui.SampleActuatorUiApplicationTests.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>Hello"));
}

From source file:comsat.sample.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);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat(entity.getBody()).contains("<html>").contains("<body>")
            .contains("Please contact the operator with the above information");
}

From source file:org.cloudfoundry.identity.uaa.integration.LoginInfoEndpointIntegrationTests.java

/**
 * tests a happy-day flow of the <code>/login</code> endpoint
 *///from ww w  .ja  va 2  s.  c  om
@Test
public void testHappyDayHtml() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));

    HttpStatus status = HttpStatus.FOUND;
    String location = "/login";
    ResponseEntity<Void> response = null;
    while (status == HttpStatus.FOUND) {
        response = serverRunning.getForResponse(location, headers);
        status = response.getStatusCode();
        if (status == HttpStatus.FOUND) {
            location = response.getHeaders().getLocation().toString();
            System.err.println("Redirected to " + location);
        }
    }

    ResponseEntity<String> finalResponse = serverRunning.getForString(location, headers);
    String body = finalResponse.getBody().toString();
    // System.err.println(body);
    assertNotNull(body);
    assertTrue("Wrong body: " + body, body.contains("<form id="));

}

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:com.opensearchserver.hadse.index.IndexTest.java

@Test
public void t01_deleteIndex() {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    RestTemplate template = new RestTemplate();

    ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.DELETE, null,
            String.class);
    assertNotNull(entity);/*from   ww  w .j  av a 2  s.  co m*/
    HttpStatus res = entity.getStatusCode();
    assertNotNull(res);
    switch (res) {
    case OK:
        assertEquals(HttpStatus.OK, res);
        break;
    case NOT_FOUND:
        assertEquals(HttpStatus.NOT_FOUND, res);
        break;
    default:
        fail("Unexpected result: " + res);
        break;
    }
}

From source file:com.github.ffremont.microservices.springboot.manager.nexus.NexusClientApiTest.java

@Test
public void testGetData() {
    String g = "gg", a = "aa", v = "1.0.0", c = "cc", p = "jar";

    // init mock//from  w  ww .j  a v a  2s. co m
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.parseMediaType(MediaType.APPLICATION_JSON.toString())));
    HttpEntity<NexusDataResult> entity = new HttpEntity<>(headers);
    NexusDataResult nexusResult = new NexusDataResult();
    nexusResult.setData(new NexusData());
    ResponseEntity responseEntity = new ResponseEntity(nexusResult, HttpStatus.OK);
    when(this.nexusRestTemplate
            .exchange(prop.getBaseurl() + "/service/local/artifact/maven/resolve?r=snapshots&g=" + g + "&a=" + a
                    + "&v=" + v + "&p=" + p + "&c=" + c, HttpMethod.GET, entity, NexusDataResult.class))
                            .thenReturn(responseEntity);

    NexusData r = nexus.getData(g, a, p, c, v);

    assertNotNull(r);
}

From source file:org.projecthdata.social.api.impl.RootTemplate.java

public RootTemplate(HData hData, RestTemplate restTemplate, boolean isAuthorizedForUser) {
    super(isAuthorizedForUser);
    this.restTemplate = restTemplate;
    this.hData = hData;
    this.ehrUri = URI.create(hData.getEhrUrl());

    // setup the correct accept headers for processing an atom feed
    List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
    acceptableMediaTypes.add(MediaType.APPLICATION_ATOM_XML);
    acceptableMediaTypes.add(MediaType.APPLICATION_XML);

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAccept(acceptableMediaTypes);

    this.atomFeedRequestEntity = new HttpEntity<Object>(requestHeaders);

}