From c0bd60f440ddab77215d918a8ae523b73d0f6558 Mon Sep 17 00:00:00 2001 From: Sourav Roy Date: Sun, 1 Dec 2024 18:02:39 +0000 Subject: [PATCH] Adding integration test for different ISO date time formats for Maria db --- .../mariadb/MariaDBCreateControllerTest.java | 14 +++++----- .../rest/mariadb/MariadbDateTimeAllTest.java | 28 +++++++++++++++++++ .../rest/mssql/MsSQLDateTimeAllTest.java | 4 +++ .../jdbc/config/dialect/MariaDBDialect.java | 13 +++++++++ 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/api-rest/src/test/java/com/homihq/db2rest/rest/mariadb/MariaDBCreateControllerTest.java b/api-rest/src/test/java/com/homihq/db2rest/rest/mariadb/MariaDBCreateControllerTest.java index 9571583d..de0df325 100644 --- a/api-rest/src/test/java/com/homihq/db2rest/rest/mariadb/MariaDBCreateControllerTest.java +++ b/api-rest/src/test/java/com/homihq/db2rest/rest/mariadb/MariaDBCreateControllerTest.java @@ -60,8 +60,8 @@ void create() throws Exception { //.andDo(print()) .andExpect(status().isCreated()) .andExpect(jsonPath("$.row", equalTo(1))) - //.andExpect(jsonPath("$.keys.GENERATED_KEY").exists()) - //.andExpect(jsonPath("$.keys.GENERATED_KEY", equalTo(5))) + .andExpect(jsonPath("$.keys.insert_id").exists()) + .andExpect(jsonPath("$.keys.insert_id", equalTo(5))) .andDo(document("mariadb-create-a-film")); } @@ -99,8 +99,8 @@ void createDirectorWithTSIDEnabled() throws Exception { //.andDo(print()) .andExpect(status().isCreated()) .andExpect(jsonPath("$.row", equalTo(1))) - //.andExpect(jsonPath("$.keys.director_id").exists()) - // .andExpect(jsonPath("$.keys.director_id").isNumber()) + .andExpect(jsonPath("$.keys.director_id").exists()) + .andExpect(jsonPath("$.keys.director_id").isNumber()) .andDo(document("mariadb-create-a-director-tsid-enabled")); } @@ -128,8 +128,8 @@ void createVanityVanWithVarcharTsIdType() throws Exception { .andDo(print()) .andExpect(status().isCreated()) .andExpect(jsonPath("$.row", equalTo(1))) - //.andExpect(jsonPath("$.keys.vanity_van_id").exists()) - //.andExpect(jsonPath("$.keys.vanity_van_id").isString()) + .andExpect(jsonPath("$.keys.van_id").exists()) + .andExpect(jsonPath("$.keys.van_id").isString()) .andDo(document("mariadb-create-a-vanity-van-tsid-varchar")); } @@ -144,7 +144,7 @@ void createFilmWithSubsetOfColumns() throws Exception { .andExpect(status().isCreated()) .andExpect(jsonPath("$.row", equalTo(1))) .andExpect(jsonPath("$.keys").exists()) - // .andExpect(jsonPath("$.keys.GENERATED_KEY", equalTo(5))) + //.andExpect(jsonPath("$.keys.insert_id", equalTo(5))) .andExpect(jsonPath("$.keys.insert_id").isNumber()) .andDo(document("mariadb-create-a-film")) .andReturn(); diff --git a/api-rest/src/test/java/com/homihq/db2rest/rest/mariadb/MariadbDateTimeAllTest.java b/api-rest/src/test/java/com/homihq/db2rest/rest/mariadb/MariadbDateTimeAllTest.java index 0d39722a..42ccc350 100644 --- a/api-rest/src/test/java/com/homihq/db2rest/rest/mariadb/MariadbDateTimeAllTest.java +++ b/api-rest/src/test/java/com/homihq/db2rest/rest/mariadb/MariadbDateTimeAllTest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.homihq.db2rest.MariaDBBaseIntegrationTest; import com.homihq.db2rest.rest.DateTimeUtil; +import com.jayway.jsonpath.JsonPath; import org.junit.jupiter.api.ClassOrderer; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.MethodOrderer; @@ -12,6 +13,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestClassOrder; import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.HashMap; import java.util.Map; @@ -19,6 +22,7 @@ import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION; import static org.hamcrest.Matchers.equalTo; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; @@ -142,4 +146,28 @@ void deleteActorByTimeStamp() throws Exception { .andExpect(jsonPath("$.rows", equalTo(1))) .andDo(document("mariadb-delete-an-actor-by-timestamp")); } + + @ParameterizedTest + @MethodSource("isoDateTimeFormats") + @Order(5) + @DisplayName("Test ISO Date Time formats") + void createActorWithIsoDateTimeFormats(String isoDateTime) throws Exception { + // Prepare the request with datetime fields + Map actorRequestWithDateTime = new HashMap<>(); + actorRequestWithDateTime.put("first_name", "Graeme"); + actorRequestWithDateTime.put("last_name", "Smith"); + actorRequestWithDateTime.put("last_update", isoDateTime); + + var result = mockMvc.perform(post(VERSION + "/mariadb/actor") + .contentType(APPLICATION_JSON) + .accept(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(actorRequestWithDateTime))) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.row", equalTo(1))) + .andDo(document("mariadb-create-an-actor-with-datetime")) + .andReturn(); + + var pk = JsonPath.read(result.getResponse().getContentAsString(), "$.keys.insert_id"); + assertTrue(deleteRow("actor", "actor_id", (int) pk)); + } } diff --git a/api-rest/src/test/java/com/homihq/db2rest/rest/mssql/MsSQLDateTimeAllTest.java b/api-rest/src/test/java/com/homihq/db2rest/rest/mssql/MsSQLDateTimeAllTest.java index 58f6b6ab..7608a8b3 100644 --- a/api-rest/src/test/java/com/homihq/db2rest/rest/mssql/MsSQLDateTimeAllTest.java +++ b/api-rest/src/test/java/com/homihq/db2rest/rest/mssql/MsSQLDateTimeAllTest.java @@ -3,8 +3,10 @@ import com.jayway.jsonpath.JsonPath; import org.junit.jupiter.api.ClassOrderer; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.TestClassOrder; +import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -22,10 +24,12 @@ @TestClassOrder(ClassOrderer.OrderAnnotation.class) @Order(506) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) class MsSQLDateTimeAllTest extends MsSQLBaseIntegrationTest { @ParameterizedTest @MethodSource("isoDateTimeFormats") + @Order(1) @DisplayName("Test ISO Date Time formats") void createActorWithIsoDateTimeFormats(String isoDateTime) throws Exception { // Prepare the request with datetime fields diff --git a/mariadb-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MariaDBDialect.java b/mariadb-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MariaDBDialect.java index 4ffc27b9..95e389c1 100644 --- a/mariadb-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MariaDBDialect.java +++ b/mariadb-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MariaDBDialect.java @@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; @@ -35,6 +37,9 @@ public void processTypes(DbTable table, List insertableColumns, Map