diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/classification/rest/ClassificationControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/classification/rest/ClassificationControllerIntTest.java index ff2d6fa09..ae4d37ddb 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/classification/rest/ClassificationControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/classification/rest/ClassificationControllerIntTest.java @@ -16,7 +16,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; import pro.taskana.classification.rest.models.ClassificationRepresentationModel; import pro.taskana.classification.rest.models.ClassificationSummaryPagedRepresentationModel; @@ -41,18 +40,18 @@ class ClassificationControllerIntTest { CLASSIFICATION_SUMMARY_REPRESENTATION_MODEL_TYPE = new ParameterizedTypeReference() {}; - static RestTemplate template = RestHelper.TEMPLATE; @Autowired RestHelper restHelper; @Test void testGetClassification() { + String url = + restHelper.toUrl( + RestEndpoints.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000002"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - template.exchange( - restHelper.toUrl( - RestEndpoints.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000002"), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getHeaders().getContentType()).isEqualTo(MediaTypes.HAL_JSON); @@ -60,25 +59,24 @@ class ClassificationControllerIntTest { @Test void testGetAllClassifications() { + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); } @Test void testGetAllClassificationsFilterByCustomAttribute() { + String url = + restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS) + "?domain=DOMAIN_A&custom-1-like=RVNR"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS) - + "?domain=DOMAIN_A&custom-1-like=RVNR", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); @@ -87,13 +85,14 @@ class ClassificationControllerIntTest { @Test void testGetAllClassificationsKeepingFilters() { + String url = + restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS) + + "?domain=DOMAIN_A&sort-by=KEY&order=ASCENDING"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS) - + "?domain=DOMAIN_A&sort-by=KEY&order=ASCENDING", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF).getHref()) @@ -104,13 +103,14 @@ class ClassificationControllerIntTest { @Test void testGetSecondPageSortedByKey() { + String url = + restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS) + + "?domain=DOMAIN_A&sort-by=KEY&order=ASCENDING&page-size=5&page=2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS) - + "?domain=DOMAIN_A&sort-by=KEY&order=ASCENDING&page-size=5&page=2", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getContent()).hasSize(5); assertThat(response.getBody().getContent().iterator().next().getKey()).isEqualTo("L1050"); @@ -132,14 +132,12 @@ class ClassificationControllerIntTest { "{\"classificationId\":\"\",\"category\":\"MANUAL\"," + "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\"," + "\"name\":\"new classification\",\"type\":\"TASK\", \"serviceLevel\":\"P1D\"}"; + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS); + HttpEntity auth = + new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()); ResponseEntity responseEntity = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); - + TEMPLATE.exchange(url, HttpMethod.POST, auth, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); assertThat(responseEntity).isNotNull(); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); @@ -147,14 +145,11 @@ class ClassificationControllerIntTest { "{\"classificationId\":\"\",\"category\":\"MANUAL\"," + "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS_2\"," + "\"name\":\"new classification\",\"type\":\"TASK\", \"serviceLevel\":\"P1D\"}"; + HttpEntity auth2 = + new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()); responseEntity = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); - + TEMPLATE.exchange(url, HttpMethod.POST, auth2, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); } @@ -165,14 +160,13 @@ class ClassificationControllerIntTest { "{\"classificationId\":\"\",\"category\":\"MANUAL\"," + "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\"," + "\"name\":\"new classification\",\"type\":\"TASK\"}"; + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS); + HttpEntity auth = new HttpEntity<>(newClassification, restHelper.getHeadersUser_1_1()); ThrowingCallable httpCall = - () -> - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeadersUser_1_1()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.POST, auth, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) @@ -188,13 +182,12 @@ class ClassificationControllerIntTest { + "\"domain\":\"DOMAIN_B\",\"key\":\"NEW_CLASS_P1\"," + "\"name\":\"new classification\",\"type\":\"TASK\",\"serviceLevel\":\"P1D\"," + "\"parentId\":\"CLI:200000000000000000000000000000000015\"}"; + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS); + HttpEntity auth = + new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()); ResponseEntity responseEntity = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.POST, auth, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); assertThat(responseEntity).isNotNull(); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); @@ -208,13 +201,12 @@ class ClassificationControllerIntTest { "{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_B\"," + "\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\"," + "\"type\":\"TASK\",\"parentKey\":\"T2100\",\"serviceLevel\":\"P1D\"}"; + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS); + HttpEntity auth = + new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()); ResponseEntity responseEntity = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.POST, auth, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); assertThat(responseEntity).isNotNull(); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); @@ -227,23 +219,18 @@ class ClassificationControllerIntTest { "{\"classificationId\":\"\",\"category\":\"MANUAL\",\"domain\":\"DOMAIN_A\"," + "\"key\":\"NEW_CLASS_P2\",\"name\":\"new classification\"," + "\"type\":\"TASK\",\"parentKey\":\"T2100\",\"serviceLevel\":\"P1D\"}"; + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS); + HttpEntity auth = + new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()); ResponseEntity responseEntity = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); - + TEMPLATE.exchange(url, HttpMethod.POST, auth, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); assertThat(responseEntity).isNotNull(); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); + HttpEntity auth2 = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth2, CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); @@ -269,14 +256,15 @@ class ClassificationControllerIntTest { + "\"key\":\"NEW_CLASS_P3\",\"name\":\"new classification\"," + "\"type\":\"TASK\",\"parentId\":\"CLI:200000000000000000000000000000000015\"," + "\"parentKey\":\"T2000\",\"serviceLevel\":\"P1D\"}"; + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS); + HttpEntity auth = + new HttpEntity<>(newClassification, restHelper.getHeadersBusinessAdmin()); ThrowingCallable httpCall = - () -> - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeadersBusinessAdmin()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.POST, auth, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -290,14 +278,15 @@ class ClassificationControllerIntTest { "{\"classificationId\":\"someId\",\"category\":\"MANUAL\"," + "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\"," + "\"name\":\"new classification\",\"type\":\"TASK\",\"serviceLevel\":\"P1D\"}"; + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS); + HttpEntity auth = + new HttpEntity<>(newClassification, restHelper.getHeadersBusinessAdmin()); ThrowingCallable httpCall = - () -> - template.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeadersBusinessAdmin()), - CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.POST, auth, CLASSIFICATION_REPRESENTATION_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -306,15 +295,15 @@ class ClassificationControllerIntTest { @Test void testGetClassificationWithSpecialCharacter() { + String url = + restHelper.toUrl( + RestEndpoints.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); - HttpEntity request = new HttpEntity<>(restHelper.getHeadersAdmin()); ResponseEntity response = - template.exchange( - restHelper.toUrl( - RestEndpoints.URL_CLASSIFICATIONS_ID, "CLI:100000000000000000000000000000000009"), - HttpMethod.GET, - request, - CLASSIFICATION_SUMMARY_REPRESENTATION_MODEL_TYPE); + TEMPLATE.exchange( + url, HttpMethod.GET, auth, CLASSIFICATION_SUMMARY_REPRESENTATION_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getName()).isEqualTo("Zustimmungserklärung"); } @@ -322,43 +311,37 @@ class ClassificationControllerIntTest { @Test @DirtiesContext void testDeleteClassification() { - HttpEntity request = new HttpEntity<>(restHelper.getHeadersBusinessAdmin()); + String url = + restHelper.toUrl( + RestEndpoints.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersBusinessAdmin()); ResponseEntity response = - template.exchange( - restHelper.toUrl( - RestEndpoints.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"), - HttpMethod.DELETE, - request, - CLASSIFICATION_SUMMARY_REPRESENTATION_MODEL_TYPE); + TEMPLATE.exchange( + url, HttpMethod.DELETE, auth, CLASSIFICATION_SUMMARY_REPRESENTATION_MODEL_TYPE); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); ThrowingCallable httpCall = () -> - template.exchange( - restHelper.toUrl( - RestEndpoints.URL_CLASSIFICATIONS_ID, - "CLI:200000000000000000000000000000000004"), - HttpMethod.GET, - request, - CLASSIFICATION_SUMMARY_REPRESENTATION_MODEL_TYPE); + TEMPLATE.exchange( + url, HttpMethod.GET, auth, CLASSIFICATION_SUMMARY_REPRESENTATION_MODEL_TYPE); assertThatThrownBy(httpCall).isInstanceOf(HttpClientErrorException.class); } @Test void should_ThrowException_When_ProvidingInvalidFilterParams() { + String url = + restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS) + + "?domain=DOMAIN_A" + + "&illegalParam=illegal" + + "&anotherIllegalParam=stillIllegal" + + "&sort-by=NAME&order=DESCENDING&page-size=5&page=2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS) - + "?domain=DOMAIN_A" - + "&illegalParam=illegal" - + "&anotherIllegalParam=stillIllegal" - + "&sort-by=NAME&order=DESCENDING&page-size=5&page=2", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_SUMMARY_PAGE_MODEL_TYPE); + }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/classification/rest/ClassificationDefinitionControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/classification/rest/ClassificationDefinitionControllerIntTest.java index a6e71f4a8..e55611fa1 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/classification/rest/ClassificationDefinitionControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/classification/rest/ClassificationDefinitionControllerIntTest.java @@ -50,6 +50,12 @@ import pro.taskana.common.test.rest.TaskanaSpringBootTest; @TestMethodOrder(OrderAnnotation.class) class ClassificationDefinitionControllerIntTest { + private static final ParameterizedTypeReference< + ClassificationDefinitionCollectionRepresentationModel> + CLASSIFICATION_DEFINITION_COLLECTION = + new ParameterizedTypeReference< + ClassificationDefinitionCollectionRepresentationModel>() {}; + private static final Logger LOGGER = LoggerFactory.getLogger(ClassificationController.class); private final RestHelper restHelper; @@ -72,13 +78,12 @@ class ClassificationDefinitionControllerIntTest { @Test @Order(1) // since the import tests adds Classifications this has to be tested first. void should_ExportAllClassifications_When_ExportIsRequested() { + String url = + restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_DEFINITIONS) + "?domain=DOMAIN_B"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_DEFINITIONS) + "?domain=DOMAIN_B", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType( - ClassificationDefinitionCollectionRepresentationModel.class)); + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_DEFINITION_COLLECTION); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getContent()) @@ -94,13 +99,13 @@ class ClassificationDefinitionControllerIntTest { @Test void should_NotContainAnyLinks_When_ExportIsRequested() { + String url = + restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_DEFINITIONS) + "?domain=DOMAIN_B"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_DEFINITIONS) + "?domain=DOMAIN_B", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType( - ClassificationDefinitionCollectionRepresentationModel.class)); + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_DEFINITION_COLLECTION); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isPresent(); @@ -113,13 +118,12 @@ class ClassificationDefinitionControllerIntTest { @Test void should_ExportNothing_When_DomainIsUnknown() { + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_DEFINITIONS) + "?domain=ADdfe"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_DEFINITIONS) + "?domain=ADdfe", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType( - ClassificationDefinitionCollectionRepresentationModel.class)); + TEMPLATE.exchange(url, HttpMethod.GET, auth, CLASSIFICATION_DEFINITION_COLLECTION); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getContent()).isEmpty(); } @@ -414,7 +418,7 @@ class ClassificationDefinitionControllerIntTest { LOGGER.debug("Start Import"); File tmpFile = File.createTempFile("test", ".tmp"); try (FileOutputStream out = new FileOutputStream(tmpFile); - OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); ) { + OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) { mapper.writeValue(writer, clList); } MultiValueMap body = new LinkedMultiValueMap<>(); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/AccessIdControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/AccessIdControllerIntTest.java index 4905df6cf..84bc0edd3 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/AccessIdControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/AccessIdControllerIntTest.java @@ -34,13 +34,14 @@ class AccessIdControllerIntTest { @Test void testQueryGroupsByDn() { + String url = + restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + + "?search-for=cn=ksc-users,cn=groups,OU=Test,O=TASKANA"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) - + "?search-for=cn=ksc-users,cn=groups,OU=Test,O=TASKANA", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); + assertThat(response.getBody()) .isNotNull() .extracting(AccessIdRepresentationModel::getAccessId) @@ -50,13 +51,14 @@ class AccessIdControllerIntTest { @Test void testQueryUserByDn() { + String url = + restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + + "?search-for=uid=teamlead-1,cn=users,OU=Test,O=TASKANA"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) - + "?search-for=uid=teamlead-1,cn=users,OU=Test,O=TASKANA", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); + assertThat(response.getBody()) .isNotNull() .extracting(AccessIdRepresentationModel::getAccessId) @@ -66,12 +68,12 @@ class AccessIdControllerIntTest { @Test void testQueryGroupsByCn() { + String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=ksc-use"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=ksc-use", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); + assertThat(response.getBody()) .isNotNull() .extracting(AccessIdRepresentationModel::getAccessId) @@ -81,23 +83,23 @@ class AccessIdControllerIntTest { @Test void should_ReturnEmptyResults_ifInvalidCharacterIsUsedInCondition() { + String url = + restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=ksc-teamleads,cn=groups"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=ksc-teamleads,cn=groups", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); + assertThat(response.getBody()).isNotNull().isEmpty(); } @Test void testGetMatches() { + String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=rig"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=rig", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); assertThat(response.getBody()) .isNotNull() @@ -107,12 +109,11 @@ class AccessIdControllerIntTest { @Test void should_ReturnAccessIdWithUmlauten_ifBased64EncodedUserIsLookedUp() { + String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=läf"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=läf", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); assertThat(response.getBody()) .isNotNull() @@ -122,13 +123,15 @@ class AccessIdControllerIntTest { @Test void should_ThrowException_When_SearchForIsTooShort() { + String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=al"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=al", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType(List.class)); + () -> { + TEMPLATE.exchange( + url, HttpMethod.GET, auth, ParameterizedTypeReference.forType(List.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("Minimum Length is") @@ -138,12 +141,11 @@ class AccessIdControllerIntTest { @Test void should_ReturnAccessIdsOfGroupsTheAccessIdIsMemberOf_ifAccessIdOfUserIsGiven() { + String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) + "?access-id=teamlead-2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) + "?access-id=teamlead-2", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); assertThat(response.getBody()) .isNotNull() @@ -159,12 +161,11 @@ class AccessIdControllerIntTest { @Test void should_ValidateAccessIdWithEqualsFilterAndReturnAccessIdsOfGroupsTheAccessIdIsMemberOf() { + String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) + "?access-id=user-2-1"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) + "?access-id=user-2-1", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); assertThat(response.getBody()) .isNotNull() @@ -178,14 +179,14 @@ class AccessIdControllerIntTest { @Test void should_ReturnBadRequest_ifAccessIdOfUserContainsInvalidCharacter() { + String url = + restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) + "?access-id=teamlead-2,cn=users"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ThrowingCallable call = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) - + "?access-id=teamlead-2,cn=users", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); + }; assertThatThrownBy(call) .isInstanceOf(HttpClientErrorException.class) @@ -196,14 +197,14 @@ class AccessIdControllerIntTest { @Test void should_ReturnAccessIdsOfGroupsTheAccessIdIsMemberOf_ifAccessIdOfGroupIsGiven() { + String url = + restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) + + "?access-id=cn=Organisationseinheit KSC 1," + + "cn=Organisationseinheit KSC,cn=organisation,OU=Test,O=TASKANA"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) - + "?access-id=cn=Organisationseinheit KSC 1," - + "cn=Organisationseinheit KSC,cn=organisation,OU=Test,O=TASKANA", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ACCESS_ID_LIST_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); assertThat(response.getBody()) .isNotNull() @@ -214,13 +215,13 @@ class AccessIdControllerIntTest { @Test void should_ThrowNotAuthorizedException_ifCallerOfGroupRetrievalIsNotAdminOrBusinessAdmin() { + String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) + "?access-id=teamlead-2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_1()); + ThrowingCallable call = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID_GROUPS) + "?access-id=teamlead-2", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_1()), - ACCESS_ID_LIST_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); + }; assertThatThrownBy(call) .isInstanceOf(HttpClientErrorException.class) @@ -230,13 +231,13 @@ class AccessIdControllerIntTest { @Test void should_ThrowNotAuthorizedException_ifCallerOfValidationIsNotAdminOrBusinessAdmin() { + String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=al"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_1()); + ThrowingCallable call = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_ACCESS_ID) + "?search-for=al", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_1()), - ACCESS_ID_LIST_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, ACCESS_ID_LIST_TYPE); + }; assertThatThrownBy(call) .isInstanceOf(HttpClientErrorException.class) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/GeneralExceptionHandlingTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/GeneralExceptionHandlingTest.java index 101a1f972..f593082bd 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/GeneralExceptionHandlingTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/GeneralExceptionHandlingTest.java @@ -28,14 +28,19 @@ class GeneralExceptionHandlingTest { @Test void testDeleteNonExisitingClassificationExceptionIsLogged() { + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS_ID, "non-existing-id"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATIONS_ID, "non-existing-id"), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType( - ClassificationSummaryPagedRepresentationModel.class)); + () -> { + TEMPLATE.exchange( + url, + HttpMethod.DELETE, + auth, + ParameterizedTypeReference.forType( + ClassificationSummaryPagedRepresentationModel.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("non-existing-id"); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/TaskanaEngineControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/TaskanaEngineControllerIntTest.java index ffefabdce..427567119 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/TaskanaEngineControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/TaskanaEngineControllerIntTest.java @@ -31,45 +31,48 @@ class TaskanaEngineControllerIntTest { @Test void testDomains() { + String url = restHelper.toUrl(RestEndpoints.URL_DOMAIN); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_DOMAIN), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType(List.class)); + url, HttpMethod.GET, auth, ParameterizedTypeReference.forType(List.class)); assertThat(response.getBody()).contains("DOMAIN_A"); } @Test void testClassificationTypes() { + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_TYPES); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_TYPES), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType(List.class)); + url, HttpMethod.GET, auth, ParameterizedTypeReference.forType(List.class)); assertThat(response.getBody()).containsExactlyInAnyOrder("TASK", "DOCUMENT"); } @Test void testClassificationCategories() { + String url = restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_CATEGORIES); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity> response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_CLASSIFICATION_CATEGORIES), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType(List.class)); + url, HttpMethod.GET, auth, ParameterizedTypeReference.forType(List.class)); assertThat(response.getBody()) .containsExactlyInAnyOrder("MANUAL", "EXTERNAL", "AUTOMATIC", "PROCESS", "EXTERNAL"); } @Test void testGetCurrentUserInfo() { + String url = restHelper.toUrl(RestEndpoints.URL_CURRENT_USER); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_CURRENT_USER), + url, HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), + auth, ParameterizedTypeReference.forType(TaskanaUserInfoRepresentationModel.class)); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getUserId()).isEqualTo("teamlead-1"); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/monitor/rest/MonitorControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/monitor/rest/MonitorControllerIntTest.java index 2451cd4bd..aadd89944 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/monitor/rest/MonitorControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/monitor/rest/MonitorControllerIntTest.java @@ -20,26 +20,26 @@ import pro.taskana.monitor.rest.models.ReportRepresentationModel; @TaskanaSpringBootTest class MonitorControllerIntTest { + private static final ParameterizedTypeReference REPORT_MODEL = + new ParameterizedTypeReference() {}; + @Autowired RestHelper restHelper; @Test void should_ReturnAllOpenTasksByState_When_QueryingForAWorkbasketAndReadyAndClaimedState() { + String url = + restHelper.toUrl(RestEndpoints.URL_MONITOR_TASKS_STATUS_REPORT) + + "?workbasket-ids=WBI:100000000000000000000000000000000007" + + "&states=READY&states=CLAIMED"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); - HttpEntity request = new HttpEntity<>(restHelper.getHeadersAdmin()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_MONITOR_TASKS_STATUS_REPORT) - + "?workbasket-ids=WBI:100000000000000000000000000000000007" - + "&states=READY&states=CLAIMED", - HttpMethod.GET, - request, - ParameterizedTypeReference.forType(ReportRepresentationModel.class)); + TEMPLATE.exchange(url, HttpMethod.GET, auth, REPORT_MODEL); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); - int totalOpenTasks = response.getBody().getSumRow().get(0).getTotal(); assertThat(totalOpenTasks).isEqualTo(15); - int[] tasksPerState = response.getBody().getSumRow().get(0).getCells(); // should be 2 READY, 13 CLAIMED int[] expectedTasksPerState = new int[] {2, 13}; @@ -48,19 +48,20 @@ class MonitorControllerIntTest { @Test void should_ReturnAllOpenTasksByState_When_QueryingForSpecificWbAndStateReadyAndMinimumPrio() { + String url = restHelper.toUrl(RestEndpoints.URL_MONITOR_TASKS_STATUS_REPORT); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); - HttpEntity request = new HttpEntity<>(restHelper.getHeadersAdmin()); ResponseEntity response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_MONITOR_TASKS_STATUS_REPORT) + url + "?workbasket-ids=WBI:100000000000000000000000000000000007" + "&states=READY&priority-minimum=1", HttpMethod.GET, - request, - ParameterizedTypeReference.forType(ReportRepresentationModel.class)); + auth, + REPORT_MODEL); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); - int[] tasksInStateReady = response.getBody().getSumRow().get(0).getCells(); // should be 2 READY int[] expectedTasksPerState = new int[] {2}; diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskCommentControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskCommentControllerIntTest.java index 61f4f3e05..984593b54 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskCommentControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskCommentControllerIntTest.java @@ -30,6 +30,8 @@ class TaskCommentControllerIntTest { private static final ParameterizedTypeReference TASK_COMMENT_PAGE_MODEL_TYPE = new ParameterizedTypeReference() {}; + private static final ParameterizedTypeReference + TASK_COMMENT_TYPE = new ParameterizedTypeReference() {}; private final RestHelper restHelper; @@ -40,17 +42,14 @@ class TaskCommentControllerIntTest { @Test void should_FailToReturnTaskComment_When_TaskCommentIsNotExisting() { - - String urlToNonExistingTaskComment = - restHelper.toUrl(RestEndpoints.URL_TASK_COMMENT, "Non existing task comment Id"); + String url = restHelper.toUrl(RestEndpoints.URL_TASK_COMMENT, "Non existing task comment Id"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - urlToNonExistingTaskComment, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_COMMENT_TYPE); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.NOT_FOUND); @@ -58,18 +57,16 @@ class TaskCommentControllerIntTest { @Test void should_FailToReturnTaskComments_When_TaskIstNotVisible() { - - String urlToNotVisibleTask = + String url = restHelper.toUrl( RestEndpoints.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000004"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - urlToNotVisibleTask, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_1()), - TASK_COMMENT_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_COMMENT_PAGE_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.FORBIDDEN); @@ -77,61 +74,45 @@ class TaskCommentControllerIntTest { @Test void should_ReturnSortedAndOrederedTaskCommentsSortedByModified_When_UsingSortAndOrderParams() { - String url = restHelper.toUrl( RestEndpoints.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); + String url1 = url + "?sort-by=MODIFIED&order=DESCENDING"; ResponseEntity getTaskCommentsSortedByModifiedOrderedByDescendingResponse = - TEMPLATE.exchange( - url + "?sort-by=MODIFIED&order=DESCENDING", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_COMMENT_PAGE_MODEL_TYPE); - + TEMPLATE.exchange(url1, HttpMethod.GET, auth, TASK_COMMENT_PAGE_MODEL_TYPE); assertThat(getTaskCommentsSortedByModifiedOrderedByDescendingResponse.getBody()).isNotNull(); assertThat(getTaskCommentsSortedByModifiedOrderedByDescendingResponse.getBody().getContent()) .hasSize(3) .extracting(TaskCommentRepresentationModel::getModified) .isSortedAccordingTo(Comparator.reverseOrder()); + String url2 = url + "?sort-by=MODIFIED"; ResponseEntity getTaskCommentsSortedByModifiedOrderedByAscendingResponse = - TEMPLATE.exchange( - url + "?sort-by=MODIFIED", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_COMMENT_PAGE_MODEL_TYPE); - + TEMPLATE.exchange(url2, HttpMethod.GET, auth, TASK_COMMENT_PAGE_MODEL_TYPE); assertThat(getTaskCommentsSortedByModifiedOrderedByAscendingResponse.getBody()).isNotNull(); assertThat(getTaskCommentsSortedByModifiedOrderedByAscendingResponse.getBody().getContent()) .hasSize(3) .extracting(TaskCommentRepresentationModel::getModified) .isSortedAccordingTo(Comparator.naturalOrder()); + String url3 = url + "?sort-by=CREATED&order=DESCENDING"; ResponseEntity getTaskCommentsSortedByCreatedOrderedByDescendingResponse = - TEMPLATE.exchange( - url + "?sort-by=CREATED&order=DESCENDING", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_COMMENT_PAGE_MODEL_TYPE); - + TEMPLATE.exchange(url3, HttpMethod.GET, auth, TASK_COMMENT_PAGE_MODEL_TYPE); assertThat(getTaskCommentsSortedByCreatedOrderedByDescendingResponse.getBody()).isNotNull(); assertThat(getTaskCommentsSortedByCreatedOrderedByDescendingResponse.getBody().getContent()) .hasSize(3) .extracting(TaskCommentRepresentationModel::getCreated) .isSortedAccordingTo(Comparator.reverseOrder()); + String url4 = url + "?sort-by=CREATED"; ResponseEntity getTaskCommentsSortedByCreatedOrderedByAscendingResponse = - TEMPLATE.exchange( - url + "?sort-by=CREATED", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_COMMENT_PAGE_MODEL_TYPE); - + TEMPLATE.exchange(url4, HttpMethod.GET, auth, TASK_COMMENT_PAGE_MODEL_TYPE); assertThat(getTaskCommentsSortedByCreatedOrderedByAscendingResponse.getBody()).isNotNull(); assertThat(getTaskCommentsSortedByCreatedOrderedByAscendingResponse.getBody().getContent()) .hasSize(3) @@ -141,18 +122,20 @@ class TaskCommentControllerIntTest { @Test void should_ThrowException_When_UsingInvalidSortParam() { - String url = restHelper.toUrl( RestEndpoints.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - url + "?sort-by=invalidSortParam", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_1()), - TASK_COMMENT_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange( + url + "?sort-by=invalidSortParam", + HttpMethod.GET, + auth, + TASK_COMMENT_PAGE_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.BAD_REQUEST); @@ -160,18 +143,16 @@ class TaskCommentControllerIntTest { @Test void should_FailToReturnTaskComment_When_TaskIstNotVisible() { - - String urlToNotVisibleTask = + String url = restHelper.toUrl( RestEndpoints.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000012"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - urlToNotVisibleTask, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_COMMENT_TYPE); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.FORBIDDEN); @@ -179,21 +160,21 @@ class TaskCommentControllerIntTest { @Test void should_FailToCreateTaskComment_When_TaskIsNotVisible() { - TaskCommentRepresentationModel taskCommentRepresentationModelToCreate = new TaskCommentRepresentationModel(); taskCommentRepresentationModelToCreate.setTaskId("TKI:000000000000000000000000000000000000"); taskCommentRepresentationModelToCreate.setTextField("newly created task comment"); + String url = + restHelper.toUrl( + RestEndpoints.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"); + HttpEntity auth = + new HttpEntity<>(taskCommentRepresentationModelToCreate, restHelper.getHeadersUser_b_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl( - RestEndpoints.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000000"), - HttpMethod.POST, - new HttpEntity<>( - taskCommentRepresentationModelToCreate, restHelper.getHeadersUser_b_1()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> { + TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_COMMENT_TYPE); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.FORBIDDEN); @@ -201,20 +182,19 @@ class TaskCommentControllerIntTest { @Test void should_FailToCreateTaskComment_When_TaskIdIsNonExisting() { - TaskCommentRepresentationModel taskCommentRepresentationModelToCreate = new TaskCommentRepresentationModel(); taskCommentRepresentationModelToCreate.setTaskId("DefinatelyNotExistingId"); taskCommentRepresentationModelToCreate.setTextField("newly created task comment"); + String url = restHelper.toUrl(RestEndpoints.URL_TASK_COMMENTS, "DefinatelyNotExistingId"); + HttpEntity auth = + new HttpEntity<>(taskCommentRepresentationModelToCreate, restHelper.getHeadersAdmin()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASK_COMMENTS, "DefinatelyNotExistingId"), - HttpMethod.POST, - new HttpEntity<>( - taskCommentRepresentationModelToCreate, restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> { + TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_COMMENT_TYPE); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.NOT_FOUND); @@ -225,13 +205,10 @@ class TaskCommentControllerIntTest { String url = restHelper.toUrl( RestEndpoints.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); ResponseEntity getTaskCommentResponse = - TEMPLATE.exchange( - url, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_COMMENT_TYPE); TaskCommentRepresentationModel taskCommentToUpdate = getTaskCommentResponse.getBody(); assertThat(taskCommentToUpdate).isNotNull(); assertThat(taskCommentToUpdate.getLink(IanaLinkRelations.SELF)).isNotNull(); @@ -239,14 +216,13 @@ class TaskCommentControllerIntTest { assertThat(taskCommentToUpdate.getTextField()).isEqualTo("some text in textfield"); taskCommentToUpdate.setModified(Instant.now()); + HttpEntity auth2 = + new HttpEntity<>(taskCommentToUpdate, restHelper.getHeadersUser_1_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - url, - HttpMethod.PUT, - new HttpEntity<>(taskCommentToUpdate, restHelper.getHeadersUser_1_1()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> { + TEMPLATE.exchange(url, HttpMethod.PUT, auth2, TASK_COMMENT_TYPE); + }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.CONFLICT); @@ -257,13 +233,10 @@ class TaskCommentControllerIntTest { String url = restHelper.toUrl( RestEndpoints.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_1()); ResponseEntity getTaskCommentResponse = - TEMPLATE.exchange( - url, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_1()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_COMMENT_TYPE); TaskCommentRepresentationModel taskComment = getTaskCommentResponse.getBody(); assertThat(taskComment).isNotNull(); assertThat(taskComment.getLink(IanaLinkRelations.SELF)).isNotNull(); @@ -271,14 +244,13 @@ class TaskCommentControllerIntTest { assertThat(taskComment.getTextField()).isEqualTo("some text in textfield"); taskComment.setTextField("updated textfield"); + HttpEntity auth2 = + new HttpEntity<>(taskComment, restHelper.getHeadersUser_1_2()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - url, - HttpMethod.PUT, - new HttpEntity<>(taskComment, restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> { + TEMPLATE.exchange(url, HttpMethod.PUT, auth2, TASK_COMMENT_TYPE); + }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.FORBIDDEN); @@ -286,17 +258,13 @@ class TaskCommentControllerIntTest { @Test void should_FailToUpdateTaskComment_When_TaskCommentIdInResourceDoesNotMatchPathVariable() { - String url = restHelper.toUrl( RestEndpoints.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000000"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); ResponseEntity getTaskCommentResponse = - TEMPLATE.exchange( - url, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_COMMENT_TYPE); assertThat(getTaskCommentResponse.getBody()).isNotNull(); assertThat(getTaskCommentResponse.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(getTaskCommentResponse.getBody().getCreator()).isEqualTo("user-1-1"); @@ -306,15 +274,13 @@ class TaskCommentControllerIntTest { getTaskCommentResponse.getBody(); taskCommentRepresentationModelToUpdate.setTextField("updated text"); taskCommentRepresentationModelToUpdate.setTaskCommentId("DifferentTaskCommentId"); + HttpEntity auth2 = + new HttpEntity<>(taskCommentRepresentationModelToUpdate, restHelper.getHeadersUser_1_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - url, - HttpMethod.PUT, - new HttpEntity<>( - taskCommentRepresentationModelToUpdate, restHelper.getHeadersUser_1_1()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> { + TEMPLATE.exchange(url, HttpMethod.PUT, auth2, TASK_COMMENT_TYPE); + }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.BAD_REQUEST); @@ -322,29 +288,23 @@ class TaskCommentControllerIntTest { @Test void should_FailToDeleteTaskComment_When_UserHasNoAuthorization() { + String url = + restHelper.toUrl( + RestEndpoints.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000001"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); ResponseEntity getTaskCommentsBeforeDeleteionResponse = - TEMPLATE.exchange( - restHelper.toUrl( - RestEndpoints.URL_TASK_COMMENTS, "TKI:000000000000000000000000000000000001"), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_COMMENT_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_COMMENT_PAGE_MODEL_TYPE); assertThat(getTaskCommentsBeforeDeleteionResponse.getBody()).isNotNull(); assertThat(getTaskCommentsBeforeDeleteionResponse.getBody().getContent()).hasSize(2); - String url = + String url2 = restHelper.toUrl( RestEndpoints.URL_TASK_COMMENT, "TCI:000000000000000000000000000000000004"); - ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - url, - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> TEMPLATE.exchange(url2, HttpMethod.DELETE, auth, TASK_COMMENT_TYPE); + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("TaskComment creator and current user must match.") @@ -356,14 +316,13 @@ class TaskCommentControllerIntTest { void should_FailToDeleteTaskComment_When_TaskCommentIsNotExisting() { String url = restHelper.toUrl(RestEndpoints.URL_TASK_COMMENT, "NotExistingTaskComment"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - url, - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(TaskCommentRepresentationModel.class)); + () -> { + TEMPLATE.exchange(url, HttpMethod.DELETE, auth, TASK_COMMENT_TYPE); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.NOT_FOUND); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerIntTest.java index b31369f0d..37985c02a 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/task/rest/TaskControllerIntTest.java @@ -11,14 +11,12 @@ import java.net.HttpURLConnection; import java.net.URL; import java.time.Instant; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.stream.Stream; import javax.sql.DataSource; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; @@ -32,7 +30,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; import pro.taskana.classification.rest.models.ClassificationSummaryRepresentationModel; import pro.taskana.common.rest.RestEndpoints; @@ -63,7 +60,6 @@ class TaskControllerIntTest { private static final ParameterizedTypeReference TASK_MODEL_TYPE = ParameterizedTypeReference.forType(TaskRepresentationModel.class); - private static RestTemplate template; private final RestHelper restHelper; private final DataSource dataSource; @@ -79,11 +75,6 @@ class TaskControllerIntTest { this.schemaName = schemaName; } - @BeforeAll - static void init() { - template = RestHelper.TEMPLATE; - } - void resetDb() { SampleDataGenerator sampleDataGenerator = new SampleDataGenerator(dataSource, schemaName); sampleDataGenerator.generateSampleData(); @@ -91,12 +82,12 @@ class TaskControllerIntTest { @Test void testGetAllTasks() { + String url = restHelper.toUrl(RestEndpoints.URL_TASKS); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(58); @@ -104,13 +95,14 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketId() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(22); @@ -118,27 +110,24 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithinMultiplePlannedTimeIntervals() { - Instant firstInstant = Instant.now().minus(7, ChronoUnit.DAYS); Instant secondInstant = Instant.now().minus(10, ChronoUnit.DAYS); Instant thirdInstant = Instant.now().minus(10, ChronoUnit.DAYS); Instant fourthInstant = Instant.now().minus(11, ChronoUnit.DAYS); - - String parameters = - String.format( - "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&planned=%s&planned=" - + "&planned=%s&planned=%s" - + "&planned=&planned=%s" - + "&sort-by=PLANNED", - firstInstant, secondInstant, thirdInstant, fourthInstant); + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + String.format( + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&planned=%s&planned=" + + "&planned=%s&planned=%s" + + "&planned=&planned=%s" + + "&sort-by=PLANNED", + firstInstant, secondInstant, thirdInstant, fourthInstant); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) + parameters, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(6); @@ -146,22 +135,21 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithinSinglePlannedTimeInterval() { - Instant plannedFromInstant = Instant.now().minus(6, ChronoUnit.DAYS); Instant plannedToInstant = Instant.now().minus(3, ChronoUnit.DAYS); + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&planned-from=" + + plannedFromInstant + + "&planned-until=" + + plannedToInstant + + "&sort-by=PLANNED"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&planned-from=" - + plannedFromInstant - + "&planned-until=" - + plannedToInstant - + "&sort-by=PLANNED", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(3); @@ -169,19 +157,18 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithinSingleIndefinitePlannedTimeInterval() { - Instant plannedFromInstant = Instant.now().minus(6, ChronoUnit.DAYS); + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&planned-from=" + + plannedFromInstant + + "&sort-by=PLANNED"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&planned-from=" - + plannedFromInstant - + "&sort-by=PLANNED", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(4); @@ -189,19 +176,21 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithInvalidPlannedParamsCombination() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&planned=2020-01-22T09:44:47.453Z,," + + "2020-01-19T07:44:47.453Z,2020-01-19T19:44:47.453Z," + + ",2020-01-18T09:44:47.453Z" + + "&planned-from=2020-01-19T07:44:47.453Z" + + "&sort-by=planned"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&planned=2020-01-22T09:44:47.453Z,," - + "2020-01-19T07:44:47.453Z,2020-01-19T19:44:47.453Z," - + ",2020-01-18T09:44:47.453Z" - + "&planned-from=2020-01-19T07:44:47.453Z" - + "&sort-by=planned", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); @@ -209,28 +198,24 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithinMultipleDueTimeIntervals() { - Instant firstInstant = Instant.now().minus(7, ChronoUnit.DAYS); Instant secondInstant = Instant.now().minus(10, ChronoUnit.DAYS); Instant thirdInstant = Instant.now().minus(10, ChronoUnit.DAYS); Instant fourthInstant = Instant.now().minus(11, ChronoUnit.DAYS); + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + String.format( + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&due=%s&due=" + + "&due=%s&due=%s" + + "&due=&due=%s" + + "&sort-by=DUE", + firstInstant, secondInstant, thirdInstant, fourthInstant); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); - String parameters = - String.format( - "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&due=%s&due=" - + "&due=%s&due=%s" - + "&due=&due=%s" - + "&sort-by=DUE", - firstInstant, secondInstant, thirdInstant, fourthInstant); - - System.out.println(parameters); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) + parameters, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(22); @@ -238,95 +223,66 @@ class TaskControllerIntTest { @Test void should_ReturnAllTasksByWildcardSearch_For_ProvidedSearchValue() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?wildcard-search-value=99" + + "&wildcard-search-fields=NAME" + + "&wildcard-search-fields=CUSTOM_3" + + "&wildcard-search-fields=CUSTOM_4"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?wildcard-search-value=99" - + "&wildcard-search-fields=NAME" - + "&wildcard-search-fields=CUSTOM_3" - + "&wildcard-search-fields=CUSTOM_4", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(4); } - @Test - void should_ThrowException_When_ProvidingInvalidFormatForCustomAttributes() { - TaskRepresentationModel taskRepresentationModel = getTaskResourceSample(); + @TestFactory + Stream should_ThrowException_When_ProvidingInvalidFormatForCustomAttributes() { + Iterator iterator = + Arrays.asList( + CustomAttribute.of(null, "value"), + CustomAttribute.of("", "value"), + CustomAttribute.of("key", null)) + .iterator(); - List customAttributesWithNullKey = new ArrayList<>(); - customAttributesWithNullKey.add(CustomAttribute.of(null, "value")); + ThrowingConsumer test = + customAttribute -> { + TaskRepresentationModel taskRepresentationModel = getTaskResourceSample(); + taskRepresentationModel.setCustomAttributes(List.of(customAttribute)); + String url = restHelper.toUrl(RestEndpoints.URL_TASKS); + HttpEntity auth = + new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersTeamlead_1()); - taskRepresentationModel.setCustomAttributes(customAttributesWithNullKey); + ThrowingCallable httpCall = + () -> { + TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) + .isInstanceOf(HttpClientErrorException.class) + .hasMessageContaining("Format of custom attributes is not valid") + .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) + .isEqualTo(HttpStatus.BAD_REQUEST); + }; - ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS), - HttpMethod.POST, - new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersTeamlead_1()), - TASK_MODEL_TYPE); - - assertThatThrownBy(httpCall) - .isInstanceOf(HttpClientErrorException.class) - .hasMessageContaining("Format of custom attributes is not valid") - .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) - .isEqualTo(HttpStatus.BAD_REQUEST); - - List customAttributesWithEmptyKey = new ArrayList<>(); - customAttributesWithEmptyKey.add(CustomAttribute.of("", "value")); - - taskRepresentationModel.setCustomAttributes(customAttributesWithEmptyKey); - - httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS), - HttpMethod.POST, - new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersTeamlead_1()), - TASK_MODEL_TYPE); - - assertThatThrownBy(httpCall) - .isInstanceOf(HttpClientErrorException.class) - .hasMessageContaining("Format of custom attributes is not valid") - .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) - .isEqualTo(HttpStatus.BAD_REQUEST); - - List customAttributesWithNullValue = new ArrayList<>(); - customAttributesWithNullValue.add(CustomAttribute.of("key", null)); - - taskRepresentationModel.setCustomAttributes(customAttributesWithNullValue); - - httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS), - HttpMethod.POST, - new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersTeamlead_1()), - TASK_MODEL_TYPE); - - assertThatThrownBy(httpCall) - .isInstanceOf(HttpClientErrorException.class) - .hasMessageContaining("Format of custom attributes is not valid") - .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) - .isEqualTo(HttpStatus.BAD_REQUEST); + return DynamicTest.stream(iterator, c -> "customAttribute: '" + c.getKey() + "'", test); } @Test void should_DeleteAllTasks_For_ProvidedParams() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?task-id=TKI:000000000000000000000000000000000036" + + "&task-id=TKI:000000000000000000000000000000000037" + + "&task-id=TKI:000000000000000000000000000000000038" + + "&custom14=abc"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); + ResponseEntity response = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?task-id=TKI:000000000000000000000000000000000036" - + "&task-id=TKI:000000000000000000000000000000000037" - + "&task-id=TKI:000000000000000000000000000000000038" - + "&custom14=abc", - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_SUMMARY_COLLECTION_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.DELETE, auth, TASK_SUMMARY_COLLECTION_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(3); @@ -334,28 +290,28 @@ class TaskControllerIntTest { @Test void should_ThrowException_When_ProvidingInvalidWildcardSearchParameters() { + String url = restHelper.toUrl(RestEndpoints.URL_TASKS) + "?wildcard-search-value=%rt%"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) + "?wildcard-search-value=%rt%", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400") .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.BAD_REQUEST); + String url2 = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?wildcard-search-fields=NAME,CUSTOM_3,CUSTOM_4"; ThrowingCallable httpCall2 = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?wildcard-search-fields=NAME,CUSTOM_3,CUSTOM_4", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url2, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + }; + assertThatThrownBy(httpCall2) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400") @@ -365,22 +321,21 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithinSingleDueTimeInterval() { - Instant dueFromInstant = Instant.now().minus(8, ChronoUnit.DAYS); Instant dueToInstant = Instant.now().minus(3, ChronoUnit.DAYS); + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&due-from=" + + dueFromInstant + + "&due-until=" + + dueToInstant + + "&sort-by=DUE"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&due-from=" - + dueFromInstant - + "&due-until=" - + dueToInstant - + "&sort-by=DUE", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(1); @@ -388,19 +343,18 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithinSingleIndefiniteDueTimeInterval() { - Instant dueToInstant = Instant.now().minus(1, ChronoUnit.DAYS); + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&due-until=" + + dueToInstant + + "&sort-by=DUE"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&due-until=" - + dueToInstant - + "&sort-by=DUE", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(6); @@ -408,19 +362,21 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithInvalidDueParamsCombination() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&due=2020-01-22T09:44:47.453Z,," + + "2020-01-19T07:44:47.453Z,2020-01-19T19:44:47.453Z," + + ",2020-01-18T09:44:47.453Z" + + "&due-from=2020-01-19T07:44:47.453Z" + + "&sort-by=planned"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&due=2020-01-22T09:44:47.453Z,," - + "2020-01-19T07:44:47.453Z,2020-01-19T19:44:47.453Z," - + ",2020-01-18T09:44:47.453Z" - + "&due-from=2020-01-19T07:44:47.453Z" - + "&sort-by=planned", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); @@ -428,13 +384,13 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketKeyAndDomain() { - HttpEntity request = new HttpEntity<>(restHelper.getHeadersUser_1_2()); + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + "?workbasket-key=USER-1-2&domain=DOMAIN_A"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) + "?workbasket-key=USER-1-2&domain=DOMAIN_A", - HttpMethod.GET, - request, - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(20); @@ -442,14 +398,15 @@ class TaskControllerIntTest { @Test void testGetAllTasksByExternalId() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?external-id=ETI:000000000000000000000000000000000003" + + "&external-id=ETI:000000000000000000000000000000000004"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?external-id=ETI:000000000000000000000000000000000003" - + "&external-id=ETI:000000000000000000000000000000000004", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(2); @@ -457,15 +414,14 @@ class TaskControllerIntTest { @Test void testExceptionIfKeyIsSetButDomainIsMissing() { - HttpEntity request = new HttpEntity<>(restHelper.getHeadersUser_1_2()); + String url = restHelper.toUrl(RestEndpoints.URL_TASKS) + "?workbasket-key=USER-1-2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) + "?workbasket-key=USER-1-2", - HttpMethod.GET, - request, - TASK_SUMMARY_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); @@ -473,12 +429,12 @@ class TaskControllerIntTest { @Test void testGetAllTasksWithAdminRole() { + String url = restHelper.toUrl(RestEndpoints.URL_TASKS); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(88); @@ -486,13 +442,14 @@ class TaskControllerIntTest { @Test void testGetAllTasksKeepingFilters() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?por.type=VNR&por.value=22334455&sort-by=POR_VALUE&order=DESCENDING"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?por.type=VNR&por.value=22334455&sort-by=POR_VALUE&order=DESCENDING", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF).getHref()) @@ -503,29 +460,26 @@ class TaskControllerIntTest { @Test void testGetLastPageSortedByPorValue() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?state=READY&state=CLAIMED&sort-by=POR_VALUE" + + "&order=DESCENDING&page-size=5&page=16"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); - HttpEntity request = new HttpEntity<>(restHelper.getHeadersAdmin()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?state=READY&state=CLAIMED&sort-by=POR_VALUE" - + "&order=DESCENDING&page-size=5&page=16", - HttpMethod.GET, - request, - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getContent()).hasSize(3); assertThat(response.getBody().getRequiredLink(IanaLinkRelations.LAST).getHref()) .contains("page=16"); assertThat(response.getBody().getContent().iterator().next().getTaskId()) .isEqualTo("TKI:000000000000000000000000000000000064"); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF).getHref()) .endsWith( "/api/v1/tasks?state=READY&state=CLAIMED" + "&sort-by=POR_VALUE&order=DESCENDING&page-size=5&page=16"); - assertThat(response.getBody().getLink(IanaLinkRelations.FIRST)).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.LAST)).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.PREV)).isNotNull(); @@ -537,31 +491,26 @@ class TaskControllerIntTest { // required because // ClassificationControllerIntTest.testGetQueryByPorSecondPageSortedByType changes // tasks and this test depends on the tasks as they are in sampledata + String url = restHelper.toUrl(RestEndpoints.URL_TASKS) + "?sort-by=DUE&order=DESCENDING"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); - HttpEntity request = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) + "?sort-by=DUE&order=DESCENDING", - HttpMethod.GET, - request, - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getContent()).hasSize(58); - response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?sort-by=DUE&order=DESCENDING&page-size=5&page=5", - HttpMethod.GET, - request, - TASK_SUMMARY_PAGE_MODEL_TYPE); + String url2 = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?sort-by=DUE&order=DESCENDING&page-size=5&page=5"; + response = TEMPLATE.exchange(url2, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat((response.getBody()).getContent()).hasSize(5); assertThat(response.getBody().getRequiredLink(IanaLinkRelations.LAST).getHref()) .contains("page=12"); assertThat(response.getBody().getContent().iterator().next().getTaskId()) .isEqualTo("TKI:000000000000000000000000000000000073"); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF).getHref()) .endsWith("/api/v1/tasks?sort-by=DUE&order=DESCENDING&page-size=5&page=5"); @@ -575,24 +524,21 @@ class TaskControllerIntTest { resetDb(); // required because // ClassificationControllerIntTest.testGetQueryByPorSecondPageSortedByType changes // tasks and this test depends on the tasks as they are in sampledata + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?por.company=00&por.system=PASystem&por.instance=00&" + + "por.type=VNR&por.value=22334455&sort-by=POR_TYPE&" + + "order=ASCENDING&page-size=5&page=2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); - HttpEntity request = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?por.company=00&por.system=PASystem&por.instance=00&" - + "por.type=VNR&por.value=22334455&sort-by=POR_TYPE&" - + "order=ASCENDING&page-size=5&page=2", - HttpMethod.GET, - request, - TASK_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getContent()) .extracting(TaskSummaryRepresentationModel::getTaskId) .containsExactlyInAnyOrder("TKI:000000000000000000000000000000000013"); - assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); - assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF).getHref()) .endsWith( "/api/v1/tasks?por.company=00&por.system=PASystem&por.instance=00&" @@ -605,13 +551,12 @@ class TaskControllerIntTest { @Test void should_NotGetEmptyAttachmentList_When_GettingTaskWithAttachment() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:000000000000000000000000000000000002"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); + ResponseEntity response = - template.exchange( - restHelper.toUrl( - RestEndpoints.URL_TASKS_ID, "TKI:000000000000000000000000000000000002"), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_MODEL_TYPE); TaskRepresentationModel repModel = response.getBody(); assertThat(repModel).isNotNull(); @@ -621,24 +566,19 @@ class TaskControllerIntTest { @Test void should_ChangeValueOfModified_When_UpdatingTask() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:100000000000000000000000000000000000"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity responseGet = - template.exchange( - restHelper.toUrl( - RestEndpoints.URL_TASKS_ID, "TKI:100000000000000000000000000000000000"), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_MODEL_TYPE); final TaskRepresentationModel originalTask = responseGet.getBody(); + HttpEntity auth2 = + new HttpEntity<>(originalTask, restHelper.getHeadersTeamlead_1()); ResponseEntity responseUpdate = - template.exchange( - restHelper.toUrl( - RestEndpoints.URL_TASKS_ID, "TKI:100000000000000000000000000000000000"), - HttpMethod.PUT, - new HttpEntity<>(originalTask, restHelper.getHeadersTeamlead_1()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.PUT, auth2, TASK_MODEL_TYPE); TaskRepresentationModel updatedTask = responseUpdate.getBody(); assertThat(originalTask).isNotNull(); @@ -648,29 +588,26 @@ class TaskControllerIntTest { @Test void testCreateAndDeleteTask() { - TaskRepresentationModel taskRepresentationModel = getTaskResourceSample(); + String url = restHelper.toUrl(RestEndpoints.URL_TASKS); + HttpEntity auth = + new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersTeamlead_1()); + ResponseEntity responseCreate = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS), - HttpMethod.POST, - new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersTeamlead_1()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_MODEL_TYPE); assertThat(responseCreate.getStatusCode()).isEqualTo(HttpStatus.CREATED); assertThat(responseCreate.getBody()).isNotNull(); String taskIdOfCreatedTask = responseCreate.getBody().getTaskId(); - assertThat(taskIdOfCreatedTask).isNotNull(); assertThat(taskIdOfCreatedTask).startsWith("TKI:"); + String url2 = restHelper.toUrl(RestEndpoints.URL_TASKS_ID, taskIdOfCreatedTask); + HttpEntity auth2 = new HttpEntity<>(restHelper.getHeadersAdmin()); + ResponseEntity responseDeleted = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS_ID, taskIdOfCreatedTask), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersAdmin()), - ParameterizedTypeReference.forType(Void.class)); - + url2, HttpMethod.DELETE, auth2, ParameterizedTypeReference.forType(Void.class)); assertThat(responseDeleted.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); } @@ -684,14 +621,15 @@ class TaskControllerIntTest { Instant now = Instant.now(); taskRepresentationModel.setPlanned(now); taskRepresentationModel.setDue(now); + String url = restHelper.toUrl(RestEndpoints.URL_TASKS); + HttpEntity auth = + new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersUser_1_1()); ThrowingCallable httpCall = - () -> - template.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS), - HttpMethod.POST, - new HttpEntity<>(taskRepresentationModel, restHelper.getHeadersUser_1_1()), - TASK_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_MODEL_TYPE); + }; + assertThatThrownBy(httpCall).isInstanceOf(HttpClientErrorException.class); } @@ -741,65 +679,51 @@ class TaskControllerIntTest { @Test void should_CancelTask_when_CallingCancelEndpoint() { - - final String claimed_task_id = "TKI:000000000000000000000000000000000026"; + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:000000000000000000000000000000000026"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); // retrieve task from Rest Api ResponseEntity responseGet = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS_ID, claimed_task_id), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_MODEL_TYPE); assertThat(responseGet.getBody()).isNotNull(); TaskRepresentationModel theTaskRepresentationModel = responseGet.getBody(); assertThat(theTaskRepresentationModel.getState()).isEqualTo(TaskState.CLAIMED); // cancel the task - responseGet = - template.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS_ID_CANCEL, claimed_task_id), - HttpMethod.POST, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + String url2 = + restHelper.toUrl( + RestEndpoints.URL_TASKS_ID_CANCEL, "TKI:000000000000000000000000000000000026"); + responseGet = TEMPLATE.exchange(url2, HttpMethod.POST, auth, TASK_MODEL_TYPE); assertThat(responseGet.getBody()).isNotNull(); - theTaskRepresentationModel = responseGet.getBody(); - assertThat(theTaskRepresentationModel.getState()).isEqualTo(TaskState.CANCELLED); + assertThat(responseGet.getBody().getState()).isEqualTo(TaskState.CANCELLED); } @Test void testCancelClaimTask() { - - final String claimed_task_id = "TKI:000000000000000000000000000000000027"; - final String user_id_of_claimed_task = "user-1-2"; + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:000000000000000000000000000000000027"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); // retrieve task from Rest Api ResponseEntity getTaskResponse = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS_ID, claimed_task_id), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); - + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_MODEL_TYPE); assertThat(getTaskResponse.getBody()).isNotNull(); - TaskRepresentationModel claimedTaskRepresentationModel = getTaskResponse.getBody(); assertThat(claimedTaskRepresentationModel.getState()).isEqualTo(TaskState.CLAIMED); - assertThat(claimedTaskRepresentationModel.getOwner()).isEqualTo(user_id_of_claimed_task); + assertThat(claimedTaskRepresentationModel.getOwner()).isEqualTo("user-1-2"); // cancel claim + String url2 = + restHelper.toUrl( + RestEndpoints.URL_TASKS_ID_CLAIM, "TKI:000000000000000000000000000000000027"); ResponseEntity cancelClaimResponse = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS_ID_CLAIM, claimed_task_id), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url2, HttpMethod.DELETE, auth, TASK_MODEL_TYPE); assertThat(cancelClaimResponse.getBody()).isNotNull(); assertThat(cancelClaimResponse.getStatusCode().is2xxSuccessful()).isTrue(); - TaskRepresentationModel cancelClaimedtaskRepresentationModel = cancelClaimResponse.getBody(); assertThat(cancelClaimedtaskRepresentationModel.getOwner()).isNull(); assertThat(cancelClaimedtaskRepresentationModel.getClaimed()).isNull(); @@ -808,31 +732,28 @@ class TaskControllerIntTest { @Test void testCancelClaimOfClaimedTaskByAnotherUserShouldThrowException() { - - final String claimed_task_id = "TKI:000000000000000000000000000000000026"; - final String user_id_of_claimed_task = "user-1-1"; + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:000000000000000000000000000000000026"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); // retrieve task from Rest Api ResponseEntity responseGet = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS_ID, claimed_task_id), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_MODEL_TYPE); assertThat(responseGet.getBody()).isNotNull(); TaskRepresentationModel theTaskRepresentationModel = responseGet.getBody(); assertThat(theTaskRepresentationModel.getState()).isEqualTo(TaskState.CLAIMED); - assertThat(theTaskRepresentationModel.getOwner()).isEqualTo(user_id_of_claimed_task); + assertThat(theTaskRepresentationModel.getOwner()).isEqualTo("user-1-1"); // try to cancel claim + String url2 = + restHelper.toUrl( + RestEndpoints.URL_TASKS_ID_CLAIM, "TKI:000000000000000000000000000000000026"); ThrowingCallable httpCall = - () -> - template.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS_ID_CLAIM, claimed_task_id), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url2, HttpMethod.DELETE, auth, TASK_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.CONFLICT); @@ -840,17 +761,12 @@ class TaskControllerIntTest { @Test void testUpdateTaskOwnerOfReadyTaskSucceeds() { - // setup - final String taskUrlString = - restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000025"); + final String url = restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000025"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); // retrieve task from Rest Api ResponseEntity responseGet = - TEMPLATE.exchange( - taskUrlString, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_MODEL_TYPE); assertThat(responseGet.getBody()).isNotNull(); TaskRepresentationModel theTaskRepresentationModel = responseGet.getBody(); @@ -858,35 +774,27 @@ class TaskControllerIntTest { assertThat(theTaskRepresentationModel.getOwner()).isNull(); // set Owner and update Task + theTaskRepresentationModel.setOwner("dummyUser"); + HttpEntity auth2 = + new HttpEntity<>(theTaskRepresentationModel, restHelper.getHeadersUser_1_2()); - final String anyUserName = "dummyUser"; - theTaskRepresentationModel.setOwner(anyUserName); ResponseEntity responseUpdate = - TEMPLATE.exchange( - taskUrlString, - HttpMethod.PUT, - new HttpEntity<>(theTaskRepresentationModel, restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.PUT, auth2, TASK_MODEL_TYPE); assertThat(responseUpdate.getBody()).isNotNull(); TaskRepresentationModel theUpdatedTaskRepresentationModel = responseUpdate.getBody(); assertThat(theUpdatedTaskRepresentationModel.getState()).isEqualTo(TaskState.READY); - assertThat(theUpdatedTaskRepresentationModel.getOwner()).isEqualTo(anyUserName); + assertThat(theUpdatedTaskRepresentationModel.getOwner()).isEqualTo("dummyUser"); } @Test void testUpdateTaskOwnerOfClaimedTaskFails() { - // setup - final String taskUrlString = - restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000026"); + final String url = restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000026"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_1_2()); // retrieve task from Rest Api ResponseEntity responseGet = - TEMPLATE.exchange( - taskUrlString, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_MODEL_TYPE); assertThat(responseGet.getBody()).isNotNull(); TaskRepresentationModel theTaskRepresentationModel = responseGet.getBody(); @@ -894,17 +802,15 @@ class TaskControllerIntTest { assertThat(theTaskRepresentationModel.getOwner()).isEqualTo("user-1-1"); // set Owner and update Task - - final String anyUserName = "dummyuser"; - theTaskRepresentationModel.setOwner(anyUserName); + theTaskRepresentationModel.setOwner("dummyuser"); + HttpEntity auth2 = + new HttpEntity<>(theTaskRepresentationModel, restHelper.getHeadersUser_1_2()); ThrowingCallable httpCall = - () -> - template.exchange( - taskUrlString, - HttpMethod.PUT, - new HttpEntity<>(theTaskRepresentationModel, restHelper.getHeadersUser_1_2()), - TASK_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.PUT, auth2, TASK_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("409"); @@ -914,14 +820,16 @@ class TaskControllerIntTest { void should_ThrowNotAuthorized_When_UserHasNoAuthorizationOnTask() { String url = restHelper.toUrl(RestEndpoints.URL_TASKS_ID, "TKI:000000000000000000000000000000000000"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersUser_b_1()); ThrowingCallable httpCall = - () -> - template.exchange( - url, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersUser_b_1()), - ParameterizedTypeReference.forType(TaskRepresentationModel.class)); + () -> { + TEMPLATE.exchange( + url, + HttpMethod.GET, + auth, + ParameterizedTypeReference.forType(TaskRepresentationModel.class)); + }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -930,18 +838,18 @@ class TaskControllerIntTest { @Test void should_ThrowException_When_ProvidingInvalidFilterParams() { + String url = + restHelper.toUrl(RestEndpoints.URL_TASKS) + + "?workbasket-id=WBI:100000000000000000000000000000000001" + + "&illegalParam=illegal" + + "&anotherIllegalParam=stillIllegal" + + "&sort-by=NAME&order=DESCENDING&page-size=5&page=2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_TASKS) - + "?workbasket-id=WBI:100000000000000000000000000000000001" - + "&illegalParam=illegal" - + "&anotherIllegalParam=stillIllegal" - + "&sort-by=NAME&order=DESCENDING&page-size=5&page=2", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - TASK_SUMMARY_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, TASK_SUMMARY_PAGE_MODEL_TYPE); + }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) @@ -954,24 +862,23 @@ class TaskControllerIntTest { @TestFactory Stream should_SetTransferFlagDependentOnRequestBody_When_TransferringTask() { Iterator iterator = Arrays.asList(true, false).iterator(); + String url = + restHelper.toUrl( + RestEndpoints.URL_TASKS_ID_TRANSFER_WORKBASKET_ID, + "TKI:000000000000000000000000000000000003", + "WBI:100000000000000000000000000000000006"); ThrowingConsumer test = setTransferFlag -> { + HttpEntity auth = + new HttpEntity<>(setTransferFlag.toString(), restHelper.getHeadersAdmin()); ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl( - RestEndpoints.URL_TASKS_ID_TRANSFER_WORKBASKET_ID, - "TKI:000000000000000000000000000000000003", - "WBI:100000000000000000000000000000000006"), - HttpMethod.POST, - new HttpEntity<>(setTransferFlag.toString(), restHelper.getHeadersAdmin()), - TASK_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_MODEL_TYPE); - TaskRepresentationModel task = response.getBody(); - assertThat(task).isNotNull(); - assertThat(task.getWorkbasketSummary().getWorkbasketId()) + assertThat(response.getBody()).isNotNull(); + assertThat(response.getBody().getWorkbasketSummary().getWorkbasketId()) .isEqualTo("WBI:100000000000000000000000000000000006"); - assertThat(task.isTransferred()).isEqualTo(setTransferFlag); + assertThat(response.getBody().isTransferred()).isEqualTo(setTransferFlag); }; return DynamicTest.stream(iterator, c -> "for setTransferFlag: " + c, test); @@ -979,21 +886,20 @@ class TaskControllerIntTest { @Test void should_SetTransferFlagToTrue_When_TransferringWithoutRequestBody() { - ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl( - RestEndpoints.URL_TASKS_ID_TRANSFER_WORKBASKET_ID, - "TKI:000000000000000000000000000000000003", - "WBI:100000000000000000000000000000000006"), - HttpMethod.POST, - new HttpEntity<>(restHelper.getHeadersAdmin()), - TASK_MODEL_TYPE); + String url = + restHelper.toUrl( + RestEndpoints.URL_TASKS_ID_TRANSFER_WORKBASKET_ID, + "TKI:000000000000000000000000000000000003", + "WBI:100000000000000000000000000000000006"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersAdmin()); - TaskRepresentationModel task = response.getBody(); - assertThat(task).isNotNull(); - assertThat(task.getWorkbasketSummary().getWorkbasketId()) + ResponseEntity response = + TEMPLATE.exchange(url, HttpMethod.POST, auth, TASK_MODEL_TYPE); + + assertThat(response.getBody()).isNotNull(); + assertThat(response.getBody().getWorkbasketSummary().getWorkbasketId()) .isEqualTo("WBI:100000000000000000000000000000000006"); - assertThat(task.isTransferred()).isTrue(); + assertThat(response.getBody().isTransferred()).isTrue(); } private TaskRepresentationModel getTaskResourceSample() { diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketAccessItemControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketAccessItemControllerIntTest.java index 73bb95459..269de6a53 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketAccessItemControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketAccessItemControllerIntTest.java @@ -45,12 +45,12 @@ class WorkbasketAccessItemControllerIntTest { @Test void testGetAllWorkbasketAccessItems() { + String url = restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE); + url, HttpMethod.GET, auth, WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); } @@ -59,12 +59,12 @@ class WorkbasketAccessItemControllerIntTest { void testGetWorkbasketAccessItemsKeepingFilters() { String parameters = "?sort-by=WORKBASKET_KEY&order=ASCENDING&page-size=9&access-id=user-1-1&page=1"; + String url = restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + parameters; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + parameters, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE); + url, HttpMethod.GET, auth, WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat( @@ -80,12 +80,12 @@ class WorkbasketAccessItemControllerIntTest { void testGetSecondPageSortedByWorkbasketKey() { String parameters = "?sort-by=WORKBASKET_KEY&order=ASCENDING&page=2&page-size=9&access-id=user-1-1"; + String url = restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + parameters; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + parameters, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE); + url, HttpMethod.GET, auth, WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getContent()).hasSize(1); assertThat(response.getBody().getContent().iterator().next().getAccessId()) @@ -108,33 +108,32 @@ class WorkbasketAccessItemControllerIntTest { @Test void should_DeleteAllAccessItemForUser_ifValidAccessIdOfUserIsSupplied() { + String url = + restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + "?access-id=teamlead-2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); - String parameters = "?access-id=teamlead-2"; ResponseEntity response = TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + parameters, - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType(Void.class)); + url, HttpMethod.DELETE, auth, ParameterizedTypeReference.forType(Void.class)); assertThat(response.getBody()).isNull(); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); } @Test void should_ThrowException_When_ProvidingInvalidFilterParams() { + String url = + restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + + "?access-id=teamlead-2" + + "&illegalParam=illegal" + + "&anotherIllegalParam=stillIllegal" + + "&sort-by=WORKBASKET_KEY&order=DESCENDING&page-size=5&page=2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) - + "?access-id=teamlead-2" - + "&illegalParam=illegal" - + "&anotherIllegalParam=stillIllegal" - + "&sort-by=WORKBASKET_KEY&order=DESCENDING&page-size=5&page=2", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE); - + () -> { + TEMPLATE.exchange( + url, HttpMethod.GET, auth, WORKBASKET_ACCESS_ITEM_PAGED_REPRESENTATION_MODEL_TYPE); + }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining( @@ -153,19 +152,23 @@ class WorkbasketAccessItemControllerIntTest { ThrowingConsumer test = accessId -> { - String parameters = "?access-id=" + accessId; + String url = + restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + + "?access-id=" + + accessId; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ACCESS_ITEMS) + parameters, - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - ParameterizedTypeReference.forType(Void.class)); + () -> { + TEMPLATE.exchange( + url, HttpMethod.DELETE, auth, ParameterizedTypeReference.forType(Void.class)); + }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.BAD_REQUEST); }; + return DynamicTest.stream(accessIds.iterator(), s -> String.format("for user '%s'", s), test); } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketControllerIntTest.java index 4e4d8ff47..106569acc 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketControllerIntTest.java @@ -61,12 +61,11 @@ class WorkbasketControllerIntTest { final String url = restHelper.toUrl( RestEndpoints.URL_WORKBASKET_ID, "WBI:100000000000000000000000000000000006"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - url, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_REPRESENTATION_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_REPRESENTATION_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)) @@ -76,24 +75,24 @@ class WorkbasketControllerIntTest { @Test void testGetAllWorkbaskets() { + String url = restHelper.toUrl(RestEndpoints.URL_WORKBASKET); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); } @Test void testGetAllWorkbasketsBusinessAdminHasOpenPermission() { + String url = restHelper.toUrl(RestEndpoints.URL_WORKBASKET) + "?required-permission=OPEN"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET) + "?required-permission=OPEN", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getRequiredLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getBody().getContent()).hasSize(6); @@ -102,12 +101,12 @@ class WorkbasketControllerIntTest { @Test void testGetAllWorkbasketsKeepingFilters() { String parameters = "?type=PERSONAL&sort-by=KEY&order=DESCENDING"; + String url = restHelper.toUrl(RestEndpoints.URL_WORKBASKET) + parameters; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET) + parameters, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat( @@ -121,34 +120,30 @@ class WorkbasketControllerIntTest { @Test void testUpdateWorkbasketWithConcurrentModificationShouldThrowException() { - - String workbasketId = "WBI:100000000000000000000000000000000001"; + String url = + restHelper.toUrl( + RestEndpoints.URL_WORKBASKET_ID, "WBI:100000000000000000000000000000000001"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ResponseEntity initialWorkbasketResourceRequestResponse = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ID, workbasketId), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_REPRESENTATION_MODEL_TYPE); - + TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_REPRESENTATION_MODEL_TYPE); WorkbasketRepresentationModel workbasketRepresentationModel = initialWorkbasketResourceRequestResponse.getBody(); - assertThat(workbasketRepresentationModel).isNotNull(); + workbasketRepresentationModel.setKey("GPK_KSC"); workbasketRepresentationModel.setDomain("DOMAIN_A"); workbasketRepresentationModel.setType(WorkbasketType.PERSONAL); workbasketRepresentationModel.setName("was auch immer"); workbasketRepresentationModel.setOwner("Joerg"); workbasketRepresentationModel.setModified(Instant.now()); + HttpEntity auth2 = + new HttpEntity<>(workbasketRepresentationModel, restHelper.getHeadersTeamlead_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ID, workbasketId), - HttpMethod.PUT, - new HttpEntity<>(workbasketRepresentationModel, restHelper.getHeadersTeamlead_1()), - WORKBASKET_REPRESENTATION_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.PUT, auth2, WORKBASKET_REPRESENTATION_MODEL_TYPE); + }; assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.CONFLICT); @@ -156,16 +151,16 @@ class WorkbasketControllerIntTest { @Test void testUpdateWorkbasketOfNonExistingWorkbasketShouldThrowException() { - - String workbasketId = "WBI:100004857400039500000999999999999999"; + String url = + restHelper.toUrl( + RestEndpoints.URL_WORKBASKET_ID, "WBI:100004857400039500000999999999999999"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersBusinessAdmin()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ID, workbasketId), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersBusinessAdmin()), - WORKBASKET_REPRESENTATION_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_REPRESENTATION_MODEL_TYPE); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -174,14 +169,13 @@ class WorkbasketControllerIntTest { @Test void testGetSecondPageSortedByKey() { - String parameters = "?sort-by=KEY&order=DESCENDING&page-size=5&page=2"; + String url = restHelper.toUrl(RestEndpoints.URL_WORKBASKET) + parameters; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET) + parameters, - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getContent()).hasSize(5); assertThat(response.getBody().getContent().iterator().next().getKey()).isEqualTo("USER-1-1"); @@ -201,29 +195,28 @@ class WorkbasketControllerIntTest { @Test void testMarkWorkbasketForDeletionAsBusinessAdminWithoutExplicitReadPermission() { + String url = + restHelper.toUrl( + RestEndpoints.URL_WORKBASKET_ID, "WBI:100000000000000000000000000000000005"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersBusinessAdmin()); - String workbasketID = "WBI:100000000000000000000000000000000005"; + ResponseEntity response = TEMPLATE.exchange(url, HttpMethod.DELETE, auth, Void.class); - ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ID, workbasketID), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersBusinessAdmin()), - Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED); } @Test void statusCode423ShouldBeReturnedIfWorkbasketContainsNonCompletedTasks() { - String workbasketWithNonCompletedTasks = "WBI:100000000000000000000000000000000004"; + String url = + restHelper.toUrl( + RestEndpoints.URL_WORKBASKET_ID, "WBI:100000000000000000000000000000000004"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersBusinessAdmin()); ThrowingCallable call = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_ID, workbasketWithNonCompletedTasks), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersBusinessAdmin()), - Void.class); + () -> { + TEMPLATE.exchange(url, HttpMethod.DELETE, auth, Void.class); + }; + assertThatThrownBy(call) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -232,24 +225,23 @@ class WorkbasketControllerIntTest { @Test void testRemoveWorkbasketAsDistributionTarget() { - ResponseEntity response = - TEMPLATE.exchange( - restHelper.toUrl( - RestEndpoints.URL_WORKBASKET_ID_DISTRIBUTION, - "WBI:100000000000000000000000000000000007"), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - Void.class); + String url = + restHelper.toUrl( + RestEndpoints.URL_WORKBASKET_ID_DISTRIBUTION, + "WBI:100000000000000000000000000000000007"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + + ResponseEntity response = TEMPLATE.exchange(url, HttpMethod.DELETE, auth, Void.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); + String url2 = + restHelper.toUrl( + RestEndpoints.URL_WORKBASKET_ID_DISTRIBUTION, + "WBI:100000000000000000000000000000000002"); ResponseEntity response2 = TEMPLATE.exchange( - restHelper.toUrl( - RestEndpoints.URL_WORKBASKET_ID_DISTRIBUTION, - "WBI:100000000000000000000000000000000002"), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - DISTRIBUTION_TARGETS_COLLECTION_REPRESENTATION_MODEL_TYPE); + url2, HttpMethod.GET, auth, DISTRIBUTION_TARGETS_COLLECTION_REPRESENTATION_MODEL_TYPE); + assertThat(response2.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(response2.getBody()).isNotNull(); assertThat(response2.getBody().getContent()) @@ -259,14 +251,16 @@ class WorkbasketControllerIntTest { @Test void testGetWorkbasketAccessItems() { + String url = + restHelper.toUrl( + RestEndpoints.URL_WORKBASKET_ID_ACCESS_ITEMS, + "WBI:100000000000000000000000000000000005"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = TEMPLATE.exchange( - restHelper.toUrl( - RestEndpoints.URL_WORKBASKET_ID_ACCESS_ITEMS, - "WBI:100000000000000000000000000000000005"), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_ACCESS_ITEM_COLLECTION_REPRESENTATION_TYPE); + url, HttpMethod.GET, auth, WORKBASKET_ACCESS_ITEM_COLLECTION_REPRESENTATION_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getHeaders().getContentType()).isEqualTo(MediaTypes.HAL_JSON); @@ -275,14 +269,16 @@ class WorkbasketControllerIntTest { @Test void testGetWorkbasketDistributionTargets() { + String url = + restHelper.toUrl( + RestEndpoints.URL_WORKBASKET_ID_DISTRIBUTION, + "WBI:100000000000000000000000000000000001"); + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + ResponseEntity response = TEMPLATE.exchange( - restHelper.toUrl( - RestEndpoints.URL_WORKBASKET_ID_DISTRIBUTION, - "WBI:100000000000000000000000000000000001"), - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - DISTRIBUTION_TARGETS_COLLECTION_REPRESENTATION_MODEL_TYPE); + url, HttpMethod.GET, auth, DISTRIBUTION_TARGETS_COLLECTION_REPRESENTATION_MODEL_TYPE); + assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getLink(IanaLinkRelations.SELF)).isNotNull(); assertThat(response.getHeaders().getContentType()).isEqualTo(MediaTypes.HAL_JSON); @@ -291,18 +287,18 @@ class WorkbasketControllerIntTest { @Test void should_ThrowException_When_ProvidingInvalidFilterParams() { + String url = + restHelper.toUrl(RestEndpoints.URL_WORKBASKET) + + "?type=PERSONAL" + + "&illegalParam=illegal" + + "&anotherIllegalParam=stillIllegal" + + "&sort-by=KEY&order=DESCENDING&page-size=5&page=2"; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); ThrowingCallable httpCall = - () -> - TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET) - + "?type=PERSONAL" - + "&illegalParam=illegal" - + "&anotherIllegalParam=stillIllegal" - + "&sort-by=KEY&order=DESCENDING&page-size=5&page=2", - HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), - WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + () -> { + TEMPLATE.exchange(url, HttpMethod.GET, auth, WORKBASKET_SUMMARY_PAGE_MODEL_TYPE); + }; assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketDefinitionControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketDefinitionControllerIntTest.java index ae5452064..57ccbc105 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketDefinitionControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/workbasket/rest/WorkbasketDefinitionControllerIntTest.java @@ -271,10 +271,13 @@ class WorkbasketDefinitionControllerIntTest { private ResponseEntity executeExportRequestForDomain(String domain) { + String url = restHelper.toUrl(RestEndpoints.URL_WORKBASKET_DEFINITIONS) + "?domain=" + domain; + HttpEntity auth = new HttpEntity<>(restHelper.getHeadersTeamlead_1()); + return TEMPLATE.exchange( - restHelper.toUrl(RestEndpoints.URL_WORKBASKET_DEFINITIONS) + "?domain=" + domain, + url, HttpMethod.GET, - new HttpEntity<>(restHelper.getHeadersTeamlead_1()), + auth, ParameterizedTypeReference.forType( WorkbasketDefinitionCollectionRepresentationModel.class)); }