diff --git a/src/main/java/org/tkit/onecx/workspace/domain/daos/MenuItemDAO.java b/src/main/java/org/tkit/onecx/workspace/domain/daos/MenuItemDAO.java index e1d7275..71ef85f 100644 --- a/src/main/java/org/tkit/onecx/workspace/domain/daos/MenuItemDAO.java +++ b/src/main/java/org/tkit/onecx/workspace/domain/daos/MenuItemDAO.java @@ -18,6 +18,7 @@ import org.tkit.quarkus.jpa.daos.Page; import org.tkit.quarkus.jpa.daos.PageResult; import org.tkit.quarkus.jpa.exceptions.DAOException; +import org.tkit.quarkus.jpa.models.AbstractTraceableEntity_; import org.tkit.quarkus.jpa.models.TraceableEntity_; @ApplicationScoped @@ -31,7 +32,7 @@ public void deleteAllMenuItemsByWorkspaceAndAppId(String workspaceId, String app var root = cq.from(MenuItem.class); cq.where(cb.and( - cb.equal(root.get(MenuItem_.WORKSPACE).get(Workspace_.ID), workspaceId), + cb.equal(root.get(MenuItem_.WORKSPACE).get(TraceableEntity_.ID), workspaceId), cb.equal(root.get(MenuItem_.APPLICATION_ID), appId))); var items = getEntityManager().createQuery(cq).getResultList(); @@ -127,7 +128,7 @@ public MenuItem loadAllChildren(String id) { var cq = cb.createQuery(MenuItem.class); var root = cq.from(MenuItem.class); - cq.where(cb.equal(root.get(MenuItem_.ID), id)); + cq.where(cb.equal(root.get(TraceableEntity_.ID), id)); return getEntityManager() .createQuery(cq) @@ -209,7 +210,7 @@ private void updatePosition(String menuId, String parentId, int position, int su List predicates = new ArrayList<>(); predicates.add(cb.greaterThanOrEqualTo(root.get(MenuItem_.POSITION), position)); - predicates.add(cb.notEqual(root.get(MenuItem_.ID), menuId)); + predicates.add(cb.notEqual(root.get(TraceableEntity_.ID), menuId)); if (parentId == null) { predicates.add(cb.isNull(root.get(MenuItem_.PARENT_ID))); } else { @@ -217,7 +218,8 @@ private void updatePosition(String menuId, String parentId, int position, int su } uq.set(MenuItem_.POSITION, cb.sum(root.get(MenuItem_.POSITION), sum)) - .set(MenuItem_.MODIFICATION_COUNT, cb.sum(root.get(MenuItem_.MODIFICATION_COUNT), 1)) + .set(AbstractTraceableEntity_.MODIFICATION_COUNT, + cb.sum(root.get(AbstractTraceableEntity_.MODIFICATION_COUNT), 1)) .where(cb.and(predicates.toArray(new Predicate[0]))); this.getEntityManager().createQuery(uq).executeUpdate(); diff --git a/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/mappers/ExportImportMapperV1.java b/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/mappers/ExportImportMapperV1.java index a1b51fa..1a71b26 100644 --- a/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/mappers/ExportImportMapperV1.java +++ b/src/main/java/org/tkit/onecx/workspace/rs/exim/v1/mappers/ExportImportMapperV1.java @@ -102,7 +102,7 @@ default EximMenuStructureDTOV1 map(List menuItems) { default List children(Set set, Map> roles) { if (set == null) { - return null; + return List.of(); } List list = new ArrayList<>(set.size()); for (MenuItem item : set) { diff --git a/src/main/java/org/tkit/onecx/workspace/rs/legacy/mappers/TkitPortalMapper.java b/src/main/java/org/tkit/onecx/workspace/rs/legacy/mappers/TkitPortalMapper.java index 2908a02..9d1f8b7 100644 --- a/src/main/java/org/tkit/onecx/workspace/rs/legacy/mappers/TkitPortalMapper.java +++ b/src/main/java/org/tkit/onecx/workspace/rs/legacy/mappers/TkitPortalMapper.java @@ -67,7 +67,7 @@ default void updateMenu(MenuItem menuItem, int position, Workspace workspace, MenuItem.Scope map(ScopeDTO scope); default List mapToEmptyTree() { - return new ArrayList(); + return new ArrayList<>(); } default List mapToTree(List menuItems, String portalId) { diff --git a/src/test/java/org/tkit/onecx/workspace/AfterStartDataImportTest.java b/src/test/java/org/tkit/onecx/workspace/AfterStartDataImportTest.java index a487f73..ee2bff0 100644 --- a/src/test/java/org/tkit/onecx/workspace/AfterStartDataImportTest.java +++ b/src/test/java/org/tkit/onecx/workspace/AfterStartDataImportTest.java @@ -33,7 +33,7 @@ void importDataFromFileTest() { assertThat(w.getRoles()).isNotNull().isNotEmpty().hasSize(4); var map = w.getRoles().stream().collect(Collectors.toMap(Role::getName, x -> x)); - assertThat(map.keySet()).containsOnly("role1", "role2", "roleA", "roleB"); + assertThat(map).containsOnlyKeys("role1", "role2", "roleA", "roleB"); } } diff --git a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/AssignmentRestControllerTest.java b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/AssignmentRestControllerTest.java index c909959..3909800 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/AssignmentRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/AssignmentRestControllerTest.java @@ -19,7 +19,7 @@ @QuarkusTest @TestHTTPEndpoint(AssignmentInternalRestController.class) @WithDBData(value = "data/testdata-internal.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true) -public class AssignmentRestControllerTest extends AbstractTest { +class AssignmentRestControllerTest extends AbstractTest { @Test void createAssignment() { @@ -179,8 +179,8 @@ void searchAssignmentTest() { .as(AssignmentPageResultDTO.class); assertThat(data).isNotNull(); - assertThat(data.getTotalElements()).isEqualTo(0); - assertThat(data.getStream()).isNotNull().hasSize(0); + assertThat(data.getTotalElements()).isZero(); + assertThat(data.getStream()).isNotNull().isEmpty(); var criteria2 = new AssignmentSearchCriteriaDTO(); @@ -215,8 +215,8 @@ void searchAssignmentTest() { .as(AssignmentPageResultDTO.class); assertThat(multipleAppIdsResult).isNotNull(); - assertThat(multipleAppIdsResult.getTotalElements()).isEqualTo(0); - assertThat(multipleAppIdsResult.getStream()).isNotNull().hasSize(0); + assertThat(multipleAppIdsResult.getTotalElements()).isZero(); + assertThat(multipleAppIdsResult.getStream()).isNotNull().isEmpty(); } diff --git a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/AssignmentRestControllerTestIT.java b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/AssignmentRestControllerTestIT.java index 1c662d7..ba88785 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/AssignmentRestControllerTestIT.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/AssignmentRestControllerTestIT.java @@ -3,5 +3,5 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; @QuarkusIntegrationTest -public class AssignmentRestControllerTestIT extends AssignmentRestControllerTest { +class AssignmentRestControllerTestIT extends AssignmentRestControllerTest { } diff --git a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/MenuInternalRestControllerParentChangeTest.java b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/MenuInternalRestControllerParentChangeTest.java index 7946ea2..b5f3362 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/MenuInternalRestControllerParentChangeTest.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/MenuInternalRestControllerParentChangeTest.java @@ -4,10 +4,15 @@ import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; import static jakarta.ws.rs.core.Response.Status.*; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; import java.util.List; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.tkit.onecx.workspace.test.AbstractTest; import org.tkit.quarkus.test.WithDBData; @@ -20,77 +25,23 @@ @WithDBData(value = "data/testdata-parent-change.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true) class MenuInternalRestControllerParentChangeTest extends AbstractTest { - @Test - void updateMenuItemLastPositionTest() { - - printWorkspace(); - - // 4-2-3 pos 2 -> change parent to 4-1 pos 1 - var request = new UpdateMenuItemParentRequestDTO() - .parentItemId("4-1") - .position(3) - .modificationCount(0); - - given() - .when() - .contentType(APPLICATION_JSON) - .body(request) - .pathParam("menuItemId", "4-2-2") - .put("{menuItemId}/parentItemId") - .then().statusCode(OK.getStatusCode()); - - var dto = printWorkspace(); - - // 4-1 -> 4-1-2 pos 2 - var parent = dto.getMenuItems().stream().filter(x -> x.getId().equals("4-1")).findFirst(); - assertThat(parent).isPresent(); - assertThat(parent.get().getPosition()).isEqualTo(0); - - var item = parent.get().getChildren().stream().filter(x -> x.getId().equals("4-2-2")).findFirst(); - assertThat(item).isPresent(); - assertThat(item.get().getPosition()).isEqualTo(3); - } - - @Test - void updateMenuItemMaxPositionTest() { - - printWorkspace(); - - // 4-2-3 pos 2 -> change parent to 4-1 pos 1 - var request = new UpdateMenuItemParentRequestDTO() - .parentItemId("4-1") - .position(30) - .modificationCount(0); - - given() - .when() - .contentType(APPLICATION_JSON) - .body(request) - .pathParam("menuItemId", "4-2-2") - .put("{menuItemId}/parentItemId") - .then().statusCode(OK.getStatusCode()); - - var dto = printWorkspace(); - - // 4-1 -> 4-1-2 pos 2 - var parent = dto.getMenuItems().stream().filter(x -> x.getId().equals("4-1")).findFirst(); - assertThat(parent).isPresent(); - assertThat(parent.get().getPosition()).isEqualTo(0); - - var item = parent.get().getChildren().stream().filter(x -> x.getId().equals("4-2-2")).findFirst(); - assertThat(item).isPresent(); - assertThat(item.get().getPosition()).isEqualTo(3); + private static Stream menuPosition() { + return Stream.of( + arguments(3, 3), + arguments(30, 3), + arguments(1, 1)); } - @Test - void updateMenuItemParentTest() { + @ParameterizedTest + @MethodSource("menuPosition") + void updateMenuItemLastPositionTest(int position, int result) { printWorkspace(); // 4-2-3 pos 2 -> change parent to 4-1 pos 1 var request = new UpdateMenuItemParentRequestDTO() .parentItemId("4-1") - .position(1) + .position(position) .modificationCount(0); given() @@ -106,11 +57,11 @@ void updateMenuItemParentTest() { // 4-1 -> 4-1-2 pos 2 var parent = dto.getMenuItems().stream().filter(x -> x.getId().equals("4-1")).findFirst(); assertThat(parent).isPresent(); - assertThat(parent.get().getPosition()).isEqualTo(0); + assertThat(parent.get().getPosition()).isZero(); var item = parent.get().getChildren().stream().filter(x -> x.getId().equals("4-2-2")).findFirst(); assertThat(item).isPresent(); - assertThat(item.get().getPosition()).isEqualTo(1); + assertThat(item.get().getPosition()).isEqualTo(result); } @Test @@ -173,7 +124,7 @@ void updateMenuItemParentToNullTest() { // null -> 4-1-2 pos 2 var item = dto.getMenuItems().stream().filter(x -> x.getId().equals("4-2-2")).findFirst(); assertThat(item).isPresent(); - assertThat(item.get().getPosition()).isEqualTo(0); + assertThat(item.get().getPosition()).isZero(); } @Test diff --git a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/RoleRestControllerTest.java b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/RoleRestControllerTest.java index 566b18f..8cc838f 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/RoleRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/RoleRestControllerTest.java @@ -19,7 +19,7 @@ @QuarkusTest @TestHTTPEndpoint(RoleInternalRestController.class) @WithDBData(value = "data/testdata-internal.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true) -public class RoleRestControllerTest extends AbstractTest { +class RoleRestControllerTest extends AbstractTest { @Test void createNewRoleTest() { diff --git a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/RoleRestControllerTestIT.java b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/RoleRestControllerTestIT.java index 90cb37b..2bc1a87 100644 --- a/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/RoleRestControllerTestIT.java +++ b/src/test/java/org/tkit/onecx/workspace/rs/internal/controllers/RoleRestControllerTestIT.java @@ -3,5 +3,5 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; @QuarkusIntegrationTest -public class RoleRestControllerTestIT extends RoleRestControllerTest { +class RoleRestControllerTestIT extends RoleRestControllerTest { }