From fc3f9e186850c7a8eb42c60875e516b357ae20e8 Mon Sep 17 00:00:00 2001 From: Sascha Frevel <3075075+sfrevel@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:47:52 +0100 Subject: [PATCH] TSK-1164: refactor code which is using assertJ's assertThatThrownBy and lambda expression with line breaks --- .../TaskHistoryEventControllerIntTest.java | 33 +++-- .../task/DeleteTaskCommentAccTest.java | 9 +- .../task/GetTaskCommentAccTest.java | 9 +- .../task/ServiceLevelPriorityAccTest.java | 5 +- .../taskana/TaskanaTransactionIntTest.java | 11 +- .../rest/AccessIdControllerIntTest.java | 16 ++- .../rest/ClassificationControllerIntTest.java | 52 ++++--- .../rest/GeneralExceptionHandlingTest.java | 17 ++- .../taskana/rest/TaskControllerIntTest.java | 136 ++++++++++-------- ...WorkbasketAccessItemControllerIntTest.java | 35 +++-- .../rest/WorkbasketControllerIntTest.java | 48 ++++--- ...WorkbasketDefinitionControllerIntTest.java | 12 +- 12 files changed, 219 insertions(+), 164 deletions(-) diff --git a/history/taskana-simplehistory-spring-test/src/test/java/pro/taskana/TaskHistoryEventControllerIntTest.java b/history/taskana-simplehistory-spring-test/src/test/java/pro/taskana/TaskHistoryEventControllerIntTest.java index 9828d9fec..d49793dba 100644 --- a/history/taskana-simplehistory-spring-test/src/test/java/pro/taskana/TaskHistoryEventControllerIntTest.java +++ b/history/taskana-simplehistory-spring-test/src/test/java/pro/taskana/TaskHistoryEventControllerIntTest.java @@ -9,6 +9,7 @@ import java.sql.SQLException; import java.time.LocalDateTime; import java.util.Collections; import javax.sql.DataSource; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -120,13 +121,15 @@ public class TaskHistoryEventControllerIntTest { @Test public void testThrowsExceptionIfInvalidFilterIsUsed() { - assertThatThrownBy( - () -> - template.exchange( - server + port + "/api/v1/task-history-event?invalid=BPI:01", - HttpMethod.GET, - request, - ParameterizedTypeReference.forType(TaskHistoryEventListResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + server + port + "/api/v1/task-history-event?invalid=BPI:01", + HttpMethod.GET, + request, + ParameterizedTypeReference.forType(TaskHistoryEventListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("[invalid]") .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -137,13 +140,15 @@ public class TaskHistoryEventControllerIntTest { public void testGetHistoryEventOfDate() { String currentTime = LocalDateTime.now().toString(); final String finalCurrentTime = currentTime; - assertThatThrownBy( - () -> - template.exchange( - server + port + "/api/v1/task-history-event?created=" + finalCurrentTime, - HttpMethod.GET, - request, - ParameterizedTypeReference.forType(TaskHistoryEventListResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + server + port + "/api/v1/task-history-event?created=" + finalCurrentTime, + HttpMethod.GET, + request, + ParameterizedTypeReference.forType(TaskHistoryEventListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining(currentTime) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) diff --git a/lib/taskana-core/src/test/java/acceptance/task/DeleteTaskCommentAccTest.java b/lib/taskana-core/src/test/java/acceptance/task/DeleteTaskCommentAccTest.java index 8ca37e4cb..d2678cc42 100644 --- a/lib/taskana-core/src/test/java/acceptance/task/DeleteTaskCommentAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/task/DeleteTaskCommentAccTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import acceptance.AbstractAccTest; import java.util.List; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -59,9 +60,11 @@ public class DeleteTaskCommentAccTest extends AbstractAccTest { taskService.getTaskComments("TKI:000000000000000000000000000000000002"); assertThat(taskComments).hasSize(2); - assertThatThrownBy( - () -> taskService.deleteTaskComment("TCI:000000000000000000000000000000000005")) - .isInstanceOf(NotAuthorizedException.class); + ThrowingCallable httpCall = + () -> { + taskService.deleteTaskComment("TCI:000000000000000000000000000000000005"); + }; + assertThatThrownBy(httpCall).isInstanceOf(NotAuthorizedException.class); // make sure the task comment was not deleted List taskCommentsAfterDeletion = diff --git a/lib/taskana-core/src/test/java/acceptance/task/GetTaskCommentAccTest.java b/lib/taskana-core/src/test/java/acceptance/task/GetTaskCommentAccTest.java index 49f93f011..6b45e6ba1 100644 --- a/lib/taskana-core/src/test/java/acceptance/task/GetTaskCommentAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/task/GetTaskCommentAccTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import acceptance.AbstractAccTest; import java.util.List; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -58,9 +59,11 @@ public class GetTaskCommentAccTest extends AbstractAccTest { TaskService taskService = taskanaEngine.getTaskService(); - assertThatThrownBy( - () -> taskService.getTaskComments("TKI:000000000000000000000000000000000004")) - .isInstanceOf(NotAuthorizedException.class); + ThrowingCallable httpCall = + () -> { + taskService.getTaskComments("TKI:000000000000000000000000000000000004"); + }; + assertThatThrownBy(httpCall).isInstanceOf(NotAuthorizedException.class); } @WithAccessId( diff --git a/lib/taskana-core/src/test/java/acceptance/task/ServiceLevelPriorityAccTest.java b/lib/taskana-core/src/test/java/acceptance/task/ServiceLevelPriorityAccTest.java index 763186059..3c8305b1f 100644 --- a/lib/taskana-core/src/test/java/acceptance/task/ServiceLevelPriorityAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/task/ServiceLevelPriorityAccTest.java @@ -36,6 +36,7 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest { ServiceLevelPriorityAccTest() { super(); + DaysToWorkingDaysConverter.setGermanPublicHolidaysEnabled(true); taskService = taskanaEngine.getTaskService(); } @@ -231,9 +232,9 @@ public class ServiceLevelPriorityAccTest extends AbstractAccTest { Instant dueBulk3 = taskService.getTask(tkId3).getDue(); Instant dueBulk4 = taskService.getTask(tkId4).getDue(); assertThat(dueBulk1).isEqualTo(getInstant("2020-05-14T07:00:00")); - assertThat(dueBulk2).isEqualTo(getInstant("2020-05-21T07:00:00")); + assertThat(dueBulk2).isEqualTo(getInstant("2020-05-22T07:00:00")); assertThat(dueBulk3).isEqualTo(getInstant("2020-05-14T07:00:00")); - assertThat(dueBulk4).isEqualTo(getInstant("2020-05-21T07:00:00")); + assertThat(dueBulk4).isEqualTo(getInstant("2020-05-22T07:00:00")); } @WithAccessId( diff --git a/lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionIntTest.java b/lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionIntTest.java index 5bccad79d..ac762db2a 100644 --- a/lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionIntTest.java +++ b/lib/taskana-spring-example/src/test/java/pro/taskana/TaskanaTransactionIntTest.java @@ -7,6 +7,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -211,10 +212,12 @@ class TaskanaTransactionIntTest { new TaskCleanupJob(taskanaEngine, springTransactionProvider, null); taskCleanupJob.run(); - assertThatThrownBy( - () -> - workbasketService.deleteWorkbasket( - workbasketService.getWorkbasket("key3", "DOMAIN_A").getId())) + ThrowingCallable httpCall = + () -> { + workbasketService.deleteWorkbasket( + workbasketService.getWorkbasket("key3", "DOMAIN_A").getId()); + }; + assertThatThrownBy(httpCall) .isInstanceOf(WorkbasketInUseException.class) .hasMessageContaining("contains 1 non-completed tasks"); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/AccessIdControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/AccessIdControllerIntTest.java index 336e2e801..babc4c66f 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/AccessIdControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/AccessIdControllerIntTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.ArrayList; import java.util.List; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -79,12 +80,15 @@ class AccessIdControllerIntTest { @Test void testBadRequestWhenSearchForIsTooShort() { - assertThatThrownBy(() -> - template.exchange( - restHelper.toUrl(Mapping.URL_ACCESSID) + "?search-for=al", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(List.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_ACCESSID) + "?search-for=al", + HttpMethod.GET, + restHelper.defaultRequest(), + ParameterizedTypeReference.forType(List.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("Minimum searchFor length =") .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationControllerIntTest.java index 86508ceb0..cb1b82947 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationControllerIntTest.java @@ -3,6 +3,7 @@ package pro.taskana.rest; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; @@ -238,13 +239,15 @@ class ClassificationControllerIntTest { + "\"type\":\"TASK\",\"parentId\":\"CLI:200000000000000000000000000000000015\"," + "\"parentKey\":\"T2000\"}"; - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), + HttpMethod.POST, + new HttpEntity<>(newClassification, restHelper.getHeaders()), + ParameterizedTypeReference.forType(ClassificationResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.BAD_REQUEST); @@ -258,13 +261,15 @@ class ClassificationControllerIntTest { + "\"domain\":\"DOMAIN_A\",\"key\":\"NEW_CLASS\"," + "\"name\":\"new classification\",\"type\":\"TASK\"}"; - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), - HttpMethod.POST, - new HttpEntity<>(newClassification, restHelper.getHeaders()), - ParameterizedTypeReference.forType(ClassificationResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), + HttpMethod.POST, + new HttpEntity<>(newClassification, restHelper.getHeaders()), + ParameterizedTypeReference.forType(ClassificationResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.BAD_REQUEST); @@ -299,14 +304,15 @@ class ClassificationControllerIntTest { assertThat(HttpStatus.NO_CONTENT).isEqualTo(response.getStatusCode()); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl( - Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"), - HttpMethod.GET, - request, - ParameterizedTypeReference.forType(ClassificationSummaryResource.class))) - .isInstanceOf(HttpClientErrorException.class); + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl( + Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"), + HttpMethod.GET, + request, + ParameterizedTypeReference.forType(ClassificationSummaryResource.class)); + }; + assertThatThrownBy(httpCall).isInstanceOf(HttpClientErrorException.class); } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/GeneralExceptionHandlingTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/GeneralExceptionHandlingTest.java index 9d051503d..ebe4df257 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/GeneralExceptionHandlingTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/GeneralExceptionHandlingTest.java @@ -2,6 +2,7 @@ package pro.taskana.rest; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -28,13 +29,15 @@ class GeneralExceptionHandlingTest { @Test void testDeleteNonExisitingClassificationExceptionIsLogged() { - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.URL_CLASSIFICATIONS_ID, "non-existing-id"), - HttpMethod.DELETE, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(ClassificationSummaryListResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_CLASSIFICATIONS_ID, "non-existing-id"), + HttpMethod.DELETE, + restHelper.defaultRequest(), + ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("non-existing-id"); } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskControllerIntTest.java index 9136b4fde..05a6bd47d 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/TaskControllerIntTest.java @@ -17,6 +17,7 @@ import java.net.URL; import java.time.Instant; import java.time.temporal.ChronoUnit; import javax.sql.DataSource; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -163,19 +164,21 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithInvalidPlannedParamsCombination() { - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.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, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.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, + restHelper.defaultRequest(), + ParameterizedTypeReference.forType(TaskSummaryListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); } @@ -252,19 +255,21 @@ class TaskControllerIntTest { @Test void testGetAllTasksByWorkbasketIdWithInvalidDueParamsCombination() { - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.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, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.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, + restHelper.defaultRequest(), + ParameterizedTypeReference.forType(TaskSummaryListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); } @@ -291,15 +296,15 @@ class TaskControllerIntTest { headers.add("Authorization", "Basic dXNlcl8xXzI6dXNlcl8xXzI="); // user_1_2 HttpEntity request = new HttpEntity<>(headers); - assertThatThrownBy( + ThrowingCallable httpCall = () -> { - ResponseEntity response = - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-key=USER_1_2", - HttpMethod.GET, - request, - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - }) + template.exchange( + restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-key=USER_1_2", + HttpMethod.GET, + request, + ParameterizedTypeReference.forType(TaskSummaryListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); } @@ -338,13 +343,15 @@ class TaskControllerIntTest { @Test void testThrowsExceptionIfInvalidFilterIsUsed() { - assertThatThrownBy( - () -> + ThrowingCallable httpCall = + () -> { template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?invalid=VNR", HttpMethod.GET, restHelper.defaultRequest(), - ParameterizedTypeReference.forType(TaskSummaryListResource.class))) + ParameterizedTypeReference.forType(TaskSummaryListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("[invalid]") .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -584,14 +591,15 @@ class TaskControllerIntTest { taskResource.setPlanned(now.toString()); taskResource.setDue(now.toString()); - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS), - HttpMethod.POST, - new HttpEntity<>(taskResource, restHelper.getHeaders()), - ParameterizedTypeReference.forType(TaskResource.class))) - .isInstanceOf(HttpClientErrorException.class); + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_TASKS), + HttpMethod.POST, + new HttpEntity<>(taskResource, restHelper.getHeaders()), + ParameterizedTypeReference.forType(TaskResource.class)); + }; + assertThatThrownBy(httpCall).isInstanceOf(HttpClientErrorException.class); } @Test @@ -658,7 +666,7 @@ class TaskControllerIntTest { assertThat(claimedTaskResource.getState()).isEqualTo(TaskState.CLAIMED); assertThat(claimedTaskResource.getOwner()).isEqualTo(user_id_of_claimed_task); - //cancel claim + // cancel claim ResponseEntity cancelClaimResponse = template.exchange( restHelper.toUrl(Mapping.URL_TASKS_ID_CLAIM, claimed_task_id), @@ -694,20 +702,20 @@ class TaskControllerIntTest { assertThat(theTaskResource.getState()).isEqualTo(TaskState.CLAIMED); assertThat(theTaskResource.getOwner()).isEqualTo(user_id_of_claimed_task); - //try to cancel claim - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS_ID_CLAIM, claimed_task_id), - HttpMethod.DELETE, - new HttpEntity<>(restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class))) + // try to cancel claim + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_TASKS_ID_CLAIM, claimed_task_id), + HttpMethod.DELETE, + new HttpEntity<>(restHelper.getHeadersUser_1_2()), + ParameterizedTypeReference.forType(TaskResource.class)); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.CONFLICT); } - - @Test void testUpdateTaskOwnerOfReadyTaskSucceeds() { // setup @@ -768,13 +776,15 @@ class TaskControllerIntTest { final String anyUserName = "dummyuser"; theTaskResource.setOwner(anyUserName); - assertThatThrownBy( - () -> - template.exchange( - taskUrlString, - HttpMethod.PUT, - new HttpEntity<>(theTaskResource, restHelper.getHeadersUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + taskUrlString, + HttpMethod.PUT, + new HttpEntity<>(theTaskResource, restHelper.getHeadersUser_1_2()), + ParameterizedTypeReference.forType(TaskResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("409"); } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketAccessItemControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketAccessItemControllerIntTest.java index e049ed621..040d3ea7e 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketAccessItemControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketAccessItemControllerIntTest.java @@ -3,6 +3,7 @@ package pro.taskana.rest; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; @@ -59,14 +60,16 @@ class WorkbasketAccessItemControllerIntTest { @Test void testThrowsExceptionIfInvalidFilterIsUsed() { - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) - + "?sort-by=workbasket-key&order=asc&page=1&page-size=9&invalid=user_1_1", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketAccessItemListResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + + "?sort-by=workbasket-key&order=asc&page=1&page-size=9&invalid=user_1_1", + HttpMethod.GET, + restHelper.defaultRequest(), + ParameterizedTypeReference.forType(WorkbasketAccessItemListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("[invalid]") .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -112,13 +115,15 @@ class WorkbasketAccessItemControllerIntTest { @Test void testGetBadRequestIfTryingToDeleteAccessItemsForGroup() { String parameters = "?access-id=cn=DevelopersGroup,ou=groups,o=TaskanaTest"; - assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters, - HttpMethod.DELETE, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(Void.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_WORKBASKETACCESSITEMS) + parameters, + HttpMethod.DELETE, + restHelper.defaultRequest(), + ParameterizedTypeReference.forType(Void.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.BAD_REQUEST); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketControllerIntTest.java index 21fd2fdad..2213556e5 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketControllerIntTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.fasterxml.jackson.databind.ObjectMapper; import java.time.Instant; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -90,12 +91,15 @@ class WorkbasketControllerIntTest { @Test void testThrowsExceptionIfInvalidFilterIsUsed() { - assertThatThrownBy(() -> - template.exchange( - restHelper.toUrl(Mapping.URL_WORKBASKET) + "?invalid=PERSONAL", - HttpMethod.GET, - restHelper.defaultRequest(), - ParameterizedTypeReference.forType(WorkbasketSummaryListResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_WORKBASKET) + "?invalid=PERSONAL", + HttpMethod.GET, + restHelper.defaultRequest(), + ParameterizedTypeReference.forType(WorkbasketSummaryListResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("[invalid]") .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) @@ -125,13 +129,16 @@ class WorkbasketControllerIntTest { workbasketResource.setOwner("Joerg"); workbasketResource.setModified(String.valueOf(Instant.now())); - assertThatThrownBy(() -> - template.exchange( - restHelper.toUrl(Mapping.URL_WORKBASKET_ID, workbasketId), - HttpMethod.PUT, - new HttpEntity<>( - mapper.writeValueAsString(workbasketResource), restHelper.getHeaders()), - ParameterizedTypeReference.forType(WorkbasketResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_WORKBASKET_ID, workbasketId), + HttpMethod.PUT, + new HttpEntity<>( + mapper.writeValueAsString(workbasketResource), restHelper.getHeaders()), + ParameterizedTypeReference.forType(WorkbasketResource.class)); + }; + assertThatThrownBy(httpCall) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.CONFLICT); } @@ -141,12 +148,15 @@ class WorkbasketControllerIntTest { String workbasketId = "WBI:100004857400039500000999999999999999"; - assertThatThrownBy(() -> - template.exchange( - restHelper.toUrl(Mapping.URL_WORKBASKET_ID, workbasketId), - HttpMethod.GET, - new HttpEntity(restHelper.getHeaders()), - ParameterizedTypeReference.forType(WorkbasketResource.class))) + ThrowingCallable httpCall = + () -> { + template.exchange( + restHelper.toUrl(Mapping.URL_WORKBASKET_ID, workbasketId), + HttpMethod.GET, + new HttpEntity(restHelper.getHeaders()), + ParameterizedTypeReference.forType(WorkbasketResource.class)); + }; + assertThatThrownBy(httpCall) .isInstanceOf(HttpClientErrorException.class) .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) .isEqualTo(HttpStatus.NOT_FOUND); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketDefinitionControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketDefinitionControllerIntTest.java index 49680de38..eb13c67ae 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketDefinitionControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/WorkbasketDefinitionControllerIntTest.java @@ -17,6 +17,7 @@ import java.util.HashSet; import java.util.List; import java.util.stream.Collectors; import javax.sql.DataSource; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -211,11 +212,12 @@ class WorkbasketDefinitionControllerIntTest { String w1String = workbasketToString(w); w.getWorkbasket().setKey("new Key for this WB"); String w2String = workbasketToString(w); - assertThatThrownBy( - () -> - expectStatusWhenExecutingImportRequestOfWorkbaskets( - HttpStatus.CONFLICT, Arrays.asList(w1String, w2String))) - .isInstanceOf(HttpClientErrorException.class); + ThrowingCallable httpCall = + () -> { + expectStatusWhenExecutingImportRequestOfWorkbaskets( + HttpStatus.CONFLICT, Arrays.asList(w1String, w2String)); + }; + assertThatThrownBy(httpCall).isInstanceOf(HttpClientErrorException.class); } private void changeWorkbasketIdOrKey(