diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResource.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResource.java index f4dbba61b..0dcab860f 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResource.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/rest/resource/ClassificationSummaryResource.java @@ -7,23 +7,23 @@ import pro.taskana.classification.api.ClassificationSummary; /** Resource class for {@link ClassificationSummary}. */ public class ClassificationSummaryResource extends ResourceSupport { - public String classificationId; - public String key; - public String parentId; - public String parentKey; - public String category; - public String type; - public String domain; - public String name; - public int priority; - public String custom1; - public String custom2; - public String custom3; - public String custom4; - public String custom5; - public String custom6; - public String custom7; - public String custom8; + private String classificationId; + private String key; + private String parentId; + private String parentKey; + private String category; + private String type; + private String domain; + private String name; + private int priority; + private String custom1; + private String custom2; + private String custom3; + private String custom4; + private String custom5; + private String custom6; + private String custom7; + private String custom8; public ClassificationSummaryResource() {} 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 f3def5dc2..7a6b10d7d 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 @@ -77,10 +77,15 @@ class ClassificationControllerIntTest { restHelper.defaultRequest(), ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); assertThat(response.getBody().getLink(Link.REL_SELF)).isNotNull(); - assertThat(response.getBody().getLink(Link.REL_SELF).getHref()) - .endsWith("/api/v1/classifications?domain=DOMAIN_A&sort-by=key&order=asc"); + assertThat( + response + .getBody() + .getLink(Link.REL_SELF) + .getHref() + .endsWith("/api/v1/classifications?domain=DOMAIN_A&sort-by=key&order=asc")) + .isTrue(); assertThat(response.getBody().getContent()).hasSize(17); - assertThat(response.getBody().getContent().iterator().next().key).isEqualTo("A12"); + assertThat(response.getBody().getContent().iterator().next().getKey()).isEqualTo("A12"); } @Test @@ -93,12 +98,17 @@ class ClassificationControllerIntTest { restHelper.defaultRequest(), ParameterizedTypeReference.forType(ClassificationSummaryListResource.class)); assertThat(response.getBody().getContent()).hasSize(5); - assertThat(response.getBody().getContent().iterator().next().key).isEqualTo("L1050"); + assertThat(response.getBody().getContent().iterator().next().getKey()).isEqualTo("L1050"); assertThat(response.getBody().getLink(Link.REL_SELF)).isNotNull(); - assertThat(response.getBody().getLink(Link.REL_SELF).getHref()) - .endsWith( - "/api/v1/classifications?" - + "domain=DOMAIN_A&sort-by=key&order=asc&page=2&page-size=5"); + assertThat( + response + .getBody() + .getLink(Link.REL_SELF) + .getHref() + .endsWith( + "/api/v1/classifications?" + + "domain=DOMAIN_A&sort-by=key&order=asc&page=2&page-size=5")) + .isTrue(); assertThat(response.getBody().getLink(Link.REL_FIRST)).isNotNull(); assertThat(response.getBody().getLink(Link.REL_LAST)).isNotNull(); assertThat(response.getBody().getLink(Link.REL_NEXT)).isNotNull(); @@ -121,7 +131,7 @@ class ClassificationControllerIntTest { ParameterizedTypeReference.forType(ClassificationResource.class)); assertThat(responseEntity).isNotNull(); - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); newClassification = "{\"classificationId\":\"\",\"category\":\"MANUAL\"," @@ -135,7 +145,7 @@ class ClassificationControllerIntTest { new HttpEntity<>(newClassification, restHelper.getHeaders()), ParameterizedTypeReference.forType(ClassificationResource.class)); - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); } @Test @@ -155,7 +165,7 @@ class ClassificationControllerIntTest { ParameterizedTypeReference.forType(ClassificationResource.class)); assertThat(responseEntity).isNotNull(); - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); } @Test @@ -175,7 +185,7 @@ class ClassificationControllerIntTest { ParameterizedTypeReference.forType(ClassificationResource.class)); assertThat(responseEntity).isNotNull(); - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); } @Test @@ -194,7 +204,7 @@ class ClassificationControllerIntTest { ParameterizedTypeReference.forType(ClassificationResource.class)); assertThat(responseEntity).isNotNull(); - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED); + assertThat(HttpStatus.CREATED).isEqualTo(responseEntity.getStatusCode()); ResponseEntity response = template.exchange( @@ -209,6 +219,7 @@ class ClassificationControllerIntTest { && "".equals(classification.getDomain()) && "T2100".equals(classification.getParentKey())) { foundClassificationCreated = true; + break; } } @@ -223,17 +234,17 @@ class ClassificationControllerIntTest { + "\"key\":\"NEW_CLASS_P3\",\"name\":\"new classification\"," + "\"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))) + () -> + template.exchange( + restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), + HttpMethod.POST, + new HttpEntity<>(newClassification, restHelper.getHeaders()), + ParameterizedTypeReference.forType(ClassificationResource.class))) .isInstanceOf(HttpClientErrorException.class) - .extracting(ex -> ((HttpClientErrorException)ex).getStatusCode()) - .isEqualTo(HttpStatus.BAD_REQUEST);; + .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) + .isEqualTo(HttpStatus.BAD_REQUEST); } @Test @@ -244,21 +255,22 @@ 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))) + assertThatThrownBy( + () -> + template.exchange( + restHelper.toUrl(Mapping.URL_CLASSIFICATIONS), + HttpMethod.POST, + new HttpEntity<>(newClassification, restHelper.getHeaders()), + ParameterizedTypeReference.forType(ClassificationResource.class))) .isInstanceOf(HttpClientErrorException.class) - .extracting(ex -> ((HttpClientErrorException)ex).getStatusCode()) - .isEqualTo(HttpStatus.BAD_REQUEST); + .extracting(ex -> ((HttpClientErrorException) ex).getStatusCode()) + .isEqualTo(HttpStatus.BAD_REQUEST); } @Test void testGetClassificationWithSpecialCharacter() { - HttpEntity request = new HttpEntity(restHelper.getHeadersAdmin()); + HttpEntity request = new HttpEntity<>(restHelper.getHeadersAdmin()); ResponseEntity response = template.exchange( restHelper.toUrl( @@ -266,13 +278,13 @@ class ClassificationControllerIntTest { HttpMethod.GET, request, ParameterizedTypeReference.forType(ClassificationSummaryResource.class)); - assertThat(response.getBody().name).isEqualTo("Zustimmungserklärung"); + assertThat(response.getBody().getName()).isEqualTo("Zustimmungserklärung"); } @Test @DirtiesContext void testDeleteClassification() { - HttpEntity request = new HttpEntity(restHelper.getHeaders()); + HttpEntity request = new HttpEntity<>(restHelper.getHeaders()); ResponseEntity response = template.exchange( @@ -281,15 +293,17 @@ class ClassificationControllerIntTest { HttpMethod.DELETE, request, ParameterizedTypeReference.forType(ClassificationSummaryResource.class)); + 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); + assertThatThrownBy( + () -> + template.exchange( + restHelper.toUrl( + Mapping.URL_CLASSIFICATIONS_ID, "CLI:200000000000000000000000000000000004"), + HttpMethod.GET, + request, + ParameterizedTypeReference.forType(ClassificationSummaryResource.class))) + .isInstanceOf(HttpClientErrorException.class); } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationDefinitionControllerIntTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationDefinitionControllerIntTest.java index 4a48f3d2f..9bae64e45 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationDefinitionControllerIntTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/ClassificationDefinitionControllerIntTest.java @@ -1,12 +1,7 @@ package pro.taskana.rest; -import static org.hamcrest.Matchers.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; @@ -62,10 +57,10 @@ class ClassificationDefinitionControllerIntTest { HttpMethod.GET, restHelper.defaultRequest(), ParameterizedTypeReference.forType(ClassificationResource[].class)); - assertEquals(HttpStatus.OK, response.getStatusCode()); - assertTrue(response.getBody().length >= 5); - assertTrue(response.getBody().length <= 7); - assertThat(response.getBody()[0], instanceOf(ClassificationResource.class)); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody().length >= 5).isTrue(); + assertThat(response.getBody().length <= 7).isTrue(); + assertThat(response.getBody()[0]).isInstanceOf(ClassificationResource.class); } @Test @@ -76,7 +71,7 @@ class ClassificationDefinitionControllerIntTest { HttpMethod.GET, restHelper.defaultRequest(), ParameterizedTypeReference.forType(ClassificationResource[].class)); - assertEquals(0, response.getBody().length); + assertThat(response.getBody()).isEmpty(); } @Test @@ -110,7 +105,7 @@ class ClassificationDefinitionControllerIntTest { clList.add(objMapper.writeValueAsString(classification)); ResponseEntity response = importRequest(clList); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -123,7 +118,7 @@ class ClassificationDefinitionControllerIntTest { try { importRequest(clList); } catch (HttpClientErrorException e) { - assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode()); + assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); } } @@ -137,7 +132,7 @@ class ClassificationDefinitionControllerIntTest { try { importRequest(clList); } catch (HttpClientErrorException e) { - assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode()); + assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); } } @@ -152,7 +147,7 @@ class ClassificationDefinitionControllerIntTest { try { importRequest(clList); } catch (HttpClientErrorException e) { - assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode()); + assertThat(e.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); } } @@ -182,7 +177,7 @@ class ClassificationDefinitionControllerIntTest { clList.add(c2); ResponseEntity response = importRequest(clList); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); } @Test @@ -200,7 +195,7 @@ class ClassificationDefinitionControllerIntTest { try { importRequest(clList); } catch (HttpClientErrorException e) { - assertEquals(HttpStatus.CONFLICT, e.getStatusCode()); + assertThat(e.getStatusCode()).isEqualTo(HttpStatus.CONFLICT); } } @@ -213,18 +208,18 @@ class ClassificationDefinitionControllerIntTest { clList.add(objMapper.writeValueAsString(existingClassification)); ResponseEntity response = importRequest(clList); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); existingClassification.setName("second new Name"); clList = new ArrayList<>(); clList.add(objMapper.writeValueAsString(existingClassification)); response = importRequest(clList); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); ClassificationSummaryResource testClassification = this.getClassificationWithKeyAndDomain("L110107", "DOMAIN_A"); - assertEquals("second new Name", testClassification.getName()); + assertThat(testClassification.getName()).isEqualTo("second new Name"); } @Test @@ -241,7 +236,7 @@ class ClassificationDefinitionControllerIntTest { clList.add(objMapper.writeValueAsString(newClassification)); ResponseEntity response = importRequest(clList); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); ClassificationSummaryResource parentCl = getClassificationWithKeyAndDomain("L11010", "DOMAIN_A"); @@ -250,11 +245,11 @@ class ClassificationDefinitionControllerIntTest { ClassificationSummaryResource testExistingCl = getClassificationWithKeyAndDomain("L110102", "DOMAIN_A"); - assertNotNull(parentCl); - assertNotNull(testNewCl); - assertNotNull(testExistingCl); - assertEquals(testNewCl.getClassificationId(), testExistingCl.getParentId()); - assertEquals(parentCl.getClassificationId(), testNewCl.getParentId()); + assertThat(parentCl).isNotNull(); + assertThat(testNewCl).isNotNull(); + assertThat(testExistingCl).isNotNull(); + assertThat(testExistingCl.getParentId()).isEqualTo(testNewCl.getClassificationId()); + assertThat(testNewCl.getParentId()).isEqualTo(parentCl.getClassificationId()); } @Test @@ -286,7 +281,7 @@ class ClassificationDefinitionControllerIntTest { clList.add(c1); ResponseEntity response = importRequest(clList); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); ClassificationSummaryResource parentCl = getClassificationWithKeyAndDomain("ImportKey6", "DOMAIN_A"); @@ -295,11 +290,11 @@ class ClassificationDefinitionControllerIntTest { ClassificationSummaryResource grandchildCl = getClassificationWithKeyAndDomain("ImportKey9", "DOMAIN_A"); - assertNotNull(parentCl); - assertNotNull(childCl); - assertNotNull(grandchildCl); - assertEquals(childCl.getClassificationId(), grandchildCl.getParentId()); - assertEquals(parentCl.getClassificationId(), childCl.getParentId()); + assertThat(parentCl).isNotNull(); + assertThat(childCl).isNotNull(); + assertThat(grandchildCl).isNotNull(); + assertThat(grandchildCl.getParentId()).isEqualTo(childCl.getClassificationId()); + assertThat(childCl.getParentId()).isEqualTo(parentCl.getClassificationId()); } @Test @@ -321,7 +316,7 @@ class ClassificationDefinitionControllerIntTest { clList.add(child); ResponseEntity response = importRequest(clList); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); ClassificationSummaryResource rightParentCl = getClassificationWithKeyAndDomain("ImportKey11", "DOMAIN_A"); @@ -330,11 +325,11 @@ class ClassificationDefinitionControllerIntTest { ClassificationSummaryResource childCl = getClassificationWithKeyAndDomain("ImportKey13", "DOMAIN_A"); - assertNotNull(rightParentCl); - assertNotNull(wrongParentCl); - assertNotNull(childCl); - assertEquals(rightParentCl.getClassificationId(), childCl.getParentId()); - assertNotEquals(wrongParentCl.getClassificationId(), childCl.getParentId()); + assertThat(rightParentCl).isNotNull(); + assertThat(wrongParentCl).isNotNull(); + assertThat(childCl).isNotNull(); + assertThat(childCl.getParentId()).isEqualTo(rightParentCl.getClassificationId()); + assertThat(childCl.getParentId()).isNotEqualTo(wrongParentCl.getClassificationId()); } @Test @@ -342,14 +337,14 @@ class ClassificationDefinitionControllerIntTest { throws IOException, InterruptedException { ClassificationSummaryResource child1 = this.getClassificationWithKeyAndDomain("L110105", "DOMAIN_A"); - assertEquals("L11010", child1.getParentKey()); + assertThat(child1.getParentKey()).isEqualTo("L11010"); child1.setParentId("CLI:100000000000000000000000000000000002"); child1.setParentKey("L10303"); final String withNewParent = objMapper.writeValueAsString(child1); ClassificationSummaryResource child2 = this.getClassificationWithKeyAndDomain("L110107", "DOMAIN_A"); - assertEquals("L11010", child2.getParentKey()); + assertThat(child2.getParentKey()).isEqualTo("L11010"); child2.setParentId(""); child2.setParentKey(""); String withoutParent = objMapper.writeValueAsString(child2); @@ -359,18 +354,18 @@ class ClassificationDefinitionControllerIntTest { clList.add(withoutParent); ResponseEntity response = importRequest(clList); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); Thread.sleep(10); LOGGER.debug("Wait 10 ms to give the system a chance to update"); ClassificationSummaryResource childWithNewParent = this.getClassificationWithKeyAndDomain("L110105", "DOMAIN_A"); - assertEquals(child1.parentKey, childWithNewParent.parentKey); + assertThat(childWithNewParent.getParentKey()).isEqualTo(child1.getParentKey()); ClassificationSummaryResource childWithoutParent = this.getClassificationWithKeyAndDomain("L110107", "DOMAIN_A"); - assertEquals(child2.parentId, childWithoutParent.parentId); - assertEquals(child2.parentKey, childWithoutParent.parentKey); + assertThat(childWithoutParent.getParentId()).isEqualTo(child2.getParentId()); + assertThat(childWithoutParent.getParentKey()).isEqualTo(child2.getParentKey()); } @Test @@ -387,7 +382,7 @@ class ClassificationDefinitionControllerIntTest { importRequest(clList); fail("Expected http-Status 409"); } catch (HttpClientErrorException e) { - assertEquals(HttpStatus.CONFLICT, e.getStatusCode()); + assertThat(e.getStatusCode()).isEqualTo(HttpStatus.CONFLICT); } } @@ -405,7 +400,7 @@ class ClassificationDefinitionControllerIntTest { private ClassificationSummaryResource getClassificationWithKeyAndDomain( String key, String domain) { LOGGER.debug("Request classification with key={} in domain={}", key, domain); - HttpEntity request = new HttpEntity(restHelper.getHeaders()); + HttpEntity request = new HttpEntity<>(restHelper.getHeaders()); ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_CLASSIFICATIONS) + "?key=" + key + "&domain=" + domain, 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 c9b4eb735..e40d4756a 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 @@ -165,18 +165,18 @@ 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))) + () -> + 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))) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); } @@ -255,17 +255,17 @@ class TaskControllerIntTest { 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))) + 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))) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); } @@ -274,7 +274,7 @@ class TaskControllerIntTest { void testGetAllTasksByWorkbasketKeyAndDomain() { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic dXNlcl8xXzI6dXNlcl8xXzI="); // user_1_2 - HttpEntity request = new HttpEntity(headers); + HttpEntity request = new HttpEntity<>(headers); ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-key=USER_1_2&domain=DOMAIN_A", @@ -290,17 +290,17 @@ class TaskControllerIntTest { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic dXNlcl8xXzI6dXNlcl8xXzI="); // user_1_2 - HttpEntity request = new HttpEntity(headers); + HttpEntity request = new HttpEntity<>(headers); assertThatThrownBy( - () -> { - ResponseEntity response = - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-key=USER_1_2", - HttpMethod.GET, - request, - ParameterizedTypeReference.forType(TaskSummaryListResource.class)); - }) + () -> { + ResponseEntity response = + template.exchange( + restHelper.toUrl(Mapping.URL_TASKS) + "?workbasket-key=USER_1_2", + HttpMethod.GET, + request, + ParameterizedTypeReference.forType(TaskSummaryListResource.class)); + }) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("400"); } @@ -355,7 +355,7 @@ class TaskControllerIntTest { @Test void testGetLastPageSortedByPorValue() { - HttpEntity request = new HttpEntity(restHelper.getHeadersAdmin()); + HttpEntity request = new HttpEntity<>(restHelper.getHeadersAdmin()); ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) @@ -393,7 +393,7 @@ class TaskControllerIntTest { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"); - HttpEntity request = new HttpEntity(headers); + HttpEntity request = new HttpEntity<>(headers); ResponseEntity response = template.exchange( @@ -436,7 +436,7 @@ class TaskControllerIntTest { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic dGVhbWxlYWRfMTp0ZWFtbGVhZF8x"); - HttpEntity request = new HttpEntity(headers); + HttpEntity request = new HttpEntity<>(headers); ResponseEntity response = template.exchange( restHelper.toUrl(Mapping.URL_TASKS) @@ -586,12 +586,12 @@ class TaskControllerIntTest { taskResource.setDue(now.toString()); assertThatThrownBy( - () -> - template.exchange( - restHelper.toUrl(Mapping.URL_TASKS), - HttpMethod.POST, - new HttpEntity<>(taskResource, restHelper.getHeaders()), - ParameterizedTypeReference.forType(TaskResource.class))) + () -> + template.exchange( + restHelper.toUrl(Mapping.URL_TASKS), + HttpMethod.POST, + new HttpEntity<>(taskResource, restHelper.getHeaders()), + ParameterizedTypeReference.forType(TaskResource.class))) .isInstanceOf(HttpClientErrorException.class); } @@ -640,7 +640,7 @@ class TaskControllerIntTest { } @Test - void testUpdateTaskOwnerOfReadyTaskSucceeds() throws IOException { + void testUpdateTaskOwnerOfReadyTaskSucceeds() { // setup final String taskUrlString = restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000025"); @@ -648,10 +648,10 @@ class TaskControllerIntTest { // retrieve task from Rest Api ResponseEntity responseGet = template.exchange( - taskUrlString, - HttpMethod.GET, - new HttpEntity<>(getHeadersForUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + taskUrlString, + HttpMethod.GET, + new HttpEntity<>(getHeadersForUser_1_2()), + ParameterizedTypeReference.forType(TaskResource.class)); assertThat(responseGet.getBody()).isNotNull(); TaskResource theTaskResource = responseGet.getBody(); @@ -664,10 +664,10 @@ class TaskControllerIntTest { theTaskResource.setOwner(anyUserName); ResponseEntity responseUpdate = template.exchange( - taskUrlString, - HttpMethod.PUT, - new HttpEntity<>(theTaskResource, getHeadersForUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + taskUrlString, + HttpMethod.PUT, + new HttpEntity<>(theTaskResource, getHeadersForUser_1_2()), + ParameterizedTypeReference.forType(TaskResource.class)); assertThat(responseUpdate.getBody()).isNotNull(); TaskResource theUpdatedTaskResource = responseUpdate.getBody(); @@ -676,7 +676,7 @@ class TaskControllerIntTest { } @Test - void testUpdateTaskOwnerOfClaimedTaskFails() throws IOException { + void testUpdateTaskOwnerOfClaimedTaskFails() { // setup final String taskUrlString = restHelper.toUrl("/api/v1/tasks/TKI:000000000000000000000000000000000026"); @@ -684,10 +684,10 @@ class TaskControllerIntTest { // retrieve task from Rest Api ResponseEntity responseGet = template.exchange( - taskUrlString, - HttpMethod.GET, - new HttpEntity<>(getHeadersForUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class)); + taskUrlString, + HttpMethod.GET, + new HttpEntity<>(getHeadersForUser_1_2()), + ParameterizedTypeReference.forType(TaskResource.class)); assertThat(responseGet.getBody()).isNotNull(); TaskResource theTaskResource = responseGet.getBody(); @@ -700,12 +700,12 @@ class TaskControllerIntTest { theTaskResource.setOwner(anyUserName); assertThatThrownBy( - () -> - template.exchange( - taskUrlString, - HttpMethod.PUT, - new HttpEntity<>(theTaskResource, getHeadersForUser_1_2()), - ParameterizedTypeReference.forType(TaskResource.class))) + () -> + template.exchange( + taskUrlString, + HttpMethod.PUT, + new HttpEntity<>(theTaskResource, getHeadersForUser_1_2()), + ParameterizedTypeReference.forType(TaskResource.class))) .isInstanceOf(HttpClientErrorException.class) .hasMessageContaining("409"); } @@ -719,7 +719,7 @@ class TaskControllerIntTest { private TaskResource getTaskResourceSample() { ClassificationSummaryResource classificationResource = new ClassificationSummaryResource(); - classificationResource.key = "L11010"; + classificationResource.setKey("L11010"); WorkbasketSummaryResource workbasketSummaryResource = new WorkbasketSummaryResource(); workbasketSummaryResource.setWorkbasketId("WBI:100000000000000000000000000000000004"); diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationSummaryAssemblerTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationSummaryAssemblerTest.java index 18c80cb4a..2833b288a 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationSummaryAssemblerTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/ClassificationSummaryAssemblerTest.java @@ -1,7 +1,8 @@ package pro.taskana.rest.resource; +import static org.assertj.core.api.Assertions.assertThat; + import java.time.Instant; -import org.junit.Assert; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -78,22 +79,22 @@ class ClassificationSummaryAssemblerTest { private void testEquality( ClassificationSummary classificationSummary, ClassificationSummaryResource resource) { - Assert.assertEquals(classificationSummary.getKey(), resource.key); - Assert.assertEquals(classificationSummary.getDomain(), resource.domain); - Assert.assertEquals(classificationSummary.getId(), resource.classificationId); - Assert.assertEquals(classificationSummary.getName(), resource.name); - Assert.assertEquals(classificationSummary.getCategory(), resource.category); - Assert.assertEquals(classificationSummary.getCustom1(), resource.custom1); - Assert.assertEquals(classificationSummary.getCustom2(), resource.custom2); - Assert.assertEquals(classificationSummary.getCustom3(), resource.custom3); - Assert.assertEquals(classificationSummary.getCustom4(), resource.custom4); - Assert.assertEquals(classificationSummary.getCustom5(), resource.custom5); - Assert.assertEquals(classificationSummary.getCustom6(), resource.custom6); - Assert.assertEquals(classificationSummary.getCustom7(), resource.custom7); - Assert.assertEquals(classificationSummary.getCustom8(), resource.custom8); - Assert.assertEquals(classificationSummary.getParentId(), resource.parentId); - Assert.assertEquals(classificationSummary.getParentKey(), resource.parentKey); - Assert.assertEquals(classificationSummary.getType(), resource.type); - Assert.assertEquals(classificationSummary.getPriority(), resource.priority); + assertThat(resource.getKey()).isEqualTo(classificationSummary.getKey()); + assertThat(resource.getDomain()).isEqualTo(classificationSummary.getDomain()); + assertThat(resource.getClassificationId()).isEqualTo(classificationSummary.getId()); + assertThat(resource.getName()).isEqualTo(classificationSummary.getName()); + assertThat(resource.getCategory()).isEqualTo(classificationSummary.getCategory()); + assertThat(resource.getCustom1()).isEqualTo(classificationSummary.getCustom1()); + assertThat(resource.getCustom2()).isEqualTo(classificationSummary.getCustom2()); + assertThat(resource.getCustom3()).isEqualTo(classificationSummary.getCustom3()); + assertThat(resource.getCustom4()).isEqualTo(classificationSummary.getCustom4()); + assertThat(resource.getCustom5()).isEqualTo(classificationSummary.getCustom5()); + assertThat(resource.getCustom6()).isEqualTo(classificationSummary.getCustom6()); + assertThat(resource.getCustom7()).isEqualTo(classificationSummary.getCustom7()); + assertThat(resource.getCustom8()).isEqualTo(classificationSummary.getCustom8()); + assertThat(resource.getParentId()).isEqualTo(classificationSummary.getParentId()); + assertThat(resource.getParentKey()).isEqualTo(classificationSummary.getParentKey()); + assertThat(resource.getType()).isEqualTo(classificationSummary.getType()); + assertThat(resource.getPriority()).isEqualTo(classificationSummary.getPriority()); } } diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskResourceAssemberTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskResourceAssemberTest.java index ec97574f1..8a795f930 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskResourceAssemberTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/rest/resource/TaskResourceAssemberTest.java @@ -1,10 +1,11 @@ package pro.taskana.rest.resource; +import static org.assertj.core.api.Assertions.assertThat; + import java.time.Instant; import java.util.Collections; import java.util.List; import java.util.Map; -import org.junit.Assert; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -40,9 +41,9 @@ class TaskResourceAssemberTest { WorkbasketSummaryResource workbasketResource = new WorkbasketSummaryResource(); workbasketResource.setWorkbasketId("workbasketId"); ClassificationSummaryResource classificationResource = new ClassificationSummaryResource(); - classificationResource.key = "keyabc"; - classificationResource.domain = "DOMAIN_A"; - classificationResource.type = "MANUAL"; + classificationResource.setKey("keyabc"); + classificationResource.setDomain("DOMAIN_A"); + classificationResource.setType("MANUAL"); AttachmentResource attachement = new AttachmentResource(); attachement.setClassificationSummary(classificationResource); attachement.setAttachmentId("attachementId"); @@ -155,82 +156,79 @@ class TaskResourceAssemberTest { } void testEquality(Task task, TaskResource resource) throws InvalidArgumentException { - Assert.assertEquals(task.getId(), resource.getTaskId()); - Assert.assertEquals(task.getExternalId(), resource.getExternalId()); - Assert.assertEquals( - task.getCreated() == null ? null : task.getCreated().toString(), resource.getCreated()); - Assert.assertEquals( - task.getClaimed() == null ? null : task.getClaimed().toString(), resource.getClaimed()); - Assert.assertEquals( - task.getCompleted() == null ? null : task.getCompleted().toString(), - resource.getCompleted()); - Assert.assertEquals( - task.getModified() == null ? null : task.getModified().toString(), resource.getModified()); - Assert.assertEquals( - task.getPlanned() == null ? null : task.getPlanned().toString(), resource.getPlanned()); - Assert.assertEquals(task.getDue() == null ? null : task.getDue().toString(), resource.getDue()); - Assert.assertEquals(task.getName(), resource.getName()); - Assert.assertEquals(task.getCreator(), resource.getCreator()); - Assert.assertEquals(task.getDescription(), resource.getDescription()); - Assert.assertEquals(task.getNote(), resource.getNote()); - Assert.assertEquals(task.getPriority(), resource.getPriority()); - Assert.assertEquals(task.getState(), resource.getState()); - Assert.assertEquals( - task.getClassificationSummary().getId(), - resource.getClassificationSummaryResource().getClassificationId()); - Assert.assertEquals( - task.getWorkbasketSummary().getId(), - resource.getWorkbasketSummaryResource().getWorkbasketId()); - Assert.assertEquals(task.getBusinessProcessId(), resource.getBusinessProcessId()); - Assert.assertEquals(task.getParentBusinessProcessId(), resource.getParentBusinessProcessId()); - Assert.assertEquals(task.getOwner(), resource.getOwner()); - Assert.assertEquals(task.getPrimaryObjRef(), resource.getPrimaryObjRef()); - Assert.assertEquals(task.isRead(), resource.isRead()); - Assert.assertEquals(task.isTransferred(), resource.isTransferred()); + assertThat(resource.getTaskId()).isEqualTo(task.getId()); + assertThat(resource.getExternalId()).isEqualTo(task.getExternalId()); + assertThat(resource.getCreated()) + .isEqualTo(task.getCreated() == null ? null : task.getCreated().toString()); + assertThat(resource.getClaimed()) + .isEqualTo(task.getClaimed() == null ? null : task.getClaimed().toString()); + assertThat(resource.getCompleted()) + .isEqualTo(task.getCompleted() == null ? null : task.getCompleted().toString()); + assertThat(resource.getModified()) + .isEqualTo(task.getModified() == null ? null : task.getModified().toString()); + assertThat(resource.getPlanned()) + .isEqualTo(task.getPlanned() == null ? null : task.getPlanned().toString()); + assertThat(resource.getDue()) + .isEqualTo(task.getDue() == null ? null : task.getDue().toString()); + assertThat(resource.getName()).isEqualTo(task.getName()); + assertThat(resource.getCreator()).isEqualTo(task.getCreator()); + assertThat(resource.getDescription()).isEqualTo(task.getDescription()); + assertThat(resource.getNote()).isEqualTo(task.getNote()); + assertThat(resource.getPriority()).isEqualTo(task.getPriority()); + assertThat(resource.getState()).isEqualTo(task.getState()); + assertThat(resource.getClassificationSummaryResource().getClassificationId()) + .isEqualTo(task.getClassificationSummary().getId()); + assertThat(resource.getWorkbasketSummaryResource().getWorkbasketId()) + .isEqualTo(task.getWorkbasketSummary().getId()); + assertThat(resource.getBusinessProcessId()).isEqualTo(task.getBusinessProcessId()); + assertThat(resource.getParentBusinessProcessId()).isEqualTo(task.getParentBusinessProcessId()); + assertThat(resource.getOwner()).isEqualTo(task.getOwner()); + assertThat(resource.getPrimaryObjRef()).isEqualTo(task.getPrimaryObjRef()); + assertThat(resource.isRead()).isEqualTo(task.isRead()); + assertThat(resource.isTransferred()).isEqualTo(task.isTransferred()); testEquality(task.getCustomAttributes(), resource.getCustomAttributes()); testEquality(task.getCallbackInfo(), resource.getCallbackInfo()); testEqualityAttachements(task.getAttachments(), resource.getAttachments()); - Assert.assertEquals(task.getCustomAttribute("1"), resource.getCustom1()); - Assert.assertEquals(task.getCustomAttribute("2"), resource.getCustom2()); - Assert.assertEquals(task.getCustomAttribute("3"), resource.getCustom3()); - Assert.assertEquals(task.getCustomAttribute("4"), resource.getCustom4()); - Assert.assertEquals(task.getCustomAttribute("5"), resource.getCustom5()); - Assert.assertEquals(task.getCustomAttribute("6"), resource.getCustom6()); - Assert.assertEquals(task.getCustomAttribute("7"), resource.getCustom7()); - Assert.assertEquals(task.getCustomAttribute("8"), resource.getCustom8()); - Assert.assertEquals(task.getCustomAttribute("9"), resource.getCustom9()); - Assert.assertEquals(task.getCustomAttribute("10"), resource.getCustom10()); - Assert.assertEquals(task.getCustomAttribute("11"), resource.getCustom11()); - Assert.assertEquals(task.getCustomAttribute("12"), resource.getCustom12()); - Assert.assertEquals(task.getCustomAttribute("13"), resource.getCustom13()); - Assert.assertEquals(task.getCustomAttribute("14"), resource.getCustom14()); - Assert.assertEquals(task.getCustomAttribute("15"), resource.getCustom15()); - Assert.assertEquals(task.getCustomAttribute("16"), resource.getCustom16()); + assertThat(resource.getCustom1()).isEqualTo(task.getCustomAttribute("1")); + assertThat(resource.getCustom2()).isEqualTo(task.getCustomAttribute("2")); + assertThat(resource.getCustom3()).isEqualTo(task.getCustomAttribute("3")); + assertThat(resource.getCustom4()).isEqualTo(task.getCustomAttribute("4")); + assertThat(resource.getCustom5()).isEqualTo(task.getCustomAttribute("5")); + assertThat(resource.getCustom6()).isEqualTo(task.getCustomAttribute("6")); + assertThat(resource.getCustom7()).isEqualTo(task.getCustomAttribute("7")); + assertThat(resource.getCustom8()).isEqualTo(task.getCustomAttribute("8")); + assertThat(resource.getCustom9()).isEqualTo(task.getCustomAttribute("9")); + assertThat(resource.getCustom10()).isEqualTo(task.getCustomAttribute("10")); + assertThat(resource.getCustom11()).isEqualTo(task.getCustomAttribute("11")); + assertThat(resource.getCustom12()).isEqualTo(task.getCustomAttribute("12")); + assertThat(resource.getCustom13()).isEqualTo(task.getCustomAttribute("13")); + assertThat(resource.getCustom14()).isEqualTo(task.getCustomAttribute("14")); + assertThat(resource.getCustom15()).isEqualTo(task.getCustomAttribute("15")); + assertThat(resource.getCustom16()).isEqualTo(task.getCustomAttribute("16")); } private void testEquality( Map customAttributes, List resourceAttributes) { - Assert.assertEquals(customAttributes.size(), resourceAttributes.size()); + assertThat(resourceAttributes).hasSize(customAttributes.size()); resourceAttributes.forEach( attribute -> - Assert.assertEquals(customAttributes.get(attribute.getKey()), attribute.getValue())); + assertThat(attribute.getValue()).isEqualTo(customAttributes.get(attribute.getKey()))); } private void testEqualityAttachements( List attachments, List resources) { - Assert.assertEquals(attachments.size(), resources.size()); + assertThat(resources).hasSize(attachments.size()); for (int i = 0; i < resources.size(); i++) { AttachmentResource resource = resources.get(i); Attachment attachment = attachments.get(i); - // Anything else shoulde be tested in AttachementResourceAssemblerTest - Assert.assertEquals(attachment.getId(), resource.getAttachmentId()); + // Anything else should be be tested in AttachementResourceAssemblerTest + assertThat(resource.getAttachmentId()).isEqualTo(attachment.getId()); } } private void testLinks(TaskResource resource) { - Assert.assertEquals(1, resource.getLinks().size()); - Assert.assertEquals( - Mapping.URL_TASKS_ID.replaceAll("\\{.*}", resource.getTaskId()), - resource.getLink("self").getHref()); + assertThat(resource.getLinks()).hasSize(1); + assertThat(resource.getLink("self").getHref()) + .isEqualTo(Mapping.URL_TASKS_ID.replaceAll("\\{.*}", resource.getTaskId())); } }