chore: Initial import of FLEX training material

This commit is contained in:
Alexander Kobjolke 2024-11-07 21:02:53 +01:00
parent c01246d4f7
commit 12235acc42
1020 changed files with 53940 additions and 0 deletions

View file

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed</artifactId>
<version>2024.3.0</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<artifactId>flexinale-distributed-testdata</artifactId>
<version>2024.3.0</version>
<name>Flexinale Distributed Testdata - cleaning and loading</name>
<description>Flexinale - FLEX case-study &quot;film festival&quot;, distributed services - testdata cleaning and loading</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${apache-poi.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${apache-poi.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-besucherportal</artifactId>
<version>2024.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-common</artifactId>
<version>2024.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-common</artifactId>
<version>2024.3.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-security</artifactId>
<version>2024.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-security_api_contract</artifactId>
<version>2024.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-backoffice</artifactId>
<version>2024.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-backoffice_api_contract</artifactId>
<version>2024.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-ticketing</artifactId>
<version>2024.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.accso</groupId>
<artifactId>flexinale-distributed-ticketing_api_contract</artifactId>
<version>2024.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<plugins>
<plugin>
<groupId>com.h3xstream.findsecbugs</groupId>
<artifactId>findsecbugs-plugin</artifactId>
<version>${findsecbugs-maven-plugin.version}</version>
</plugin>
</plugins>
</configuration>
<dependencies>
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotbugs.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,18 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - clean all Kafka topics" type="JUnit" factoryName="JUnit" folderName="Testdata Distributed">
<module name="flexinale-distributed-testdata" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="testdata.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="testdata" />
<option name="MAIN_CLASS_NAME" value="testdata.KafkaTopicCleaner" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View file

@ -0,0 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - clean all data from database and Kafka topics" type="CompoundRunConfigurationType">
<toRun name="Distributed - clean all Kafka topics" type="JUnit" />
<toRun name="Distributed - delete all data from database" type="JUnit" />
<method v="2" />
</configuration>
</component>

View file

@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - delete Benutzer data" type="JUnit" factoryName="JUnit" folderName="Testdata Distributed">
<module name="flexinale-distributed-testdata" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="testdata.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="testdata" />
<option name="MAIN_CLASS_NAME" value="testdata.BenutzerDatabaseCleaner" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea -Dspring.jpa.hibernate.ddl-auto=create" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View file

@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - delete Film, Kino, KinoSaal, Vorfuehrung data" type="JUnit" factoryName="JUnit" folderName="Testdata Distributed">
<module name="flexinale-distributed-testdata" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="testdata.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="testdata" />
<option name="MAIN_CLASS_NAME" value="testdata.FKKsVDatabaseCleaner" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea -Dspring.jpa.hibernate.ddl-auto=create" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View file

@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - delete Ticket and Kontingente data" type="JUnit" factoryName="JUnit" folderName="Testdata Distributed">
<module name="flexinale-distributed-testdata" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="testdata.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="testdata" />
<option name="MAIN_CLASS_NAME" value="testdata.TicketsAndKontingenteDatabaseCleaner" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea -Dspring.jpa.hibernate.ddl-auto=create" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View file

@ -0,0 +1,18 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - delete all data from database" type="JUnit" factoryName="JUnit" folderName="Testdata Distributed">
<module name="flexinale-distributed-testdata" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="testdata.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="testdata" />
<option name="MAIN_CLASS_NAME" value="testdata.AllDatabaseCleaner" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View file

@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - load Benutzer data" type="JUnit" factoryName="JUnit" folderName="Testdata Distributed">
<module name="flexinale-distributed-testdata" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="testdata.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="testdata" />
<option name="MAIN_CLASS_NAME" value="testdata.BenutzerTestDataLoader" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View file

@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - load Film, Kino, KinoSaal, Vorfuehrung data" type="JUnit" factoryName="JUnit" folderName="Testdata Distributed">
<module name="flexinale-distributed-testdata" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="testdata.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="testdata" />
<option name="MAIN_CLASS_NAME" value="testdata.FKKsVTestDataLoader" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="-ea" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View file

@ -0,0 +1,18 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed - load all data to database" type="JUnit" factoryName="JUnit" folderName="Testdata Distributed">
<module name="flexinale-distributed-testdata" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="testdata.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="testdata" />
<option name="MAIN_CLASS_NAME" value="testdata.AllTestDataLoader" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View file

@ -0,0 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed Backoffice - REST upload to add and update filme" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" folderName="REST upload Distributed" path="$PROJECT_DIR$/flexinale-distributed/flexinale-distributed-testdata/src/test/curl/rest-post-upload-to-add-and-update-filme.http" requestIdentifier="#1">
<method v="2" />
</configuration>
</component>

View file

@ -0,0 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed Backoffice - REST upload to add and update kinos" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" folderName="REST upload Distributed" path="$PROJECT_DIR$/flexinale-distributed/flexinale-distributed-testdata/src/test/curl/rest-post-upload-to-add-and-update-kinos.http" requestIdentifier="#1">
<method v="2" />
</configuration>
</component>

View file

@ -0,0 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Distributed Backoffice - REST upload to add and update vorfuehrungen" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" folderName="REST upload Distributed" path="$PROJECT_DIR$/flexinale-distributed/flexinale-distributed-testdata/src/test/curl/rest-post-upload-to-add-and-update-vorfuehrungen.http" requestIdentifier="#1">
<method v="2" />
</configuration>
</component>

View file

@ -0,0 +1,10 @@
# curl -v -X POST -u admin:admin1 -F file=@TestdataFilmKinoKinoSaalVorfuehrung.xlsx http://localhost:8081/rest/filme
POST http://localhost:8081/rest/filme
Authorization: Basic admin admin1
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="../resources/testdata/TestdataFilmKinoKinoSaalVorfuehrung.xlsx"
< ../resources/testdata/TestDataFilmKinoKinoSaalVorfuehrung.xlsx
--WebAppBoundary--

View file

@ -0,0 +1,10 @@
# curl -v -X POST -u admin:admin1 -F file=@TestdataFilmKinoKinoSaalVorfuehrung.xlsx http://localhost:8081/rest/kinos
POST http://localhost:8081/rest/kinos
Authorization: Basic admin admin1
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="../resources/testdata/TestdataFilmKinoKinoSaalVorfuehrung.xlsx"
< ../resources/testdata/TestDataFilmKinoKinoSaalVorfuehrung.xlsx
--WebAppBoundary--

View file

@ -0,0 +1,10 @@
# curl -v -X POST -u admin:admin1 -F file=@TestdataFilmKinoKinoSaalVorfuehrung.xlsx http://localhost:8081/rest/vorfuehrungen
POST http://localhost:8081/rest/vorfuehrungen
Authorization: Basic admin admin1
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="file"; filename="../resources/testdata/TestdataFilmKinoKinoSaalVorfuehrung.xlsx"
< ../resources/testdata/TestDataFilmKinoKinoSaalVorfuehrung.xlsx
--WebAppBoundary--

View file

@ -0,0 +1,21 @@
package de.accso.flexinale;
import jakarta.persistence.EntityManagerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
@SpringBootApplication
public class FlexinaleDistributedApplicationTestdata {
public static void main(String[] args) {
SpringApplication.run(FlexinaleDistributedApplicationTestdata.class, args);
}
@Bean
public PlatformTransactionManager transactionManager(final EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}

View file

@ -0,0 +1,119 @@
package testdata;
import de.accso.flexinale.FlexinaleDistributedApplicationTestdata;
import de.accso.flexinale.backoffice.domain.dao.FilmDao;
import de.accso.flexinale.backoffice.domain.dao.KinoDao;
import de.accso.flexinale.backoffice.domain.dao.VorfuehrungDao;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import de.accso.flexinale.security.infrastructure.persistence.BenutzerDao;
import de.accso.flexinale.ticketing.domain.dao.KontingentDao;
import de.accso.flexinale.ticketing.domain.dao.TicketDao;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import static testdata.DatabaseConfig.*;
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
class AllDatabaseCleaner {
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-backoffice" })
public class AllDatabaseCleanerForBackoffice {
@Autowired
private KinoDao kinoDao;
@Autowired
private FilmDao filmDao;
@Autowired
private VorfuehrungDao vorfuehrungDao;
@Autowired
private BenutzerDao benutzerDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseBackoffice);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Create);
}
@Test
public void deleteAllFilmeAndKinosAndVorfuehrungenFromDatabase() {
// as we set the spring.jpa.hibernate.ddl-auto to create, the data is already cleaned,
// hence the following call is actually useless
FKKsVDatabaseCleaner.internal_deleteAllFilmeAndKinosAndVorfuehrungenFromDatabase(
kinoDao, filmDao, vorfuehrungDao);
}
@Test
public void deleteAllBenutzerFromDatabase() {
// as we set the spring.jpa.hibernate.ddl-auto to create, the data is already cleaned,
// hence the following call is actually useless
BenutzerDatabaseCleaner.internal_deleteAllBenutzerFromDatabase(
benutzerDao);
}
}
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-besucherportal" })
public class AllDatabaseCleanerForBesucherportal {
@Autowired
private BenutzerDao benutzerDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseBesucherportal);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Create);
}
@Test
public void deleteAllBenutzerFromDatabase() {
// as we set the spring.jpa.hibernate.ddl-auto to create, the data is already cleaned,
// hence the following call is atually useless
BenutzerDatabaseCleaner.internal_deleteAllBenutzerFromDatabase(
benutzerDao);
}
}
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-ticketing" })
public class AllDatabaseCleanerForTicketing {
@Autowired
private TicketDao ticketDao;
@Autowired
private KontingentDao kontingentDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseTicketing);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Create);
}
@Test
public void deleteAllTicketsAndKontingenteFromDatabase() {
// as we set the spring.jpa.hibernate.ddl-auto to create, the data is already cleaned,
// hence the following call is atually useless
TicketsAndKontingenteDatabaseCleaner.internal_deleteAllTicketsAndKontingenteFromDatabase(
ticketDao, kontingentDao);
}
}
}

View file

@ -0,0 +1,109 @@
package testdata;
import de.accso.flexinale.FlexinaleDistributedApplicationTestdata;
import de.accso.flexinale.backoffice.application.services.FilmUploadService;
import de.accso.flexinale.backoffice.application.services.KinoUploadService;
import de.accso.flexinale.backoffice.application.services.KinoSaalUploadService;
import de.accso.flexinale.backoffice.application.services.VorfuehrungUploadService;
import de.accso.flexinale.backoffice.domain.dao.FilmDao;
import de.accso.flexinale.backoffice.domain.dao.KinoDao;
import de.accso.flexinale.backoffice.domain.dao.VorfuehrungDao;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import de.accso.flexinale.security.infrastructure.persistence.BenutzerDao;
import de.accso.flexinale.security.infrastructure.persistence.BenutzerUploadService;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import java.io.IOException;
import static testdata.DatabaseConfig.*;
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
class AllTestDataLoader {
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-backoffice" })
public class AllDatabaseLoaderForBackoffice {
@Autowired
private KinoUploadService kinoUploadService;
@Autowired
private KinoSaalUploadService kinoSaalUploadService;
@Autowired
private FilmUploadService filmUploadService;
@Autowired
private VorfuehrungUploadService vorfuehrungUploadService;
@Autowired
private KinoDao kinoDao;
@Autowired
private FilmDao filmDao;
@Autowired
private VorfuehrungDao vorfuehrungDao;
@Autowired
private BenutzerUploadService benutzerDataLoader;
@Autowired
private BenutzerDao benutzerDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseBackoffice);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Update);
}
@Test
public void loadAllBenutzerAndFilmeAndKinosAndVorfuehrungenToDatabase() throws IOException {
FKKsVTestDataLoader.internal_loadFilmeTestDataAndPersistToDatabase(
filmUploadService, filmDao);
FKKsVTestDataLoader.internal_loadKinosAndKinoSaeleTestDataAndPersistToDatabase(
kinoSaalUploadService, kinoUploadService, kinoDao);
FKKsVTestDataLoader.internal_loadVorfuehrungenTestDataAndPersistToDatabase(
vorfuehrungUploadService, vorfuehrungDao);
}
@Test
public void loadAllBenutzerToDatabase() throws IOException {
BenutzerTestDataLoader.internal_loadBenutzerTestDataAndPersistToDatabase(
benutzerDataLoader, benutzerDao);
}
}
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-besucherportal" })
public class AllDatabaseLoaderForBesucherportal {
@Autowired
private BenutzerUploadService benutzerDataLoader;
@Autowired
private BenutzerDao benutzerDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseBesucherportal);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Update);
}
@Test
public void loadAllBenutzerToDatabase() throws IOException {
BenutzerTestDataLoader.internal_loadBenutzerTestDataAndPersistToDatabase(
benutzerDataLoader, benutzerDao);
}
}
}

View file

@ -0,0 +1,64 @@
package testdata;
import de.accso.flexinale.FlexinaleDistributedApplicationTestdata;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import de.accso.flexinale.security.infrastructure.persistence.BenutzerDao;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import static testdata.DatabaseConfig.*;
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
class BenutzerDatabaseCleaner {
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-backoffice" })
public class BenutzerDatabaseCleanerForBackoffice {
@Autowired
private BenutzerDao benutzerDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseBackoffice);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Update);
}
@Test
public void deleteAllBenutzerFromDatabase() {
internal_deleteAllBenutzerFromDatabase(benutzerDao);
}
}
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-besucherportal" })
public class BenutzerDatabaseCleanerForBesucherportal {
@Autowired
private BenutzerDao benutzerDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseBesucherportal);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Update);
}
@Test
public void deleteAllBenutzerFromDatabase() {
internal_deleteAllBenutzerFromDatabase(benutzerDao);
}
}
static void internal_deleteAllBenutzerFromDatabase(final BenutzerDao benutzerDao) {
benutzerDao.deleteAll();
}
}

View file

@ -0,0 +1,84 @@
package testdata;
import de.accso.flexinale.FlexinaleDistributedApplicationTestdata;
import de.accso.flexinale.common.application.PersistMode;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import de.accso.flexinale.security.infrastructure.persistence.BenutzerDao;
import de.accso.flexinale.security.infrastructure.persistence.BenutzerUploadService;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
import static testdata.DatabaseConfig.*;
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
public class BenutzerTestDataLoader {
private static final String xlsDataFile = "/testdata/TestDataBenutzer.xlsx";
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-backoffice" })
public class BenutzerTestDataLoaderForBackoffice {
@Autowired
private BenutzerUploadService benutzerUploadService;
@Autowired
private BenutzerDao benutzerDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseBackoffice);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Update);
}
@Test
public void loadBenutzerTestDataAndPersistToDatabase() throws IOException {
internal_loadBenutzerTestDataAndPersistToDatabase(benutzerUploadService, benutzerDao);
}
}
@Nested
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ActiveProfiles({ "testdata", "testdata-besucherportal" })
public class BenutzerTestDataLoaderForBesucherportal {
@Autowired
private BenutzerUploadService benutzerUploadService;
@Autowired
private BenutzerDao benutzerDao;
@DynamicPropertySource // @TestPropertySource would work as well
static void registerDynamicProperties(DynamicPropertyRegistry registry) {
registry.add(dataBaseUrlKey, () -> databaseBesucherportal);
registry.add(dataBaseDDLAutoKey, () -> dataBaseDDLAuto_Update);
}
@Test
public void loadBenutzerTestDataAndPersistToDatabase() throws IOException {
internal_loadBenutzerTestDataAndPersistToDatabase(benutzerUploadService, benutzerDao);
}
}
static void internal_loadBenutzerTestDataAndPersistToDatabase(final BenutzerUploadService benutzerUploadService,
final BenutzerDao benutzerDao) throws IOException {
// arrange
// act
int numPersistedBesucher = benutzerUploadService.
loadDataFromExcelSheetAndPersist(xlsDataFile, PersistMode.UPDATE);
// assert
assertThat(benutzerDao.findAll()).hasSizeGreaterThanOrEqualTo(11);
assertThat(numPersistedBesucher).isEqualTo(11);
}
}

View file

@ -0,0 +1,12 @@
package testdata;
public final class DatabaseConfig {
public static final String dataBaseUrlKey = "spring.datasource.url";
public static final String databaseBackoffice = "jdbc:postgresql://127.0.0.1:5432/distributed-backoffice";
public static final String databaseBesucherportal = "jdbc:postgresql://127.0.0.1:5432/distributed-besucherportal";
public static final String databaseTicketing = "jdbc:postgresql://127.0.0.1:5432/distributed-ticketing";
public static final String dataBaseDDLAutoKey = "spring.jpa.hibernate.ddl-auto";
public static final String dataBaseDDLAuto_Create = "create";
public static final String dataBaseDDLAuto_Update = "update";
}

View file

@ -0,0 +1,49 @@
package testdata;
import de.accso.flexinale.FlexinaleDistributedApplicationTestdata;
import de.accso.flexinale.backoffice.domain.dao.FilmDao;
import de.accso.flexinale.backoffice.domain.dao.KinoDao;
import de.accso.flexinale.backoffice.domain.dao.VorfuehrungDao;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import static testdata.DatabaseConfig.*;
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@TestPropertySource(properties = {
dataBaseUrlKey + " = " + databaseBackoffice,
dataBaseDDLAutoKey + " = " + dataBaseDDLAuto_Update
})
@ActiveProfiles({ "testdata", "testdata-backoffice" })
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
class FKKsVDatabaseCleaner {
@Autowired
private KinoDao kinoDao;
@Autowired
private FilmDao filmDao;
@Autowired
private VorfuehrungDao vorfuehrungDao;
@Test
void deleteAllFilmeAndKinosAndVorfuehrungenFromDatabase() {
internal_deleteAllFilmeAndKinosAndVorfuehrungenFromDatabase(kinoDao, filmDao, vorfuehrungDao);
}
static void internal_deleteAllFilmeAndKinosAndVorfuehrungenFromDatabase(final KinoDao kinoDao,
final FilmDao filmDao,
final VorfuehrungDao vorfuehrungDao) {
vorfuehrungDao.deleteAll();
filmDao.deleteAll();
kinoDao.deleteAll();
}
}

View file

@ -0,0 +1,137 @@
package testdata;
import de.accso.flexinale.FlexinaleDistributedApplicationTestdata;
import de.accso.flexinale.backoffice.application.services.FilmUploadService;
import de.accso.flexinale.backoffice.application.services.KinoUploadService;
import de.accso.flexinale.backoffice.application.services.KinoSaalUploadService;
import de.accso.flexinale.backoffice.application.services.VorfuehrungUploadService;
import de.accso.flexinale.backoffice.domain.dao.FilmDao;
import de.accso.flexinale.backoffice.domain.dao.KinoDao;
import de.accso.flexinale.backoffice.domain.dao.VorfuehrungDao;
import de.accso.flexinale.backoffice.domain.model.Kino;
import de.accso.flexinale.backoffice.domain.model.KinoSaal;
import de.accso.flexinale.common.application.PersistMode;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import de.accso.flexinale.common.shared_kernel.Identifiable;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
import static testdata.DatabaseConfig.*;
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@TestPropertySource(properties = {
dataBaseUrlKey + " = " + databaseBackoffice,
dataBaseDDLAutoKey + " = " + dataBaseDDLAuto_Update
})
@ActiveProfiles({ "testdata", "testdata-backoffice" })
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
public class FKKsVTestDataLoader {
private static final String xlsDataFile = "/testdata/TestDataFilmKinoKinoSaalVorfuehrung.xlsx";
@Autowired
private KinoUploadService kinoUploadService;
@Autowired
private KinoSaalUploadService kinoSaalUploadService;
@Autowired
private FilmUploadService filmUploadService;
@Autowired
private VorfuehrungUploadService vorfuehrungUploadService;
@Autowired
private KinoDao kinoDao;
@Autowired
private FilmDao filmDao;
@Autowired
private VorfuehrungDao vorfuehrungDao;
@Test
void loadFilmeAndKinosAndVorfuehrungenTestDataAndPersistToDatabase() throws IOException {
// Loading: order is important because of foreign key relations
internal_loadFilmeTestDataAndPersistToDatabase(filmUploadService, filmDao);
internal_loadKinosAndKinoSaeleTestDataAndPersistToDatabase(kinoSaalUploadService, kinoUploadService, kinoDao);
internal_loadVorfuehrungenTestDataAndPersistToDatabase(vorfuehrungUploadService, vorfuehrungDao);
}
static void internal_loadFilmeTestDataAndPersistToDatabase(final FilmUploadService filmUploadService, final FilmDao filmDao) throws IOException {
// arrange
// act
int numPersistedFilms = filmUploadService.
loadDataFromExcelSheetAndPersist(xlsDataFile, PersistMode.UPDATE);
// assert
assertThat(filmDao.findAll()).hasSize(26);
assertThat(numPersistedFilms).isEqualTo(26);
}
static void internal_loadKinosAndKinoSaeleTestDataAndPersistToDatabase(final KinoSaalUploadService kinoSaalUploadService, final KinoUploadService kinoUploadService, final KinoDao kinoDao) throws IOException {
// arrange
// act
Collection<KinoSaal> kinoSaele = kinoSaalUploadService.loadDataFromExcelSheet(xlsDataFile);
Map<Identifiable.Id, Collection<KinoSaal>> alleKinosUndIhreSaele = kinoSaalUploadService.mapKinoSaeleToKino(kinoSaele);
// assert
assertThat(alleKinosUndIhreSaele.keySet()).hasSize(10);
alleKinosUndIhreSaele.keySet().forEach(kinoId -> {
Collection<KinoSaal> saeleImKino = alleKinosUndIhreSaele.get(kinoId);
assertThat(saeleImKino).hasSize(2);
saeleImKino.forEach(kinoSaal -> assertThat(kinoSaal.anzahlPlaetze.raw()).isBetween(10, 100));
});
// arrange
// act
kinoUploadService.beforeLoad(alleKinosUndIhreSaele);
int numPersistedKinos = kinoUploadService.
loadDataFromExcelSheetAndPersist(xlsDataFile, PersistMode.UPDATE);
// assert
assertThat(numPersistedKinos).isEqualTo(10);
List<Kino> alleKinos = kinoDao.findAll();
assertThat(alleKinos).hasSizeGreaterThanOrEqualTo(10);
assertThat(alleKinos.size()).isGreaterThanOrEqualTo(numPersistedKinos);
for (Identifiable.Id kinoId: alleKinosUndIhreSaele.keySet()) {
Optional<Kino> optionalKino = kinoDao.findById(kinoId);
assertThat(optionalKino.isEmpty()).isFalse();
assertThat(optionalKino.get().kinoSaele).hasSize(2);
}
}
static void internal_loadVorfuehrungenTestDataAndPersistToDatabase(final VorfuehrungUploadService vorfuehrungUploadService,
final VorfuehrungDao vorfuehrungDao) throws IOException {
// arrange
// act
// load all vorfuehrungen
vorfuehrungUploadService.loadDataFromExcelSheet(xlsDataFile);
// Mind that we do intentionally not persist kontingents in this step! This is done by the ticketing application
// when backoffice publishes all of its vorfuehrungen.
int numPersistedVorfuehrungen = vorfuehrungUploadService.
loadDataFromExcelSheetAndPersist(xlsDataFile, PersistMode.UPDATE);
// assert
assertThat(vorfuehrungDao.findAll()).hasSize(52);
assertThat(numPersistedVorfuehrungen).isEqualTo(52);
}
}

View file

@ -0,0 +1,26 @@
package testdata;
import de.accso.flexinale.common.infrastructure.eventbus.KafkaAvailabilityChecker;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import static de.accso.flexinale.common.infrastructure.eventbus.KafkaTopicHelper.deleteKafkaTopicsWithPrefixAndSuffix;
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
@Disabled("needs Kafka and hence only to be called manually and explicitely")
class KafkaTopicCleaner {
private static final Logger LOGGER = LoggerFactory.getLogger(KafkaTopicCleaner.class);
@Test
void deleteAllFlexinaleKafkaTopics() throws ExecutionException, TimeoutException {
new KafkaAvailabilityChecker().isKafkaAvailable();
deleteKafkaTopicsWithPrefixAndSuffix("de.accso.flexinale", "");
}
}

View file

@ -0,0 +1,43 @@
package testdata;
import de.accso.flexinale.FlexinaleDistributedApplicationTestdata;
import de.accso.flexinale.common.shared_kernel.DoNotCheckInArchitectureTests;
import de.accso.flexinale.ticketing.domain.dao.KontingentDao;
import de.accso.flexinale.ticketing.domain.dao.TicketDao;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import static testdata.DatabaseConfig.*;
@SpringBootTest(classes = {FlexinaleDistributedApplicationTestdata.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@TestPropertySource(properties = {
dataBaseUrlKey + " = " + databaseTicketing,
dataBaseDDLAutoKey + " = " + dataBaseDDLAuto_Update
})
@ActiveProfiles({ "testdata", "testdata-ticketing" })
@DoNotCheckInArchitectureTests
@SuppressWarnings("NewClassNamingConvention")
class TicketsAndKontingenteDatabaseCleaner {
@Autowired
private TicketDao ticketDao;
@Autowired
private KontingentDao kontingentDao;
@Test
void deleteAllTicketsAndKontingenteFromDatabase() {
internal_deleteAllTicketsAndKontingenteFromDatabase(ticketDao, kontingentDao);
}
static void internal_deleteAllTicketsAndKontingenteFromDatabase(final TicketDao ticketDao,
final KontingentDao kontingentDao) {
ticketDao.deleteAll();
kontingentDao.deleteAll();
}
}

View file

@ -0,0 +1,40 @@
application.title=FLEXinale as Distributed Services, Test
application.version=test
spring.banner.location=classpath:/flexinale-banner.txt
#########################################################################
# For endpoint /version
#########################################################################
build.version=@pom.version@
build.date=@maven.build.timestamp@
#########################################################################
# Persistence
#########################################################################
# spring.datasource.url will be set dynamically, hence not here
# spring.jpa.hibernate.ddl-auto will be set dynamically, hence not here
spring.datasource.name=flexinale
spring.datasource.username=flexinale
spring.datasource.password=flexinale
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database=postgresql
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
# spring.jpa.show-sql=true
server.port=9093
#########################################################################
# Web
#########################################################################
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
server.error.path=/error
#########################################################################
# flexinale properties
#########################################################################
# Quote for online kontingent in percent
de.accso.flexinale.kontingent.quote.online=33
# time in minutes
de.accso.flexinale.vorfuehrung.min-zeit-zwischen-vorfuehrungen-in-minuten=30

View file

@ -0,0 +1,21 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{YYYYMMdd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.springframework.orm.jpa" level="INFO"/>
<logger name="org.springframework.boot.autoconfigure.domain.EntityScan" level="INFO"/>
<logger name="org.apache.kafka" level="WARN"/>
<logger name="org.apache.kafka.clients.admin.AdminClient" level="INFO"/>
<logger name="org.apache.kafka.clients.consumer.ConsumerConfig" level="INFO"/>
<logger name="org.apache.kafka.clients.producer.ProducerConfig" level="INFO"/>
<logger name="de.accso" level="WARN"/>
<logger name="testdata" level="INFO"/>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>