From 5ada0dae35f03103104d9d2998c25a26912f5baa Mon Sep 17 00:00:00 2001
From: Michael Hoennig <michael@hoennig.de>
Date: Fri, 21 Oct 2022 17:05:28 +0200
Subject: [PATCH] fixes instable debitor temp test data deletion and code coverage exclusions

---
 src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java |   28 +++++++++-------------------
 build.gradle                                                                                            |    6 +++---
 2 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/build.gradle b/build.gradle
index 10c62ea..d4aa51f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -230,8 +230,8 @@
             excludes = [
                     'net.hostsharing.hsadminng.**.generated.**',
                     'net.hostsharing.hsadminng.HsadminNgApplication',
-                    'net.hostsharing.hsadminng.PingController',
-                    'net.hostsharing.hsadminng.Mapper'
+                    'net.hostsharing.hsadminng.ping.PingController',
+                    'net.hostsharing.hsadminng.mapper.Mapper'
             ]
 
             limit {
@@ -245,7 +245,7 @@
             excludes = [
                     'net.hostsharing.hsadminng.**.generated.**',
                     'net.hostsharing.hsadminng.HsadminNgApplication.main',
-                    'net.hostsharing.hsadminng.PingController.*'
+                    'net.hostsharing.hsadminng.ping.PingController.*'
             ]
 
             limit {
diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java
index a63ee11..25e78dd 100644
--- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java
+++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java
@@ -78,12 +78,12 @@
 
             // when
             final var result = attempt(em, () -> {
-                final var newDebitor = toCleanup(HsOfficeDebitorEntity.builder()
+                final var newDebitor = HsOfficeDebitorEntity.builder()
                         .uuid(UUID.randomUUID())
                         .debitorNumber(20001)
                         .partner(givenPartner)
                         .billingContact(givenContact)
-                        .build());
+                        .build();
                 return debitorRepo.save(newDebitor);
             });
 
@@ -111,12 +111,12 @@
             attempt(em, () -> {
                 final var givenPartner = partnerRepo.findPartnerByOptionalNameLike("Fourth").get(0);
                 final var givenContact = contactRepo.findContactByOptionalLabelLike("forth contact").get(0);
-                final var newDebitor = toCleanup(HsOfficeDebitorEntity.builder()
+                final var newDebitor = HsOfficeDebitorEntity.builder()
                         .uuid(UUID.randomUUID())
                         .debitorNumber(20002)
                         .partner(givenPartner)
                         .billingContact(givenContact)
-                        .build());
+                        .build();
                 return debitorRepo.save(newDebitor);
             }).assertSuccessful();
 
@@ -278,7 +278,7 @@
                 givenDebitor.setVatId(givenNewVatId);
                 givenDebitor.setVatCountryCode(givenNewVatCountryCode);
                 givenDebitor.setVatBusiness(givenNewVatBusiness);
-                return toCleanup(debitorRepo.save(givenDebitor));
+                return debitorRepo.save(givenDebitor);
             });
 
             // then
@@ -327,7 +327,7 @@
             final var result = jpaAttempt.transacted(() -> {
                 context("superuser-alex@hostsharing.net");
                 givenDebitor.setRefundBankAccount(givenNewBankAccount);
-                return toCleanup(debitorRepo.save(givenDebitor));
+                return debitorRepo.save(givenDebitor);
             });
 
             // then
@@ -356,7 +356,7 @@
             final var result = jpaAttempt.transacted(() -> {
                 context("superuser-alex@hostsharing.net");
                 givenDebitor.setRefundBankAccount(null);
-                return toCleanup(debitorRepo.save(givenDebitor));
+                return debitorRepo.save(givenDebitor);
             });
 
             // then
@@ -551,25 +551,15 @@
                     .refundBankAccount(givenBankAccount)
                     .build();
 
-            toCleanup(newDebitor);
-
             return debitorRepo.save(newDebitor);
         }).assertSuccessful().returnedValue();
-    }
-
-    private HsOfficeDebitorEntity toCleanup(final HsOfficeDebitorEntity tempDebitor) {
-        tempDebitors.add(tempDebitor);
-        return tempDebitor;
     }
 
     @BeforeEach
     @AfterEach
     void cleanup() {
-        context("superuser-alex@hostsharing.net", null);
-        tempDebitors.forEach(tempDebitor -> {
-            System.out.println("DELETING temporary debitor: " + tempDebitor.toString());
-            debitorRepo.deleteByUuid(tempDebitor.getUuid());
-        });
+        context("superuser-alex@hostsharing.net");
+        em.createQuery("DELETE FROM HsOfficeDebitorEntity d where d.debitorNumber >= 20000").executeUpdate();
     }
 
     void exactlyTheseDebitorsAreReturned(final List<HsOfficeDebitorEntity> actualResult, final String... debitorNames) {

--
Gitblit v1.9.3