testDataPopulators = new ArrayList<>();
+
@Inject
private UserService userService;
@@ -101,6 +104,9 @@ public class DataInitializer implements Lifecycle {
@Override
public void start() {
if (profile.getCurrentProfile() == Profiles.DEV && noUsers()) {
+ for (TestDataPopulator testDataPopulator : testDataPopulators) {
+ testDataPopulator.populate(this, this);
+ }
createDefaultProjectTypesIfNotDone();
createDefaultChecklistCategoriesIfNotDone();
createApplicationPeriodIfNotDone();
@@ -1958,6 +1964,36 @@ public class DataInitializer implements Lifecycle {
return entity;
}
+ @Override
+ public ProjectType bachelor() {
+ return bachelorClass;
+ }
+
+ @Override
+ public ProjectType magister() {
+ return magisterClass;
+ }
+
+ @Override
+ public ProjectType master() {
+ return masterClass;
+ }
+
+ @Override
+ public User createAuthor(String firstName) {
+ return createStudent(firstName);
+ }
+
+ @Override
+ public User createSupervisor(String firstName) {
+ return createEmployee(firstName);
+ }
+
+ @Override
+ public User createReviewer(String firstName) {
+ return createEmployee(firstName);
+ }
+
private static final class SimpleTextFile implements FileUpload {
private final User uploader;
diff --git a/test-data/src/main/java/se/su/dsv/scipro/testdata/Factory.java b/test-data/src/main/java/se/su/dsv/scipro/testdata/Factory.java
new file mode 100644
index 0000000000..4a9ae43a77
--- /dev/null
+++ b/test-data/src/main/java/se/su/dsv/scipro/testdata/Factory.java
@@ -0,0 +1,12 @@
+package se.su.dsv.scipro.testdata;
+
+import se.su.dsv.scipro.system.User;
+
+/**
+ * A factory to help with repetitive tasks when populating test data.
+ */
+public interface Factory {
+ User createAuthor(String firstName);
+ User createSupervisor(String firstName);
+ User createReviewer(String firstName);
+}
diff --git a/test-data/src/main/java/se/su/dsv/scipro/testdata/TestDataConfiguration.java b/test-data/src/main/java/se/su/dsv/scipro/testdata/TestDataConfiguration.java
new file mode 100644
index 0000000000..ffd372628b
--- /dev/null
+++ b/test-data/src/main/java/se/su/dsv/scipro/testdata/TestDataConfiguration.java
@@ -0,0 +1,16 @@
+package se.su.dsv.scipro.testdata;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import se.su.dsv.scipro.war.PluginConfiguration;
+
+@Configuration(proxyBeanMethods = false)
+@ComponentScan(basePackages = "se.su.dsv.scipro.testdata.populators")
+public class TestDataConfiguration implements PluginConfiguration {
+
+ @Bean
+ public DataInitializer dataInitializer() {
+ return new DataInitializer();
+ }
+}
diff --git a/test-data/src/main/java/se/su/dsv/scipro/testdata/TestDataPopulator.java b/test-data/src/main/java/se/su/dsv/scipro/testdata/TestDataPopulator.java
new file mode 100644
index 0000000000..41d250ac71
--- /dev/null
+++ b/test-data/src/main/java/se/su/dsv/scipro/testdata/TestDataPopulator.java
@@ -0,0 +1,11 @@
+package se.su.dsv.scipro.testdata;
+
+public interface TestDataPopulator {
+ /**
+ * Add test data to the system to help with testing a specific feature.
+ *
+ * @param baseData the base data already populated
+ * @param factory helper object to make repetitive tasks easier (such as creating users)
+ */
+ void populate(BaseData baseData, Factory factory);
+}
diff --git a/test-data/src/main/java/se/su/dsv/scipro/testdata/package-info.java b/test-data/src/main/java/se/su/dsv/scipro/testdata/package-info.java
new file mode 100644
index 0000000000..6b93353f29
--- /dev/null
+++ b/test-data/src/main/java/se/su/dsv/scipro/testdata/package-info.java
@@ -0,0 +1,8 @@
+/**
+ * This package contains the infrastructure that is used when generating test data for the application. To add new test
+ * data to the system, add a new class to the {@link se.su.dsv.scipro.testdata.populators} package that implements the
+ * {@link se.su.dsv.scipro.testdata.TestDataPopulator} interface and annotate it with
+ * {@link org.springframework.stereotype.Service @Service}. Inject dependencies as needed using
+ * {@link jakarta.inject.Inject @Inject}.
+ */
+package se.su.dsv.scipro.testdata;
diff --git a/test-data/src/main/java/se/su/dsv/scipro/testdata/populators/package-info.java b/test-data/src/main/java/se/su/dsv/scipro/testdata/populators/package-info.java
new file mode 100644
index 0000000000..c9d116ca5a
--- /dev/null
+++ b/test-data/src/main/java/se/su/dsv/scipro/testdata/populators/package-info.java
@@ -0,0 +1,13 @@
+/**
+ * Contains classes that populate the database with test data.
+ *
+ * Prefer to use methods on the various services to create data, rather than directly interacting with the database
+ * using an {@link jakarta.persistence.EntityManager}. This is to make sure all business rules are enforced and that
+ * any additional logic is executed such as sending notifications or calculating statistics.
+ *
+ * @see se.su.dsv.scipro.testdata how to add new populators
+ * @see se.su.dsv.scipro.testdata.TestDataPopulator
+ * @see se.su.dsv.scipro.testdata.BaseData
+ * @see se.su.dsv.scipro.testdata.Factory
+ */
+package se.su.dsv.scipro.testdata.populators;
diff --git a/test-data/src/main/resources/META-INF/services/se.su.dsv.scipro.war.PluginConfiguration b/test-data/src/main/resources/META-INF/services/se.su.dsv.scipro.war.PluginConfiguration
new file mode 100644
index 0000000000..99b97f03e4
--- /dev/null
+++ b/test-data/src/main/resources/META-INF/services/se.su.dsv.scipro.war.PluginConfiguration
@@ -0,0 +1 @@
+se.su.dsv.scipro.testdata.TestDataConfiguration
diff --git a/war/pom.xml b/war/pom.xml
index c1dd889587..6a347c9b09 100644
--- a/war/pom.xml
+++ b/war/pom.xml
@@ -140,5 +140,18 @@
branch