Search in sources :

Example 96 with RestTemplate

use of org.springframework.web.client.RestTemplate in project taskana by Taskana.

the class WorkbasketControllerIntTest method getRestTemplate.

/**
 * Return a REST template which is capable of dealing with responses in HAL format
 *
 * @return RestTemplate
 */
private RestTemplate getRestTemplate() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jackson2HalModule());
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
    converter.setObjectMapper(mapper);
    RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
    return template;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2HalModule(org.springframework.hateoas.hal.Jackson2HalModule)

Example 97 with RestTemplate

use of org.springframework.web.client.RestTemplate in project taskana by Taskana.

the class WorkbasketControllerIntTest method testGetAllWorkbasketsKeepingFilters.

@Test
public void testGetAllWorkbasketsKeepingFilters() {
    RestTemplate template = getRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
    HttpEntity<String> request = new HttpEntity<String>(headers);
    ResponseEntity<PagedResources<WorkbasketSummaryResource>> response = template.exchange("http://127.0.0.1:" + port + "/v1/workbaskets?type=PERSONAL&sortBy=key&order=desc", HttpMethod.GET, request, new ParameterizedTypeReference<PagedResources<WorkbasketSummaryResource>>() {
    });
    assertNotNull(response.getBody().getLink(Link.REL_SELF));
    assertTrue(response.getBody().getLink(Link.REL_SELF).getHref().endsWith("/v1/workbaskets?type=PERSONAL&sortBy=key&order=desc"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) PagedResources(org.springframework.hateoas.PagedResources) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 98 with RestTemplate

use of org.springframework.web.client.RestTemplate in project taskana by Taskana.

the class TaskControllerIntTest method testGetQueryByPorSecondPageSortedByType.

@Test
@Ignore
public void testGetQueryByPorSecondPageSortedByType() {
    RestTemplate template = getRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
    HttpEntity<String> request = new HttpEntity<String>(headers);
    ResponseEntity<PagedResources<TaskSummaryResource>> response = template.exchange("http://127.0.0.1:" + port + "/v1/tasks?porCompany=00&porSystem=PASystem&porInstance=00&porType=VNR&porValue=22334455&sortBy=porType&order=asc&page=2&pageSize=5", HttpMethod.GET, request, new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
    });
    assertEquals(5, response.getBody().getContent().size());
    assertEquals("USER_1_1", response.getBody().getContent().iterator().next().getTaskId());
    assertNotNull(response.getBody().getLink(Link.REL_SELF));
    assertTrue(response.getBody().getLink(Link.REL_SELF).getHref().endsWith("/v1/tasks?sortBy=due&order=desc&page=2&pageSize=5"));
    assertNotNull(response.getBody().getLink("allTasks"));
    assertTrue(response.getBody().getLink("allTasks").getHref().endsWith("/v1/tasks"));
    assertNotNull(response.getBody().getLink(Link.REL_FIRST));
    assertNotNull(response.getBody().getLink(Link.REL_LAST));
    assertNotNull(response.getBody().getLink(Link.REL_NEXT));
    assertNotNull(response.getBody().getLink(Link.REL_PREVIOUS));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) PagedResources(org.springframework.hateoas.PagedResources) RestTemplate(org.springframework.web.client.RestTemplate) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 99 with RestTemplate

use of org.springframework.web.client.RestTemplate in project taskana by Taskana.

the class TaskControllerIntTest method testGetLastPageSortedByDueWithHiddenTasksRemovedFromResult.

@Test
@Ignore
public void testGetLastPageSortedByDueWithHiddenTasksRemovedFromResult() {
    RestTemplate template = getRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
    HttpEntity<String> request = new HttpEntity<String>(headers);
    ResponseEntity<PagedResources<TaskSummaryResource>> response = template.exchange("http://127.0.0.1:" + port + "/v1/tasks?sortBy=due&order=desc&page=14&pageSize=5", HttpMethod.GET, request, new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
    });
    assertEquals(2, response.getBody().getContent().size());
    assertTrue(response.getBody().getLink(Link.REL_LAST).getHref().contains("page=14"));
    assertEquals("TKI:000000000000000000000000000000000005", response.getBody().getContent().iterator().next().getTaskId());
    assertNotNull(response.getBody().getLink(Link.REL_SELF));
    assertTrue(response.getBody().getLink(Link.REL_SELF).getHref().endsWith("/v1/tasks?sortBy=due&order=desc&page=2&pageSize=5"));
    assertNotNull(response.getBody().getLink("allTasks"));
    assertTrue(response.getBody().getLink("allTasks").getHref().endsWith("/v1/tasks"));
    assertNotNull(response.getBody().getLink(Link.REL_FIRST));
    assertNotNull(response.getBody().getLink(Link.REL_LAST));
    assertNotNull(response.getBody().getLink(Link.REL_NEXT));
    assertNotNull(response.getBody().getLink(Link.REL_PREVIOUS));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) PagedResources(org.springframework.hateoas.PagedResources) RestTemplate(org.springframework.web.client.RestTemplate) Ignore(org.junit.Ignore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 100 with RestTemplate

use of org.springframework.web.client.RestTemplate in project taskana by Taskana.

the class TaskControllerIntTest method testGetAllTasks.

@Test
public void testGetAllTasks() {
    RestTemplate template = getRestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
    HttpEntity<String> request = new HttpEntity<String>(headers);
    ResponseEntity<PagedResources<TaskSummaryResource>> response = template.exchange("http://127.0.0.1:" + port + "/v1/tasks", HttpMethod.GET, request, new ParameterizedTypeReference<PagedResources<TaskSummaryResource>>() {
    });
    assertNotNull(response.getBody().getLink(Link.REL_SELF));
    assertEquals(22, response.getBody().getContent().size());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) PagedResources(org.springframework.hateoas.PagedResources) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

RestTemplate (org.springframework.web.client.RestTemplate)519 Test (org.junit.Test)135 Test (org.junit.jupiter.api.Test)78 HttpHeaders (org.springframework.http.HttpHeaders)77 HttpEntity (org.springframework.http.HttpEntity)76 URI (java.net.URI)73 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)45 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)44 HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)40 IOException (java.io.IOException)36 Bean (org.springframework.context.annotation.Bean)35 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)32 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)27 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)27 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)22 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)22 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)22