Skip to content

Commit

Permalink
Adding integration test for different ISO date time formats for Oracl…
Browse files Browse the repository at this point in the history
…e db
  • Loading branch information
souravroy committed Nov 30, 2024
1 parent a07deda commit 3538706
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
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;
import org.junit.jupiter.api.Order;
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;
Expand Down Expand Up @@ -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<String, Object> 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<Arguments> 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]"));
}

}

0 comments on commit 3538706

Please sign in to comment.