Compare commits

..

No commits in common. "dddc91bf4d32b85dec59e23a258e207759b25b8d" and "d9b9e2f8158f34551e80bf3ccc493f0ce2f0d140" have entirely different histories.

5 changed files with 40 additions and 60 deletions

View file

@ -65,7 +65,6 @@ dependencies {
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:postgresql")
testRuntimeOnly("com.h2database:h2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
//OAS
@ -96,6 +95,7 @@ swaggerSources {
}
tasks {
withType()
withType<Checkstyle> {
reports {
xml.required.set(true)

View file

@ -11,6 +11,7 @@ import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
import org.springframework.security.web.session.HttpSessionEventPublisher;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@Configuration
@EnableWebSecurity

View file

@ -1,73 +1,26 @@
package de.hmmh.pmt;
//import de.hmmh.pmt.db.Project;
//import de.hmmh.pmt.db.ProjectRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
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.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import java.time.LocalDateTime;
@SpringBootTest
@AutoConfigureMockMvc(addFilters = false)
@AutoConfigureMockMvc
@ActiveProfiles("test")
@ContextConfiguration(initializers = PostgresContextInitializer.class)
public abstract class IntegrationTest {
protected final static String baseUri = "/api/v1";
@Autowired
protected MockMvc mvc;
//@Autowired
//protected ProjectRepository projectRepository;
protected MockMvc mockMvc;
//protected Repository repository;
@BeforeEach
void setUp() {
//projectRepository.deleteAll();
}
@AfterEach
void cleanUp() {
//projectRepository.deleteAll();
}
protected void createTestData() {
/*Project testProject1 = new Project(
0L,
"testName1",
"testGoaaaaaaaal!",
0L,
0L,
LocalDateTime.of(2001, 9, 11, 13, 34),
LocalDateTime.of(2002, 8, 13, 14, 34),
LocalDateTime.of(2003, 7, 12, 23, 34)
);
Project testProject2 = new Project(
0L,
"testName2",
"testGoaaaaaaaal!",
0L,
0L,
LocalDateTime.of(2009, 9, 11, 13, 34),
LocalDateTime.of(2009, 12, 13, 14, 34),
LocalDateTime.of(2010, 7, 12, 23, 34)
);
Project testProject3 = new Project(
0L,
"testName3",
"testGoaaaaaaaal!",
0L,
0L,
LocalDateTime.of(2010, 9, 11, 13, 34),
LocalDateTime.of(2012, 8, 13, 14, 34),
LocalDateTime.of(2013, 7, 12, 23, 34)
);
projectRepository.save(testProject1);
projectRepository.save(testProject2);
projectRepository.save(testProject3);
*/
//repository.deleteAll();
}
}

View file

@ -0,0 +1,28 @@
package de.hmmh.pmt;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;
public class PostgresContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(
DockerImageName.parse("postgres:16")
)
.withDatabaseName("test_db")
.withUsername("test-db-user")
.withPassword("test-db-password")
.withReuse(true);
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
postgres.start();
TestPropertyValues.of(
"spring.datasource.url=" + postgres.getJdbcUrl(),
"spring.datasource.username=" + postgres.getUsername(),
"spring.datasource.password=" + postgres.getPassword()
).applyTo(configurableApplicationContext.getEnvironment());
}
}

View file

@ -1,5 +1,3 @@
spring.datasource.url=jdbc:h2:mem:test_db
spring.datasource.username=test
spring.datasource.password=test
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=set_by_test_containers
spring.datasource.username=set_by_test_containers
spring.datasource.password=set_by_test_containers