From bb05eb4ac4f7d9c98ab87de47950fc90026902fa Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 3 Aug 2022 06:11:39 +0200 Subject: [PATCH] refactoring packages, moving Hostsharing related entities etc. to hs package --- .../RestResponseEntityExceptionHandler.java | 16 +++++++++++----- .../{ => hs}/hscustomer/CustomerController.java | 2 +- .../{ => hs}/hscustomer/CustomerEntity.java | 2 +- .../{ => hs}/hscustomer/CustomerRepository.java | 2 +- .../{ => hs}/hspackage/PackageController.java | 2 +- .../{ => hs}/hspackage/PackageEntity.java | 4 ++-- .../{ => hs}/hspackage/PackageRepository.java | 2 +- .../hostsharing/hsadminng/arch/ArchUnitTest.java | 8 ++++---- .../hscustomer/CustomerControllerRestTest.java | 2 +- .../hscustomer/CustomerControllerUnitTest.java | 2 +- .../CustomerRepositoryIntegrationTest.java | 4 +++- .../{ => hs}/hscustomer/TestCustomer.java | 4 +++- .../hspackage/PackageControllerRestTest.java | 5 +---- .../{ => hs}/hspackage/TestPackage.java | 7 ++++--- 14 files changed, 35 insertions(+), 27 deletions(-) rename src/main/java/net/hostsharing/hsadminng/{ => hs}/hscustomer/CustomerController.java (96%) rename src/main/java/net/hostsharing/hsadminng/{ => hs}/hscustomer/CustomerEntity.java (89%) rename src/main/java/net/hostsharing/hsadminng/{ => hs}/hscustomer/CustomerRepository.java (84%) rename src/main/java/net/hostsharing/hsadminng/{ => hs}/hspackage/PackageController.java (96%) rename src/main/java/net/hostsharing/hsadminng/{ => hs}/hspackage/PackageEntity.java (79%) rename src/main/java/net/hostsharing/hsadminng/{ => hs}/hspackage/PackageRepository.java (78%) rename src/test/java/net/hostsharing/hsadminng/{ => hs}/hscustomer/CustomerControllerRestTest.java (97%) rename src/test/java/net/hostsharing/hsadminng/{ => hs}/hscustomer/CustomerControllerUnitTest.java (97%) rename src/test/java/net/hostsharing/hsadminng/{ => hs}/hscustomer/CustomerRepositoryIntegrationTest.java (97%) rename src/test/java/net/hostsharing/hsadminng/{ => hs}/hscustomer/TestCustomer.java (79%) rename src/test/java/net/hostsharing/hsadminng/{ => hs}/hspackage/PackageControllerRestTest.java (94%) rename src/test/java/net/hostsharing/hsadminng/{ => hs}/hspackage/TestPackage.java (67%) diff --git a/src/main/java/net/hostsharing/hsadminng/errors/RestResponseEntityExceptionHandler.java b/src/main/java/net/hostsharing/hsadminng/errors/RestResponseEntityExceptionHandler.java index 64ab4095..f5e38ba7 100644 --- a/src/main/java/net/hostsharing/hsadminng/errors/RestResponseEntityExceptionHandler.java +++ b/src/main/java/net/hostsharing/hsadminng/errors/RestResponseEntityExceptionHandler.java @@ -23,7 +23,7 @@ public class RestResponseEntityExceptionHandler final RuntimeException exc, final WebRequest request) { return new ResponseEntity<>( - new CustomErrorResponse(exc, HttpStatus.CONFLICT), HttpStatus.CONFLICT); + new CustomErrorResponse(request.getContextPath(), exc, HttpStatus.CONFLICT), HttpStatus.CONFLICT); } @ExceptionHandler(JpaSystemException.class) @@ -31,7 +31,7 @@ public class RestResponseEntityExceptionHandler final RuntimeException exc, final WebRequest request) { return new ResponseEntity<>( - new CustomErrorResponse(exc, HttpStatus.FORBIDDEN), HttpStatus.FORBIDDEN); + new CustomErrorResponse(request.getContextPath(), exc, HttpStatus.FORBIDDEN), HttpStatus.FORBIDDEN); } } @@ -41,13 +41,19 @@ class CustomErrorResponse { @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss") private final LocalDateTime timestamp; - private final HttpStatus status; + private final String path; + + private final int status; + + private final String error; private final String message; - public CustomErrorResponse(final RuntimeException exc, final HttpStatus status) { + public CustomErrorResponse(final String path, final RuntimeException exc, final HttpStatus status) { this.timestamp = LocalDateTime.now(); - this.status = status; + this.path = path; + this.status = status.value(); + this.error = status.getReasonPhrase(); this.message = firstLine(NestedExceptionUtils.getMostSpecificCause(exc).getMessage()); } diff --git a/src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerController.java b/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerController.java similarity index 96% rename from src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerController.java rename to src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerController.java index 27aaf23a..ec13941b 100644 --- a/src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerController.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hscustomer; +package net.hostsharing.hsadminng.hs.hscustomer; import net.hostsharing.hsadminng.context.Context; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerEntity.java similarity index 89% rename from src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerEntity.java rename to src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerEntity.java index ccc97488..174d2d83 100644 --- a/src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerEntity.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hscustomer; +package net.hostsharing.hsadminng.hs.hscustomer; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepository.java similarity index 84% rename from src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerRepository.java rename to src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepository.java index c98d6bac..d9f954aa 100644 --- a/src/main/java/net/hostsharing/hsadminng/hscustomer/CustomerRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepository.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hscustomer; +package net.hostsharing.hsadminng.hs.hscustomer; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/net/hostsharing/hsadminng/hspackage/PackageController.java b/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageController.java similarity index 96% rename from src/main/java/net/hostsharing/hsadminng/hspackage/PackageController.java rename to src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageController.java index 19f0b48c..63b071e9 100644 --- a/src/main/java/net/hostsharing/hsadminng/hspackage/PackageController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageController.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hspackage; +package net.hostsharing.hsadminng.hs.hspackage; import net.hostsharing.hsadminng.context.Context; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/net/hostsharing/hsadminng/hspackage/PackageEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageEntity.java similarity index 79% rename from src/main/java/net/hostsharing/hsadminng/hspackage/PackageEntity.java rename to src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageEntity.java index 0792e843..18117473 100644 --- a/src/main/java/net/hostsharing/hsadminng/hspackage/PackageEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageEntity.java @@ -1,9 +1,9 @@ -package net.hostsharing.hsadminng.hspackage; +package net.hostsharing.hsadminng.hs.hspackage; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import net.hostsharing.hsadminng.hscustomer.CustomerEntity; +import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity; import javax.persistence.*; import java.util.UUID; diff --git a/src/main/java/net/hostsharing/hsadminng/hspackage/PackageRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepository.java similarity index 78% rename from src/main/java/net/hostsharing/hsadminng/hspackage/PackageRepository.java rename to src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepository.java index 0f3c8c38..125bd63a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hspackage/PackageRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepository.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hspackage; +package net.hostsharing.hsadminng.hs.hspackage; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchUnitTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchUnitTest.java index c54641d6..156ce4e8 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchUnitTest.java @@ -39,16 +39,16 @@ public class ArchUnitTest { @ArchTest @SuppressWarnings("unused") public static final ArchRule hsPackagesRule = classes() - .that().resideInAPackage("..hs*") + .that().resideInAPackage("..hs.(*)..") .should().onlyBeAccessed().byClassesThat() - .resideInAnyPackage("..hs*"); + .resideInAnyPackage("..hs.(*).."); @ArchTest @SuppressWarnings("unused") public static final ArchRule hsPackagePackageRule = classes() - .that().resideInAPackage("..hspackage..") + .that().resideInAPackage("..hs.hspackage..") .should().onlyBeAccessed().byClassesThat() - .resideInAnyPackage("..hspackage.."); + .resideInAnyPackage("..hs.hspackage.."); @Test public void everythingShouldBeFreeOfCycles() { diff --git a/src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerRestTest.java similarity index 97% rename from src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerControllerRestTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerRestTest.java index 26d24803..ed1f1196 100644 --- a/src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerRestTest.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hscustomer; +package net.hostsharing.hsadminng.hs.hscustomer; import net.hostsharing.hsadminng.context.Context; import org.junit.jupiter.api.Test; diff --git a/src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerControllerUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerUnitTest.java similarity index 97% rename from src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerControllerUnitTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerUnitTest.java index 71bd0dab..01ccd926 100644 --- a/src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerControllerUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerUnitTest.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hscustomer; +package net.hostsharing.hsadminng.hs.hscustomer; import net.hostsharing.hsadminng.context.Context; import org.junit.jupiter.api.Test; diff --git a/src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java similarity index 97% rename from src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerRepositoryIntegrationTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java index b516948a..0e34c0e1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hscustomer/CustomerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java @@ -1,6 +1,8 @@ -package net.hostsharing.hsadminng.hscustomer; +package net.hostsharing.hsadminng.hs.hscustomer; import net.hostsharing.hsadminng.context.Context; +import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity; +import net.hostsharing.hsadminng.hs.hscustomer.CustomerRepository; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/test/java/net/hostsharing/hsadminng/hscustomer/TestCustomer.java b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java similarity index 79% rename from src/test/java/net/hostsharing/hsadminng/hscustomer/TestCustomer.java rename to src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java index f90b7e42..c77b0f91 100644 --- a/src/test/java/net/hostsharing/hsadminng/hscustomer/TestCustomer.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java @@ -1,4 +1,6 @@ -package net.hostsharing.hsadminng.hscustomer; +package net.hostsharing.hsadminng.hs.hscustomer; + +import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity; import static java.util.UUID.randomUUID; diff --git a/src/test/java/net/hostsharing/hsadminng/hspackage/PackageControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerRestTest.java similarity index 94% rename from src/test/java/net/hostsharing/hsadminng/hspackage/PackageControllerRestTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerRestTest.java index 1100080c..bc7691f1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hspackage/PackageControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerRestTest.java @@ -1,7 +1,6 @@ -package net.hostsharing.hsadminng.hspackage; +package net.hostsharing.hsadminng.hs.hspackage; import net.hostsharing.hsadminng.context.Context; -import net.hostsharing.hsadminng.hscustomer.TestCustomer; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -10,8 +9,6 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import java.util.UUID; - import static java.util.Arrays.asList; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; diff --git a/src/test/java/net/hostsharing/hsadminng/hspackage/TestPackage.java b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java similarity index 67% rename from src/test/java/net/hostsharing/hsadminng/hspackage/TestPackage.java rename to src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java index 37651767..e586cc1c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hspackage/TestPackage.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java @@ -1,7 +1,8 @@ -package net.hostsharing.hsadminng.hspackage; +package net.hostsharing.hsadminng.hs.hspackage; -import net.hostsharing.hsadminng.hscustomer.CustomerEntity; -import net.hostsharing.hsadminng.hscustomer.TestCustomer; +import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity; +import net.hostsharing.hsadminng.hs.hspackage.PackageEntity; +import net.hostsharing.hsadminng.hs.hscustomer.TestCustomer; import static java.util.UUID.randomUUID;