-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding integration test for different ISO date time formats for MsSql db
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
api-rest/src/test/java/com/homihq/db2rest/rest/mssql/MsSQLDateTimeAllTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.homihq.db2rest.rest.mssql; | ||
|
||
import com.jayway.jsonpath.JsonPath; | ||
import org.junit.jupiter.api.ClassOrderer; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.TestClassOrder; | ||
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.assertTrue; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@TestClassOrder(ClassOrderer.OrderAnnotation.class) | ||
@Order(506) | ||
class MsSQLDateTimeAllTest extends MsSQLBaseIntegrationTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource("isoDateTimeFormats") | ||
@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", "Graeme"); | ||
actorRequestWithDateTime.put("last_name", "Smith"); | ||
actorRequestWithDateTime.put("last_update", isoDateTime); | ||
|
||
var result = mockMvc.perform(post(VERSION + "/mssql/actor") | ||
.contentType(APPLICATION_JSON) | ||
.accept(APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(actorRequestWithDateTime))) | ||
.andExpect(status().isCreated()) | ||
.andExpect(jsonPath("$.row", equalTo(1))) | ||
.andDo(document("mssql-create-an-actor-with-datetime")) | ||
.andReturn(); | ||
|
||
var pk = JsonPath.read(result.getResponse().getContentAsString(), "$.keys.GENERATED_KEYS"); | ||
assertTrue(deleteRow("actor", "actor_id", (int) pk)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters