use customer/package/unixuser only as test data structure (Java part)
This commit is contained in:
parent
a33cb4ec29
commit
84ce90b28f
@ -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();
|
||||
}
|
@ -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())
|
@ -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;
|
@ -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();
|
||||
}
|
@ -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;
|
@ -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;
|
||||
|
@ -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;
|
@ -39,16 +39,16 @@ public class ArchTest {
|
||||
@com.tngtech.archunit.junit.ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule hsPackagesRule = classes()
|
||||
.that().resideInAPackage("..hs.(*)..")
|
||||
.that().resideInAPackage("..test.(*)..")
|
||||
.should().onlyBeAccessed().byClassesThat()
|
||||
.resideInAnyPackage("..hs.(*)..");
|
||||
.resideInAnyPackage("..test.(*)..");
|
||||
|
||||
@com.tngtech.archunit.junit.ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule hsPackagePackageRule = classes()
|
||||
.that().resideInAPackage("..hs.hspackage..")
|
||||
.that().resideInAPackage("..test.pac..")
|
||||
.should().onlyBeAccessed().byClassesThat()
|
||||
.resideInAnyPackage("..hs.hspackage..");
|
||||
.resideInAnyPackage("..test.pac..");
|
||||
|
||||
@com.tngtech.archunit.junit.ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
@ -68,7 +68,7 @@ public class ArchTest {
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule doNotUseJavaxTransactionAnnotationAtClassLevel = noClasses()
|
||||
.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(),
|
||||
javax.transaction.Transactional.class));
|
||||
|
||||
@ -76,7 +76,7 @@ public class ArchTest {
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule doNotUseJavaxTransactionAnnotationAtMethodLevel = noMethods()
|
||||
.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(),
|
||||
javax.transaction.Transactional.class.getName()));
|
||||
|
||||
@ -84,7 +84,7 @@ public class 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()));
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<CustomerEntity> actualResult, final String... customerPrefixes) {
|
||||
void exactlyTheseCustomersAreReturned(final List<TestCustomerEntity> actualResult, final String... customerPrefixes) {
|
||||
assertThat(actualResult)
|
||||
.hasSize(customerPrefixes.length)
|
||||
.extracting(CustomerEntity::getPrefix)
|
||||
.extracting(TestCustomerEntity::getPrefix)
|
||||
.containsExactlyInAnyOrder(customerPrefixes);
|
||||
}
|
||||
|
||||
void allTheseCustomersAreReturned(final List<CustomerEntity> actualResult, final String... customerPrefixes) {
|
||||
void allTheseCustomersAreReturned(final List<TestCustomerEntity> actualResult, final String... customerPrefixes) {
|
||||
assertThat(actualResult)
|
||||
.extracting(CustomerEntity::getPrefix)
|
||||
.extracting(TestCustomerEntity::getPrefix)
|
||||
.contains(customerPrefixes);
|
||||
}
|
||||
}
|
@ -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;
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user