add assigned-asset, add more hosting-asset test-data and introduce HsBookingDebitor+hs_booking_debitor_rv #58
@ -0,0 +1,55 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.debitor;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.stringify.Stringify;
|
||||
import net.hostsharing.hsadminng.stringify.Stringifyable;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
|
||||
|
||||
// a partial HsOfficeDebitorEntity to reduce the number of SQL queries to load the entity
|
||||
@Entity
|
||||
@Table(name = "hs_office_debitor_rv") // TODO.impl: create a readonly view for this, which also joins the partner-number?
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("BookingDebitor")
|
||||
public class HsBookingDebitorEntity implements Stringifyable {
|
||||
|
||||
public static final String DEBITOR_NUMBER_TAG = "D-";
|
||||
|
||||
private static Stringify<HsBookingDebitorEntity> stringify =
|
||||
stringify(HsBookingDebitorEntity.class, "booking-debitor")
|
||||
.withIdProp(HsBookingDebitorEntity::toShortString)
|
||||
.withProp(HsBookingDebitorEntity::getDefaultPrefix)
|
||||
.quotedValues(false);
|
||||
|
||||
@Id
|
||||
private UUID uuid;
|
||||
|
||||
@Column(name = "debitornumbersuffix", length = 2)
|
||||
private String debitorNumberSuffix;
|
||||
|
||||
@Column(name = "defaultprefix", columnDefinition = "char(3) not null")
|
||||
private String defaultPrefix;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stringify.apply(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toShortString() {
|
||||
return DEBITOR_NUMBER_TAG + defaultPrefix;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.project;
|
||||
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
|
||||
@ -49,7 +50,7 @@ public class HsBookingProjectEntity implements Stringifyable, RbacObject {
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "debitoruuid")
|
||||
private HsOfficeDebitorEntity debitor; // FIXME: introduce HsBookingDebitorEntity
|
||||
private HsBookingDebitorEntity debitor;
|
||||
|
||||
@Column(name = "caption")
|
||||
private String caption;
|
||||
@ -61,7 +62,7 @@ public class HsBookingProjectEntity implements Stringifyable, RbacObject {
|
||||
|
||||
@Override
|
||||
public String toShortString() {
|
||||
return ofNullable(debitor).map(HsOfficeDebitorEntity::toShortString).orElse("D-???????") +
|
||||
return ofNullable(debitor).map(HsBookingDebitorEntity::toShortString).orElse("D-???????") +
|
||||
":" + caption;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.debitor;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class HsBookingDebitorEntityTest {
|
||||
|
||||
@Test
|
||||
void toStringContainsDebitorNumberAndDefaultPrefix() {
|
||||
final var given = HsBookingDebitorEntity.builder()
|
||||
.debitorNumberSuffix("67")
|
||||
.defaultPrefix("som")
|
||||
.build();
|
||||
|
||||
final var result = given.toString();
|
||||
|
||||
assertThat(result).isEqualTo("booking-debitor(D-som: som)"); // FIXME: I want "booking-debitor(D-1000167: som)"
|
||||
}
|
||||
|
||||
@Test
|
||||
void toShortStringContainsDefaultPrefix() {
|
||||
final var given = HsBookingDebitorEntity.builder()
|
||||
.debitorNumberSuffix("67")
|
||||
.defaultPrefix("som")
|
||||
.build();
|
||||
|
||||
final var result = given.toShortString();
|
||||
|
||||
assertThat(result).isEqualTo("D-som"); // FIXME: I want "booking-debitor(D-1000167: som)"
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.debitor;
|
||||
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface HsBookingDebitorRepository extends Repository<HsBookingDebitorEntity, UUID> {
|
||||
|
||||
Optional<HsBookingDebitorEntity> findByUuid(UUID id);
|
||||
|
||||
List<HsBookingDebitorEntity> findByDefaultPrefix(String defaultPrefix);
|
||||
|
||||
long count();
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.debitor;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
|
||||
@UtilityClass
|
||||
public class TestHsBookingDebitor {
|
||||
|
||||
public String DEFAULT_DEBITOR_SUFFIX = "00";
|
||||
|
||||
public static final HsBookingDebitorEntity TEST_BOOKING_DEBITOR = HsBookingDebitorEntity.builder()
|
||||
.debitorNumberSuffix(DEFAULT_DEBITOR_SUFFIX)
|
||||
.defaultPrefix("abc")
|
||||
.build();
|
||||
}
|
@ -6,7 +6,6 @@ import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity;
|
||||
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
@ -17,8 +16,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -53,9 +50,6 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
@Autowired
|
||||
JpaAttempt jpaAttempt;
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
|
||||
@Nested
|
||||
class ListBookingItems {
|
||||
|
||||
@ -181,8 +175,9 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
void globalAdmin_canGetArbitraryBookingItem() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenBookingItemUuid = bookingItemRepo.findByCaption("some ManagedWebspace").stream()
|
||||
.filter(bi -> belongsToDebitorNumber(bi, 1000111))
|
||||
.findAny().orElseThrow().getUuid();
|
||||
.filter(bi -> belongsToDebitorWithDefaultPrefix(bi, "fir"))
|
||||
.map(HsBookingItemEntity::getUuid)
|
||||
.findAny().orElseThrow();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
@ -213,7 +208,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
void normalUser_canNotGetUnrelatedBookingItem() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenBookingItemUuid = bookingItemRepo.findByCaption("separate ManagedServer").stream()
|
||||
.filter(bi -> belongsToDebitorNumber(bi, 1000212))
|
||||
.filter(bi -> belongsToDebitorWithDefaultPrefix(bi, "sec"))
|
||||
.map(HsBookingItemEntity::getUuid)
|
||||
.findAny().orElseThrow();
|
||||
|
||||
@ -228,15 +223,17 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
}
|
||||
|
||||
@Test
|
||||
void debitorAgentUser_canGetRelatedBookingItem() {
|
||||
void projectAdmin_canGetRelatedBookingItem() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenBookingItemUuid = bookingItemRepo.findByCaption("separate ManagedServer").stream()
|
||||
.filter(bi -> belongsToDebitorNumber(bi, 1000313))
|
||||
.findAny().orElseThrow().getUuid();
|
||||
.filter(bi -> belongsToDebitorWithDefaultPrefix(bi, "thi"))
|
||||
.map(HsBookingItemEntity::getUuid)
|
||||
.findAny().orElseThrow();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "person-TuckerJack@example.com")
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.header("assumend-roles", "hs_booking_project#D-1000212-D-1000212defaultproject")
|
||||
hsh-michaelhoennig marked this conversation as resolved
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/hs/booking/items/" + givenBookingItemUuid)
|
||||
@ -259,12 +256,11 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
""")); // @formatter:on
|
||||
}
|
||||
|
||||
private static boolean belongsToDebitorNumber(final HsBookingItemEntity bi, final int i) {
|
||||
private static boolean belongsToDebitorWithDefaultPrefix(final HsBookingItemEntity bi, final String defaultPrefix) {
|
||||
return ofNullable(bi)
|
||||
.map(HsBookingItemEntity::getProject)
|
||||
.map(HsBookingProjectEntity::getDebitor)
|
||||
.map(HsOfficeDebitorEntity::getDebitorNumber)
|
||||
.filter(debitorNumber -> debitorNumber == i)
|
||||
.map(bd -> bd.getDefaultPrefix().equals(defaultPrefix))
|
||||
.isPresent();
|
||||
}
|
||||
}
|
||||
@ -315,7 +311,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
assertThat(bookingItemRepo.findByUuid(givenBookingItem.getUuid())).isPresent().get()
|
||||
.matches(mandate -> {
|
||||
assertThat(mandate.getProject().getDebitor().toString()).isEqualTo("debitor(D-1000111: rel(anchor='LP First GmbH', type='DEBITOR', holder='LP First GmbH'), fir)");
|
||||
assertThat(mandate.getProject().getDebitor().toString()).isEqualTo("booking-debitor(D-fir: fir)");
|
||||
assertThat(mandate.getValidFrom()).isEqualTo("2022-11-01");
|
||||
assertThat(mandate.getValidTo()).isEqualTo("2022-12-31");
|
||||
return true;
|
||||
|
@ -29,14 +29,14 @@ class HsBookingItemEntityUnitTest {
|
||||
void toStringContainsAllPropertiesAndResourcesSortedByKey() {
|
||||
final var result = givenBookingItem.toString();
|
||||
|
||||
assertThat(result).isEqualTo("HsBookingItemEntity(D-1000100:test project, CLOUD_SERVER, [2020-01-01,2031-01-01), some caption, { CPUs: 2, HDD-storage: 2048, SSD-storage: 512 })");
|
||||
assertThat(result).isEqualTo("HsBookingItemEntity(D-abc:test project, CLOUD_SERVER, [2020-01-01,2031-01-01), some caption, { CPUs: 2, HDD-storage: 2048, SSD-storage: 512 })");
|
||||
}
|
||||
|
||||
@Test
|
||||
void toShortStringContainsOnlyMemberNumberAndCaption() {
|
||||
final var result = givenBookingItem.toShortString();
|
||||
|
||||
assertThat(result).isEqualTo("D-1000100:test project:some caption");
|
||||
assertThat(result).isEqualTo("D-abc:test project:some caption");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -174,9 +174,9 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
|
||||
// then
|
||||
allTheseBookingItemsAreReturned(
|
||||
result,
|
||||
"HsBookingItemEntity(D-1000212:D-1000212 default project, MANAGED_SERVER, [2022-10-01,), separate ManagedServer, { CPUs: 2, RAM: 8, SDD: 512, Traffic: 42 })",
|
||||
"HsBookingItemEntity(D-1000212:D-1000212 default project, MANAGED_WEBSPACE, [2022-10-01,), some ManagedWebspace, { Daemons: 2, Multi: 4, SDD: 512, Traffic: 12 })",
|
||||
"HsBookingItemEntity(D-1000212:D-1000212 default project, PRIVATE_CLOUD, [2024-04-01,), some PrivateCloud, { CPUs: 10, HDD: 10240, SDD: 10240, Traffic: 42 })");
|
||||
"HsBookingItemEntity(D-sec:D-1000212 default project, MANAGED_WEBSPACE, [2022-10-01,), some ManagedWebspace, { Daemons: 2, Multi: 4, SDD: 512, Traffic: 12 })",
|
||||
"HsBookingItemEntity(D-sec:D-1000212 default project, MANAGED_SERVER, [2022-10-01,), separate ManagedServer, { CPUs: 2, RAM: 8, SDD: 512, Traffic: 42 })",
|
||||
"HsBookingItemEntity(D-sec:D-1000212 default project, PRIVATE_CLOUD, [2024-04-01,), some PrivateCloud, { CPUs: 10, HDD: 10240, SDD: 10240, Traffic: 42 })");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -194,9 +194,9 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
|
||||
// then:
|
||||
exactlyTheseBookingItemsAreReturned(
|
||||
result,
|
||||
"HsBookingItemEntity(D-1000111:D-1000111 default project, MANAGED_SERVER, [2022-10-01,), separate ManagedServer, { CPUs: 2, RAM: 8, SDD: 512, Traffic: 42 })",
|
||||
"HsBookingItemEntity(D-1000111:D-1000111 default project, MANAGED_WEBSPACE, [2022-10-01,), some ManagedWebspace, { Daemons: 2, Multi: 4, SDD: 512, Traffic: 12 })",
|
||||
"HsBookingItemEntity(D-1000111:D-1000111 default project, PRIVATE_CLOUD, [2024-04-01,), some PrivateCloud, { CPUs: 10, HDD: 10240, SDD: 10240, Traffic: 42 })");
|
||||
"HsBookingItemEntity(D-fir:D-1000111 default project, MANAGED_SERVER, [2022-10-01,), separate ManagedServer, { CPUs: 2, RAM: 8, SDD: 512, Traffic: 42 })",
|
||||
"HsBookingItemEntity(D-fir:D-1000111 default project, MANAGED_WEBSPACE, [2022-10-01,), some ManagedWebspace, { Daemons: 2, Multi: 4, SDD: 512, Traffic: 12 })",
|
||||
"HsBookingItemEntity(D-fir:D-1000111 default project, PRIVATE_CLOUD, [2024-04-01,), some PrivateCloud, { CPUs: 10, HDD: 10240, SDD: 10240, Traffic: 42 })");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package net.hostsharing.hsadminng.hs.booking.project;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import net.hostsharing.hsadminng.HsadminNgApplication;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
@ -40,7 +40,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
HsBookingProjectRepository projectRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficeDebitorRepository debitorRepo;
|
||||
HsBookingDebitorRepository debitorRepo;
|
||||
|
||||
@Autowired
|
||||
JpaAttempt jpaAttempt;
|
||||
@ -56,7 +56,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var givenDebitor = debitorRepo.findDebitorByDebitorNumber(1000111).stream()
|
||||
final var givenDebitor = debitorRepo.findByDefaultPrefix("fir").stream()
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
@ -87,7 +87,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
void globalAdmin_canAddBookingProject() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenDebitor = debitorRepo.findDebitorByDebitorNumber(1000111).stream()
|
||||
final var givenDebitor = debitorRepo.findByDefaultPrefix("fir").stream()
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
|
||||
@ -193,7 +193,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
@Test
|
||||
void globalAdmin_canPatchAllUpdatablePropertiesOfBookingProject() {
|
||||
|
||||
final var givenBookingProject = givenSomeBookingProject(1000111, "some project");
|
||||
final var givenBookingProject = givenSomeBookingProject("fir", "some project");
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
@ -232,7 +232,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
@Test
|
||||
void globalAdmin_canDeleteArbitraryBookingProject() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenBookingProject = givenSomeBookingProject(1000111, "some project");
|
||||
final var givenBookingProject = givenSomeBookingProject("fir", "some project");
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
@ -250,7 +250,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
@Test
|
||||
void normalUser_canNotDeleteUnrelatedBookingProject() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenBookingProject = givenSomeBookingProject(1000111, "some project");
|
||||
final var givenBookingProject = givenSomeBookingProject("fir", "some project");
|
||||
|
||||
RestAssured // @formatter:off
|
||||
.given()
|
||||
@ -266,10 +266,10 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
|
||||
}
|
||||
}
|
||||
|
||||
private HsBookingProjectEntity givenSomeBookingProject(final int debitorNumber, final String caption) {
|
||||
private HsBookingProjectEntity givenSomeBookingProject(final String defaultPrefix, final String caption) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenDebitor = debitorRepo.findDebitorByDebitorNumber(debitorNumber).stream().findAny().orElseThrow();
|
||||
final var givenDebitor = debitorRepo.findByDefaultPrefix(defaultPrefix).stream().findAny().orElseThrow();
|
||||
final var newBookingProject = HsBookingProjectEntity.builder()
|
||||
.uuid(UUID.randomUUID())
|
||||
.debitor(givenDebitor)
|
||||
|
@ -13,7 +13,7 @@ import jakarta.persistence.EntityManager;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.debitor.TestHsOfficeDebitor.TEST_DEBITOR;
|
||||
import static net.hostsharing.hsadminng.hs.booking.debitor.TestHsBookingDebitor.TEST_BOOKING_DEBITOR;
|
||||
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@ -46,7 +46,7 @@ class HsBookingProjectEntityPatcherUnitTest extends PatchUnitTestBase<
|
||||
protected HsBookingProjectEntity newInitialEntity() {
|
||||
final var entity = new HsBookingProjectEntity();
|
||||
entity.setUuid(INITIAL_BOOKING_PROJECT_UUID);
|
||||
entity.setDebitor(TEST_DEBITOR);
|
||||
entity.setDebitor(TEST_BOOKING_DEBITOR);
|
||||
entity.setCaption(INITIAL_CAPTION);
|
||||
return entity;
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ package net.hostsharing.hsadminng.hs.booking.project;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.debitor.TestHsOfficeDebitor.TEST_DEBITOR;
|
||||
import static net.hostsharing.hsadminng.hs.booking.debitor.TestHsBookingDebitor.TEST_BOOKING_DEBITOR;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class HsBookingProjectEntityUnitTest {
|
||||
final HsBookingProjectEntity givenBookingProject = HsBookingProjectEntity.builder()
|
||||
.debitor(TEST_DEBITOR)
|
||||
.debitor(TEST_BOOKING_DEBITOR)
|
||||
.caption("some caption")
|
||||
.build();
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.hostsharing.hsadminng.hs.booking.project;
|
||||
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.Array;
|
||||
@ -38,7 +38,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
HsBookingProjectRepository projectRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficeDebitorRepository debitorRepo;
|
||||
HsBookingDebitorRepository debitorRepo;
|
||||
|
||||
@Autowired
|
||||
RawRbacRoleRepository rawRoleRepo;
|
||||
@ -63,7 +63,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var count = bookingProjectRepo.count();
|
||||
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
|
||||
final var givenDebitor = debitorRepo.findByDefaultPrefix("fir").get(0);
|
||||
|
||||
// when
|
||||
final var result = attempt(em, () -> {
|
||||
@ -92,7 +92,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
|
||||
// when
|
||||
attempt(em, () -> {
|
||||
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
|
||||
final var givenDebitor = debitorRepo.findByDefaultPrefix("fir").get(0);
|
||||
final var newBookingProject = HsBookingProjectEntity.builder()
|
||||
.debitor(givenDebitor)
|
||||
.caption("some new booking project")
|
||||
@ -148,7 +148,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
public void globalAdmin_withoutAssumedRole_canViewAllBookingProjectsOfArbitraryDebitor() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var debitorUuid = debitorRepo.findDebitorByDebitorNumber(1000212).stream()
|
||||
final var debitorUuid = debitorRepo.findByDefaultPrefix("sec").stream()
|
||||
.findAny().orElseThrow().getUuid();
|
||||
|
||||
// when
|
||||
@ -164,7 +164,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
public void normalUser_canViewOnlyRelatedBookingProjects() {
|
||||
// given:
|
||||
context("person-FirbySusan@example.com");
|
||||
final var debitorUuid = debitorRepo.findDebitorByDebitorNumber(1000111).stream()
|
||||
final var debitorUuid = debitorRepo.findByDefaultPrefix("fir").stream()
|
||||
.findAny().orElseThrow().getUuid();
|
||||
|
||||
// when:
|
||||
@ -183,7 +183,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
@Test
|
||||
public void hostsharingAdmin_canUpdateArbitraryBookingProject() {
|
||||
// given
|
||||
final var givenBookingProjectUuid = givenSomeTemporaryBookingProject(1000111).getUuid();
|
||||
final var givenBookingProjectUuid = givenSomeTemporaryBookingProject("fir").getUuid();
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
@ -214,7 +214,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
public void globalAdmin_withoutAssumedRole_canDeleteAnyBookingProject() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net", null);
|
||||
final var givenBookingProject = givenSomeTemporaryBookingProject(1000111);
|
||||
final var givenBookingProject = givenSomeTemporaryBookingProject("fir");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
@ -234,7 +234,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
public void nonGlobalAdmin_canNotDeleteTheirRelatedBookingProject() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net", null);
|
||||
final var givenBookingProject = givenSomeTemporaryBookingProject(1000111);
|
||||
final var givenBookingProject = givenSomeTemporaryBookingProject("fir");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
@ -260,7 +260,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var initialRoleNames = Array.from(distinctRoleNamesOf(rawRoleRepo.findAll()));
|
||||
final var initialGrantNames = Array.from(distinctGrantDisplaysOf(rawGrantRepo.findAll()));
|
||||
final var givenBookingProject = givenSomeTemporaryBookingProject(1000111);
|
||||
final var givenBookingProject = givenSomeTemporaryBookingProject("fir");
|
||||
|
||||
// when
|
||||
final var result = jpaAttempt.transacted(() -> {
|
||||
@ -295,10 +295,10 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
"[creating booking-project test-data 1000313, hs_booking_project, INSERT]");
|
||||
}
|
||||
|
||||
private HsBookingProjectEntity givenSomeTemporaryBookingProject(final int debitorNumber) {
|
||||
private HsBookingProjectEntity givenSomeTemporaryBookingProject(final String defaultPrefix) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var givenDebitor = debitorRepo.findDebitorByDebitorNumber(debitorNumber).get(0);
|
||||
final var givenDebitor = debitorRepo.findByDefaultPrefix(defaultPrefix).get(0);
|
||||
final var newBookingProject = HsBookingProjectEntity.builder()
|
||||
.debitor(givenDebitor)
|
||||
.caption("some temp project")
|
||||
@ -312,7 +312,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
final List<HsBookingProjectEntity> actualResult,
|
||||
final String... bookingProjectNames) {
|
||||
assertThat(actualResult)
|
||||
.extracting(bookingProjectEntity -> bookingProjectEntity.toString())
|
||||
.extracting(HsBookingProjectEntity::toString)
|
||||
.containsExactlyInAnyOrder(bookingProjectNames);
|
||||
}
|
||||
|
||||
@ -320,7 +320,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
|
||||
final List<HsBookingProjectEntity> actualResult,
|
||||
final String... bookingProjectNames) {
|
||||
assertThat(actualResult)
|
||||
.extracting(bookingProjectEntity -> bookingProjectEntity.toString())
|
||||
.extracting(HsBookingProjectEntity::toString)
|
||||
.contains(bookingProjectNames);
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,14 @@ package net.hostsharing.hsadminng.hs.booking.project;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.office.debitor.TestHsOfficeDebitor.TEST_DEBITOR;
|
||||
import static net.hostsharing.hsadminng.hs.booking.debitor.TestHsBookingDebitor.TEST_BOOKING_DEBITOR;
|
||||
|
||||
@UtilityClass
|
||||
public class TestHsBookingProject {
|
||||
|
||||
|
||||
public static final HsBookingProjectEntity TEST_PROJECT = HsBookingProjectEntity.builder()
|
||||
.debitor(TEST_DEBITOR)
|
||||
.debitor(TEST_BOOKING_DEBITOR)
|
||||
.caption("test project")
|
||||
.build();
|
||||
}
|
||||
|
@ -279,8 +279,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
void globalAdmin_canGetArbitraryAsset() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenAssetUuid = assetRepo.findByIdentifier("vm1011").stream()
|
||||
.filter(bi -> bi.getBookingItem().getProject().getDebitor().getDebitorNumber() == 1000111)
|
||||
.filter(item -> item.getCaption().equals("some ManagedServer"))
|
||||
.filter(bi -> bi.getBookingItem().getProject().getCaption().equals("D-1000111 default project"))
|
||||
.findAny().orElseThrow().getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
@ -306,7 +305,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
void normalUser_canNotGetUnrelatedAsset() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenAssetUuid = assetRepo.findByIdentifier("vm1012").stream()
|
||||
.filter(bi -> bi.getBookingItem().getProject().getDebitor().getDebitorNumber() == 1000212)
|
||||
.filter(bi -> bi.getBookingItem().getProject().getCaption().equals("D-1000212 default project"))
|
||||
.map(HsHostingAssetEntity::getUuid)
|
||||
.findAny().orElseThrow();
|
||||
|
||||
@ -324,8 +323,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
void debitorAgentUser_canGetRelatedAsset() {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var givenAssetUuid = assetRepo.findByIdentifier("vm1013").stream()
|
||||
.filter(bi -> bi.getBookingItem().getProject().getDebitor().getDebitorNumber() == 1000313)
|
||||
.filter(bi -> bi.getCaption().equals("some ManagedServer"))
|
||||
.filter(bi -> bi.getBookingItem().getProject().getCaption().equals("D-1000313 default project"))
|
||||
.findAny().orElseThrow().getUuid();
|
||||
|
||||
RestAssured // @formatter:off
|
||||
|
@ -4,7 +4,6 @@ import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository;
|
||||
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
|
||||
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
|
||||
import net.hostsharing.hsadminng.rbac.test.Array;
|
||||
@ -48,9 +47,6 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
@Autowired
|
||||
HsBookingProjectRepository projectRepo;
|
||||
|
||||
@Autowired
|
||||
HsOfficeDebitorRepository debitorRepo;
|
||||
|
||||
@Autowired
|
||||
RawRbacRoleRepository rawRoleRepo;
|
||||
|
||||
@ -143,7 +139,6 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
"{ grant role:hs_hosting_asset#vm9000:AGENT to role:hs_hosting_asset#vm9000:ADMIN by system and assume }",
|
||||
|
||||
// tenant
|
||||
"{ grant perm:hs_hosting_asset#vm9000:SELECT to role:hs_hosting_asset#vm9000:TENANT by system and assume }",
|
||||
"{ grant role:hs_booking_item#somePrivateCloud:TENANT to role:hs_hosting_asset#vm9000:TENANT by system and assume }",
|
||||
|
||||
null));
|
||||
|
@ -745,7 +745,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
|
||||
jpaAttempt.transacted(() -> {
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
final var count = em.createQuery(
|
||||
"DELETE FROM HsOfficeDebitorEntity d WHERE d.debitorNumberSuffix >= " + LOWEST_TEMP_DEBITOR_SUFFIX)
|
||||
"DELETE FROM HsBookingDebitorEntity d WHERE d.debitorNumberSuffix >= " + LOWEST_TEMP_DEBITOR_SUFFIX)
|
||||
.executeUpdate();
|
||||
System.out.printf("deleted %d entities%n", count);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user
assumed-roles + "admin"