Skip to content

Commit

Permalink
Merge pull request #788 from thadguidry/make-tests-filesystem-agnostic
Browse files Browse the repository at this point in the history
Fixes #787 make JSON File tests agnostic of FileSystem used
  • Loading branch information
kdhrubo authored Nov 12, 2024
2 parents b331315 + 304ae05 commit 798ee64
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package com.homihq.db2rest.rest.mariadb;

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.MariaDBBaseIntegrationTest;
import org.junit.jupiter.api.*;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MvcResult;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

import static com.homihq.db2rest.jdbc.rest.RdbmsRestApi.VERSION;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.AnyOf.anyOf;
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.request.MockMvcRequestBuilders.asyncDispatch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
Expand All @@ -32,16 +24,18 @@
@TestWithResources
class MariaDBJsonFileCreateControllerTest extends MariaDBBaseIntegrationTest {

String actorFile = getClass().getResource("/testdata/actor.json").getPath();
String filmFile = getClass().getResource("/testdata/BULK_CREATE_FILM_REQUEST.json").getPath();
String nonArrayActorFile = getClass().getResource("/testdata/CREATE_ACTOR_REQUEST.json").getPath();
String directorFile = getClass().getResource("/testdata/director.json").getPath();
Path dir = FileSystems.getDefault().getPath("src/test/resources/testdata");

Path actorFile = dir.resolve("actor.json");
Path filmFile = dir.resolve("BULK_CREATE_FILM_REQUEST.json");
Path nonArrayActorFile = dir.resolve("CREATE_ACTOR_REQUEST.json");
Path directorFile = dir.resolve("director.json");

@Test
@DisplayName("Create many actors via JSON file upload.")
void uploadActorsFile() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "actor.json",
"application/json", Files.readAllBytes(Path.of(actorFile)));
"application/json", Files.readAllBytes(actorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mariadb/actor/upload")
.file(file)
Expand All @@ -61,7 +55,7 @@ void uploadActorsFile() throws Exception {
@DisplayName("Error create actor via JSON file upload.")
void uploadActorFileNonJsonArray() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", nonArrayActorFile.toString(),
"application/json", Files.readAllBytes(Path.of(nonArrayActorFile)));
"application/json", Files.readAllBytes(nonArrayActorFile));

mockMvc.perform(multipart(VERSION + "/mariadb/actor/upload")
.file(file)
Expand All @@ -76,7 +70,7 @@ void uploadActorFileNonJsonArray() throws Exception {
@DisplayName("Create many directors via file upload.")
void createDirectorViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkDirector.json",
"application/json", Files.readAllBytes(Path.of(directorFile)));
"application/json", Files.readAllBytes(directorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mariadb/director/upload")
.file(file)
Expand All @@ -96,7 +90,7 @@ void createDirectorViaUpload() throws Exception {
@DisplayName("Create many films via file upload.")
void createFilmsViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkFilm.json",
"application/json", Files.readAllBytes(Path.of(filmFile)));
"application/json", Files.readAllBytes(filmFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mariadb/film/upload")
.file(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MvcResult;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

Expand All @@ -24,11 +25,13 @@
@TestWithResources
class MsSQLJsonFileCreateControllerTest extends MsSQLBaseIntegrationTest {

String actorFile = getClass().getResource("/testdata/actor.json").getPath();
String filmFile = getClass().getResource("/testdata/BULK_CREATE_FILM_REQUEST.json").getPath();
String nonArrayActorFile = getClass().getResource("/testdata/CREATE_ACTOR_REQUEST.json").getPath();
String directorFile = getClass().getResource("/testdata/director.json").getPath();
Path dir = FileSystems.getDefault().getPath("src/test/resources/testdata");

Path actorFile = dir.resolve("actor.json");
Path filmFile = dir.resolve("BULK_CREATE_FILM_REQUEST.json");
Path nonArrayActorFile = dir.resolve("CREATE_ACTOR_REQUEST.json");
Path directorFile = dir.resolve("director.json");

@Autowired
JdbcTemplate jdbcTemplate;

Expand All @@ -38,7 +41,7 @@ void uploadActorsFile() throws Exception {
jdbcTemplate.execute("SET IDENTITY_INSERT dbo.actor ON");

MockMultipartFile file = new MockMultipartFile("file", "actor.json",
"application/json", Files.readAllBytes(Path.of(actorFile)));
"application/json", Files.readAllBytes(actorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mssql/actor/upload")
.file(file)
Expand All @@ -60,7 +63,7 @@ void uploadActorsFile() throws Exception {
@DisplayName("Error create actor via JSON file upload.")
void uploadActorFileNonJsonArray() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", nonArrayActorFile.toString(),
"application/json", Files.readAllBytes(Path.of(nonArrayActorFile)));
"application/json", Files.readAllBytes(nonArrayActorFile));

mockMvc.perform(multipart(VERSION + "/mssql/actor/upload")
.file(file)
Expand All @@ -75,7 +78,7 @@ void uploadActorFileNonJsonArray() throws Exception {
@DisplayName("Create many directors via file upload.")
void createDirectorViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkDirector.json",
"application/json", Files.readAllBytes(Path.of(directorFile)));
"application/json", Files.readAllBytes(directorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mssql/director/upload")
.file(file)
Expand All @@ -95,7 +98,7 @@ void createDirectorViaUpload() throws Exception {
@DisplayName("Create many films via file upload.")
void createFilmsViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkFilm.json",
"application/json", Files.readAllBytes(Path.of(filmFile)));
"application/json", Files.readAllBytes(filmFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mssql/film/upload")
.file(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MvcResult;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

Expand All @@ -24,16 +25,18 @@
@TestWithResources
class MySQLJsonFileCreateControllerTest extends MySQLBaseIntegrationTest {

String actorFile = getClass().getResource("/testdata/actor.json").getPath();
String filmFile = getClass().getResource("/testdata/BULK_CREATE_FILM_REQUEST.json").getPath();
String nonArrayActorFile = getClass().getResource("/testdata/CREATE_ACTOR_REQUEST.json").getPath();
String directorFile = getClass().getResource("/testdata/director.json").getPath();
Path dir = FileSystems.getDefault().getPath("src/test/resources/testdata");

Path actorFile = dir.resolve("actor.json");
Path filmFile = dir.resolve("BULK_CREATE_FILM_REQUEST.json");
Path nonArrayActorFile = dir.resolve("CREATE_ACTOR_REQUEST.json");
Path directorFile = dir.resolve("director.json");

@Test
@DisplayName("Create many actors via JSON file upload.")
void uploadActorsFile() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "actor.json",
"application/json", Files.readAllBytes(Path.of(actorFile)));
"application/json", Files.readAllBytes(actorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mysqldb/actor/upload")
.file(file)
Expand All @@ -53,7 +56,7 @@ void uploadActorsFile() throws Exception {
@DisplayName("Error create actor via JSON file upload.")
void uploadActorFileNonJsonArray() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", nonArrayActorFile.toString(),
"application/json", Files.readAllBytes(Path.of(nonArrayActorFile)));
"application/json", Files.readAllBytes(nonArrayActorFile));

mockMvc.perform(multipart(VERSION + "/mysqldb/actor/upload")
.file(file)
Expand All @@ -68,7 +71,7 @@ void uploadActorFileNonJsonArray() throws Exception {
@DisplayName("Create many directors via file upload.")
void createDirectorViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkDirector.json",
"application/json", Files.readAllBytes(Path.of(directorFile)));
"application/json", Files.readAllBytes(directorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mysqldb/director/upload")
.file(file)
Expand All @@ -88,7 +91,7 @@ void createDirectorViaUpload() throws Exception {
@DisplayName("Create many films via file upload.")
void createFilmsViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkFilm.json",
"application/json", Files.readAllBytes(Path.of(filmFile)));
"application/json", Files.readAllBytes(filmFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/mysqldb/film/upload")
.file(file)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.homihq.db2rest.rest.oracle;

import com.adelean.inject.resources.junit.jupiter.TestWithResources;
import com.homihq.db2rest.MySQLBaseIntegrationTest;
import com.homihq.db2rest.OracleBaseIntegrationTest;
import org.junit.jupiter.api.*;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MvcResult;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

Expand All @@ -24,16 +24,17 @@
@TestWithResources
class OracleJsonFileCreateControllerTest extends OracleBaseIntegrationTest {

String actorFile = getClass().getResource("/testdata/actor.json").getPath();
String filmFile = getClass().getResource("/testdata/BULK_CREATE_FILM_REQUEST.json").getPath();
String nonArrayActorFile = getClass().getResource("/testdata/CREATE_ACTOR_REQUEST.json").getPath();
String directorFile = getClass().getResource("/testdata/director.json").getPath();
Path dir = FileSystems.getDefault().getPath("src/test/resources/testdata");

Path actorFile = dir.resolve("actor.json");
Path filmFile = dir.resolve("BULK_CREATE_FILM_REQUEST.json");
Path nonArrayActorFile = dir.resolve("CREATE_ACTOR_REQUEST.json");
Path directorFile = dir.resolve("director.json");
@Test
@DisplayName("Create many actors via JSON file upload.")
void uploadActorsFile() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "actor.json",
"application/json", Files.readAllBytes(Path.of(actorFile)));
"application/json", Files.readAllBytes(actorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/oradb/ACTOR/upload")
.file(file)
Expand All @@ -53,7 +54,7 @@ void uploadActorsFile() throws Exception {
@DisplayName("Error create actor via JSON file upload.")
void uploadActorFileNonJsonArray() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", nonArrayActorFile.toString(),
"application/json", Files.readAllBytes(Path.of(nonArrayActorFile)));
"application/json", Files.readAllBytes(nonArrayActorFile));

mockMvc.perform(multipart(VERSION + "/oradb/ACTOR/upload")
.file(file)
Expand All @@ -68,7 +69,7 @@ void uploadActorFileNonJsonArray() throws Exception {
@DisplayName("Create many directors via file upload.")
void createDirectorViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkDirector.json",
"application/json", Files.readAllBytes(Path.of(directorFile)));
"application/json", Files.readAllBytes(directorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/oradb/DIRECTOR/upload")
.file(file)
Expand All @@ -88,7 +89,7 @@ void createDirectorViaUpload() throws Exception {
@DisplayName("Create many films via file upload.")
void createFilmsViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkFilm.json",
"application/json", Files.readAllBytes(Path.of(filmFile)));
"application/json", Files.readAllBytes(filmFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/oradb/FILM/upload")
.file(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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.homihq.db2rest.PostgreSQLBaseIntegrationTest;
import org.junit.jupiter.api.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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.homihq.db2rest.PostgreSQLBaseIntegrationTest;
import org.junit.jupiter.api.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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.homihq.db2rest.PostgreSQLBaseIntegrationTest;
import org.junit.jupiter.api.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.homihq.db2rest.rest.pg;

import com.adelean.inject.resources.junit.jupiter.TestWithResources;
import com.homihq.db2rest.MySQLBaseIntegrationTest;
import com.homihq.db2rest.PostgreSQLBaseIntegrationTest;
import org.junit.jupiter.api.*;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MvcResult;

import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

Expand All @@ -24,16 +24,18 @@
@TestWithResources
class PgJsonFileCreateControllerTest extends PostgreSQLBaseIntegrationTest {

String actorFile = getClass().getResource("/testdata/actor.json").getPath();
String filmFile = getClass().getResource("/testdata/BULK_CREATE_FILM_REQUEST.json").getPath();
String nonArrayActorFile = getClass().getResource("/testdata/CREATE_ACTOR_REQUEST.json").getPath();
String directorFile = getClass().getResource("/testdata/director.json").getPath();
Path dir = FileSystems.getDefault().getPath("src/test/resources/testdata");

Path actorFile = dir.resolve("actor.json");
Path filmFile = dir.resolve("BULK_CREATE_FILM_REQUEST.json");
Path nonArrayActorFile = dir.resolve("CREATE_ACTOR_REQUEST.json");
Path directorFile = dir.resolve("director.json");

@Test
@DisplayName("Create many actors via JSON file upload.")
void uploadActorsFile() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "actor.json",
"application/json", Files.readAllBytes(Path.of(actorFile)));
MockMultipartFile file = new MockMultipartFile("file", actorFile.toString(),
"application/json", Files.readAllBytes(actorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/pgsqldb/actor/upload")
.file(file)
Expand All @@ -53,7 +55,7 @@ void uploadActorsFile() throws Exception {
@DisplayName("Error create actor via JSON file upload.")
void uploadActorFileNonJsonArray() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", nonArrayActorFile.toString(),
"application/json", Files.readAllBytes(Path.of(nonArrayActorFile)));
"application/json", Files.readAllBytes(nonArrayActorFile));

mockMvc.perform(multipart(VERSION + "/pgsqldb/actor/upload")
.file(file)
Expand All @@ -67,8 +69,8 @@ void uploadActorFileNonJsonArray() throws Exception {
@Test
@DisplayName("Create many directors via file upload.")
void createDirectorViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkDirector.json",
"application/json", Files.readAllBytes(Path.of(directorFile)));
MockMultipartFile file = new MockMultipartFile("file", directorFile.toString(),
"application/json", Files.readAllBytes(directorFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/pgsqldb/director/upload")
.file(file)
Expand All @@ -87,8 +89,8 @@ void createDirectorViaUpload() throws Exception {
@Test
@DisplayName("Create many films via file upload.")
void createFilmsViaUpload() throws Exception {
MockMultipartFile file = new MockMultipartFile("file", "bulkFilm.json",
"application/json", Files.readAllBytes(Path.of(filmFile)));
MockMultipartFile file = new MockMultipartFile("file", filmFile.toString(),
"application/json", Files.readAllBytes(filmFile));

MvcResult mvcResult = mockMvc.perform(multipart(VERSION + "/pgsqldb/film/upload")
.file(file)
Expand Down

0 comments on commit 798ee64

Please sign in to comment.