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); } }