diff --git a/api-rest/src/test/java/com/homihq/db2rest/rest/oracle/OracleDateTimeAllTest.java b/api-rest/src/test/java/com/homihq/db2rest/rest/oracle/OracleDateTimeAllTest.java index 8d670136..070d2351 100644 --- a/api-rest/src/test/java/com/homihq/db2rest/rest/oracle/OracleDateTimeAllTest.java +++ b/api-rest/src/test/java/com/homihq/db2rest/rest/oracle/OracleDateTimeAllTest.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.homihq.db2rest.OracleBaseIntegrationTest; 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,13 +13,18 @@ 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.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import java.util.HashMap; +import java.util.List; import java.util.Map; 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; @@ -144,4 +150,42 @@ void deleteActorByTimeStamp() throws Exception { .andExpect(jsonPath("$.rows", equalTo(1))) .andDo(document("oracle-delete-an-actor-by-timestamp")); } + + @ParameterizedTest + @MethodSource("isoDateTimeFormats") + @Order(5) + @DisplayName("Test ISO Date Time formats") + void createActorWithIsoDateTimeWithoutOffset(String input) 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", input); + var result = mockMvc.perform(post(VERSION + "/oradb/ACTOR") + .queryParam("sequences", "actor_id:actor_sequence") + .contentType(APPLICATION_JSON) + .accept(APPLICATION_JSON) + .content(objectMapper.writeValueAsString(actorRequestWithDateTime))) + .andDo(print()) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.row", equalTo(1))) + .andDo(document("oracle-create-an-actor-with-datetime")) + .andReturn(); + + var pk = JsonPath.read(result.getResponse().getContentAsString(), "$.keys.ACTOR_ID"); + assertTrue(deleteRow("actor", "actor_id", (int) pk)); + } + + private static List isoDateTimeFormats() { + return List.of(Arguments.of("2011-12-03T10:15:30"), + Arguments.of("2011-12-03T10:15:30.123"), + Arguments.of("2011-12-03T10:15:30+01:00"), + Arguments.of("2011-12-03T10:15:30-05:00"), + Arguments.of("2011-12-03T10:15:30Z"), + Arguments.of("2011-12-03T10:15:30.123Z"), + Arguments.of("2011-12-03T10:15:30.123+05:30"), + Arguments.of("2011-12-03T10:15:30+01:00[Europe/Paris]"), + Arguments.of("2011-12-03T10:15:30.123+01:00[Europe/Paris]")); + } + }