use customer/package/unixuser only as test data structure (Java part)

This commit is contained in:
Michael Hoennig 2022-08-31 09:47:35 +02:00
parent a33cb4ec29
commit 84ce90b28f
15 changed files with 123 additions and 125 deletions

View File

@ -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<CustomerEntity, UUID> {
Optional<CustomerEntity> findByUuid(UUID id);
@Query("SELECT c FROM CustomerEntity c WHERE :prefix is null or c.prefix like concat(:prefix, '%')")
List<CustomerEntity> findCustomerByOptionalPrefixLike(String prefix);
CustomerEntity save(final CustomerEntity entity);
long count();
}

View File

@ -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.Context;
import net.hostsharing.hsadminng.generated.api.v1.api.CustomersApi; import net.hostsharing.hsadminng.generated.api.v1.api.CustomersApi;
@ -17,13 +17,13 @@ import static net.hostsharing.hsadminng.Mapper.mapList;
@RestController @RestController
public class CustomerController implements CustomersApi { public class TestCustomerController implements CustomersApi {
@Autowired @Autowired
private Context context; private Context context;
@Autowired @Autowired
private CustomerRepository customerRepository; private TestCustomerRepository testCustomerRepository;
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
@ -34,7 +34,7 @@ public class CustomerController implements CustomersApi {
) { ) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var result = customerRepository.findCustomerByOptionalPrefixLike(prefix); final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(prefix);
return ResponseEntity.ok(mapList(result, CustomerResource.class)); return ResponseEntity.ok(mapList(result, CustomerResource.class));
} }
@ -52,7 +52,7 @@ public class CustomerController implements CustomersApi {
customer.setUuid(UUID.randomUUID()); 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 = final var uri =
MvcUriComponentsBuilder.fromController(getClass()) MvcUriComponentsBuilder.fromController(getClass())

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.hscustomer; package net.hostsharing.hsadminng.test.cust;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -14,7 +14,7 @@ import java.util.UUID;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class CustomerEntity { public class TestCustomerEntity {
private @Id UUID uuid; private @Id UUID uuid;
private String prefix; private String prefix;
private int reference; private int reference;

View File

@ -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<TestCustomerEntity, UUID> {
Optional<TestCustomerEntity> findByUuid(UUID id);
@Query("SELECT c FROM TestCustomerEntity c WHERE :prefix is null or c.prefix like concat(:prefix, '%')")
List<TestCustomerEntity> findCustomerByOptionalPrefixLike(String prefix);
TestCustomerEntity save(final TestCustomerEntity entity);
long count();
}

View File

@ -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.OptionalFromJson;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
@ -28,9 +28,9 @@ public class PackageController implements PackagesApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<PackageResource>> listPackages( public ResponseEntity<List<PackageResource>> listPackages(
String currentUser, String currentUser,
String assumedRoles, String assumedRoles,
String name String name
) { ) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
@ -41,10 +41,10 @@ public class PackageController implements PackagesApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<PackageResource> updatePackage( public ResponseEntity<PackageResource> updatePackage(
final String currentUser, final String currentUser,
final String assumedRoles, final String assumedRoles,
final UUID packageUuid, final UUID packageUuid,
final PackageUpdateResource body) { final PackageUpdateResource body) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);

View File

@ -1,10 +1,10 @@
package net.hostsharing.hsadminng.hs.hspackage; package net.hostsharing.hsadminng.test.pac;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity; import net.hostsharing.hsadminng.test.cust.TestCustomerEntity;
import javax.persistence.*; import javax.persistence.*;
import java.util.UUID; import java.util.UUID;
@ -24,7 +24,7 @@ public class PackageEntity {
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "customeruuid") @JoinColumn(name = "customeruuid")
private CustomerEntity customer; private TestCustomerEntity customer;
private String name; private String name;

View File

@ -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.jpa.repository.Query;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;

View File

@ -18,73 +18,73 @@ public class ArchTest {
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule contextPackageRule = classes() public static final ArchRule contextPackageRule = classes()
.that().resideInAPackage("..context..") .that().resideInAPackage("..context..")
.should().onlyDependOnClassesThat() .should().onlyDependOnClassesThat()
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule configPackageRule = classes() public static final ArchRule configPackageRule = classes()
.that().resideInAPackage("..config..") .that().resideInAPackage("..config..")
.should().onlyDependOnClassesThat() .should().onlyDependOnClassesThat()
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule errorsPackageRule = classes() public static final ArchRule errorsPackageRule = classes()
.that().resideInAPackage("..errors..") .that().resideInAPackage("..errors..")
.should().onlyDependOnClassesThat() .should().onlyDependOnClassesThat()
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG); .resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule hsPackagesRule = classes() public static final ArchRule hsPackagesRule = classes()
.that().resideInAPackage("..hs.(*)..") .that().resideInAPackage("..test.(*)..")
.should().onlyBeAccessed().byClassesThat() .should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.(*).."); .resideInAnyPackage("..test.(*)..");
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule hsPackagePackageRule = classes() public static final ArchRule hsPackagePackageRule = classes()
.that().resideInAPackage("..hs.hspackage..") .that().resideInAPackage("..test.pac..")
.should().onlyBeAccessed().byClassesThat() .should().onlyBeAccessed().byClassesThat()
.resideInAnyPackage("..hs.hspackage.."); .resideInAnyPackage("..test.pac..");
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule acceptsAnnotationOnMethodsRule = methods() public static final ArchRule acceptsAnnotationOnMethodsRule = methods()
.that().areAnnotatedWith(Accepts.class) .that().areAnnotatedWith(Accepts.class)
.should().beDeclaredInClassesThat().haveSimpleNameEndingWith("AcceptanceTest") .should().beDeclaredInClassesThat().haveSimpleNameEndingWith("AcceptanceTest")
.orShould().beDeclaredInClassesThat().haveSimpleNameNotContaining("AcceptanceTest$"); .orShould().beDeclaredInClassesThat().haveSimpleNameNotContaining("AcceptanceTest$");
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule acceptsAnnotationOnClasesRule = classes() public static final ArchRule acceptsAnnotationOnClasesRule = classes()
.that().areAnnotatedWith(Accepts.class) .that().areAnnotatedWith(Accepts.class)
.should().haveSimpleNameEndingWith("AcceptanceTest") .should().haveSimpleNameEndingWith("AcceptanceTest")
.orShould().haveSimpleNameNotContaining("AcceptanceTest$"); .orShould().haveSimpleNameNotContaining("AcceptanceTest$");
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule doNotUseJavaxTransactionAnnotationAtClassLevel = noClasses() public static final ArchRule doNotUseJavaxTransactionAnnotationAtClassLevel = noClasses()
.should().beAnnotatedWith(javax.transaction.Transactional.class.getName()) .should().beAnnotatedWith(javax.transaction.Transactional.class.getName())
.as("Use @%s instead of @%s." .formatted( .as("Use @%s instead of @%s.".formatted(
org.springframework.transaction.annotation.Transactional.class.getName(), org.springframework.transaction.annotation.Transactional.class.getName(),
javax.transaction.Transactional.class)); javax.transaction.Transactional.class));
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule doNotUseJavaxTransactionAnnotationAtMethodLevel = noMethods() public static final ArchRule doNotUseJavaxTransactionAnnotationAtMethodLevel = noMethods()
.should().beAnnotatedWith(javax.transaction.Transactional.class) .should().beAnnotatedWith(javax.transaction.Transactional.class)
.as("Use @%s instead of @%s." .formatted( .as("Use @%s instead of @%s.".formatted(
org.springframework.transaction.annotation.Transactional.class.getName(), org.springframework.transaction.annotation.Transactional.class.getName(),
javax.transaction.Transactional.class.getName())); javax.transaction.Transactional.class.getName()));
@com.tngtech.archunit.junit.ArchTest @com.tngtech.archunit.junit.ArchTest
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static final ArchRule doNotUseOrgJUnitTestAnnotation = noMethods() public static final ArchRule doNotUseOrgJUnitTestAnnotation = noMethods()
.should().beAnnotatedWith(org.junit.Test.class) .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.jupiter.api.Test.class.getName(),
org.junit.Test.class.getName())); org.junit.Test.class.getName()));

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.hscustomer; package net.hostsharing.hsadminng.test.cust;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
@ -22,7 +22,7 @@ import static org.hamcrest.Matchers.*;
classes = HsadminNgApplication.class classes = HsadminNgApplication.class
) )
@Transactional @Transactional
class CustomerControllerAcceptanceTest { class TestCustomerControllerAcceptanceTest {
@LocalServerPort @LocalServerPort
private Integer port; private Integer port;
@ -33,7 +33,7 @@ class CustomerControllerAcceptanceTest {
@Autowired @Autowired
Context contextMock; Context contextMock;
@Autowired @Autowired
CustomerRepository customerRepository; TestCustomerRepository testCustomerRepository;
@Nested @Nested
class ListCustomers { class ListCustomers {
@ -137,7 +137,7 @@ class CustomerControllerAcceptanceTest {
final var newUserUuid = UUID.fromString( final var newUserUuid = UUID.fromString(
location.substring(location.lastIndexOf('/') + 1)); location.substring(location.lastIndexOf('/') + 1));
context.define("customer-admin@ttt.example.com"); context.define("customer-admin@ttt.example.com");
assertThat(customerRepository.findByUuid(newUserUuid)) assertThat(testCustomerRepository.findByUuid(newUserUuid))
.hasValueSatisfying(c -> assertThat(c.getPrefix()).isEqualTo("ttt")); .hasValueSatisfying(c -> assertThat(c.getPrefix()).isEqualTo("ttt"));
} }
@ -172,7 +172,7 @@ class CustomerControllerAcceptanceTest {
final var newUserUuid = UUID.fromString( final var newUserUuid = UUID.fromString(
location.substring(location.lastIndexOf('/') + 1)); location.substring(location.lastIndexOf('/') + 1));
context.define("customer-admin@vvv.example.com"); context.define("customer-admin@vvv.example.com");
assertThat(customerRepository.findByUuid(newUserUuid)) assertThat(testCustomerRepository.findByUuid(newUserUuid))
.hasValueSatisfying(c -> { .hasValueSatisfying(c -> {
assertThat(c.getPrefix()).isEqualTo("vvv"); assertThat(c.getPrefix()).isEqualTo("vvv");
assertThat(c.getUuid()).isEqualTo(givenUuid); assertThat(c.getUuid()).isEqualTo(givenUuid);
@ -206,7 +206,7 @@ class CustomerControllerAcceptanceTest {
// finally, the new customer was not created // finally, the new customer was not created
context.define("sven@example.org"); context.define("sven@example.org");
assertThat(customerRepository.findCustomerByOptionalPrefixLike("uuu")).hasSize(0); assertThat(testCustomerRepository.findCustomerByOptionalPrefixLike("uuu")).hasSize(0);
} }
@Test @Test
@ -235,7 +235,7 @@ class CustomerControllerAcceptanceTest {
// finally, the new customer was not created // finally, the new customer was not created
context.define("sven@example.org"); context.define("sven@example.org");
assertThat(customerRepository.findCustomerByOptionalPrefixLike("uuu")).hasSize(0); assertThat(testCustomerRepository.findCustomerByOptionalPrefixLike("uuu")).hasSize(0);
} }
} }
} }

View File

@ -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.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest; 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; import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@ComponentScan(basePackageClasses = { Context.class, CustomerRepository.class }) @ComponentScan(basePackageClasses = { Context.class, TestCustomerRepository.class })
@DirtiesContext @DirtiesContext
class CustomerRepositoryIntegrationTest extends ContextBasedTest { class TestCustomerRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
CustomerRepository customerRepository; TestCustomerRepository testCustomerRepository;
@Autowired @Autowired
EntityManager em; EntityManager em;
@ -40,21 +40,21 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
public void testGlobalAdmin_withoutAssumedRole_canCreateNewCustomer() { public void testGlobalAdmin_withoutAssumedRole_canCreateNewCustomer() {
// given // given
context("mike@example.org", null); context("mike@example.org", null);
final var count = customerRepository.count(); final var count = testCustomerRepository.count();
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newCustomer = new CustomerEntity( final var newCustomer = new TestCustomerEntity(
UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com");
return customerRepository.save(newCustomer); return testCustomerRepository.save(newCustomer);
}); });
// then // then
assertThat(result.wasSuccessful()).isTrue(); assertThat(result.wasSuccessful()).isTrue();
assertThat(result.returnedValue()).isNotNull().extracting(CustomerEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(TestCustomerEntity::getUuid).isNotNull();
assertThatCustomerIsPersisted(result.returnedValue()); assertThatCustomerIsPersisted(result.returnedValue());
assertThat(customerRepository.count()).isEqualTo(count + 1); assertThat(testCustomerRepository.count()).isEqualTo(count + 1);
} }
@Test @Test
@ -64,9 +64,9 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newCustomer = new CustomerEntity( final var newCustomer = new TestCustomerEntity(
UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com");
return customerRepository.save(newCustomer); return testCustomerRepository.save(newCustomer);
}); });
// then // then
@ -82,9 +82,9 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newCustomer = new CustomerEntity( final var newCustomer = new TestCustomerEntity(
UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com"); UUID.randomUUID(), "www", 90001, "customer-admin@www.example.com");
return customerRepository.save(newCustomer); return testCustomerRepository.save(newCustomer);
}); });
// then // then
@ -94,8 +94,8 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
} }
private void assertThatCustomerIsPersisted(final CustomerEntity saved) { private void assertThatCustomerIsPersisted(final TestCustomerEntity saved) {
final var found = customerRepository.findByUuid(saved.getUuid()); final var found = testCustomerRepository.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved); assertThat(found).isNotEmpty().get().usingRecursiveComparison().isEqualTo(saved);
} }
} }
@ -109,7 +109,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
context("mike@example.org", null); context("mike@example.org", null);
// when // when
final var result = customerRepository.findCustomerByOptionalPrefixLike(null); final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(null);
// then // then
allTheseCustomersAreReturned(result, "xxx", "yyy", "zzz"); allTheseCustomersAreReturned(result, "xxx", "yyy", "zzz");
@ -121,7 +121,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
context("mike@example.org", "global#test-global.admin"); context("mike@example.org", "global#test-global.admin");
// when // when
final var result = customerRepository.findCustomerByOptionalPrefixLike(null); final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(null);
then: then:
allTheseCustomersAreReturned(result, "xxx", "yyy", "zzz"); allTheseCustomersAreReturned(result, "xxx", "yyy", "zzz");
@ -133,7 +133,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
context("customer-admin@xxx.example.com", null); context("customer-admin@xxx.example.com", null);
// when: // when:
final var result = customerRepository.findCustomerByOptionalPrefixLike(null); final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(null);
// then: // then:
exactlyTheseCustomersAreReturned(result, "xxx"); exactlyTheseCustomersAreReturned(result, "xxx");
@ -143,7 +143,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
public void customerAdmin_withAssumedOwnedPackageAdminRole_canViewOnlyItsOwnCustomer() { public void customerAdmin_withAssumedOwnedPackageAdminRole_canViewOnlyItsOwnCustomer() {
context("customer-admin@xxx.example.com", "test_package#xxx00.admin"); 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"); exactlyTheseCustomersAreReturned(result, "xxx");
} }
@ -158,7 +158,7 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
context("mike@example.org", null); context("mike@example.org", null);
// when // when
final var result = customerRepository.findCustomerByOptionalPrefixLike("yyy"); final var result = testCustomerRepository.findCustomerByOptionalPrefixLike("yyy");
// then // then
exactlyTheseCustomersAreReturned(result, "yyy"); exactlyTheseCustomersAreReturned(result, "yyy");
@ -170,23 +170,23 @@ class CustomerRepositoryIntegrationTest extends ContextBasedTest {
context("customer-admin@xxx.example.com", null); context("customer-admin@xxx.example.com", null);
// when: // when:
final var result = customerRepository.findCustomerByOptionalPrefixLike("yyy"); final var result = testCustomerRepository.findCustomerByOptionalPrefixLike("yyy");
// then: // then:
exactlyTheseCustomersAreReturned(result); exactlyTheseCustomersAreReturned(result);
} }
} }
void exactlyTheseCustomersAreReturned(final List<CustomerEntity> actualResult, final String... customerPrefixes) { void exactlyTheseCustomersAreReturned(final List<TestCustomerEntity> actualResult, final String... customerPrefixes) {
assertThat(actualResult) assertThat(actualResult)
.hasSize(customerPrefixes.length) .hasSize(customerPrefixes.length)
.extracting(CustomerEntity::getPrefix) .extracting(TestCustomerEntity::getPrefix)
.containsExactlyInAnyOrder(customerPrefixes); .containsExactlyInAnyOrder(customerPrefixes);
} }
void allTheseCustomersAreReturned(final List<CustomerEntity> actualResult, final String... customerPrefixes) { void allTheseCustomersAreReturned(final List<TestCustomerEntity> actualResult, final String... customerPrefixes) {
assertThat(actualResult) assertThat(actualResult)
.extracting(CustomerEntity::getPrefix) .extracting(TestCustomerEntity::getPrefix)
.contains(customerPrefixes); .contains(customerPrefixes);
} }
} }

View File

@ -1,4 +1,4 @@
package net.hostsharing.hsadminng.hs.hspackage; package net.hostsharing.hsadminng.test.pac;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;

View File

@ -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.context.Context;
import net.hostsharing.hsadminng.hs.hscustomer.CustomerRepository; import net.hostsharing.hsadminng.test.cust.TestCustomerRepository;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -19,7 +19,7 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@ComponentScan(basePackageClasses = { Context.class, CustomerRepository.class, JpaAttempt.class }) @ComponentScan(basePackageClasses = { Context.class, TestCustomerRepository.class, JpaAttempt.class })
@DirtiesContext @DirtiesContext
class PackageRepositoryIntegrationTest { class PackageRepositoryIntegrationTest {

View File

@ -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.test.cust.TestCustomer;
import net.hostsharing.hsadminng.hs.hscustomer.TestCustomer; import net.hostsharing.hsadminng.test.cust.TestCustomerEntity;
import static java.util.UUID.randomUUID; 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 xxx01 = hsPackage(TestCustomer.xxx, "xxx01");
public static final PackageEntity xxx02 = hsPackage(TestCustomer.xxx, "xxx02"); 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); return new PackageEntity(randomUUID(), 0, customer, name, "initial description of package " + name);
} }
} }