Compare commits
2 commits
d9b9e2f815
...
dddc91bf4d
Author | SHA1 | Date | |
---|---|---|---|
dddc91bf4d | |||
0e9525cde4 |
5 changed files with 60 additions and 40 deletions
|
@ -65,6 +65,7 @@ dependencies {
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
testImplementation("org.springframework.security:spring-security-test")
|
||||||
testImplementation("org.testcontainers:junit-jupiter")
|
testImplementation("org.testcontainers:junit-jupiter")
|
||||||
testImplementation("org.testcontainers:postgresql")
|
testImplementation("org.testcontainers:postgresql")
|
||||||
|
testRuntimeOnly("com.h2database:h2")
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
|
|
||||||
//OAS
|
//OAS
|
||||||
|
@ -95,7 +96,6 @@ swaggerSources {
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
withType()
|
|
||||||
withType<Checkstyle> {
|
withType<Checkstyle> {
|
||||||
reports {
|
reports {
|
||||||
xml.required.set(true)
|
xml.required.set(true)
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
|
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
|
||||||
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
|
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
|
||||||
import org.springframework.security.web.session.HttpSessionEventPublisher;
|
import org.springframework.security.web.session.HttpSessionEventPublisher;
|
||||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
|
|
|
@ -1,26 +1,73 @@
|
||||||
package de.hmmh.pmt;
|
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.junit.jupiter.api.BeforeEach;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc(addFilters = false)
|
||||||
@ActiveProfiles("test")
|
@ActiveProfiles("test")
|
||||||
@ContextConfiguration(initializers = PostgresContextInitializer.class)
|
|
||||||
public abstract class IntegrationTest {
|
public abstract class IntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
protected final static String baseUri = "/api/v1";
|
||||||
protected MockMvc mockMvc;
|
|
||||||
|
|
||||||
//protected Repository repository;
|
@Autowired
|
||||||
|
protected MockMvc mvc;
|
||||||
|
//@Autowired
|
||||||
|
//protected ProjectRepository projectRepository;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
//repository.deleteAll();
|
//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);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,3 +1,5 @@
|
||||||
spring.datasource.url=set_by_test_containers
|
spring.datasource.url=jdbc:h2:mem:test_db
|
||||||
spring.datasource.username=set_by_test_containers
|
spring.datasource.username=test
|
||||||
spring.datasource.password=set_by_test_containers
|
spring.datasource.password=test
|
||||||
|
spring.datasource.driver-class-name=org.h2.Driver
|
||||||
|
spring.jpa.hibernate.ddl-auto=create-drop
|
||||||
|
|
Loading…
Reference in a new issue