Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-emilius committed Oct 29, 2024
1 parent 1c18dd9 commit 0c97dee
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 153 deletions.
3 changes: 3 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ dependencies {

test {
useJUnitPlatform()

maxParallelForks = 1
forkEvery = 0
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package thesistrack.ls1.controller;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import thesistrack.ls1.constants.ApplicationState;
import thesistrack.ls1.controller.payload.AcceptApplicationPayload;
import thesistrack.ls1.controller.payload.CreateApplicationPayload;
Expand All @@ -16,7 +23,32 @@

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@Testcontainers
class ApplicationControllerTest extends BaseIntegrationTest {
@Container
static PostgreSQLContainer<?> dbContainer = new PostgreSQLContainer<>(
"postgres:16-alpine"
);

@BeforeAll
static void startDatabase() {
dbContainer.start();
}

@AfterAll
static void stopDatabase() {
dbContainer.stop();
}

@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
dbContainer.start();

registry.add("spring.datasource.url", dbContainer::getJdbcUrl);
registry.add("spring.datasource.username", dbContainer::getUsername);
registry.add("spring.datasource.password", dbContainer::getPassword);
}

@Test
void createApplication_Success() throws Exception {
CreateApplicationPayload payload = new CreateApplicationPayload(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package thesistrack.ls1.controller;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
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.request.MockMvcRequestBuilders;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import thesistrack.ls1.constants.*;
import thesistrack.ls1.controller.payload.*;
import thesistrack.ls1.mock.BaseIntegrationTest;
Expand All @@ -16,7 +19,32 @@
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@Testcontainers
class ThesisControllerTest extends BaseIntegrationTest {
@Container
static PostgreSQLContainer<?> dbContainer = new PostgreSQLContainer<>(
"postgres:16-alpine"
);

@BeforeAll
static void startDatabase() {
dbContainer.start();
}

@AfterAll
static void stopDatabase() {
dbContainer.stop();
}

@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
dbContainer.start();

registry.add("spring.datasource.url", dbContainer::getJdbcUrl);
registry.add("spring.datasource.username", dbContainer::getUsername);
registry.add("spring.datasource.password", dbContainer::getPassword);
}

@Nested
class ThesisBasicOperations {
@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package thesistrack.ls1.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import thesistrack.ls1.constants.ApplicationRejectReason;
import thesistrack.ls1.controller.payload.CloseTopicPayload;
import thesistrack.ls1.controller.payload.ReplaceTopicPayload;
Expand All @@ -17,7 +24,32 @@
import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@Testcontainers
class TopicControllerTest extends BaseIntegrationTest {
@Container
static PostgreSQLContainer<?> dbContainer = new PostgreSQLContainer<>(
"postgres:16-alpine"
);

@BeforeAll
static void startDatabase() {
dbContainer.start();
}

@AfterAll
static void stopDatabase() {
dbContainer.stop();
}

@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
dbContainer.start();

registry.add("spring.datasource.url", dbContainer::getJdbcUrl);
registry.add("spring.datasource.username", dbContainer::getUsername);
registry.add("spring.datasource.password", dbContainer::getPassword);
}

@Test
void getTopics_Success() throws Exception {
createTestTopic("Test Topic");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
package thesistrack.ls1.controller;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import thesistrack.ls1.mock.BaseIntegrationTest;

import java.util.List;

import static org.hamcrest.Matchers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@Testcontainers
public class UserControllerTest extends BaseIntegrationTest {
@Container
static PostgreSQLContainer<?> dbContainer = new PostgreSQLContainer<>(
"postgres:16-alpine"
);

@BeforeAll
static void startDatabase() {
dbContainer.start();
}

@AfterAll
static void stopDatabase() {
dbContainer.stop();
}

@DynamicPropertySource
static void configureProperties(DynamicPropertyRegistry registry) {
dbContainer.start();

registry.add("spring.datasource.url", dbContainer::getJdbcUrl);
registry.add("spring.datasource.username", dbContainer::getUsername);
registry.add("spring.datasource.password", dbContainer::getPassword);
}

@Test
void getUsers_AsAdmin_Success() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/v2/users")
Expand Down
Loading

0 comments on commit 0c97dee

Please sign in to comment.