-
-
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.
#135 - mysql bulk insert, minor other fixes
- Loading branch information
Showing
6 changed files
with
152 additions
and
63 deletions.
There are no files selected for viewing
31 changes: 2 additions & 29 deletions
31
src/test/java/com/homihq/db2rest/MySQLBaseIntegrationTest.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 |
---|---|---|
@@ -1,35 +1,8 @@ | ||
package com.homihq.db2rest; | ||
|
||
import org.springframework.test.context.jdbc.Sql; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Sql(scripts = {"classpath:mysql/mysql-sakila.sql", "classpath:mysql/mysql-sakila-insert-data.sql"}) | ||
@Import(MySQLContainerConfiguration.class) | ||
public class MySQLBaseIntegrationTest extends BaseIntegrationTest{ | ||
/* | ||
@ServiceConnection | ||
private static final MySQLContainer mySQLContainer = new MySQLContainer("mysql:8.2"); | ||
static { | ||
mySQLContainer | ||
.withDatabaseName("sakila") | ||
.withUsername("mysql") | ||
.withPassword("mysql") | ||
.withUrlParam("serverTimezone", "UTC"); | ||
} | ||
@BeforeAll | ||
static void beforeAll() { | ||
mySQLContainer.start(); | ||
} | ||
@AfterAll | ||
static void afterAll() { | ||
mySQLContainer.stop(); | ||
} | ||
|
||
*/ | ||
} |
29 changes: 0 additions & 29 deletions
29
src/test/java/com/homihq/db2rest/PostgreSQLBaseIntegrationTest.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 |
---|---|---|
@@ -1,37 +1,8 @@ | ||
package com.homihq.db2rest; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.jdbc.Sql; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
//@Sql(scripts = {"classpath:pg/postgres-sakila-schema.sql", "classpath:pg/postgres-sakila-insert-data.sql"}) | ||
@Import(PostgreSQLContainerConfiguration.class) | ||
public class PostgreSQLBaseIntegrationTest extends BaseIntegrationTest{ | ||
|
||
/* | ||
@ServiceConnection | ||
private static final PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:15-alpine"); | ||
static { | ||
postgreSQLContainer.withUsername("postgres") | ||
.withPassword("postgres") | ||
.withDatabaseName("postgres").withReuse(true); | ||
} | ||
@BeforeAll | ||
static void beforeAll() { | ||
postgreSQLContainer.start(); | ||
} | ||
@AfterAll | ||
static void afterAll() { | ||
postgreSQLContainer.stop(); | ||
} | ||
*/ | ||
} |
115 changes: 115 additions & 0 deletions
115
src/test/java/com/homihq/db2rest/rest/MySQLBulkCreateControllerTest.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,115 @@ | ||
package com.homihq.db2rest.rest; | ||
|
||
import com.homihq.db2rest.MySQLBaseIntegrationTest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.MediaType; | ||
|
||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
class MySQLBulkCreateControllerTest extends MySQLBaseIntegrationTest { | ||
|
||
@Test | ||
@DisplayName("Create many films.") | ||
void create() throws Exception { | ||
|
||
var json = """ | ||
[ | ||
{ | ||
"title" : "Dunki", | ||
"description" : "Film about illegal immigration" , | ||
"release_year" : 2023, | ||
"language_id" : 6, | ||
"original_language_id" : 6, | ||
"rental_duration" : 6, | ||
"rental_rate" : 0.99 , | ||
"length" : 150, | ||
"replacement_cost" : 20.99 , | ||
"rating" : "PG-13" , | ||
"special_features" : "Commentaries" | ||
}, | ||
{ | ||
"title" : "Jawan", | ||
"description" : "Socio-econmic problems and corruption" , | ||
"release_year" : 2023, | ||
"language_id" : 6, | ||
"original_language_id" : 6, | ||
"rental_duration" : 5, | ||
"rental_rate" : 0.99 , | ||
"length" : 160, | ||
"replacement_cost" : 20.99 , | ||
"rating" : "PG-13" , | ||
"special_features" : "Commentaries" | ||
} | ||
] | ||
"""; | ||
|
||
|
||
mockMvc.perform(post("/film/bulk").contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8") | ||
.header("Content-Profile", "public") | ||
.content(json).accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isCreated()) | ||
//.andExpect(jsonPath("$.rows", Matchers.equalTo(1))) | ||
.andDo(print()) | ||
.andDo(document("pg-bulk-create-films")); | ||
|
||
} | ||
|
||
|
||
@Test | ||
@DisplayName("Create many films with failure.") | ||
void createError() throws Exception { | ||
|
||
var json = """ | ||
[ | ||
{ | ||
"title" : "Dunki", | ||
"description" : "Film about illegal immigration" , | ||
"release_year" : 2023, | ||
"language_id" : 6, | ||
"original_language_id" : 6, | ||
"rental_duration" : 6, | ||
"rental_rate" : 0.99 , | ||
"length" : 150, | ||
"replacement_cost" : 20.99 , | ||
"rating" : "PG-13" , | ||
"special_features" : "Commentaries" | ||
"country" : "INDIA" | ||
}, | ||
{ | ||
"title" : "Jawan", | ||
"description" : "Socio-econmic problems and corruption" , | ||
"release_year" : 2023, | ||
"language_id" : 6, | ||
"original_language_id" : 6, | ||
"rental_duration" : 5, | ||
"rental_rate" : 0.99 , | ||
"length" : 160, | ||
"replacement_cost" : 20.99 , | ||
"rating" : "PG-13" , | ||
"special_features" : "Commentaries" | ||
} | ||
] | ||
"""; | ||
|
||
|
||
mockMvc.perform(post("/film/bulk").contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8") | ||
.header("Content-Profile", "public") | ||
.content(json).accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isBadRequest()) | ||
.andDo(print()) | ||
.andDo(document("pg-bulk-create-films-error")); | ||
|
||
} | ||
|
||
|
||
} |
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
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