From bfbf79aa2a2db2335e7535b073a25cb67a0eaab9 Mon Sep 17 00:00:00 2001 From: Markus Herhoffer Date: Sun, 8 Dec 2024 19:17:48 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20(#177):=20Add=20PersistOrganiza?= =?UTF-8?q?tionDelegate=20and=20its=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented PersistOrganizationDelegate to handle the persistence of organizations, their owners, and root Bommels. Added unit tests to verify that organizations, members, and root Bommels are correctly persisted, ensuring integrity and expected behavior. Introduced a default emoji for root Bommels to standardize their representation. --- .../PersistOrganizationDelegate.java | 35 +++++++++++ .../main/java/app/hopps/org/jpa/Bommel.java | 1 + .../PersistOrganizationDelegateTests.java | 62 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 backend/app.hopps.org/src/main/java/app/hopps/org/delegates/PersistOrganizationDelegate.java create mode 100644 backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java diff --git a/backend/app.hopps.org/src/main/java/app/hopps/org/delegates/PersistOrganizationDelegate.java b/backend/app.hopps.org/src/main/java/app/hopps/org/delegates/PersistOrganizationDelegate.java new file mode 100644 index 00000000..61e26802 --- /dev/null +++ b/backend/app.hopps.org/src/main/java/app/hopps/org/delegates/PersistOrganizationDelegate.java @@ -0,0 +1,35 @@ +package app.hopps.org.delegates; + +import app.hopps.org.jpa.*; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.transaction.Transactional; +import jakarta.validation.Valid; + +@ApplicationScoped +public class PersistOrganizationDelegate { + + @Inject + OrganizationRepository organizationRepository; + + @Inject + MemberRespository memberRepository; + + @Inject + BommelRepository bommelRepository; + + @Transactional + public void persistOrg(@Valid Organization organization, @Valid Member owner) { + memberRepository.persist(owner); + organizationRepository.persist(organization); + + Bommel rootBommel = new Bommel(); + rootBommel.setName(organization.getName()); + rootBommel.setParent(null); + rootBommel.setOrganization(organization); + rootBommel.setEmoji(Bommel.DEFAULT_ROOT_BOMMEL_EMOJI); + rootBommel.setResponsibleMember(owner); + + bommelRepository.persist(rootBommel); + } +} diff --git a/backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java b/backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java index a0ac3930..a1980b3c 100644 --- a/backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java +++ b/backend/app.hopps.org/src/main/java/app/hopps/org/jpa/Bommel.java @@ -55,6 +55,7 @@ with children_query as ( """) }) public class Bommel extends PanacheEntity { + public static final String DEFAULT_ROOT_BOMMEL_EMOJI="\uD83C\uDF33"; // tree private String name; private String emoji; diff --git a/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java new file mode 100644 index 00000000..368b583d --- /dev/null +++ b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java @@ -0,0 +1,62 @@ +package app.hopps.org.delegates; + +import app.hopps.org.jpa.*; +import io.quarkus.test.junit.QuarkusTest; +import jakarta.inject.Inject; +import jakarta.transaction.Transactional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize; + +@QuarkusTest +public class PersistOrganizationDelegateTests { + + @Inject + PersistOrganizationDelegate persistOrganizationDelegate; + + @Inject + BommelRepository bommelRepository; + + @Inject + OrganizationRepository organizationRepository; + + @Inject + MemberRespository memberRepository; + + @BeforeEach + @Transactional + void cleanupDB() + { + bommelRepository.deleteAll(); + organizationRepository.deleteAll(); + memberRepository.deleteAll(); + } + + @Test + void shouldCreateRootBommel() + { + // given + Organization kegelclub = new Organization(); + kegelclub.setName("Kegelklub 777"); + kegelclub.setType(Organization.TYPE.EINGETRAGENER_VEREIN); + kegelclub.setSlug("kegelklub-777"); + + Member kevin = new Member(); + kevin.setFirstName("Kevin"); + kevin.setLastName("Kegelkönig"); + kevin.setEmail("pinking777@gmail.com"); + + // when + persistOrganizationDelegate.persistOrg(kegelclub, kevin); + + // then + assertThat(organizationRepository.listAll(), iterableWithSize(1)); + assertThat(bommelRepository.listAll(), iterableWithSize(1)); + assertThat(bommelRepository.listAll(), hasItem(hasProperty("emoji", equalTo("\uD83C\uDF33")))); + } +} From 2a8f6a355d663505faf0114aecea99d5337aae57 Mon Sep 17 00:00:00 2001 From: Markus Herhoffer Date: Sun, 8 Dec 2024 19:29:08 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20(#177):=20Integrate=20into=20BP?= =?UTF-8?q?MN=20and=20fix=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/bpmn/NewOrganization.bpmn | 66 ++++++++++++------- .../CreationValidationDelegateTests.java | 12 ++-- .../java/app/hopps/org/jpa/BommelTest.java | 11 ++-- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/backend/app.hopps.org/src/main/resources/bpmn/NewOrganization.bpmn b/backend/app.hopps.org/src/main/resources/bpmn/NewOrganization.bpmn index 7c3ab83c..78d49da2 100644 --- a/backend/app.hopps.org/src/main/resources/bpmn/NewOrganization.bpmn +++ b/backend/app.hopps.org/src/main/resources/bpmn/NewOrganization.bpmn @@ -1,5 +1,5 @@ - + @@ -10,6 +10,8 @@ + + @@ -18,6 +20,7 @@ + @@ -36,8 +39,8 @@ - - + + _7990A710-11AA-44F2-888D-D2FE3B907C70_InMessage _7990A710-11AA-44F2-888D-D2FE3B907C70_OutMessage @@ -66,9 +69,8 @@ _DB0D419F-AB1A-46FD-8093-CD25A927EAA0_OutMessage - - - + + @@ -90,10 +92,10 @@ - + @@ -101,12 +103,12 @@ - + _A7B5AA79-B3CC-4999-9489-46EBA6AF990B @@ -168,10 +170,10 @@ _574498AF-2A70-4024-A4B4-2ECA6360F02D - _F6C8F584-EA6B-4026-839F-67DAFA0877E3 _C7D729AB-0DE5-40BA-8ED0-C2649EBCF884 + _F6C8F584-EA6B-4026-839F-67DAFA0877E3 - + @@ -179,6 +181,22 @@ _0D059BE3-7B64-436C-8931-5C673605C578 _574498AF-2A70-4024-A4B4-2ECA6360F02D + + + + + _7990A710-11AA-44F2-888D-D2FE3B907C70_organizationInputX + _7990A710-11AA-44F2-888D-D2FE3B907C70_ownerInputX + + + + organization + _7990A710-11AA-44F2-888D-D2FE3B907C70_organizationInputX + + + owner + _7990A710-11AA-44F2-888D-D2FE3B907C70_ownerInputX + @@ -229,6 +247,9 @@ + + + @@ -259,12 +280,14 @@ - - - + + + + + @@ -285,15 +308,15 @@ - - - - + + + + @@ -307,11 +330,6 @@ - - - - - @@ -449,7 +467,7 @@ - _SxOV0FA6ED2c8Z-Bgliozg - _SxOV0FA6ED2c8Z-Bgliozg + _xSRJIJe-ED2ocIyyHiENHw + _xSRJIJe-ED2ocIyyHiENHw \ No newline at end of file diff --git a/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/CreationValidationDelegateTests.java b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/CreationValidationDelegateTests.java index b1ddfbf6..2cf9d906 100644 --- a/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/CreationValidationDelegateTests.java +++ b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/CreationValidationDelegateTests.java @@ -11,6 +11,7 @@ import jakarta.inject.Inject; import jakarta.transaction.Transactional; import jakarta.validation.ConstraintViolationException; +import org.flywaydb.core.Flyway; import org.hamcrest.core.IsInstanceOf; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -23,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; @QuarkusTest -public class CreationValidationDelegateTests { +class CreationValidationDelegateTests { @Inject CreationValidationDelegate delegate; @@ -32,13 +33,12 @@ public class CreationValidationDelegateTests { OrganizationRepository organizationRepository; @Inject - MemberRespository memberRespository; + Flyway flyway; @BeforeEach - @Transactional - void setUp() { - organizationRepository.deleteAll(); - memberRespository.deleteAll(); + public void cleanDatabase() { + flyway.clean(); + flyway.migrate(); } @Test diff --git a/backend/app.hopps.org/src/test/java/app/hopps/org/jpa/BommelTest.java b/backend/app.hopps.org/src/test/java/app/hopps/org/jpa/BommelTest.java index 8e0bd9ac..0796b7e5 100644 --- a/backend/app.hopps.org/src/test/java/app/hopps/org/jpa/BommelTest.java +++ b/backend/app.hopps.org/src/test/java/app/hopps/org/jpa/BommelTest.java @@ -7,6 +7,7 @@ import jakarta.inject.Inject; import jakarta.transaction.Transactional; import jakarta.ws.rs.WebApplicationException; +import org.flywaydb.core.Flyway; import org.hamcrest.Matchers; import org.hamcrest.collection.IsIterableWithSize; import org.instancio.Instancio; @@ -36,11 +37,13 @@ class BommelTest { @Inject BommelTestResourceCreator resourceCreator; + @Inject + Flyway flyway; + @BeforeEach - @Transactional - void clearDatabase() { - orgRepo.deleteAll(); - repo.deleteAll(); + public void cleanDatabase() { + flyway.clean(); + flyway.migrate(); } @Test From 7628615763e3100f2e134687964a4e596f17c2a8 Mon Sep 17 00:00:00 2001 From: Markus Herhoffer Date: Mon, 9 Dec 2024 09:42:34 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=85=20(#177):=20Change=20test=20visib?= =?UTF-8?q?ility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hopps/org/delegates/PersistOrganizationDelegateTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java index 368b583d..14ec46ab 100644 --- a/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java +++ b/backend/app.hopps.org/src/test/java/app/hopps/org/delegates/PersistOrganizationDelegateTests.java @@ -14,7 +14,7 @@ import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize; @QuarkusTest -public class PersistOrganizationDelegateTests { +class PersistOrganizationDelegateTests { @Inject PersistOrganizationDelegate persistOrganizationDelegate;