TSK-434: added endpoints to read classification categories and types.
This commit is contained in:
parent
79b767c858
commit
9601e9a8ec
|
|
@ -0,0 +1,101 @@
|
||||||
|
package pro.taskana.rest;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
import org.springframework.boot.web.server.LocalServerPort;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
|
import org.springframework.hateoas.hal.Jackson2HalModule;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||||
|
@Import(RestConfiguration.class)
|
||||||
|
public class TaskanaEngineControllerIntTest {
|
||||||
|
|
||||||
|
@LocalServerPort
|
||||||
|
int port;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDomains() {
|
||||||
|
RestTemplate template = getRestTemplate();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
|
||||||
|
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||||
|
ResponseEntity<List<String>> response = template.exchange(
|
||||||
|
"http://127.0.0.1:" + port + "/v1/domains", HttpMethod.GET, request,
|
||||||
|
new ParameterizedTypeReference<List<String>>() {
|
||||||
|
});
|
||||||
|
assertTrue(response.getBody().contains("DOMAIN_A"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClassificationTypes() {
|
||||||
|
RestTemplate template = getRestTemplate();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
|
||||||
|
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||||
|
ResponseEntity<List<String>> response = template.exchange(
|
||||||
|
"http://127.0.0.1:" + port + "/v1/classification-types", HttpMethod.GET, request,
|
||||||
|
new ParameterizedTypeReference<List<String>>() {
|
||||||
|
});
|
||||||
|
assertTrue(response.getBody().contains("TASK"));
|
||||||
|
assertTrue(response.getBody().contains("DOCUMENT"));
|
||||||
|
assertFalse(response.getBody().contains("UNKNOWN"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClassificationCategories() {
|
||||||
|
RestTemplate template = getRestTemplate();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x");
|
||||||
|
HttpEntity<String> request = new HttpEntity<String>(headers);
|
||||||
|
ResponseEntity<List<String>> response = template.exchange(
|
||||||
|
"http://127.0.0.1:" + port + "/v1/classification-categories", HttpMethod.GET, request,
|
||||||
|
new ParameterizedTypeReference<List<String>>() {
|
||||||
|
});
|
||||||
|
assertTrue(response.getBody().contains("MANUAL"));
|
||||||
|
assertTrue(response.getBody().contains("EXTERNAL"));
|
||||||
|
assertTrue(response.getBody().contains("AUTOMATIC"));
|
||||||
|
assertTrue(response.getBody().contains("PROCESS"));
|
||||||
|
assertFalse(response.getBody().contains("UNKNOWN"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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, application/json"));
|
||||||
|
converter.setObjectMapper(mapper);
|
||||||
|
|
||||||
|
RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>> singletonList(converter));
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
package pro.taskana.rest;
|
package pro.taskana.rest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
|
||||||
|
|
||||||
import java.util.List;
|
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for TaskanaEngine related tasks.
|
* Controller for TaskanaEngine related tasks.
|
||||||
|
|
@ -16,10 +17,21 @@ import java.util.List;
|
||||||
@RestController
|
@RestController
|
||||||
public class TaskanaEngineController {
|
public class TaskanaEngineController {
|
||||||
|
|
||||||
@Autowired TaskanaEngineConfiguration taskanaEngineConfiguration;
|
@Autowired
|
||||||
|
TaskanaEngineConfiguration taskanaEngineConfiguration;
|
||||||
|
|
||||||
@GetMapping(path = "/v1/domains", produces = {MediaType.APPLICATION_JSON_VALUE})
|
@GetMapping(path = "/v1/domains", produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||||
public ResponseEntity<List<String>> getDomains() {
|
public ResponseEntity<List<String>> getDomains() {
|
||||||
return new ResponseEntity<>(taskanaEngineConfiguration.getDomains(), HttpStatus.OK);
|
return new ResponseEntity<>(taskanaEngineConfiguration.getDomains(), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping(path = "/v1/classification-categories", produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||||
|
public ResponseEntity<List<String>> getClassificationCategories() {
|
||||||
|
return new ResponseEntity<>(taskanaEngineConfiguration.getClassificationCategories(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(path = "/v1/classification-types", produces = {MediaType.APPLICATION_JSON_VALUE})
|
||||||
|
public ResponseEntity<List<String>> getClassificationTypes() {
|
||||||
|
return new ResponseEntity<>(taskanaEngineConfiguration.getClassificationTypes(), HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue