migrate hs-api to test-api

This commit is contained in:
Michael Hoennig 2022-08-31 15:44:06 +02:00
parent a117258085
commit 8731f4a7b2
17 changed files with 99 additions and 100 deletions

View File

@ -66,18 +66,18 @@ If you have at least Docker, the Java JDK and Gradle installed in appropriate ve
# the following command should return a JSON array with just all customers: # the following command should return a JSON array with just all customers:
curl \ curl \
-H 'current-user: mike@example.org' \ -H 'current-user: mike@example.org' \
http://localhost:8080/api/customers http://localhost:8080/api/test-customers
# the following command should return a JSON array with just all packages visible for the admin of the customer yyy: # the following command should return a JSON array with just all packages visible for the admin of the customer yyy:
curl \ curl \
-H 'current-user: mike@example.org' -H 'assumed-roles: test_customer#yyy.admin' \ -H 'current-user: mike@example.org' -H 'assumed-roles: test_customer#yyy.admin' \
http://localhost:8080/api/packages http://localhost:8080/api/test-packages
# add a new customer # add a new customer
curl \ curl \
-H 'current-user: mike@example.org' -H "Content-Type: application/json" \ -H 'current-user: mike@example.org' -H "Content-Type: application/json" \
-d '{ "prefix":"ttt", "reference":80001, "adminUserName":"admin@ttt.example.com" }' \ -d '{ "prefix":"ttt", "reference":80001, "adminUserName":"admin@ttt.example.com" }' \
-X POST http://localhost:8080/api/customers -X POST http://localhost:8080/api/test-customers
If you wonder who 'mike@example.org' and 'sven@example.org' are and where the data comes from: If you wonder who 'mike@example.org' and 'sven@example.org' are and where the data comes from:
Mike and Sven are just example global admin accounts as part of the example data which is automatically inserted in Testcontainers and Development environments. Mike and Sven are just example global admin accounts as part of the example data which is automatically inserted in Testcontainers and Development environments.

View File

@ -1,8 +1,8 @@
package net.hostsharing.hsadminng.test.cust; 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.TestCustomersApi;
import net.hostsharing.hsadminng.generated.api.v1.model.CustomerResource; import net.hostsharing.hsadminng.generated.api.v1.model.TestCustomerResource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -17,7 +17,7 @@ import static net.hostsharing.hsadminng.Mapper.mapList;
@RestController @RestController
public class TestCustomerController implements CustomersApi { public class TestCustomerController implements TestCustomersApi {
@Autowired @Autowired
private Context context; private Context context;
@ -27,7 +27,7 @@ public class TestCustomerController implements CustomersApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<CustomerResource>> listCustomers( public ResponseEntity<List<TestCustomerResource>> listCustomers(
String currentUser, String currentUser,
String assumedRoles, String assumedRoles,
String prefix String prefix
@ -36,15 +36,15 @@ public class TestCustomerController implements CustomersApi {
final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(prefix); final var result = testCustomerRepository.findCustomerByOptionalPrefixLike(prefix);
return ResponseEntity.ok(mapList(result, CustomerResource.class)); return ResponseEntity.ok(mapList(result, TestCustomerResource.class));
} }
@Override @Override
@Transactional @Transactional
public ResponseEntity<CustomerResource> addCustomer( public ResponseEntity<TestCustomerResource> addCustomer(
final String currentUser, final String currentUser,
final String assumedRoles, final String assumedRoles,
final CustomerResource customer) { final TestCustomerResource customer) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
@ -56,10 +56,10 @@ public class TestCustomerController implements CustomersApi {
final var uri = final var uri =
MvcUriComponentsBuilder.fromController(getClass()) MvcUriComponentsBuilder.fromController(getClass())
.path("/api/customers/{id}") .path("/api/test-customers/{id}")
.buildAndExpand(customer.getUuid()) .buildAndExpand(customer.getUuid())
.toUri(); .toUri();
return ResponseEntity.created(uri).body(map(saved, CustomerResource.class)); return ResponseEntity.created(uri).body(map(saved, TestCustomerResource.class));
} }
} }

View File

@ -1,17 +0,0 @@
package net.hostsharing.hsadminng.test.pac;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import java.util.List;
import java.util.UUID;
public interface PackageRepository extends Repository<PackageEntity, UUID> {
@Query("SELECT p FROM PackageEntity p WHERE :name is null or p.name like concat(:name, '%')")
List<PackageEntity> findAllByOptionalNameLike(final String name);
PackageEntity findByUuid(UUID packageUuid);
PackageEntity save(PackageEntity current);
}

View File

@ -2,9 +2,9 @@ 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;
import net.hostsharing.hsadminng.generated.api.v1.api.PackagesApi; import net.hostsharing.hsadminng.generated.api.v1.api.TestPackagesApi;
import net.hostsharing.hsadminng.generated.api.v1.model.PackageResource; import net.hostsharing.hsadminng.generated.api.v1.model.TestPackageResource;
import net.hostsharing.hsadminng.generated.api.v1.model.PackageUpdateResource; import net.hostsharing.hsadminng.generated.api.v1.model.TestPackageUpdateResource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -17,41 +17,41 @@ import static net.hostsharing.hsadminng.Mapper.map;
import static net.hostsharing.hsadminng.Mapper.mapList; import static net.hostsharing.hsadminng.Mapper.mapList;
@RestController @RestController
public class PackageController implements PackagesApi { public class TestPackageController implements TestPackagesApi {
@Autowired @Autowired
private Context context; private Context context;
@Autowired @Autowired
private PackageRepository packageRepository; private TestPackageRepository testPackageRepository;
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<PackageResource>> listPackages( public ResponseEntity<List<TestPackageResource>> listPackages(
String currentUser, String currentUser,
String assumedRoles, String assumedRoles,
String name String name
) { ) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var result = packageRepository.findAllByOptionalNameLike(name); final var result = testPackageRepository.findAllByOptionalNameLike(name);
return ResponseEntity.ok(mapList(result, PackageResource.class)); return ResponseEntity.ok(mapList(result, TestPackageResource.class));
} }
@Override @Override
@Transactional @Transactional
public ResponseEntity<PackageResource> updatePackage( public ResponseEntity<TestPackageResource> updatePackage(
final String currentUser, final String currentUser,
final String assumedRoles, final String assumedRoles,
final UUID packageUuid, final UUID packageUuid,
final PackageUpdateResource body) { final TestPackageUpdateResource body) {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var current = packageRepository.findByUuid(packageUuid); final var current = testPackageRepository.findByUuid(packageUuid);
OptionalFromJson.of(body.getDescription()).ifPresent(current::setDescription); OptionalFromJson.of(body.getDescription()).ifPresent(current::setDescription);
final var saved = packageRepository.save(current); final var saved = testPackageRepository.save(current);
final var mapped = map(saved, PackageResource.class); final var mapped = map(saved, TestPackageResource.class);
return ResponseEntity.ok(mapped); return ResponseEntity.ok(mapped);
} }
} }

View File

@ -15,7 +15,7 @@ import java.util.UUID;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class PackageEntity { public class TestPackageEntity {
private @Id UUID uuid; private @Id UUID uuid;

View File

@ -0,0 +1,17 @@
package net.hostsharing.hsadminng.test.pac;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import java.util.List;
import java.util.UUID;
public interface TestPackageRepository extends Repository<TestPackageEntity, UUID> {
@Query("SELECT p FROM TestPackageEntity p WHERE :name is null or p.name like concat(:name, '%')")
List<TestPackageEntity> findAllByOptionalNameLike(final String name);
TestPackageEntity findByUuid(UUID packageUuid);
TestPackageEntity save(TestPackageEntity current);
}

View File

@ -30,14 +30,14 @@ paths:
# HS # HS
/api/customers: /api/test-customers:
$ref: "./api-definition/hs-customers.yaml" $ref: "./api-definition/test-customers.yaml"
/api/packages: /api/test-packages:
$ref: "./api-definition/hs-packages.yaml" $ref: "./api-definition/test-packages.yaml"
/api/packages/{packageUUID}: /api/test-packages/{packageUUID}:
$ref: "./api-definition/hs-packages-uuid.yaml" $ref: "./api-definition/test-packages-uuid.yaml"
# Other # Other

View File

@ -3,7 +3,7 @@ components:
schemas: schemas:
Customer: TestCustomer:
type: object type: object
properties: properties:
uuid: uuid:

View File

@ -2,7 +2,7 @@ get:
summary: Returns a list of (optionally filtered) customers. summary: Returns a list of (optionally filtered) customers.
description: Returns the list of (optionally filtered) customers which are visible to the current user or any of it's assumed roles. description: Returns the list of (optionally filtered) customers which are visible to the current user or any of it's assumed roles.
tags: tags:
- customers - testCustomers
operationId: listCustomers operationId: listCustomers
parameters: parameters:
- $ref: './api-definition/auth.yaml#/components/parameters/currentUser' - $ref: './api-definition/auth.yaml#/components/parameters/currentUser'
@ -21,7 +21,7 @@ get:
schema: schema:
type: array type: array
items: items:
$ref: './api-definition/hs-customer-schemas.yaml#/components/schemas/Customer' $ref: './api-definition/test-customer-schemas.yaml#/components/schemas/TestCustomer'
"401": "401":
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized' $ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
"403": "403":
@ -30,7 +30,7 @@ get:
post: post:
summary: Adds a new customer. summary: Adds a new customer.
tags: tags:
- customers - testCustomers
operationId: addCustomer operationId: addCustomer
parameters: parameters:
- $ref: './api-definition/auth.yaml#/components/parameters/currentUser' - $ref: './api-definition/auth.yaml#/components/parameters/currentUser'
@ -39,7 +39,7 @@ post:
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './api-definition/api-definition/hs-customer-schemas.yaml#/components/schemas/Customer' $ref: './api-definition/api-definition/test-customer-schemas.yaml#/components/schemas/TestCustomer'
required: true required: true
responses: responses:
"201": "201":
@ -47,7 +47,7 @@ post:
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './api-definition/hs-customer-schemas.yaml#/components/schemas/Customer' $ref: './api-definition/test-customer-schemas.yaml#/components/schemas/TestCustomer'
"401": "401":
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized' $ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
"403": "403":

View File

@ -3,20 +3,20 @@ components:
schemas: schemas:
Package: TestPackage:
type: object type: object
properties: properties:
uuid: uuid:
type: string type: string
format: uuid format: uuid
customer: customer:
$ref: './api-definition/hs-customer-schemas.yaml#/components/schemas/Customer' $ref: './api-definition/test-customer-schemas.yaml#/components/schemas/TestCustomer'
name: name:
type: string type: string
description: description:
type: string type: string
maxLength: 80 maxLength: 80
PackageUpdate: TestPackageUpdate:
type: object type: object
properties: properties:
description: description:

View File

@ -1,6 +1,6 @@
patch: patch:
tags: tags:
- packages - testPackages
operationId: updatePackage operationId: updatePackage
parameters: parameters:
- $ref: './api-definition/auth.yaml#/components/parameters/currentUser' - $ref: './api-definition/auth.yaml#/components/parameters/currentUser'
@ -15,14 +15,14 @@ patch:
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './api-definition/hs-package-schemas.yaml#/components/schemas/PackageUpdate' $ref: './api-definition/test-package-schemas.yaml#/components/schemas/TestPackageUpdate'
responses: responses:
"200": "200":
description: OK description: OK
content: content:
'application/json': 'application/json':
schema: schema:
$ref: './api-definition/hs-package-schemas.yaml#/components/schemas/Package' $ref: './api-definition/test-package-schemas.yaml#/components/schemas/TestPackage'
"401": "401":
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized' $ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
"403": "403":

View File

@ -1,6 +1,6 @@
get: get:
tags: tags:
- packages - testPackages
operationId: listPackages operationId: listPackages
parameters: parameters:
- $ref: './api-definition/auth.yaml#/components/parameters/currentUser' - $ref: './api-definition/auth.yaml#/components/parameters/currentUser'
@ -18,7 +18,7 @@ get:
schema: schema:
type: array type: array
items: items:
$ref: './api-definition/hs-package-schemas.yaml#/components/schemas/Package' $ref: './api-definition/test-package-schemas.yaml#/components/schemas/TestPackage'
"401": "401":
$ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized' $ref: './api-definition/error-responses.yaml#/components/responses/Unauthorized'
"403": "403":

View File

@ -7,11 +7,10 @@ options:
map: map:
result: org.springframework.http.ResponseEntity result: org.springframework.http.ResponseEntity
types: types:
- type: array => java.util.List - type: array => java.util.List
- type: string:uuid => java.util.UUID - type: string:uuid => java.util.UUID
paths: paths:
/api/packages/{packageUUID}: /api/test-packages/{packageUUID}:
null: org.openapitools.jackson.nullable.JsonNullable null: org.openapitools.jackson.nullable.JsonNullable

View File

@ -45,7 +45,7 @@ class TestCustomerControllerAcceptanceTest {
.header("current-user", "mike@example.org") .header("current-user", "mike@example.org")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/customers") .get("http://localhost/api/test-customers")
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -63,7 +63,7 @@ class TestCustomerControllerAcceptanceTest {
.header("current-user", "mike@example.org") .header("current-user", "mike@example.org")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/customers?prefix=y") .get("http://localhost/api/test-customers?prefix=y")
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -80,7 +80,7 @@ class TestCustomerControllerAcceptanceTest {
.header("assumed-roles", "test_customer#yyy.admin") .header("assumed-roles", "test_customer#yyy.admin")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/customers") .get("http://localhost/api/test-customers")
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -96,7 +96,7 @@ class TestCustomerControllerAcceptanceTest {
.header("current-user", "customer-admin@yyy.example.com") .header("current-user", "customer-admin@yyy.example.com")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/customers") .get("http://localhost/api/test-customers")
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -125,7 +125,7 @@ class TestCustomerControllerAcceptanceTest {
""") """)
.port(port) .port(port)
.when() .when()
.post("http://localhost/api/customers") .post("http://localhost/api/test-customers")
.then().assertThat() .then().assertThat()
.statusCode(201) .statusCode(201)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
@ -160,7 +160,7 @@ class TestCustomerControllerAcceptanceTest {
""".formatted(givenUuid)) """.formatted(givenUuid))
.port(port) .port(port)
.when() .when()
.post("http://localhost/api/customers") .post("http://localhost/api/test-customers")
.then().assertThat() .then().assertThat()
.statusCode(201) .statusCode(201)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
@ -196,7 +196,7 @@ class TestCustomerControllerAcceptanceTest {
""") """)
.port(port) .port(port)
.when() .when()
.post("http://localhost/api/customers") .post("http://localhost/api/test-customers")
.then().assertThat() .then().assertThat()
.statusCode(403) .statusCode(403)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
@ -225,7 +225,7 @@ class TestCustomerControllerAcceptanceTest {
""") """)
.port(port) .port(port)
.when() .when()
.post("http://localhost/api/customers") .post("http://localhost/api/test-customers")
.then().assertThat() .then().assertThat()
.statusCode(403) .statusCode(403)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)

View File

@ -7,11 +7,11 @@ import static java.util.UUID.randomUUID;
public class TestPackage { public class TestPackage {
public static final PackageEntity xxx00 = hsPackage(TestCustomer.xxx, "xxx00"); public static final TestPackageEntity xxx00 = hsPackage(TestCustomer.xxx, "xxx00");
public static final PackageEntity xxx01 = hsPackage(TestCustomer.xxx, "xxx01"); public static final TestPackageEntity xxx01 = hsPackage(TestCustomer.xxx, "xxx01");
public static final PackageEntity xxx02 = hsPackage(TestCustomer.xxx, "xxx02"); public static final TestPackageEntity xxx02 = hsPackage(TestCustomer.xxx, "xxx02");
public static PackageEntity hsPackage(final TestCustomerEntity customer, final String name) { public static TestPackageEntity hsPackage(final TestCustomerEntity customer, final String name) {
return new PackageEntity(randomUUID(), 0, customer, name, "initial description of package " + name); return new TestPackageEntity(randomUUID(), 0, customer, name, "initial description of package " + name);
} }
} }

View File

@ -25,7 +25,7 @@ import static org.hamcrest.Matchers.is;
classes = HsadminNgApplication.class classes = HsadminNgApplication.class
) )
@Transactional @Transactional
class PackageControllerAcceptanceTest { class TestPackageControllerAcceptanceTest {
@LocalServerPort @LocalServerPort
Integer port; Integer port;
@ -33,7 +33,7 @@ class PackageControllerAcceptanceTest {
Context context; Context context;
@Autowired @Autowired
PackageRepository packageRepository; TestPackageRepository testPackageRepository;
@Nested @Nested
class ListPackages { class ListPackages {
@ -47,7 +47,7 @@ class PackageControllerAcceptanceTest {
.header("assumed-roles", "test_customer#xxx.admin") .header("assumed-roles", "test_customer#xxx.admin")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/packages") .get("http://localhost/api/test-packages")
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -69,7 +69,7 @@ class PackageControllerAcceptanceTest {
.header("assumed-roles", "test_customer#xxx.admin") .header("assumed-roles", "test_customer#xxx.admin")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/packages?name=xxx01") .get("http://localhost/api/test-packages?name=xxx01")
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -103,7 +103,7 @@ class PackageControllerAcceptanceTest {
""", randomDescription)) """, randomDescription))
.port(port) .port(port)
.when() .when()
.patch("http://localhost/api/packages/{uuidOfPackage}", getUuidOfPackage("xxx00")) .patch("http://localhost/api/test-packages/{uuidOfPackage}", getUuidOfPackage("xxx00"))
.then() .then()
.assertThat() .assertThat()
.statusCode(200) .statusCode(200)
@ -133,7 +133,7 @@ class PackageControllerAcceptanceTest {
""") """)
.port(port) .port(port)
.when() .when()
.patch("http://localhost/api/packages/{uuidOfPackage}", getUuidOfPackage("xxx01")) .patch("http://localhost/api/test-packages/{uuidOfPackage}", getUuidOfPackage("xxx01"))
.then() .then()
.assertThat() .assertThat()
.statusCode(200) .statusCode(200)
@ -158,7 +158,7 @@ class PackageControllerAcceptanceTest {
.body("{}") .body("{}")
.port(port) .port(port)
.when() .when()
.patch("http://localhost/api/packages/{uuidOfPackage}", getUuidOfPackage("xxx02")) .patch("http://localhost/api/test-packages/{uuidOfPackage}", getUuidOfPackage("xxx02"))
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -176,7 +176,7 @@ class PackageControllerAcceptanceTest {
.header("assumed-roles", "test_customer#xxx.admin") .header("assumed-roles", "test_customer#xxx.admin")
.port(port) .port(port)
.when() .when()
.get("http://localhost/api/packages?name={packageName}", packageName) .get("http://localhost/api/test-packages?name={packageName}", packageName)
.then() .then()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
@ -186,6 +186,6 @@ class PackageControllerAcceptanceTest {
String getDescriptionOfPackage(final String packageName) { String getDescriptionOfPackage(final String packageName) {
context.define("mike@example.org","test_customer#xxx.admin"); context.define("mike@example.org","test_customer#xxx.admin");
return packageRepository.findAllByOptionalNameLike(packageName).get(0).getDescription(); return testPackageRepository.findAllByOptionalNameLike(packageName).get(0).getDescription();
} }
} }

View File

@ -21,13 +21,13 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@ComponentScan(basePackageClasses = { Context.class, TestCustomerRepository.class, JpaAttempt.class }) @ComponentScan(basePackageClasses = { Context.class, TestCustomerRepository.class, JpaAttempt.class })
@DirtiesContext @DirtiesContext
class PackageRepositoryIntegrationTest { class TestPackageRepositoryIntegrationTest {
@Autowired @Autowired
Context context; Context context;
@Autowired @Autowired
PackageRepository packageRepository; TestPackageRepository testPackageRepository;
@Autowired @Autowired
EntityManager em; EntityManager em;
@ -47,7 +47,7 @@ class PackageRepositoryIntegrationTest {
context.define("mike@example.org"); context.define("mike@example.org");
// when // when
final var result = packageRepository.findAllByOptionalNameLike(null); final var result = testPackageRepository.findAllByOptionalNameLike(null);
// then // then
noPackagesAreReturned(result); noPackagesAreReturned(result);
@ -59,7 +59,7 @@ class PackageRepositoryIntegrationTest {
context.define("mike@example.org", "global#test-global.admin"); context.define("mike@example.org", "global#test-global.admin");
// when // when
final var result = packageRepository.findAllByOptionalNameLike(null); final var result = testPackageRepository.findAllByOptionalNameLike(null);
then: then:
noPackagesAreReturned(result); noPackagesAreReturned(result);
@ -71,7 +71,7 @@ class PackageRepositoryIntegrationTest {
context.define("customer-admin@xxx.example.com"); context.define("customer-admin@xxx.example.com");
// when: // when:
final var result = packageRepository.findAllByOptionalNameLike(null); final var result = testPackageRepository.findAllByOptionalNameLike(null);
// then: // then:
exactlyThesePackagesAreReturned(result, "xxx00", "xxx01", "xxx02"); exactlyThesePackagesAreReturned(result, "xxx00", "xxx01", "xxx02");
@ -81,7 +81,7 @@ class PackageRepositoryIntegrationTest {
public void customerAdmin_withAssumedOwnedPackageAdminRole_canViewOnlyItsOwnPackages() { public void customerAdmin_withAssumedOwnedPackageAdminRole_canViewOnlyItsOwnPackages() {
context.define("customer-admin@xxx.example.com", "test_package#xxx00.admin"); context.define("customer-admin@xxx.example.com", "test_package#xxx00.admin");
final var result = packageRepository.findAllByOptionalNameLike(null); final var result = testPackageRepository.findAllByOptionalNameLike(null);
exactlyThesePackagesAreReturned(result, "xxx00"); exactlyThesePackagesAreReturned(result, "xxx00");
} }
@ -94,18 +94,18 @@ class PackageRepositoryIntegrationTest {
public void supportsOptimisticLocking() throws InterruptedException { public void supportsOptimisticLocking() throws InterruptedException {
// given // given
testGlobalAdminWithAssumedRole("test_package#xxx00.admin"); testGlobalAdminWithAssumedRole("test_package#xxx00.admin");
final var pac = packageRepository.findAllByOptionalNameLike("%").get(0); final var pac = testPackageRepository.findAllByOptionalNameLike("%").get(0);
// when // when
final var result1 = jpaAttempt.transacted(() -> { final var result1 = jpaAttempt.transacted(() -> {
testGlobalAdminWithAssumedRole("test_package#xxx00.admin"); testGlobalAdminWithAssumedRole("test_package#xxx00.admin");
pac.setDescription("description set by thread 1"); pac.setDescription("description set by thread 1");
packageRepository.save(pac); testPackageRepository.save(pac);
}); });
final var result2 = jpaAttempt.transacted(() -> { final var result2 = jpaAttempt.transacted(() -> {
testGlobalAdminWithAssumedRole("test_package#xxx00.admin"); testGlobalAdminWithAssumedRole("test_package#xxx00.admin");
pac.setDescription("description set by thread 2"); pac.setDescription("description set by thread 2");
packageRepository.save(pac); testPackageRepository.save(pac);
sleep(1500); sleep(1500);
}); });
@ -129,15 +129,15 @@ class PackageRepositoryIntegrationTest {
context.define("mike@example.org", assumedRoles); context.define("mike@example.org", assumedRoles);
} }
void noPackagesAreReturned(final List<PackageEntity> actualResult) { void noPackagesAreReturned(final List<TestPackageEntity> actualResult) {
assertThat(actualResult) assertThat(actualResult)
.extracting(PackageEntity::getName) .extracting(TestPackageEntity::getName)
.isEmpty(); .isEmpty();
} }
void exactlyThesePackagesAreReturned(final List<PackageEntity> actualResult, final String... packageNames) { void exactlyThesePackagesAreReturned(final List<TestPackageEntity> actualResult, final String... packageNames) {
assertThat(actualResult) assertThat(actualResult)
.extracting(PackageEntity::getName) .extracting(TestPackageEntity::getName)
.containsExactlyInAnyOrder(packageNames); .containsExactlyInAnyOrder(packageNames);
} }