From 1a1fe9891f0b2f80bfaf24ae04e6c4413e2a531a Mon Sep 17 00:00:00 2001 From: Bastian Jakobi Date: Wed, 6 Mar 2024 15:14:27 +0100 Subject: [PATCH] fix: fix minor issues in v1 api --- .../controllers/SearchConfigControllerV1.java | 4 +-- .../SearchConfigControllerV1TenantTest.java | 8 ++--- .../SearchConfigControllerV1Test.java | 34 ++++++++++++++----- src/test/resources/search-config-data.xml | 16 ++++----- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1.java b/src/main/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1.java index 846c90b..d95ddf0 100644 --- a/src/main/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1.java +++ b/src/main/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1.java @@ -62,7 +62,7 @@ public Response getConfigByConfigId(String configId) { public Response deleteSearchConfig(String configId) { var data = dao.findByConfigId(configId); if (data != null) { - dao.deleteQueryById(configId); + dao.deleteQueryById(data.getId()); } return Response.noContent().build(); } @@ -75,7 +75,7 @@ public Response findSearchConfigsBySearchCriteria(SearchConfigSearchRequestDTOV1 @Override public Response updateSearchConfig(String configId, UpdateSearchConfigRequestDTOV1 updateSearchConfigRequestDTOV1) { - var searchConfig = dao.findById(configId); + var searchConfig = dao.findByConfigId(configId); if (searchConfig == null) { return Response.status(NOT_FOUND).build(); } diff --git a/src/test/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1TenantTest.java b/src/test/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1TenantTest.java index e8bbf74..b27d20e 100644 --- a/src/test/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1TenantTest.java +++ b/src/test/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1TenantTest.java @@ -40,7 +40,7 @@ private List setupColumns() { @Test void shouldGetSearchConfigsById() { - String configId = "1"; + String configId = "c1"; var dto = given() .contentType(APPLICATION_JSON) @@ -115,7 +115,7 @@ void shouldCreateSearchConfig() { @Test void shouldUpdateModificationCount() { - String searchConfigId = "1"; + String searchConfigId = "c1"; String application = "support-tool-ui"; String name = "criteria-name"; @@ -159,8 +159,8 @@ void shouldUpdateModificationCount() { } @Test - void shouldDeleteById() { - String configId = "8"; + void shouldDeleteByConfigId() { + String configId = "c8"; given() .when() diff --git a/src/test/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1Test.java b/src/test/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1Test.java index aa6bc6a..a8d5603 100644 --- a/src/test/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1Test.java +++ b/src/test/java/org/tkit/onecx/search/config/rs/v1/controllers/SearchConfigControllerV1Test.java @@ -42,7 +42,7 @@ private List setupColumns() { @Test void shouldGetSearchConfigsById() { - String configId = "1"; + String configId = "c1"; var dto = given() .contentType(APPLICATION_JSON) @@ -136,7 +136,7 @@ void shouldNotCreateSearchConfigDuplicate() { @Test void shouldUpdateModificationCount() { - String searchConfigId = "1"; + String searchConfigId = "c1"; String application = "support-tool-ui"; String name = "criteria-name"; @@ -172,7 +172,7 @@ void shouldUpdateModificationCount() { @Test void shouldUpdateModificationCountOptLock() { - String searchConfigId = "1"; + String searchConfigId = "c1"; String application = "support-tool-ui"; String name = "criteria-name"; @@ -208,7 +208,7 @@ void shouldUpdateModificationCountOptLock() { @Test void shouldNotUpdateSearchConfigWhenBadRequest() { - String configId = "1"; + String configId = "c1"; given() .contentType(APPLICATION_JSON) @@ -242,20 +242,38 @@ void shouldNotUpdateSearchConfigNotExists() { } @Test - void shouldDeleteById() { - String configId = "1"; + void shouldDeleteByConfigId() { + String configId = "c1"; + + given() + .contentType(APPLICATION_JSON) + .get(configId) + .then() + .statusCode(OK.getStatusCode()); given() .contentType(APPLICATION_JSON) .delete(configId) .then() .statusCode(NO_CONTENT.getStatusCode()); + + given() + .contentType(APPLICATION_JSON) + .get(configId) + .then() + .statusCode(NOT_FOUND.getStatusCode()); } @Test void shouldNotDeleteWhenNotExists() { String configId = "NotExists"; + given() + .contentType(APPLICATION_JSON) + .get(configId) + .then() + .statusCode(NOT_FOUND.getStatusCode()); + given() .contentType(APPLICATION_JSON) .delete(configId) @@ -270,7 +288,7 @@ void shouldFindByCriteria() { var requestBody = new SearchConfigSearchRequestDTOV1() .productName("productName1").appId(application).page("page2"); - String[] expectedIds = { "3", "4" }; + String[] expectedIds = { "c3", "c4" }; var responseDTO = given() .contentType(APPLICATION_JSON) @@ -344,7 +362,7 @@ void shouldFindOneResultByCriteria() { assertThat(responseDTO.getStream()).isNotNull().isNotEmpty().hasSize(2); List configs = responseDTO.getStream(); - assertThat(configs.stream().map(SearchConfigSearchResultDTOV1::getConfigId).toList()).contains("2", "1"); + assertThat(configs.stream().map(SearchConfigSearchResultDTOV1::getConfigId).toList()).contains("c2", "c1"); } @Test diff --git a/src/test/resources/search-config-data.xml b/src/test/resources/search-config-data.xml index 3ddfcba..d78db97 100644 --- a/src/test/resources/search-config-data.xml +++ b/src/test/resources/search-config-data.xml @@ -1,13 +1,13 @@ - - - - - - - - + + + + + + + +