From b245051ccc8c9ef520fe555384ac5e85280f70ff Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Thu, 28 Nov 2024 12:22:41 +0100 Subject: [PATCH 1/8] Use MariaDB in tests instead of HSQLDB Utilizes Testcontainers to start a MariaDB Docker container to use in tests. The empty database is then migrated using Flyway which means migrations are implicitly tested as well. --- core/pom.xml | 19 +++++++++++++-- .../main/resources/META-INF/persistence.xml | 12 ---------- .../se/su/dsv/scipro/test/SpringTest.java | 23 +++++++++++++++++-- pom.xml | 9 -------- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index a3c2a1a1e9..e34cb44596 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -86,8 +86,23 @@ test - org.hsqldb - hsqldb + org.testcontainers + junit-jupiter + test + + + org.testcontainers + mariadb + test + + + org.mariadb.jdbc + mariadb-java-client + test + + + org.flywaydb + flyway-mysql test diff --git a/core/src/main/resources/META-INF/persistence.xml b/core/src/main/resources/META-INF/persistence.xml index fc5f0a5977..902cc7aeae 100755 --- a/core/src/main/resources/META-INF/persistence.xml +++ b/core/src/main/resources/META-INF/persistence.xml @@ -4,9 +4,6 @@ xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd" version="3.0"> - - @@ -17,13 +14,4 @@ - - - - - - - - diff --git a/core/src/test/java/se/su/dsv/scipro/test/SpringTest.java b/core/src/test/java/se/su/dsv/scipro/test/SpringTest.java index 2b68b55008..04d0f70da7 100644 --- a/core/src/test/java/se/su/dsv/scipro/test/SpringTest.java +++ b/core/src/test/java/se/su/dsv/scipro/test/SpringTest.java @@ -4,28 +4,47 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityTransaction; import jakarta.persistence.Persistence; +import java.sql.SQLException; import java.time.Clock; +import java.util.Map; import java.util.Optional; +import org.flywaydb.core.Flyway; +import org.hibernate.cfg.Environment; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.mariadb.jdbc.MariaDbDataSource; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.testcontainers.containers.MariaDBContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import se.su.dsv.scipro.CoreConfig; import se.su.dsv.scipro.RepositoryConfiguration; import se.su.dsv.scipro.profiles.CurrentProfile; import se.su.dsv.scipro.sukat.Sukat; import se.su.dsv.scipro.system.CurrentUser; +@Testcontainers public abstract class SpringTest { private EntityManager entityManager; private EntityManagerFactory entityManagerFactory; + @Container + static MariaDBContainer mariaDBContainer = new MariaDBContainer<>("mariadb:10.11"); + @BeforeEach - public final void prepareSpring() { - entityManagerFactory = Persistence.createEntityManagerFactory("testPersistenceUnit"); + public final void prepareSpring() throws SQLException { + MariaDbDataSource dataSource = new MariaDbDataSource(mariaDBContainer.getJdbcUrl()); + dataSource.setUser(mariaDBContainer.getUsername()); + dataSource.setPassword(mariaDBContainer.getPassword()); + + Flyway.configure().dataSource(dataSource).load().migrate(); + + Map jpaProperties = Map.of(Environment.JAKARTA_JTA_DATASOURCE, dataSource); + entityManagerFactory = Persistence.createEntityManagerFactory("defaultPersistenceUnit", jpaProperties); this.entityManager = entityManagerFactory.createEntityManager(); EntityTransaction transaction = entityManager.getTransaction(); transaction.begin(); diff --git a/pom.xml b/pom.xml index e69b87c989..5c5ebdde52 100755 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,6 @@ 5.0.0 5.0.0 5.9.3 - 2.7.1 5.3.1 9.19.1 3.1.6 @@ -133,14 +132,6 @@ import - - - org.hsqldb - hsqldb - ${hsqldb.version} - test - - org.mariadb.jdbc mariadb-java-client -- 2.39.5 From 01ad6ae20c1a8c9a35e7e589fa8dfb56c8d9f023 Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Thu, 28 Nov 2024 12:25:14 +0100 Subject: [PATCH 2/8] Fix PeerReviewServiceImplTest It previously did not populate all the required attributes that were checked using NOT NULL constraints in the migration scripts but were not present in the Hibernate generated DDL for HSQLDB. --- .../java/se/su/dsv/scipro/peer/PeerReviewServiceImplTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/se/su/dsv/scipro/peer/PeerReviewServiceImplTest.java b/core/src/test/java/se/su/dsv/scipro/peer/PeerReviewServiceImplTest.java index 9c6a5dd3da..6495faaf7a 100644 --- a/core/src/test/java/se/su/dsv/scipro/peer/PeerReviewServiceImplTest.java +++ b/core/src/test/java/se/su/dsv/scipro/peer/PeerReviewServiceImplTest.java @@ -14,6 +14,7 @@ import se.su.dsv.scipro.file.FileDescription; import se.su.dsv.scipro.file.FileReference; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DegreeType; +import se.su.dsv.scipro.system.Language; import se.su.dsv.scipro.system.PageRequest; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; @@ -95,6 +96,7 @@ public class PeerReviewServiceImplTest extends IntegrationTest { peerRequest.setRequester( save(User.builder().firstName("Bob").lastName("Sponge").emailAddress("bob@example.com").build()) ); + peerRequest.setLanguage(Language.ENGLISH); final FileDescription fileDescription = save(new FileDescription()); final FileReference fileReference = new FileReference(); fileReference.setFileDescription(fileDescription); -- 2.39.5 From a2405ee445903a50045b6657b5749e70966e6305 Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Thu, 28 Nov 2024 12:26:06 +0100 Subject: [PATCH 3/8] Fix PeerReviewServiceImplIntegrationTest It previously did not populate all the required attributes that were checked using NOT NULL constraints in the migration scripts but were not present in the Hibernate generated DDL for HSQLDB. --- .../dsv/scipro/peer/PeerReviewServiceImplIntegrationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/se/su/dsv/scipro/peer/PeerReviewServiceImplIntegrationTest.java b/core/src/test/java/se/su/dsv/scipro/peer/PeerReviewServiceImplIntegrationTest.java index 15a004fd89..a954f455be 100644 --- a/core/src/test/java/se/su/dsv/scipro/peer/PeerReviewServiceImplIntegrationTest.java +++ b/core/src/test/java/se/su/dsv/scipro/peer/PeerReviewServiceImplIntegrationTest.java @@ -14,6 +14,7 @@ import se.su.dsv.scipro.file.FileDescription; import se.su.dsv.scipro.file.FileReference; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DegreeType; +import se.su.dsv.scipro.system.Language; import se.su.dsv.scipro.system.PageRequest; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; @@ -102,6 +103,7 @@ public class PeerReviewServiceImplIntegrationTest extends IntegrationTest { PeerRequest peerRequest = new PeerRequest(); peerRequest.setProject(createProject()); peerRequest.setRequester(createUser()); + peerRequest.setLanguage(Language.ENGLISH); final FileDescription fileDescription = save(new FileDescription()); final FileReference fileReference = new FileReference(); fileReference.setFileDescription(fileDescription); -- 2.39.5 From 3e8accd37a995498852b291d0e6e4ac1145ea2c0 Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Thu, 28 Nov 2024 12:27:42 +0100 Subject: [PATCH 4/8] Fix PeerRequestServiceImplTest It previously did not populate all the required attributes that were checked using NOT NULL constraints in the migration scripts but were not present in the Hibernate generated DDL for HSQLDB. --- .../java/se/su/dsv/scipro/peer/PeerRequestServiceImplTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/se/su/dsv/scipro/peer/PeerRequestServiceImplTest.java b/core/src/test/java/se/su/dsv/scipro/peer/PeerRequestServiceImplTest.java index 215e6c5f45..fc98ba6f7b 100644 --- a/core/src/test/java/se/su/dsv/scipro/peer/PeerRequestServiceImplTest.java +++ b/core/src/test/java/se/su/dsv/scipro/peer/PeerRequestServiceImplTest.java @@ -13,6 +13,7 @@ import se.su.dsv.scipro.file.FileDescription; import se.su.dsv.scipro.file.FileReference; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DegreeType; +import se.su.dsv.scipro.system.Language; import se.su.dsv.scipro.system.PageRequest; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; @@ -158,6 +159,7 @@ public class PeerRequestServiceImplTest extends IntegrationTest { peerRequest.setProject(project); peerRequest.setRequester(requester); peerRequest.setStatus(status); + peerRequest.setLanguage(Language.ENGLISH); final FileDescription fileDescription = save(new FileDescription()); final FileReference fileReference = new FileReference(); fileReference.setFileDescription(fileDescription); -- 2.39.5 From 04aa867900a67d782686cc023e7816f464e6a83f Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Thu, 28 Nov 2024 12:28:20 +0100 Subject: [PATCH 5/8] Fix CommentThreadServiceImplTest It previously did not populate all the required attributes that were checked using NOT NULL constraints in the migration scripts but were not present in the Hibernate generated DDL for HSQLDB. --- .../se/su/dsv/scipro/peer/CommentThreadServiceImplTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/se/su/dsv/scipro/peer/CommentThreadServiceImplTest.java b/core/src/test/java/se/su/dsv/scipro/peer/CommentThreadServiceImplTest.java index cd037f3ee5..625162f167 100644 --- a/core/src/test/java/se/su/dsv/scipro/peer/CommentThreadServiceImplTest.java +++ b/core/src/test/java/se/su/dsv/scipro/peer/CommentThreadServiceImplTest.java @@ -12,6 +12,7 @@ import se.su.dsv.scipro.file.FileDescription; import se.su.dsv.scipro.file.FileReference; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.system.DegreeType; +import se.su.dsv.scipro.system.Language; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; import se.su.dsv.scipro.test.Dates; @@ -66,6 +67,7 @@ public class CommentThreadServiceImplTest extends IntegrationTest { PeerRequest peerRequest = new PeerRequest(); peerRequest.setProject(project); peerRequest.setRequester(createUser()); + peerRequest.setLanguage(Language.ENGLISH); final FileDescription fileDescription = save(new FileDescription()); final FileReference fileReference = new FileReference(); fileReference.setFileDescription(fileDescription); -- 2.39.5 From c0dee216021f6f41275391faaec54322c7cbfbfd Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Thu, 28 Nov 2024 12:34:48 +0100 Subject: [PATCH 6/8] Fix TestPeerReview It previously did not populate all the required attributes that were checked using NOT NULL constraints in the migration scripts but were not present in the Hibernate generated DDL for HSQLDB. --- core/src/test/java/se/su/dsv/scipro/peer/TestPeerReview.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/se/su/dsv/scipro/peer/TestPeerReview.java b/core/src/test/java/se/su/dsv/scipro/peer/TestPeerReview.java index 34e5e5c7e2..fe5e2be992 100755 --- a/core/src/test/java/se/su/dsv/scipro/peer/TestPeerReview.java +++ b/core/src/test/java/se/su/dsv/scipro/peer/TestPeerReview.java @@ -19,6 +19,7 @@ import se.su.dsv.scipro.file.FileDescription; import se.su.dsv.scipro.file.FileReference; import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.project.ProjectStatus; +import se.su.dsv.scipro.system.Language; import se.su.dsv.scipro.system.PageRequest; import se.su.dsv.scipro.system.ProjectType; import se.su.dsv.scipro.system.User; @@ -196,6 +197,7 @@ public class TestPeerReview extends IntegrationTest { request.setComment(comment); request.setRequester(requester); request.setProject(project); + request.setLanguage(Language.ENGLISH); final FileDescription fileDescription = save(new FileDescription()); final FileReference fileReference = new FileReference(); fileReference.setFileDescription(fileDescription); -- 2.39.5 From 5996421aa02da445a2476a484f469f96dfd7b970 Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Thu, 28 Nov 2024 12:36:13 +0100 Subject: [PATCH 7/8] Fix UrkundSubmissionRepositoryTest It previously did not populate all the required attributes that were checked using NOT NULL constraints in the migration scripts but were not present in the Hibernate generated DDL for HSQLDB. --- .../plagiarism/urkund/UrkundSubmissionRepositoryTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/test/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmissionRepositoryTest.java b/core/src/test/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmissionRepositoryTest.java index c09f3ea67e..a3b40ed7ae 100644 --- a/core/src/test/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmissionRepositoryTest.java +++ b/core/src/test/java/se/su/dsv/scipro/plagiarism/urkund/UrkundSubmissionRepositoryTest.java @@ -13,6 +13,7 @@ import org.hamcrest.TypeSafeMatcher; import org.junit.jupiter.api.Test; import se.su.dsv.scipro.file.FileDescription; import se.su.dsv.scipro.file.FileReference; +import se.su.dsv.scipro.system.User; import se.su.dsv.scipro.test.SpringTest; public class UrkundSubmissionRepositoryTest extends SpringTest { @@ -23,11 +24,14 @@ public class UrkundSubmissionRepositoryTest extends SpringTest { @Test public void save() { final Instant submitted = Instant.now(); + User bob = User.builder().firstName("Bob").lastName("Sponge").emailAddress("bob@example.com").build(); + save(bob); final UrkundSubmission submission = new UrkundSubmission(); submission.setState(UrkundSubmission.State.SUBMITTED); submission.setMessage("Hi"); submission.setSubmitted(submitted); submission.setNextPoll(submitted); + submission.setReceiver(bob); final FileDescription file = save(new FileDescription()); final FileReference fileReference = new FileReference(); fileReference.setFileDescription(file); -- 2.39.5 From 2c819985c0fe29199c6ee7ea7cd2cd6dfb935fe9 Mon Sep 17 00:00:00 2001 From: Andreas Svanberg Date: Thu, 28 Nov 2024 12:37:12 +0100 Subject: [PATCH 8/8] Fix FinalSeminarSchedulingTest It previously did not populate all the required attributes that were checked using NOT NULL constraints in the migration scripts but were not present in the Hibernate generated DDL for HSQLDB. --- .../su/dsv/scipro/finalseminar/FinalSeminarSchedulingTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/se/su/dsv/scipro/finalseminar/FinalSeminarSchedulingTest.java b/core/src/test/java/se/su/dsv/scipro/finalseminar/FinalSeminarSchedulingTest.java index 23ebd8113c..cca047aed5 100644 --- a/core/src/test/java/se/su/dsv/scipro/finalseminar/FinalSeminarSchedulingTest.java +++ b/core/src/test/java/se/su/dsv/scipro/finalseminar/FinalSeminarSchedulingTest.java @@ -197,6 +197,7 @@ public class FinalSeminarSchedulingTest extends IntegrationTest { NonWorkDayPeriod nonWorkDayPeriod = new NonWorkDayPeriod(); nonWorkDayPeriod.setStartDate(date); nonWorkDayPeriod.setEndDate(date); + nonWorkDayPeriod.setComment("test non work day"); save(nonWorkDayPeriod); } -- 2.39.5