Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#136 - ading integration test for bulk insert for postgresql #138

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void create() throws Exception {
.andExpect(status().isCreated())
.andExpect(jsonPath("$.rows", Matchers.equalTo(1)))
.andDo(print())
.andDo(document("create-a-film"));
.andDo(document("mysql-create-a-film"));

}

Expand Down Expand Up @@ -71,7 +71,37 @@ void createError() throws Exception {
.content(json).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("create-a-film-error"));
.andDo(document("mysql-create-a-film-error"));

}

@Test
@DisplayName("Create a film - non existent table.")
void createNonExistentTable() throws Exception {

var json = """
{
"title" : "Dunki",
"description" : "Film about illegal immigration" ,
"release_year" : 2023,
"language_id" : 1,
"original_language_id" : null,
"rental_duration" : 6,
"rental_rate" : 0.99 ,
"length" : 150,
"replacement_cost" : 20.99 ,
"rating" : "PG-13" ,
"special_features" : "Commentaries"

}
""";

mockMvc.perform(post("/films").contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8")
.header("Content-Profile", "public")
.content(json).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("mysql-create-a-film-no-table"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ void findAllFilms() throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("get-all-films"));
.andDo(document("mysql-get-all-films"));
}
}
117 changes: 117 additions & 0 deletions src/test/java/com/homihq/db2rest/rest/PgBulkCreateControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.homihq.db2rest.rest;

import com.homihq.db2rest.PostgreSQLBaseIntegrationTest;
import org.hamcrest.Matchers;
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.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class PgBulkCreateControllerTest extends PostgreSQLBaseIntegrationTest {

@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"));

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void create() throws Exception {
.andExpect(status().isCreated())
.andExpect(jsonPath("$.rows", Matchers.equalTo(1)))
.andDo(print())
.andDo(document("create-a-film"));
.andDo(document("pg-create-a-film"));

}

Expand Down Expand Up @@ -73,7 +73,7 @@ void createError() throws Exception {
.content(json).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andDo(print())
.andDo(document("create-a-film-error"));
.andDo(document("pg-create-a-film-error"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ void findAllFilms() throws Exception {
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print())
.andDo(document("get-all-films"));
.andDo(document("pg-get-all-films"));
}
}