-
-
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.
#497 - multi schema update and create tests
- Loading branch information
Showing
9 changed files
with
150 additions
and
18 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/test/java/com/homihq/db2rest/rest/mysql/CreateTwoTablesSameNameDiffSchemaTest.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,57 @@ | ||
package com.homihq.db2rest.rest.mysql; | ||
|
||
import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; | ||
import com.adelean.inject.resources.junit.jupiter.TestWithResources; | ||
import com.adelean.inject.resources.junit.jupiter.WithJacksonMapper; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import com.homihq.db2rest.MySQLBaseIntegrationTest; | ||
import com.jayway.jsonpath.JsonPath; | ||
import org.junit.jupiter.api.*; | ||
|
||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
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.get; | ||
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(82) | ||
@TestWithResources | ||
class CreateTwoTablesSameNameDiffSchemaTest extends MySQLBaseIntegrationTest { | ||
@WithJacksonMapper | ||
ObjectMapper objectMapper = new ObjectMapper() | ||
.registerModule(new JavaTimeModule()); | ||
|
||
@GivenJsonResource("/testdata/CREATE_EMP_REQUEST.json") | ||
Map<String,Object> CREATE_EMP_REQUEST; | ||
|
||
|
||
|
||
@Test | ||
@DisplayName("Create emp diff schema") | ||
void create() throws Exception { | ||
|
||
mockMvc.perform(post("/employee") | ||
.contentType(APPLICATION_JSON) | ||
.accept(APPLICATION_JSON) | ||
.header("Content-Profile", "sakila") | ||
.content(objectMapper.writeValueAsString(CREATE_EMP_REQUEST)) | ||
) | ||
//.andDo(print()) | ||
.andExpect(status().isCreated()) | ||
.andExpect(jsonPath("$.row", equalTo(1))) | ||
//.andExpect(jsonPath("$.keys.GENERATED_KEY").exists()) | ||
//.andExpect(jsonPath("$.keys.GENERATED_KEY", equalTo(5))) | ||
.andDo(document("mysql-create-emp-sakila")); | ||
|
||
} | ||
|
||
|
||
} |
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
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
66 changes: 66 additions & 0 deletions
66
src/test/java/com/homihq/db2rest/rest/mysql/UpdateTwoTablesSameNameDiffSchemaTest.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,66 @@ | ||
package com.homihq.db2rest.rest.mysql; | ||
|
||
import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; | ||
import com.adelean.inject.resources.junit.jupiter.TestWithResources; | ||
import com.adelean.inject.resources.junit.jupiter.WithJacksonMapper; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import com.homihq.db2rest.MySQLBaseIntegrationTest; | ||
import org.junit.jupiter.api.*; | ||
|
||
import java.util.Map; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; | ||
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(71) | ||
@TestWithResources | ||
class UpdateTwoTablesSameNameDiffSchemaTest extends MySQLBaseIntegrationTest { | ||
|
||
@WithJacksonMapper | ||
ObjectMapper objectMapper = new ObjectMapper() | ||
.registerModule(new JavaTimeModule()); | ||
|
||
|
||
@GivenJsonResource("/testdata/UPDATE_EMPLOYEE_REQUEST.json") | ||
Map<String,Object> UPDATE_EMPLOYEE_REQUEST; | ||
|
||
@Test | ||
@DisplayName("Update employee diff schema") | ||
void updateEmployee() throws Exception { | ||
|
||
mockMvc.perform(patch("/employee") | ||
.contentType(APPLICATION_JSON) | ||
.accept(APPLICATION_JSON) | ||
.header("Content-Profile", "sakila") | ||
.param("filter", "emp_id==1") | ||
.content(objectMapper.writeValueAsString(UPDATE_EMPLOYEE_REQUEST)) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.rows", equalTo(1))) | ||
//.andDo(print()) | ||
.andDo(document("mysql-update-emp-sakila")); | ||
|
||
|
||
mockMvc.perform(patch("/employee") | ||
.contentType(APPLICATION_JSON) | ||
.accept(APPLICATION_JSON) | ||
.header("Content-Profile", "wakila") | ||
.param("filter", "emp_id==1") | ||
.content(objectMapper.writeValueAsString(UPDATE_EMPLOYEE_REQUEST)) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.rows", equalTo(1))) | ||
//.andDo(print()) | ||
.andDo(document("mysql-update-emp-wakila")); | ||
} | ||
|
||
|
||
|
||
|
||
} |
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 |
---|---|---|
|
@@ -82,8 +82,8 @@ values | |
(7, 7, 'Ivan', 'Levchenko', '[email protected]','878511311054'); | ||
|
||
|
||
Insert into employee (emp_id, first_name, last_name, create_date, is_active) values (1, 'Ivan', 'Levchenko', curdate(), 1); | ||
Insert into employee (emp_id, first_name, last_name, create_date, is_active) values (2, 'Roger', 'Federer', curdate(), 1); | ||
Insert into employee (first_name, last_name) values ('Ivan', 'Levchenko'); | ||
Insert into employee (first_name, last_name) values ('Roger', 'Federer'); | ||
|
||
|
||
-- language | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,6 @@ | ||
{ | ||
"emp_id" : "3", | ||
"first_name" : "Johny" , | ||
"last_name" : "Liver" | ||
|
||
} |
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,3 @@ | ||
{ | ||
"last_name": "Santana" | ||
} |