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.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
@ -96,6 +95,7 @@ swaggerSources {
} }
tasks { tasks {
withType()
withType<Checkstyle> { withType<Checkstyle> {
reports { reports {
xml.required.set(true) 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.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

View file

@ -1,73 +1,26 @@
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(addFilters = false) @AutoConfigureMockMvc
@ActiveProfiles("test") @ActiveProfiles("test")
@ContextConfiguration(initializers = PostgresContextInitializer.class)
public abstract class IntegrationTest { public abstract class IntegrationTest {
protected final static String baseUri = "/api/v1";
@Autowired @Autowired
protected MockMvc mvc; protected MockMvc mockMvc;
//@Autowired
//protected ProjectRepository projectRepository; //protected Repository repository;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
//projectRepository.deleteAll(); //repository.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);
*/
} }
} }

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.url=set_by_test_containers
spring.datasource.username=test spring.datasource.username=set_by_test_containers
spring.datasource.password=test spring.datasource.password=set_by_test_containers
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=create-drop