From d7ee5fb8c5d1f152a58139beda66503f3e2a171f Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 8 Oct 2024 09:57:37 +0200 Subject: [PATCH] error status for booking items without automatic hosting asset creation --- .../HsBookingItemCreatedListener.java | 26 ++++- .../HsBookingItemCreatedListenerUnitTest.java | 98 +++++++++++++++++++ .../HsOfficePartnerControllerRestTest.java | 1 - .../rbac/role/RbacRoleControllerRestTest.java | 2 - .../hsadminng/rbac/test/MapperUnitTest.java | 1 - 5 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/HsBookingItemCreatedListenerUnitTest.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/HsBookingItemCreatedListener.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/HsBookingItemCreatedListener.java index d388c61c..651d5277 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/HsBookingItemCreatedListener.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/factories/HsBookingItemCreatedListener.java @@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.SneakyThrows; import net.hostsharing.hsadminng.hs.booking.generated.api.v1.model.HsHostingAssetAutoInsertResource; import net.hostsharing.hsadminng.hs.booking.item.BookingItemCreatedAppEvent; +import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRealEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; import net.hostsharing.hsadminng.mapper.StandardMapper; import net.hostsharing.hsadminng.persistence.EntityManagerWrapper; import org.springframework.beans.factory.annotation.Autowired; @@ -40,7 +42,8 @@ public class HsBookingItemCreatedListener implements ApplicationListener null; // for now, no automatic HostingAsset possible + case PRIVATE_CLOUD, CLOUD_SERVER, MANAGED_SERVER -> + forNowNoAutomaticHostingAssetCreationPossible(emw, newBookingItemRealEntity, asset, standardMapper); case MANAGED_WEBSPACE -> new ManagedWebspaceHostingAssetFactory(emw, newBookingItemRealEntity, asset, standardMapper); case DOMAIN_SETUP -> new DomainSetupHostingAssetFactory(emw, newBookingItemRealEntity, asset, standardMapper); }; @@ -53,4 +56,25 @@ public class HsBookingItemCreatedListener implements ApplicationListener bookingItemTypesWithoutAutomaticAssetCreation() { + return Arrays.stream(HsBookingItemType.values()) + .filter(v -> v != MANAGED_WEBSPACE && v != DOMAIN_SETUP) + .toList(); + } + + private static HsBookingItemRealEntity createBookingItemFromResources( + final HsBookingItemType bookingItemType + ) { + return HsBookingItemRealEntity.builder() + .type(bookingItemType) + .build(); + } + + private void assertEventStatus( + final HsBookingItemRealEntity givenBookingItem, + final String givenAssetJson, + final String expectedErrorMessage) { + emwFake.stream(BookingItemCreatedEventEntity.class) + .reduce(Reducer::toSingleElement) + .map(eventEntity -> { + assertThat(eventEntity.getBookingItem()).isSameAs(givenBookingItem); + assertThat(eventEntity.getAssetJson()).isEqualTo(givenAssetJson); + assertThat(eventEntity.getStatusMessage()).isEqualTo(expectedErrorMessage); + return true; + }); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java index 6f07b222..42d0566c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerControllerRestTest.java @@ -19,7 +19,6 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.SynchronizationType; diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/role/RbacRoleControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/rbac/role/RbacRoleControllerRestTest.java index bf171f59..0f1abce6 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/role/RbacRoleControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/role/RbacRoleControllerRestTest.java @@ -6,7 +6,6 @@ import net.hostsharing.hsadminng.persistence.EntityManagerWrapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -16,7 +15,6 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.SynchronizationType; import java.util.Map; diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/test/MapperUnitTest.java b/src/test/java/net/hostsharing/hsadminng/rbac/test/MapperUnitTest.java index 32bf1865..5d64903f 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/test/MapperUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/test/MapperUnitTest.java @@ -10,7 +10,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import jakarta.persistence.EntityManager; import jakarta.persistence.ManyToOne; import jakarta.validation.ValidationException; import java.util.List;