From 84ce90b28f217e95edf93cc5bd22adef1f17dd8d Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 31 Aug 2022 09:47:35 +0200 Subject: [PATCH] use customer/package/unixuser only as test data structure (Java part) --- .../hs/hscustomer/CustomerRepository.java | 21 ------- .../cust/TestCustomerController.java} | 10 ++-- .../cust/TestCustomerEntity.java} | 4 +- .../test/cust/TestCustomerRepository.java | 21 +++++++ .../pac}/PackageController.java | 16 ++--- .../hspackage => test/pac}/PackageEntity.java | 6 +- .../pac}/PackageRepository.java | 2 +- .../hostsharing/hsadminng/arch/ArchTest.java | 60 +++++++++---------- .../hsadminng/hs/hscustomer/TestCustomer.java | 15 ----- .../hsadminng/test/cust/TestCustomer.java | 13 ++++ ...TestCustomerControllerAcceptanceTest.java} | 14 ++--- ...estCustomerRepositoryIntegrationTest.java} | 50 ++++++++-------- .../pac}/PackageControllerAcceptanceTest.java | 2 +- .../PackageRepositoryIntegrationTest.java | 6 +- .../hspackage => test/pac}/TestPackage.java | 8 +-- 15 files changed, 123 insertions(+), 125 deletions(-) delete mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepository.java rename src/main/java/net/hostsharing/hsadminng/{hs/hscustomer/CustomerController.java => test/cust/TestCustomerController.java} (83%) rename src/main/java/net/hostsharing/hsadminng/{hs/hscustomer/CustomerEntity.java => test/cust/TestCustomerEntity.java} (83%) create mode 100644 src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepository.java rename src/main/java/net/hostsharing/hsadminng/{hs/hspackage => test/pac}/PackageController.java (85%) rename src/main/java/net/hostsharing/hsadminng/{hs/hspackage => test/pac}/PackageEntity.java (76%) rename src/main/java/net/hostsharing/hsadminng/{hs/hspackage => test/pac}/PackageRepository.java (91%) delete mode 100644 src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java create mode 100644 src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomer.java rename src/test/java/net/hostsharing/hsadminng/{hs/hscustomer/CustomerControllerAcceptanceTest.java => test/cust/TestCustomerControllerAcceptanceTest.java} (95%) rename src/test/java/net/hostsharing/hsadminng/{hs/hscustomer/CustomerRepositoryIntegrationTest.java => test/cust/TestCustomerRepositoryIntegrationTest.java} (72%) rename src/test/java/net/hostsharing/hsadminng/{hs/hspackage => test/pac}/PackageControllerAcceptanceTest.java (99%) rename src/test/java/net/hostsharing/hsadminng/{hs/hspackage => test/pac}/PackageRepositoryIntegrationTest.java (95%) rename src/test/java/net/hostsharing/hsadminng/{hs/hspackage => test/pac}/TestPackage.java (62%) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepository.java deleted file mode 100644 index f44b4ffd..00000000 --- a/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepository.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.hostsharing.hsadminng.hs.hscustomer; - -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.Repository; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -public interface CustomerRepository extends Repository { - - - Optional findByUuid(UUID id); - - @Query("SELECT c FROM CustomerEntity c WHERE :prefix is null or c.prefix like concat(:prefix, '%')") - List findCustomerByOptionalPrefixLike(String prefix); - - CustomerEntity save(final CustomerEntity entity); - - long count(); -} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerController.java b/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerController.java similarity index 83% rename from src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerController.java rename to src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerController.java index 47205dec..85fe469b 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerController.java +++ b/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerController.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hs.hscustomer; +package net.hostsharing.hsadminng.test.cust; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.generated.api.v1.api.CustomersApi; @@ -17,13 +17,13 @@ import static net.hostsharing.hsadminng.Mapper.mapList; @RestController -public class CustomerController implements CustomersApi { +public class TestCustomerController implements CustomersApi { @Autowired private Context context; @Autowired - private CustomerRepository customerRepository; + private TestCustomerRepository testCustomerRepository; @Override @Transactional(readOnly = true) @@ -34,7 +34,7 @@ public class CustomerController implements CustomersApi { ) { context.define(currentUser, assumedRoles); - final var result = customerRepository.findCustomerByOptionalPrefixLike(prefix); + final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(prefix); return ResponseEntity.ok(mapList(result, CustomerResource.class)); } @@ -52,7 +52,7 @@ public class CustomerController implements CustomersApi { customer.setUuid(UUID.randomUUID()); } - final var saved = customerRepository.save(map(customer, CustomerEntity.class)); + final var saved = testCustomerRepository.save(map(customer, TestCustomerEntity.class)); final var uri = MvcUriComponentsBuilder.fromController(getClass()) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerEntity.java b/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerEntity.java similarity index 83% rename from src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerEntity.java rename to src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerEntity.java index a706c885..d32eaa16 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerEntity.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hs.hscustomer; +package net.hostsharing.hsadminng.test.cust; import lombok.AllArgsConstructor; import lombok.Getter; @@ -14,7 +14,7 @@ import java.util.UUID; @Setter @NoArgsConstructor @AllArgsConstructor -public class CustomerEntity { +public class TestCustomerEntity { private @Id UUID uuid; private String prefix; private int reference; diff --git a/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepository.java b/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepository.java new file mode 100644 index 00000000..ad46ab33 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepository.java @@ -0,0 +1,21 @@ +package net.hostsharing.hsadminng.test.cust; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface TestCustomerRepository extends Repository { + + + Optional findByUuid(UUID id); + + @Query("SELECT c FROM TestCustomerEntity c WHERE :prefix is null or c.prefix like concat(:prefix, '%')") + List findCustomerByOptionalPrefixLike(String prefix); + + TestCustomerEntity save(final TestCustomerEntity entity); + + long count(); +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageController.java b/src/main/java/net/hostsharing/hsadminng/test/pac/PackageController.java similarity index 85% rename from src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageController.java rename to src/main/java/net/hostsharing/hsadminng/test/pac/PackageController.java index fccc5476..d86a13c3 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageController.java +++ b/src/main/java/net/hostsharing/hsadminng/test/pac/PackageController.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hs.hspackage; +package net.hostsharing.hsadminng.test.pac; import net.hostsharing.hsadminng.OptionalFromJson; import net.hostsharing.hsadminng.context.Context; @@ -28,9 +28,9 @@ public class PackageController implements PackagesApi { @Override @Transactional(readOnly = true) public ResponseEntity> listPackages( - String currentUser, - String assumedRoles, - String name + String currentUser, + String assumedRoles, + String name ) { context.define(currentUser, assumedRoles); @@ -41,10 +41,10 @@ public class PackageController implements PackagesApi { @Override @Transactional public ResponseEntity updatePackage( - final String currentUser, - final String assumedRoles, - final UUID packageUuid, - final PackageUpdateResource body) { + final String currentUser, + final String assumedRoles, + final UUID packageUuid, + final PackageUpdateResource body) { context.define(currentUser, assumedRoles); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageEntity.java b/src/main/java/net/hostsharing/hsadminng/test/pac/PackageEntity.java similarity index 76% rename from src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageEntity.java rename to src/main/java/net/hostsharing/hsadminng/test/pac/PackageEntity.java index 9ba57d30..b07062ae 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/test/pac/PackageEntity.java @@ -1,10 +1,10 @@ -package net.hostsharing.hsadminng.hs.hspackage; +package net.hostsharing.hsadminng.test.pac; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity; +import net.hostsharing.hsadminng.test.cust.TestCustomerEntity; import javax.persistence.*; import java.util.UUID; @@ -24,7 +24,7 @@ public class PackageEntity { @ManyToOne(optional = false) @JoinColumn(name = "customeruuid") - private CustomerEntity customer; + private TestCustomerEntity customer; private String name; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepository.java b/src/main/java/net/hostsharing/hsadminng/test/pac/PackageRepository.java similarity index 91% rename from src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepository.java rename to src/main/java/net/hostsharing/hsadminng/test/pac/PackageRepository.java index 5059412b..7e3f1e63 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/test/pac/PackageRepository.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hs.hspackage; +package net.hostsharing.hsadminng.test.pac; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchTest.java index 2210d5e3..e288c097 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchTest.java @@ -18,73 +18,73 @@ public class ArchTest { @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule contextPackageRule = classes() - .that().resideInAPackage("..context..") - .should().onlyDependOnClassesThat() - .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); + .that().resideInAPackage("..context..") + .should().onlyDependOnClassesThat() + .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule configPackageRule = classes() - .that().resideInAPackage("..config..") - .should().onlyDependOnClassesThat() - .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); + .that().resideInAPackage("..config..") + .should().onlyDependOnClassesThat() + .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule errorsPackageRule = classes() - .that().resideInAPackage("..errors..") - .should().onlyDependOnClassesThat() - .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); + .that().resideInAPackage("..errors..") + .should().onlyDependOnClassesThat() + .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule hsPackagesRule = classes() - .that().resideInAPackage("..hs.(*)..") - .should().onlyBeAccessed().byClassesThat() - .resideInAnyPackage("..hs.(*).."); + .that().resideInAPackage("..test.(*)..") + .should().onlyBeAccessed().byClassesThat() + .resideInAnyPackage("..test.(*).."); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule hsPackagePackageRule = classes() - .that().resideInAPackage("..hs.hspackage..") - .should().onlyBeAccessed().byClassesThat() - .resideInAnyPackage("..hs.hspackage.."); + .that().resideInAPackage("..test.pac..") + .should().onlyBeAccessed().byClassesThat() + .resideInAnyPackage("..test.pac.."); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule acceptsAnnotationOnMethodsRule = methods() - .that().areAnnotatedWith(Accepts.class) - .should().beDeclaredInClassesThat().haveSimpleNameEndingWith("AcceptanceTest") - .orShould().beDeclaredInClassesThat().haveSimpleNameNotContaining("AcceptanceTest$"); + .that().areAnnotatedWith(Accepts.class) + .should().beDeclaredInClassesThat().haveSimpleNameEndingWith("AcceptanceTest") + .orShould().beDeclaredInClassesThat().haveSimpleNameNotContaining("AcceptanceTest$"); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule acceptsAnnotationOnClasesRule = classes() - .that().areAnnotatedWith(Accepts.class) - .should().haveSimpleNameEndingWith("AcceptanceTest") - .orShould().haveSimpleNameNotContaining("AcceptanceTest$"); + .that().areAnnotatedWith(Accepts.class) + .should().haveSimpleNameEndingWith("AcceptanceTest") + .orShould().haveSimpleNameNotContaining("AcceptanceTest$"); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule doNotUseJavaxTransactionAnnotationAtClassLevel = noClasses() - .should().beAnnotatedWith(javax.transaction.Transactional.class.getName()) - .as("Use @%s instead of @%s." .formatted( - org.springframework.transaction.annotation.Transactional.class.getName(), - javax.transaction.Transactional.class)); + .should().beAnnotatedWith(javax.transaction.Transactional.class.getName()) + .as("Use @%s instead of @%s.".formatted( + org.springframework.transaction.annotation.Transactional.class.getName(), + javax.transaction.Transactional.class)); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule doNotUseJavaxTransactionAnnotationAtMethodLevel = noMethods() - .should().beAnnotatedWith(javax.transaction.Transactional.class) - .as("Use @%s instead of @%s." .formatted( - org.springframework.transaction.annotation.Transactional.class.getName(), - javax.transaction.Transactional.class.getName())); + .should().beAnnotatedWith(javax.transaction.Transactional.class) + .as("Use @%s instead of @%s.".formatted( + org.springframework.transaction.annotation.Transactional.class.getName(), + javax.transaction.Transactional.class.getName())); @com.tngtech.archunit.junit.ArchTest @SuppressWarnings("unused") public static final ArchRule doNotUseOrgJUnitTestAnnotation = noMethods() .should().beAnnotatedWith(org.junit.Test.class) - .as("Use @%s instead of @%s." .formatted( + .as("Use @%s instead of @%s.".formatted( org.junit.jupiter.api.Test.class.getName(), org.junit.Test.class.getName())); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java deleted file mode 100644 index c92cad82..00000000 --- a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.hostsharing.hsadminng.hs.hscustomer; - - -import static java.util.UUID.randomUUID; - -public class TestCustomer { - - public static final CustomerEntity xxx = hsCustomer("xxx", 10001, "xxx@example.com"); - static final CustomerEntity yyy = hsCustomer("yyy", 10002, "yyy@example.com"); - - - static public CustomerEntity hsCustomer(final String prefix, final int reference, final String adminName) { - return new CustomerEntity(randomUUID(), prefix, reference, adminName); - } -} diff --git a/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomer.java b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomer.java new file mode 100644 index 00000000..dcee7317 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomer.java @@ -0,0 +1,13 @@ +package net.hostsharing.hsadminng.test.cust; + +import static java.util.UUID.randomUUID; + +public class TestCustomer { + + public static final TestCustomerEntity xxx = hsCustomer("xxx", 10001, "xxx@example.com"); + static final TestCustomerEntity yyy = hsCustomer("yyy", 10002, "yyy@example.com"); + + static public TestCustomerEntity hsCustomer(final String prefix, final int reference, final String adminName) { + return new TestCustomerEntity(randomUUID(), prefix, reference, adminName); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerControllerAcceptanceTest.java similarity index 95% rename from src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerAcceptanceTest.java rename to src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerControllerAcceptanceTest.java index 3a5c6186..920b4ab0 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerControllerAcceptanceTest.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hs.hscustomer; +package net.hostsharing.hsadminng.test.cust; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -22,7 +22,7 @@ import static org.hamcrest.Matchers.*; classes = HsadminNgApplication.class ) @Transactional -class CustomerControllerAcceptanceTest { +class TestCustomerControllerAcceptanceTest { @LocalServerPort private Integer port; @@ -33,7 +33,7 @@ class CustomerControllerAcceptanceTest { @Autowired Context contextMock; @Autowired - CustomerRepository customerRepository; + TestCustomerRepository testCustomerRepository; @Nested class ListCustomers { @@ -137,7 +137,7 @@ class CustomerControllerAcceptanceTest { final var newUserUuid = UUID.fromString( location.substring(location.lastIndexOf('/') + 1)); context.define("customer-admin@ttt.example.com"); - assertThat(customerRepository.findByUuid(newUserUuid)) + assertThat(testCustomerRepository.findByUuid(newUserUuid)) .hasValueSatisfying(c -> assertThat(c.getPrefix()).isEqualTo("ttt")); } @@ -172,7 +172,7 @@ class CustomerControllerAcceptanceTest { final var newUserUuid = UUID.fromString( location.substring(location.lastIndexOf('/') + 1)); context.define("customer-admin@vvv.example.com"); - assertThat(customerRepository.findByUuid(newUserUuid)) + assertThat(testCustomerRepository.findByUuid(newUserUuid)) .hasValueSatisfying(c -> { assertThat(c.getPrefix()).isEqualTo("vvv"); assertThat(c.getUuid()).isEqualTo(givenUuid); @@ -206,7 +206,7 @@ class CustomerControllerAcceptanceTest { // finally, the new customer was not created context.define("sven@example.org"); - assertThat(customerRepository.findCustomerByOptionalPrefixLike("uuu")).hasSize(0); + assertThat(testCustomerRepository.findCustomerByOptionalPrefixLike("uuu")).hasSize(0); } @Test @@ -235,7 +235,7 @@ class CustomerControllerAcceptanceTest { // finally, the new customer was not created context.define("sven@example.org"); - assertThat(customerRepository.findCustomerByOptionalPrefixLike("uuu")).hasSize(0); + assertThat(testCustomerRepository.findCustomerByOptionalPrefixLike("uuu")).hasSize(0); } } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepositoryIntegrationTest.java similarity index 72% rename from src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java rename to src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepositoryIntegrationTest.java index 7f026b17..b82ac71b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/CustomerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/test/cust/TestCustomerRepositoryIntegrationTest.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hs.hscustomer; +package net.hostsharing.hsadminng.test.cust; import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.ContextBasedTest; @@ -20,12 +20,12 @@ import static net.hostsharing.test.JpaAttempt.attempt; import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest -@ComponentScan(basePackageClasses = { Context.class, CustomerRepository.class }) +@ComponentScan(basePackageClasses = { Context.class, TestCustomerRepository.class }) @DirtiesContext -class CustomerRepositoryIntegrationTest extends ContextBasedTest { +class TestCustomerRepositoryIntegrationTest extends ContextBasedTest { @Autowired - CustomerRepository customerRepository; + TestCustomerRepository testCustomerRepository; @Autowired EntityManager em; @@ -40,21 +40,21 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { public void testGlobalAdmin_withoutAssumedRole_canCreateNewCustomer() { // given context("mike@example.org", null); - final var count = customerRepository.count(); + final var count = testCustomerRepository.count(); // when final var result = attempt(em, () -> { - final var newCustomer = new CustomerEntity( + final var newCustomer = new TestCustomerEntity( UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); - return customerRepository.save(newCustomer); + return testCustomerRepository.save(newCustomer); }); // then assertThat(result.wasSuccessful()).isTrue(); - assertThat(result.returnedValue()).isNotNull().extracting(CustomerEntity::getUuid).isNotNull(); + assertThat(result.returnedValue()).isNotNull().extracting(TestCustomerEntity::getUuid).isNotNull(); assertThatCustomerIsPersisted(result.returnedValue()); - assertThat(customerRepository.count()).isEqualTo(count + 1); + assertThat(testCustomerRepository.count()).isEqualTo(count + 1); } @Test @@ -64,9 +64,9 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { // when final var result = attempt(em, () -> { - final var newCustomer = new CustomerEntity( + final var newCustomer = new TestCustomerEntity( UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); - return customerRepository.save(newCustomer); + return testCustomerRepository.save(newCustomer); }); // then @@ -82,9 +82,9 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { // when final var result = attempt(em, () -> { - final var newCustomer = new CustomerEntity( + final var newCustomer = new TestCustomerEntity( UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); - return customerRepository.save(newCustomer); + return testCustomerRepository.save(newCustomer); }); // then @@ -94,8 +94,8 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { } - private void assertThatCustomerIsPersisted(final CustomerEntity saved) { - final var found = customerRepository.findByUuid(saved.getUuid()); + private void assertThatCustomerIsPersisted(final TestCustomerEntity saved) { + final var found = testCustomerRepository.findByUuid(saved.getUuid()); assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved); } } @@ -109,7 +109,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { context("mike@example.org", null); // when - final var result = customerRepository.findCustomerByOptionalPrefixLike(null); + final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(null); // then allTheseCustomersAreReturned(result, "xxx", "yyy", "zzz"); @@ -121,7 +121,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { context("mike@example.org", "global#test-global.admin"); // when - final var result = customerRepository.findCustomerByOptionalPrefixLike(null); + final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(null); then: allTheseCustomersAreReturned(result, "xxx", "yyy", "zzz"); @@ -133,7 +133,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { context("customer-admin@xxx.example.com", null); // when: - final var result = customerRepository.findCustomerByOptionalPrefixLike(null); + final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(null); // then: exactlyTheseCustomersAreReturned(result, "xxx"); @@ -143,7 +143,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { public void customerAdmin_withAssumedOwnedPackageAdminRole_canViewOnlyItsOwnCustomer() { context("customer-admin@xxx.example.com", "test_package#xxx00.admin"); - final var result = customerRepository.findCustomerByOptionalPrefixLike(null); + final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(null); exactlyTheseCustomersAreReturned(result, "xxx"); } @@ -158,7 +158,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { context("mike@example.org", null); // when - final var result = customerRepository.findCustomerByOptionalPrefixLike("yyy"); + final var result = testCustomerRepository.findCustomerByOptionalPrefixLike("yyy"); // then exactlyTheseCustomersAreReturned(result, "yyy"); @@ -170,23 +170,23 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest { context("customer-admin@xxx.example.com", null); // when: - final var result = customerRepository.findCustomerByOptionalPrefixLike("yyy"); + final var result = testCustomerRepository.findCustomerByOptionalPrefixLike("yyy"); // then: exactlyTheseCustomersAreReturned(result); } } - void exactlyTheseCustomersAreReturned(final List actualResult, final String... customerPrefixes) { + void exactlyTheseCustomersAreReturned(final List actualResult, final String... customerPrefixes) { assertThat(actualResult) .hasSize(customerPrefixes.length) - .extracting(CustomerEntity::getPrefix) + .extracting(TestCustomerEntity::getPrefix) .containsExactlyInAnyOrder(customerPrefixes); } - void allTheseCustomersAreReturned(final List actualResult, final String... customerPrefixes) { + void allTheseCustomersAreReturned(final List actualResult, final String... customerPrefixes) { assertThat(actualResult) - .extracting(CustomerEntity::getPrefix) + .extracting(TestCustomerEntity::getPrefix) .contains(customerPrefixes); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/test/pac/PackageControllerAcceptanceTest.java similarity index 99% rename from src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerAcceptanceTest.java rename to src/test/java/net/hostsharing/hsadminng/test/pac/PackageControllerAcceptanceTest.java index 42c152a3..a2d1ef51 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/test/pac/PackageControllerAcceptanceTest.java @@ -1,4 +1,4 @@ -package net.hostsharing.hsadminng.hs.hspackage; +package net.hostsharing.hsadminng.test.pac; import io.restassured.RestAssured; import io.restassured.http.ContentType; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/test/pac/PackageRepositoryIntegrationTest.java similarity index 95% rename from src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepositoryIntegrationTest.java rename to src/test/java/net/hostsharing/hsadminng/test/pac/PackageRepositoryIntegrationTest.java index b0a9467d..c95702b5 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/PackageRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/test/pac/PackageRepositoryIntegrationTest.java @@ -1,7 +1,7 @@ -package net.hostsharing.hsadminng.hs.hspackage; +package net.hostsharing.hsadminng.test.pac; import net.hostsharing.hsadminng.context.Context; -import net.hostsharing.hsadminng.hs.hscustomer.CustomerRepository; +import net.hostsharing.hsadminng.test.cust.TestCustomerRepository; import net.hostsharing.test.JpaAttempt; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -19,7 +19,7 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest -@ComponentScan(basePackageClasses = { Context.class, CustomerRepository.class, JpaAttempt.class }) +@ComponentScan(basePackageClasses = { Context.class, TestCustomerRepository.class, JpaAttempt.class }) @DirtiesContext class PackageRepositoryIntegrationTest { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java b/src/test/java/net/hostsharing/hsadminng/test/pac/TestPackage.java similarity index 62% rename from src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java rename to src/test/java/net/hostsharing/hsadminng/test/pac/TestPackage.java index bac92208..accfc416 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java +++ b/src/test/java/net/hostsharing/hsadminng/test/pac/TestPackage.java @@ -1,7 +1,7 @@ -package net.hostsharing.hsadminng.hs.hspackage; +package net.hostsharing.hsadminng.test.pac; -import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity; -import net.hostsharing.hsadminng.hs.hscustomer.TestCustomer; +import net.hostsharing.hsadminng.test.cust.TestCustomer; +import net.hostsharing.hsadminng.test.cust.TestCustomerEntity; import static java.util.UUID.randomUUID; @@ -11,7 +11,7 @@ public class TestPackage { public static final PackageEntity xxx01 = hsPackage(TestCustomer.xxx, "xxx01"); public static final PackageEntity xxx02 = hsPackage(TestCustomer.xxx, "xxx02"); - public static PackageEntity hsPackage(final CustomerEntity customer, final String name) { + public static PackageEntity hsPackage(final TestCustomerEntity customer, final String name) { return new PackageEntity(randomUUID(), 0, customer, name, "initial description of package " + name); } }