Skip to content

Commit

Permalink
Adding integration test for different ISO date time formats for Postg…
Browse files Browse the repository at this point in the history
…res db
  • Loading branch information
souravroy committed Nov 30, 2024
1 parent 3538706 commit 81cd4df
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
14 changes: 14 additions & 0 deletions api-rest/src/test/java/com/homihq/db2rest/BaseIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.provider.Arguments;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -19,6 +20,7 @@

import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;

import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;

Expand Down Expand Up @@ -61,4 +63,16 @@ void setupEnv() {
}
}
}

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]"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ void deleteActorByTimeStamp() throws Exception {
@MethodSource("isoDateTimeFormats")
@Order(5)
@DisplayName("Test ISO Date Time formats")
void createActorWithIsoDateTimeWithoutOffset(String input) throws Exception {
void createActorWithIsoDateTimeFormats(String isoDateTime) 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);
actorRequestWithDateTime.put("last_update", isoDateTime);
var result = mockMvc.perform(post(VERSION + "/oradb/ACTOR")
.queryParam("sequences", "actor_id:actor_sequence")
.contentType(APPLICATION_JSON)
Expand All @@ -176,16 +176,4 @@ void createActorWithIsoDateTimeWithoutOffset(String input) throws Exception {
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]"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.homihq.db2rest.PostgreSQLBaseIntegrationTest;
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.MethodSource;

import java.util.HashMap;
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 @@ -138,4 +142,30 @@ void deleteActorByTimeStamp() throws Exception {
.andExpect(jsonPath("$.rows", equalTo(1)))
.andDo(document("pg-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<String, Object> actorRequestWithDateTime = new HashMap<>();
actorRequestWithDateTime.put("first_name", "Collective");
actorRequestWithDateTime.put("last_name", "Unconscious");
actorRequestWithDateTime.put("last_update", isoDateTime);

var result = mockMvc.perform(post(VERSION + "/pgsqldb/actor")
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(actorRequestWithDateTime)))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.row", equalTo(1)))
.andDo(document("pg-create-an-actor-with-datetime"))
.andReturn();

var pk = JsonPath.read(result.getResponse().getContentAsString(), "$.keys.actor_id");
assertTrue(deleteRow("actor", "actor_id", (int) pk));
}

}

0 comments on commit 81cd4df

Please sign in to comment.