Refactoring tests, test extensions, test suites.
This commit is contained in:
parent
54118d597e
commit
f272db9bdd
32
build.gradle
32
build.gradle
@ -26,6 +26,11 @@ sourceSets {
|
|||||||
compileClasspath += main.output + testFixtures.output
|
compileClasspath += main.output + testFixtures.output
|
||||||
runtimeClasspath += main.runtimeClasspath + testFixtures.runtimeClasspath
|
runtimeClasspath += main.runtimeClasspath + testFixtures.runtimeClasspath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aiIntegrationTest {
|
||||||
|
compileClasspath += main.output + testFixtures.output
|
||||||
|
runtimeClasspath += main.runtimeClasspath + testFixtures.runtimeClasspath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
@ -35,6 +40,7 @@ configurations {
|
|||||||
|
|
||||||
testFixturesImplementation {
|
testFixturesImplementation {
|
||||||
extendsFrom implementation
|
extendsFrom implementation
|
||||||
|
extendsFrom testImplementation
|
||||||
}
|
}
|
||||||
|
|
||||||
integrationTestImplementation {
|
integrationTestImplementation {
|
||||||
@ -45,6 +51,15 @@ configurations {
|
|||||||
integrationTestRuntimeOnly {
|
integrationTestRuntimeOnly {
|
||||||
extendsFrom testRuntimeOnly
|
extendsFrom testRuntimeOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aiIntegrationTestImplementation {
|
||||||
|
extendsFrom implementation
|
||||||
|
extendsFrom testImplementation
|
||||||
|
}
|
||||||
|
|
||||||
|
aiIntegrationTestRuntimeOnly {
|
||||||
|
extendsFrom testRuntimeOnly
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
@ -122,6 +137,23 @@ tasks.register('integrationTest', Test) {
|
|||||||
classpath = sourceSets.integrationTest.runtimeClasspath
|
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 {
|
tasks.withType(Test).configureEach {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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())));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
package app.mealsmadeeasy.api.recipe.job;
|
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.File;
|
||||||
import app.mealsmadeeasy.api.file.FileService;
|
import app.mealsmadeeasy.api.file.FileService;
|
||||||
import app.mealsmadeeasy.api.recipe.RecipeDraft;
|
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.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
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.junit.jupiter.Testcontainers;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -29,19 +26,9 @@ import static org.hamcrest.Matchers.is;
|
|||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith({ PostgresTestsExtension.class, MinIOTestsExtension.class })
|
||||||
@Testcontainers
|
@Testcontainers
|
||||||
public class RecipeInferJobIntegrationTests {
|
public class RecipeInferJobAiIntegrationTests {
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@ -61,7 +48,7 @@ public class RecipeInferJobIntegrationTests {
|
|||||||
"test-pass"
|
"test-pass"
|
||||||
);
|
);
|
||||||
final File sourceFile = this.fileService.create(
|
final File sourceFile = this.fileService.create(
|
||||||
RecipeInferJobIntegrationTests.class.getResourceAsStream("recipe.jpeg"),
|
this.getClass().getResourceAsStream("/recipe.jpeg"),
|
||||||
"recipe.jpeg",
|
"recipe.jpeg",
|
||||||
127673L,
|
127673L,
|
||||||
owner
|
owner
|
||||||
15
src/aiIntegrationTest/resources/application.properties
Normal file
15
src/aiIntegrationTest/resources/application.properties
Normal 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
|
||||||
BIN
src/aiIntegrationTest/resources/recipe.jpeg
Normal file
BIN
src/aiIntegrationTest/resources/recipe.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 125 KiB |
@ -5,7 +5,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith({ PostgresTestsExtension.class, MinIOTestsExtension.class })
|
||||||
public class MealsMadeEasyApiApplicationTests {
|
public class MealsMadeEasyApiApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.auth;
|
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.User;
|
||||||
import app.mealsmadeeasy.api.user.UserCreateException;
|
import app.mealsmadeeasy.api.user.UserCreateException;
|
||||||
import app.mealsmadeeasy.api.user.UserService;
|
import app.mealsmadeeasy.api.user.UserService;
|
||||||
@ -28,7 +28,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class AuthControllerTests {
|
public class AuthControllerTests {
|
||||||
|
|
||||||
private static final String TEST_PASSWORD = "test";
|
private static final String TEST_PASSWORD = "test";
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.image;
|
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.AuthService;
|
||||||
import app.mealsmadeeasy.api.auth.LoginException;
|
import app.mealsmadeeasy.api.auth.LoginException;
|
||||||
import app.mealsmadeeasy.api.image.body.ImageUpdateBody;
|
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.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
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.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.IOException;
|
||||||
import java.io.InputStream;
|
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.request.MockMvcRequestBuilders.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||||
|
|
||||||
@Testcontainers
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class ImageControllerTests {
|
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() {
|
private static InputStream getHal9000InputStream() {
|
||||||
return ImageControllerTests.class.getResourceAsStream("HAL9000.svg");
|
return ImageControllerTests.class.getResourceAsStream("HAL9000.svg");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.image;
|
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.ImageCreateSpec;
|
||||||
import app.mealsmadeeasy.api.image.spec.ImageUpdateSpec;
|
import app.mealsmadeeasy.api.image.spec.ImageUpdateSpec;
|
||||||
import app.mealsmadeeasy.api.user.User;
|
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.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -35,23 +29,10 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|
||||||
@Testcontainers
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class S3ImageServiceTests {
|
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() {
|
private static InputStream getHal9000InputStream() {
|
||||||
return S3ImageServiceTests.class.getResourceAsStream("HAL9000.svg");
|
return S3ImageServiceTests.class.getResourceAsStream("HAL9000.svg");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.job;
|
package app.mealsmadeeasy.api.job;
|
||||||
|
|
||||||
import app.mealsmadeeasy.api.IntegrationTestsExtension;
|
import app.mealsmadeeasy.api.PostgresTestsExtension;
|
||||||
import app.mealsmadeeasy.api.recipe.job.RecipeInferJobHandler;
|
import app.mealsmadeeasy.api.recipe.job.RecipeInferJobHandler;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import static org.awaitility.Awaitility.await;
|
import static org.awaitility.Awaitility.await;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class JobServiceIntegrationTests {
|
public class JobServiceIntegrationTests {
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
package app.mealsmadeeasy.api.recipe;
|
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.InferenceService;
|
||||||
import app.mealsmadeeasy.api.ai.OcrService;
|
import app.mealsmadeeasy.api.ai.OcrService;
|
||||||
import app.mealsmadeeasy.api.auth.AuthService;
|
import app.mealsmadeeasy.api.auth.AuthService;
|
||||||
import app.mealsmadeeasy.api.auth.LoginException;
|
import app.mealsmadeeasy.api.auth.LoginException;
|
||||||
import app.mealsmadeeasy.api.recipe.body.RecipeDraftUpdateBody;
|
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.User;
|
||||||
import app.mealsmadeeasy.api.user.UserCreateException;
|
import app.mealsmadeeasy.api.user.UserCreateException;
|
||||||
import app.mealsmadeeasy.api.user.UserService;
|
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.mock.web.MockMultipartFile;
|
||||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static org.awaitility.Awaitility.await;
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
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;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
public class RecipeDraftsControllerIntegrationTests {
|
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
|
@Test
|
||||||
public void whenUpdate_returnsUpdated() throws Exception {
|
public void whenUpdate_returnsUpdated() throws Exception {
|
||||||
final User owner = this.seedUser();
|
final User owner = this.seedUser();
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.recipe;
|
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.User;
|
||||||
import app.mealsmadeeasy.api.user.UserRepository;
|
import app.mealsmadeeasy.api.user.UserRepository;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -18,7 +18,7 @@ import java.util.UUID;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class RecipeRepositoryTests {
|
public class RecipeRepositoryTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.recipe;
|
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.RecipeCreateSpec;
|
||||||
import app.mealsmadeeasy.api.recipe.spec.RecipeUpdateSpec;
|
import app.mealsmadeeasy.api.recipe.spec.RecipeUpdateSpec;
|
||||||
import app.mealsmadeeasy.api.recipe.star.RecipeStar;
|
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 mainImage included
|
||||||
// TODO: test prep/cooking/total times included
|
// TODO: test prep/cooking/total times included
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class RecipeServiceTests {
|
public class RecipeServiceTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.recipe;
|
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.AuthService;
|
||||||
import app.mealsmadeeasy.api.auth.LoginDetails;
|
import app.mealsmadeeasy.api.auth.LoginDetails;
|
||||||
import app.mealsmadeeasy.api.auth.LoginException;
|
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.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.http.MediaType;
|
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.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.io.InputStream;
|
||||||
import java.util.UUID;
|
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.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@Testcontainers
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class RecipesControllerTests {
|
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() {
|
private static InputStream getHal9000() {
|
||||||
return S3ImageServiceTests.class.getClassLoader().getResourceAsStream("HAL9000.svg");
|
return S3ImageServiceTests.class.getClassLoader().getResourceAsStream("HAL9000.svg");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.recipe.star;
|
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.Recipe;
|
||||||
import app.mealsmadeeasy.api.recipe.RecipeRepository;
|
import app.mealsmadeeasy.api.recipe.RecipeRepository;
|
||||||
import app.mealsmadeeasy.api.user.User;
|
import app.mealsmadeeasy.api.user.User;
|
||||||
@ -17,7 +17,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class RecipeStarRepositoryTests {
|
public class RecipeStarRepositoryTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.recipe.star;
|
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.Recipe;
|
||||||
import app.mealsmadeeasy.api.recipe.RecipeService;
|
import app.mealsmadeeasy.api.recipe.RecipeService;
|
||||||
import app.mealsmadeeasy.api.recipe.spec.RecipeCreateSpec;
|
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;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class RecipeStarServiceTests {
|
public class RecipeStarServiceTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@ -1,30 +1,26 @@
|
|||||||
package app.mealsmadeeasy.api.s3;
|
package app.mealsmadeeasy.api.s3;
|
||||||
|
|
||||||
|
import app.mealsmadeeasy.api.MinIOTestsExtension;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.testcontainers.containers.MinIOContainer;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@Testcontainers
|
|
||||||
public class MinioS3ManagerTests {
|
public class MinioS3ManagerTests {
|
||||||
|
|
||||||
@Container
|
@RegisterExtension
|
||||||
private static final MinIOContainer container = new MinIOContainer(
|
public static final MinIOTestsExtension minioTestsExtension = new MinIOTestsExtension();
|
||||||
DockerImageName.parse("minio/minio:latest")
|
|
||||||
);
|
|
||||||
|
|
||||||
private MinioS3Manager s3Manager;
|
private final MinioS3Manager s3Manager = new MinioS3Manager();
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void beforeEach() {
|
public void setup() {
|
||||||
this.s3Manager = new MinioS3Manager();
|
final MinIOContainer container = minioTestsExtension.getContainer();
|
||||||
this.s3Manager.setEndpoint(container.getS3URL());
|
this.s3Manager.setEndpoint(container.getS3URL());
|
||||||
this.s3Manager.setAccessKey(container.getUserName());
|
this.s3Manager.setAccessKey(container.getUserName());
|
||||||
this.s3Manager.setSecretKey(container.getPassword());
|
this.s3Manager.setSecretKey(container.getPassword());
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package app.mealsmadeeasy.api.signup;
|
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.UserCreateException.Type;
|
||||||
import app.mealsmadeeasy.api.user.UserService;
|
import app.mealsmadeeasy.api.user.UserService;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
@ -25,7 +25,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
@ExtendWith(IntegrationTestsExtension.class)
|
@ExtendWith(PostgresTestsExtension.class)
|
||||||
public class SignUpControllerTests {
|
public class SignUpControllerTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,10 +4,11 @@ import org.junit.jupiter.api.extension.BeforeAllCallback;
|
|||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
import org.testcontainers.containers.PostgreSQLContainer;
|
import org.testcontainers.containers.PostgreSQLContainer;
|
||||||
|
|
||||||
public class IntegrationTestsExtension implements BeforeAllCallback {
|
public class PostgresTestsExtension implements BeforeAllCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeAll(ExtensionContext context) {
|
public void beforeAll(ExtensionContext context) {
|
||||||
|
@SuppressWarnings("resource")
|
||||||
final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("pgvector/pgvector:pg18-trixie")
|
final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("pgvector/pgvector:pg18-trixie")
|
||||||
.withDatabaseName("meals_made_easy_api");
|
.withDatabaseName("meals_made_easy_api");
|
||||||
postgres.start();
|
postgres.start();
|
||||||
Loading…
Reference in New Issue
Block a user