diff --git a/api-rest/src/test/java/com/homihq/db2rest/rest/mysql/MySQLDateTimeAllTest.java b/api-rest/src/test/java/com/homihq/db2rest/rest/mysql/MySQLDateTimeAllTest.java index 456edb27..640690a5 100644 --- a/api-rest/src/test/java/com/homihq/db2rest/rest/mysql/MySQLDateTimeAllTest.java +++ b/api-rest/src/test/java/com/homihq/db2rest/rest/mysql/MySQLDateTimeAllTest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.homihq.db2rest.MySQLBaseIntegrationTest; 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; @@ -140,4 +144,28 @@ void deleteActorByTimeStamp() throws Exception { .andExpect(jsonPath("$.rows", equalTo(1))) .andDo(document("mysql-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 + "/mysqldb/actor") + .contentType(APPLICATION_JSON) + .accept(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(actorRequestWithDateTime))) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.row", equalTo(1))) + .andDo(document("mysql-create-an-actor-with-datetime")) + .andReturn(); + + var pk = JsonPath.read(result.getResponse().getContentAsString(), "$.keys.GENERATED_KEY"); + assertTrue(deleteRow("actor", "actor_id", (int) pk)); + } } diff --git a/api-rest/src/test/java/com/homihq/db2rest/rest/pg/PGDateTimeAllTest.java b/api-rest/src/test/java/com/homihq/db2rest/rest/pg/PGDateTimeAllTest.java index 568a1352..10af6866 100644 --- a/api-rest/src/test/java/com/homihq/db2rest/rest/pg/PGDateTimeAllTest.java +++ b/api-rest/src/test/java/com/homihq/db2rest/rest/pg/PGDateTimeAllTest.java @@ -150,8 +150,8 @@ void deleteActorByTimeStamp() throws Exception { void createActorWithIsoDateTimeFormats(String isoDateTime) throws Exception { // Prepare the request with datetime fields Map actorRequestWithDateTime = new HashMap<>(); - actorRequestWithDateTime.put("first_name", "Collective"); - actorRequestWithDateTime.put("last_name", "Unconscious"); + actorRequestWithDateTime.put("first_name", "Graeme"); + actorRequestWithDateTime.put("last_name", "Smith"); actorRequestWithDateTime.put("last_update", isoDateTime); var result = mockMvc.perform(post(VERSION + "/pgsqldb/actor") diff --git a/mysql-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MySQLDialect.java b/mysql-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MySQLDialect.java index 30c83ac3..74aead3d 100644 --- a/mysql-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MySQLDialect.java +++ b/mysql-dialect/src/main/java/com/homihq/db2rest/jdbc/config/dialect/MySQLDialect.java @@ -8,6 +8,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