Refactoring tests, test extensions, test suites.

This commit is contained in:
Jesse Brault 2026-01-24 13:29:26 -06:00
parent 54118d597e
commit f272db9bdd
20 changed files with 203 additions and 145 deletions

View File

@ -26,6 +26,11 @@ sourceSets {
compileClasspath += main.output + testFixtures.output
runtimeClasspath += main.runtimeClasspath + testFixtures.runtimeClasspath
}
aiIntegrationTest {
compileClasspath += main.output + testFixtures.output
runtimeClasspath += main.runtimeClasspath + testFixtures.runtimeClasspath
}
}
configurations {
@ -35,6 +40,7 @@ configurations {
testFixturesImplementation {
extendsFrom implementation
extendsFrom testImplementation
}
integrationTestImplementation {
@ -45,6 +51,15 @@ configurations {
integrationTestRuntimeOnly {
extendsFrom testRuntimeOnly
}
aiIntegrationTestImplementation {
extendsFrom implementation
extendsFrom testImplementation
}
aiIntegrationTestRuntimeOnly {
extendsFrom testRuntimeOnly
}
}
ext {
@ -122,6 +137,23 @@ tasks.register('integrationTest', Test) {
classpath = sourceSets.integrationTest.runtimeClasspath
}
tasks.register('aiIntegrationTest', Test) {
description = 'Run AI integration tests.'
group = 'verification'
testClassesDirs = sourceSets.aiIntegrationTest.output.classesDirs
classpath = sourceSets.aiIntegrationTest.runtimeClasspath
}
check {
dependsOn 'integrationTest'
}
tasks.register('checkWithAi') {
description = 'Run all tests, including AI integration tests.'
group = 'verification'
dependsOn 'test', 'integrationTest', 'aiIntegrationTest'
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
}

View File

@ -0,0 +1,96 @@
package app.mealsmadeeasy.api.recipe;
import app.mealsmadeeasy.api.MinIOTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.auth.AuthService;
import app.mealsmadeeasy.api.auth.LoginException;
import app.mealsmadeeasy.api.recipe.view.RecipeDraftView;
import app.mealsmadeeasy.api.user.User;
import app.mealsmadeeasy.api.user.UserCreateException;
import app.mealsmadeeasy.api.user.UserService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.MimeTypeUtils;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@ExtendWith({ PostgresTestsExtension.class, MinIOTestsExtension.class })
@AutoConfigureMockMvc
public class RecipeDraftsControllerAiIntegrationTests {
private static final String TEST_PASSWORD = "test";
@Autowired
private UserService userService;
@Autowired
private MockMvc mockMvc;
@Autowired
private AuthService authService;
@Autowired
private ObjectMapper objectMapper;
private User seedUser() {
final String uuid = UUID.randomUUID().toString();
try {
return this.userService.createUser(uuid, uuid + "@test.com", "test");
} catch (UserCreateException e) {
throw new RuntimeException(e);
}
}
private String getAccessToken(User user) throws LoginException {
return this.authService.login(user.getUsername(), TEST_PASSWORD)
.getAccessToken()
.getToken();
}
@Test
public void pollAiDraft_returnsDraft() throws Exception {
final User owner = this.seedUser();
final MockMultipartFile sourceFile = new MockMultipartFile(
"sourceFile",
"recipe.jpeg",
MimeTypeUtils.IMAGE_JPEG_VALUE,
this.getClass().getResourceAsStream("/recipe.jpeg")
);
final MvcResult multipartResult = this.mockMvc.perform(
multipart("/recipe-drafts/ai")
.file(sourceFile)
.param("sourceFileName", sourceFile.getOriginalFilename())
.header("Authorization", "Bearer " + this.getAccessToken(owner))
)
.andExpect(status().isCreated())
.andReturn();
final String rawContent = multipartResult.getResponse().getContentAsString();
final RecipeDraftView recipeDraftView = this.objectMapper.readValue(rawContent, RecipeDraftView.class);
await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> {
this.mockMvc.perform(
get("/recipe-drafts/{id}", recipeDraftView.id())
.header("Authorization", "Bearer " + this.getAccessToken(owner))
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.state", is(RecipeDraft.State.ENTER_DATA.toString())));
});
}
}

View File

@ -1,6 +1,7 @@
package app.mealsmadeeasy.api.recipe.job;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.MinIOTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.file.File;
import app.mealsmadeeasy.api.file.FileService;
import app.mealsmadeeasy.api.recipe.RecipeDraft;
@ -12,10 +13,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.MinIOContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import java.io.IOException;
@ -29,19 +26,9 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith({ PostgresTestsExtension.class, MinIOTestsExtension.class })
@Testcontainers
public class RecipeInferJobIntegrationTests {
@Container
private static final MinIOContainer minioContainer = new MinIOContainer("minio/minio:latest");
@DynamicPropertySource
public static void minioProperties(DynamicPropertyRegistry registry) {
registry.add("app.mealsmadeeasy.api.minio.endpoint", minioContainer::getS3URL);
registry.add("app.mealsmadeeasy.api.minio.accessKey", minioContainer::getUserName);
registry.add("app.mealsmadeeasy.api.minio.secretKey", minioContainer::getPassword);
}
public class RecipeInferJobAiIntegrationTests {
@Autowired
private UserService userService;
@ -61,7 +48,7 @@ public class RecipeInferJobIntegrationTests {
"test-pass"
);
final File sourceFile = this.fileService.create(
RecipeInferJobIntegrationTests.class.getResourceAsStream("recipe.jpeg"),
this.getClass().getResourceAsStream("/recipe.jpeg"),
"recipe.jpeg",
127673L,
owner

View File

@ -0,0 +1,15 @@
app.mealsmadeeasy.api.baseUrl=http://localhost:8080
app.mealsmadeeasy.api.security.access-token-lifetime=60
app.mealsmadeeasy.api.security.refresh-token-lifetime=120
app.mealsmadeeasy.api.minio.endpoint=http://localhost:9000
app.mealsmadeeasy.api.minio.accessKey=minio-root
app.mealsmadeeasy.api.minio.secretKey=test0123
app.mealsmadeeasy.api.images.bucketName=images
app.mealsmadeeasy.api.files.bucketName=files
# Source - https://stackoverflow.com/questions/3164072/large-objects-may-not-be-used-in-auto-commit-mode
# Posted by Iogui, modified by community. See post 'Timeline' for change history
# Retrieved 2025-12-25, License - CC BY-SA 4.0
spring.datasource.hikari.auto-commit=false
logging.level.app.mealsmadeeasy.api=debug

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

View File

@ -5,7 +5,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith({ PostgresTestsExtension.class, MinIOTestsExtension.class })
public class MealsMadeEasyApiApplicationTests {
@Test

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.auth;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.user.User;
import app.mealsmadeeasy.api.user.UserCreateException;
import app.mealsmadeeasy.api.user.UserService;
@ -28,7 +28,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest
@AutoConfigureMockMvc
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class AuthControllerTests {
private static final String TEST_PASSWORD = "test";

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.image;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.auth.AuthService;
import app.mealsmadeeasy.api.auth.LoginException;
import app.mealsmadeeasy.api.image.body.ImageUpdateBody;
@ -18,13 +18,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.testcontainers.containers.MinIOContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.io.IOException;
import java.io.InputStream;
@ -37,24 +31,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@Testcontainers
@SpringBootTest
@AutoConfigureMockMvc
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class ImageControllerTests {
@Container
private static final MinIOContainer container = new MinIOContainer(
DockerImageName.parse("minio/minio:latest")
);
@DynamicPropertySource
public static void minioProperties(DynamicPropertyRegistry registry) {
registry.add("app.mealsmadeeasy.api.minio.endpoint", container::getS3URL);
registry.add("app.mealsmadeeasy.api.minio.accessKey", container::getUserName);
registry.add("app.mealsmadeeasy.api.minio.secretKey", container::getPassword);
}
private static InputStream getHal9000InputStream() {
return ImageControllerTests.class.getResourceAsStream("HAL9000.svg");
}

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.image;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.image.spec.ImageCreateSpec;
import app.mealsmadeeasy.api.image.spec.ImageUpdateSpec;
import app.mealsmadeeasy.api.user.User;
@ -11,12 +11,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.MinIOContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.io.IOException;
import java.io.InputStream;
@ -35,23 +29,10 @@ import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@Testcontainers
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class S3ImageServiceTests {
@Container
private static final MinIOContainer container = new MinIOContainer(
DockerImageName.parse("minio/minio:latest")
);
@DynamicPropertySource
public static void minioProperties(DynamicPropertyRegistry registry) {
registry.add("app.mealsmadeeasy.api.minio.endpoint", container::getS3URL);
registry.add("app.mealsmadeeasy.api.minio.accessKey", container::getUserName);
registry.add("app.mealsmadeeasy.api.minio.secretKey", container::getPassword);
}
private static InputStream getHal9000InputStream() {
return S3ImageServiceTests.class.getResourceAsStream("HAL9000.svg");
}

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.job;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.recipe.job.RecipeInferJobHandler;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class JobServiceIntegrationTests {
@Component

View File

@ -1,12 +1,11 @@
package app.mealsmadeeasy.api.recipe;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.ai.InferenceService;
import app.mealsmadeeasy.api.ai.OcrService;
import app.mealsmadeeasy.api.auth.AuthService;
import app.mealsmadeeasy.api.auth.LoginException;
import app.mealsmadeeasy.api.recipe.body.RecipeDraftUpdateBody;
import app.mealsmadeeasy.api.recipe.view.RecipeDraftView;
import app.mealsmadeeasy.api.user.User;
import app.mealsmadeeasy.api.user.UserCreateException;
import app.mealsmadeeasy.api.user.UserService;
@ -20,14 +19,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.MimeTypeUtils;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.hasSize;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
@ -35,7 +31,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
@AutoConfigureMockMvc
public class RecipeDraftsControllerIntegrationTests {
@ -175,37 +171,6 @@ public class RecipeDraftsControllerIntegrationTests {
}
@Test
public void pollAiDraft_returnsDraft() throws Exception {
final User owner = this.seedUser();
final MockMultipartFile sourceFile = new MockMultipartFile(
"sourceFile",
"recipe.jpeg",
MimeTypeUtils.IMAGE_JPEG_VALUE,
RecipeDraftsControllerIntegrationTests.class.getResourceAsStream("recipe.jpeg")
);
final MvcResult multipartResult = this.mockMvc.perform(
multipart("/recipe-drafts/ai")
.file(sourceFile)
.param("sourceFileName", sourceFile.getOriginalFilename())
.header("Authorization", "Bearer " + this.getAccessToken(owner))
)
.andExpect(status().isCreated())
.andReturn();
final String rawContent = multipartResult.getResponse().getContentAsString();
final RecipeDraftView recipeDraftView = this.objectMapper.readValue(rawContent, RecipeDraftView.class);
await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> {
this.mockMvc.perform(
get("/recipe-drafts/{id}", recipeDraftView.id())
.header("Authorization", "Bearer " + this.getAccessToken(owner))
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.state", is(RecipeDraft.State.ENTER_DATA.toString())));
});
}
@Test
public void whenUpdate_returnsUpdated() throws Exception {
final User owner = this.seedUser();

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.recipe;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.user.User;
import app.mealsmadeeasy.api.user.UserRepository;
import org.junit.jupiter.api.Test;
@ -18,7 +18,7 @@ import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class RecipeRepositoryTests {
@Autowired

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.recipe;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.recipe.spec.RecipeCreateSpec;
import app.mealsmadeeasy.api.recipe.spec.RecipeUpdateSpec;
import app.mealsmadeeasy.api.recipe.star.RecipeStar;
@ -29,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
// TODO: test mainImage included
// TODO: test prep/cooking/total times included
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class RecipeServiceTests {
@Autowired

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.recipe;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.auth.AuthService;
import app.mealsmadeeasy.api.auth.LoginDetails;
import app.mealsmadeeasy.api.auth.LoginException;
@ -22,13 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.MockMvc;
import org.testcontainers.containers.MinIOContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.io.InputStream;
import java.util.UUID;
@ -38,24 +32,11 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Testcontainers
@SpringBootTest
@AutoConfigureMockMvc
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class RecipesControllerTests {
@Container
private static final MinIOContainer container = new MinIOContainer(
DockerImageName.parse("minio/minio:latest")
);
@DynamicPropertySource
public static void minioProperties(DynamicPropertyRegistry registry) {
registry.add("app.mealsmadeeasy.api.minio.endpoint", container::getS3URL);
registry.add("app.mealsmadeeasy.api.minio.accessKey", container::getUserName);
registry.add("app.mealsmadeeasy.api.minio.secretKey", container::getPassword);
}
private static InputStream getHal9000() {
return S3ImageServiceTests.class.getClassLoader().getResourceAsStream("HAL9000.svg");
}

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.recipe.star;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.recipe.Recipe;
import app.mealsmadeeasy.api.recipe.RecipeRepository;
import app.mealsmadeeasy.api.user.User;
@ -17,7 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class RecipeStarRepositoryTests {
@Autowired

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.recipe.star;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.recipe.Recipe;
import app.mealsmadeeasy.api.recipe.RecipeService;
import app.mealsmadeeasy.api.recipe.spec.RecipeCreateSpec;
@ -21,7 +21,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@SpringBootTest
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class RecipeStarServiceTests {
@Autowired

View File

@ -1,30 +1,26 @@
package app.mealsmadeeasy.api.s3;
import app.mealsmadeeasy.api.MinIOTestsExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.containers.MinIOContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.io.IOException;
import java.io.InputStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
@Testcontainers
public class MinioS3ManagerTests {
@Container
private static final MinIOContainer container = new MinIOContainer(
DockerImageName.parse("minio/minio:latest")
);
@RegisterExtension
public static final MinIOTestsExtension minioTestsExtension = new MinIOTestsExtension();
private MinioS3Manager s3Manager;
private final MinioS3Manager s3Manager = new MinioS3Manager();
@BeforeEach
public void beforeEach() {
this.s3Manager = new MinioS3Manager();
public void setup() {
final MinIOContainer container = minioTestsExtension.getContainer();
this.s3Manager.setEndpoint(container.getS3URL());
this.s3Manager.setAccessKey(container.getUserName());
this.s3Manager.setSecretKey(container.getPassword());

View File

@ -1,6 +1,6 @@
package app.mealsmadeeasy.api.signup;
import app.mealsmadeeasy.api.IntegrationTestsExtension;
import app.mealsmadeeasy.api.PostgresTestsExtension;
import app.mealsmadeeasy.api.user.UserCreateException.Type;
import app.mealsmadeeasy.api.user.UserService;
import com.fasterxml.jackson.core.JsonProcessingException;
@ -25,7 +25,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest
@AutoConfigureMockMvc
@ExtendWith(IntegrationTestsExtension.class)
@ExtendWith(PostgresTestsExtension.class)
public class SignUpControllerTests {
@Autowired

View File

@ -0,0 +1,23 @@
package app.mealsmadeeasy.api;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.containers.MinIOContainer;
public class MinIOTestsExtension implements BeforeAllCallback {
private final MinIOContainer container = new MinIOContainer("minio/minio:latest");
@Override
public void beforeAll(ExtensionContext context) {
this.container.start();
System.setProperty("app.mealsmadeeasy.api.minio.endpoint", this.container.getS3URL());
System.setProperty("app.mealsmadeeasy.api.minio.accessKey", this.container.getUserName());
System.setProperty("app.mealsmadeeasy.api.minio.secretKey", this.container.getPassword());
}
public MinIOContainer getContainer() {
return this.container;
}
}

View File

@ -4,10 +4,11 @@ import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.containers.PostgreSQLContainer;
public class IntegrationTestsExtension implements BeforeAllCallback {
public class PostgresTestsExtension implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) {
@SuppressWarnings("resource")
final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("pgvector/pgvector:pg18-trixie")
.withDatabaseName("meals_made_easy_api");
postgres.start();