real rbac-entities in booking+hosting #89

Merged
hsh-michaelhoennig merged 15 commits from real-and-rbac-entities-everywhere into master 2024-08-21 06:18:38 +02:00
32 changed files with 315 additions and 180 deletions
Showing only changes of commit 06784e03f4 - Show all commits

View File

@ -9,8 +9,9 @@ import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProject;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity;
import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider;
import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
@ -90,7 +91,7 @@ public class HsBookingItemEntity implements Stringifyable, BaseEntity<HsBookingI
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "projectuuid") @JoinColumn(name = "projectuuid")
private HsBookingProjectEntity project; private HsBookingProjectRealEntity project;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parentitemuuid") @JoinColumn(name = "parentitemuuid")
@ -120,7 +121,7 @@ public class HsBookingItemEntity implements Stringifyable, BaseEntity<HsBookingI
private List<HsBookingItemEntity> subBookingItems; private List<HsBookingItemEntity> subBookingItems;
@OneToOne(mappedBy="bookingItem") @OneToOne(mappedBy="bookingItem")
private HsHostingAssetRbacEntity relatedHostingAsset; private HsHostingAssetRealEntity relatedHostingAsset;
@Transient @Transient
private PatchableMapWrapper<Object> resourcesWrapper; private PatchableMapWrapper<Object> resourcesWrapper;
@ -181,18 +182,18 @@ public class HsBookingItemEntity implements Stringifyable, BaseEntity<HsBookingI
@Override @Override
public String toShortString() { public String toShortString() {
return ofNullable(relatedProject()).map(HsBookingProjectEntity::toShortString).orElse("D-???????-?") + return ofNullable(relatedProject()).map(HsBookingProject::toShortString).orElse("D-???????-?") +
":" + caption; ":" + caption;
} }
private HsBookingProjectEntity relatedProject() { private HsBookingProject relatedProject() {
if (project != null) { if (project != null) {
return project; return project;
} }
return parentItem == null ? null : parentItem.relatedProject(); return parentItem == null ? null : parentItem.relatedProject();
} }
public HsBookingProjectEntity getRelatedProject() { public HsBookingProject getRelatedProject() {
return project != null ? project return project != null ? project
: parentItem != null ? parentItem.getRelatedProject() : parentItem != null ? parentItem.getRelatedProject()
: null; // can be the case for technical assets like IP-numbers : null; // can be the case for technical assets like IP-numbers
@ -206,7 +207,7 @@ public class HsBookingItemEntity implements Stringifyable, BaseEntity<HsBookingI
.toRole("global", ADMIN).grantPermission(INSERT) // TODO.impl: Why is this necessary to insert test data? .toRole("global", ADMIN).grantPermission(INSERT) // TODO.impl: Why is this necessary to insert test data?
.toRole("global", ADMIN).grantPermission(DELETE) .toRole("global", ADMIN).grantPermission(DELETE)
.importEntityAlias("project", HsBookingProjectEntity.class, usingDefaultCase(), .importEntityAlias("project", HsBookingProject.class, usingDefaultCase(),
dependsOnColumn("projectUuid"), dependsOnColumn("projectUuid"),
directlyFetchedByDependsOnColumn(), directlyFetchedByDependsOnColumn(),
NULLABLE) NULLABLE)

View File

@ -1,6 +1,7 @@
package net.hostsharing.hsadminng.hs.booking.project; package net.hostsharing.hsadminng.hs.booking.project;
import lombok.*; import lombok.*;
import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity; import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
@ -27,18 +28,17 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.fetchedBySql;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
import static net.hostsharing.hsadminng.stringify.Stringify.stringify; import static net.hostsharing.hsadminng.stringify.Stringify.stringify;
@Builder @MappedSuperclass
@Entity
@Table(name = "hs_booking_project_rv")
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor @AllArgsConstructor(access = AccessLevel.PROTECTED)
public class HsBookingProjectEntity implements Stringifyable, BaseEntity<HsBookingProjectEntity> { @SuperBuilder(builderMethodName = "baseBuilder", toBuilder = true)
public class HsBookingProject implements Stringifyable, BaseEntity<HsBookingProject> {
private static Stringify<HsBookingProjectEntity> stringify = stringify(HsBookingProjectEntity.class) private static Stringify<HsBookingProject> stringify = stringify(HsBookingProject.class)
.withProp(HsBookingProjectEntity::getDebitor) .withProp(HsBookingProject::getDebitor)
.withProp(HsBookingProjectEntity::getCaption) .withProp(HsBookingProject::getCaption)
.quotedValues(false); .quotedValues(false);
@Id @Id
@ -67,7 +67,7 @@ public class HsBookingProjectEntity implements Stringifyable, BaseEntity<HsBooki
} }
public static RbacView rbac() { public static RbacView rbac() {
return rbacViewFor("project", HsBookingProjectEntity.class) return rbacViewFor("project", HsBookingProject.class)
.withIdentityView(SQL.query(""" .withIdentityView(SQL.query("""
SELECT bookingProject.uuid as uuid, debitorIV.idName || '-' || cleanIdentifier(bookingProject.caption) as idName SELECT bookingProject.uuid as uuid, debitorIV.idName || '-' || cleanIdentifier(bookingProject.caption) as idName
FROM hs_booking_project bookingProject FROM hs_booking_project bookingProject

View File

@ -28,7 +28,7 @@ public class HsBookingProjectController implements HsBookingProjectsApi {
private Mapper mapper; private Mapper mapper;
@Autowired @Autowired
private HsBookingProjectRepository bookingProjectRepo; private HsBookingProjectRbacRepository bookingProjectRepo;
@Autowired @Autowired
private HsBookingDebitorRepository debitorRepo; private HsBookingDebitorRepository debitorRepo;
@ -56,7 +56,7 @@ public class HsBookingProjectController implements HsBookingProjectsApi {
context.define(currentUser, assumedRoles); context.define(currentUser, assumedRoles);
final var entityToSave = mapper.map(body, HsBookingProjectEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER); final var entityToSave = mapper.map(body, HsBookingProjectRbacEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER);
final var saved = bookingProjectRepo.save(entityToSave); final var saved = bookingProjectRepo.save(entityToSave);
@ -118,7 +118,7 @@ public class HsBookingProjectController implements HsBookingProjectsApi {
return ResponseEntity.ok(mapped); return ResponseEntity.ok(mapped);
} }
final BiConsumer<HsBookingProjectInsertResource, HsBookingProjectEntity> RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { final BiConsumer<HsBookingProjectInsertResource, HsBookingProjectRbacEntity> RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> {
if (resource.getDebitorUuid() != null) { if (resource.getDebitorUuid() != null) {
entity.setDebitor(debitorRepo.findByUuid(resource.getDebitorUuid()) entity.setDebitor(debitorRepo.findByUuid(resource.getDebitorUuid())
.orElseThrow(() -> new EntityNotFoundException("ERROR: [400] debitorUuid %s not found".formatted( .orElseThrow(() -> new EntityNotFoundException("ERROR: [400] debitorUuid %s not found".formatted(

View File

@ -8,9 +8,9 @@ import net.hostsharing.hsadminng.mapper.OptionalFromJson;
public class HsBookingProjectEntityPatcher implements EntityPatcher<HsBookingProjectPatchResource> { public class HsBookingProjectEntityPatcher implements EntityPatcher<HsBookingProjectPatchResource> {
private final HsBookingProjectEntity entity; private final HsBookingProject entity;
public HsBookingProjectEntityPatcher(final HsBookingProjectEntity entity) { public HsBookingProjectEntityPatcher(final HsBookingProject entity) {
this.entity = entity; this.entity = entity;
} }

View File

@ -0,0 +1,86 @@
package net.hostsharing.hsadminng.hs.booking.project;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationRbacEntity;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView;
import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import java.io.IOException;
import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingCase;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingDefaultCase;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Nullable.NOT_NULL;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.DELETE;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.INSERT;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.SELECT;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.UPDATE;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.ADMIN;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.AGENT;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.OWNER;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.TENANT;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.directlyFetchedByDependsOnColumn;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.fetchedBySql;
import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor;
@Entity
@Table(name = "hs_booking_project_rv")
@SuperBuilder(toBuilder = true)
@Getter
@Setter
@NoArgsConstructor
public class HsBookingProjectRbacEntity extends HsBookingProject {
public static RbacView rbac() {
return rbacViewFor("project", HsBookingProjectRbacEntity.class)
.withIdentityView(SQL.query("""
SELECT bookingProject.uuid as uuid, debitorIV.idName || '-' || cleanIdentifier(bookingProject.caption) as idName
FROM hs_booking_project bookingProject
JOIN hs_office_debitor_iv debitorIV ON debitorIV.uuid = bookingProject.debitorUuid
"""))
.withRestrictedViewOrderBy(SQL.expression("caption"))
.withUpdatableColumns("version", "caption")
.importEntityAlias("debitor", HsOfficeDebitorEntity.class, usingDefaultCase(),
dependsOnColumn("debitorUuid"),
directlyFetchedByDependsOnColumn(),
NOT_NULL)
.importEntityAlias("debitorRel", HsOfficeRelationRbacEntity.class, usingCase(DEBITOR),
dependsOnColumn("debitorUuid"),
fetchedBySql("""
SELECT ${columns}
FROM hs_office_relation debitorRel
JOIN hs_office_debitor debitor ON debitor.debitorRelUuid = debitorRel.uuid
WHERE debitor.uuid = ${REF}.debitorUuid
"""),
NOT_NULL)
.toRole("debitorRel", ADMIN).grantPermission(INSERT)
.toRole("global", ADMIN).grantPermission(DELETE)
.createRole(OWNER, (with) -> {
with.incomingSuperRole("debitorRel", AGENT).unassumed();
})
.createSubRole(ADMIN, (with) -> {
with.permission(UPDATE);
})
.createSubRole(AGENT)
.createSubRole(TENANT, (with) -> {
with.outgoingSubRole("debitorRel", TENANT);
with.permission(SELECT);
})
.limitDiagramTo("project", "debitorRel", "global");
}
public static void main(String[] args) throws IOException {
rbac().generateWithBaseFileName("6-hs-booking/620-booking-project/6203-hs-booking-project-rbac");
}
}

View File

@ -0,0 +1,21 @@
package net.hostsharing.hsadminng.hs.booking.project;
import org.springframework.data.repository.Repository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface HsBookingProjectRbacRepository extends Repository<HsBookingProjectRbacEntity, UUID> {
Optional<HsBookingProjectRbacEntity> findByUuid(final UUID bookingProjectUuid);
List<HsBookingProjectRbacEntity> findByCaption(final String projectCaption);
List<HsBookingProjectRbacEntity> findAllByDebitorUuid(final UUID bookingProjectUuid);
HsBookingProjectRbacEntity save(HsBookingProjectRbacEntity current);
int deleteByUuid(final UUID uuid);
long count();
}

View File

@ -0,0 +1,19 @@
package net.hostsharing.hsadminng.hs.booking.project;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
@Entity
@Table(name = "hs_booking_project")
@SuperBuilder(toBuilder = true)
@Getter
@Setter
@NoArgsConstructor
public class HsBookingProjectRealEntity extends HsBookingProject {
}

View File

@ -0,0 +1,21 @@
package net.hostsharing.hsadminng.hs.booking.project;
import org.springframework.data.repository.Repository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface HsBookingProjectRealRepository extends Repository<HsBookingProjectRealEntity, UUID> {
Optional<HsBookingProjectRealEntity> findByUuid(final UUID bookingProjectUuid);
List<HsBookingProjectRealEntity> findByCaption(final String projectCaption);
List<HsBookingProjectRealEntity> findAllByDebitorUuid(final UUID bookingProjectUuid);
HsBookingProjectRealEntity save(HsBookingProjectRealEntity current);
int deleteByUuid(final UUID uuid);
long count();
}

View File

@ -1,21 +0,0 @@
package net.hostsharing.hsadminng.hs.booking.project;
import org.springframework.data.repository.Repository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface HsBookingProjectRepository extends Repository<HsBookingProjectEntity, UUID> {
Optional<HsBookingProjectEntity> findByUuid(final UUID bookingProjectUuid);
List<HsBookingProjectEntity> findByCaption(final String projectCaption);
List<HsBookingProjectEntity> findAllByDebitorUuid(final UUID bookingProjectUuid);
HsBookingProjectEntity save(HsBookingProjectEntity current);
int deleteByUuid(final UUID uuid);
long count();
}

View File

@ -9,7 +9,7 @@ import lombok.Setter;
import lombok.Getter; import lombok.Getter;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProject;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider;
import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper;
@ -127,7 +127,7 @@ public class HsHostingAsset implements Stringifyable, BaseEntity<HsHostingAsset>
return getConfig(); return getConfig();
} }
public HsBookingProjectEntity getRelatedProject() { public HsBookingProject getRelatedProject() {
return Optional.ofNullable(getBookingItem()) return Optional.ofNullable(getBookingItem())
.map(HsBookingItemEntity::getRelatedProject) .map(HsBookingItemEntity::getRelatedProject)
.orElseGet(() -> Optional.ofNullable(getParentAsset()) .orElseGet(() -> Optional.ofNullable(getParentAsset())

View File

@ -4,7 +4,7 @@ import io.hypersistence.utils.hibernate.type.range.Range;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealRepository;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
@ -47,7 +47,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
HsBookingItemRepository bookingItemRepo; HsBookingItemRepository bookingItemRepo;
@Autowired @Autowired
HsBookingProjectRepository projectRepo; HsBookingProjectRealRepository realProjectRepo;
@Autowired @Autowired
HsOfficeDebitorRepository debitorRepo; HsOfficeDebitorRepository debitorRepo;
@ -65,7 +65,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenProject = debitorRepo.findDebitorByDebitorNumber(1000111).stream() final var givenProject = debitorRepo.findDebitorByDebitorNumber(1000111).stream()
.map(d -> projectRepo.findAllByDebitorUuid(d.getUuid())) .map(d -> realProjectRepo.findAllByDebitorUuid(d.getUuid()))
.flatMap(List::stream) .flatMap(List::stream)
.findFirst() .findFirst()
.orElseThrow(); .orElseThrow();
@ -133,7 +133,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenProject = debitorRepo.findDebitorByDebitorNumber(1000111).stream() final var givenProject = debitorRepo.findDebitorByDebitorNumber(1000111).stream()
.map(d -> projectRepo.findAllByDebitorUuid(d.getUuid())) .map(d -> realProjectRepo.findAllByDebitorUuid(d.getUuid()))
.flatMap(List::stream) .flatMap(List::stream)
.findFirst() .findFirst()
.orElseThrow(); .orElseThrow();
@ -386,7 +386,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
final HsBookingItemType hsBookingItemType, final Map.Entry<String, Object>... resources) { final HsBookingItemType hsBookingItemType, final Map.Entry<String, Object>... resources) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenProject = projectRepo.findByCaption(projectCaption).stream() final var givenProject = realProjectRepo.findByCaption(projectCaption).stream()
.findAny().orElseThrow(); .findAny().orElseThrow();
final var newBookingItem = HsBookingItemEntity.builder() final var newBookingItem = HsBookingItemEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())

View File

@ -1,8 +1,8 @@
package net.hostsharing.hsadminng.hs.booking.item; package net.hostsharing.hsadminng.hs.booking.item;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealRepository;
import net.hostsharing.hsadminng.mapper.Mapper; import net.hostsharing.hsadminng.mapper.Mapper;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
@ -51,7 +51,7 @@ class HsBookingItemControllerRestTest {
EntityManagerFactory emf; EntityManagerFactory emf;
@MockBean @MockBean
HsBookingProjectRepository bookingProjectRepo; HsBookingProjectRealRepository realProjectRepo;
@MockBean @MockBean
HsBookingItemRepository bookingItemRepo; HsBookingItemRepository bookingItemRepo;
@ -73,8 +73,8 @@ class HsBookingItemControllerRestTest {
final var givenProjectUuid = UUID.randomUUID(); final var givenProjectUuid = UUID.randomUUID();
// given // given
when(em.find(HsBookingProjectEntity.class, givenProjectUuid)).thenAnswer(invocation -> when(em.find(HsBookingProjectRealEntity.class, givenProjectUuid)).thenAnswer(invocation ->
HsBookingProjectEntity.builder() HsBookingProjectRealEntity.builder()
.uuid(invocation.getArgument(1)) .uuid(invocation.getArgument(1))
.build() .build()
); );
@ -123,8 +123,8 @@ class HsBookingItemControllerRestTest {
final var givenProjectUuid = UUID.randomUUID(); final var givenProjectUuid = UUID.randomUUID();
// given // given
when(em.find(HsBookingProjectEntity.class, givenProjectUuid)).thenAnswer(invocation -> when(em.find(HsBookingProjectRealEntity.class, givenProjectUuid)).thenAnswer(invocation ->
HsBookingProjectEntity.builder() HsBookingProjectRealEntity.builder()
.uuid(invocation.getArgument(1)) .uuid(invocation.getArgument(1))
.build() .build()
); );

View File

@ -17,7 +17,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Stream; import java.util.stream.Stream;
import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.TEST_PROJECT; import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.PROJECT_TEST_ENTITY;
import static net.hostsharing.hsadminng.mapper.PatchMap.entry; import static net.hostsharing.hsadminng.mapper.PatchMap.entry;
import static net.hostsharing.hsadminng.mapper.PatchMap.patchMap; import static net.hostsharing.hsadminng.mapper.PatchMap.patchMap;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;
@ -70,7 +70,7 @@ class HsBookingItemEntityPatcherUnitTest extends PatchUnitTestBase<
protected HsBookingItemEntity newInitialEntity() { protected HsBookingItemEntity newInitialEntity() {
final var entity = new HsBookingItemEntity(); final var entity = new HsBookingItemEntity();
entity.setUuid(INITIAL_BOOKING_ITEM_UUID); entity.setUuid(INITIAL_BOOKING_ITEM_UUID);
entity.setProject(TEST_PROJECT); entity.setProject(PROJECT_TEST_ENTITY);
entity.getResources().putAll(KeyValueMap.from(INITIAL_RESOURCES)); entity.getResources().putAll(KeyValueMap.from(INITIAL_RESOURCES));
entity.setCaption(INITIAL_CAPTION); entity.setCaption(INITIAL_CAPTION);
entity.setValidity(Range.closedInfinite(GIVEN_VALID_FROM)); entity.setValidity(Range.closedInfinite(GIVEN_VALID_FROM));

View File

@ -10,7 +10,7 @@ import java.time.Month;
import java.util.Map; import java.util.Map;
import static java.util.Map.entry; import static java.util.Map.entry;
import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.TEST_PROJECT; import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.PROJECT_TEST_ENTITY;
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange; import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -21,7 +21,7 @@ class HsBookingItemEntityUnitTest {
private MockedStatic<LocalDate> localDateMockedStatic = Mockito.mockStatic(LocalDate.class, Mockito.CALLS_REAL_METHODS); private MockedStatic<LocalDate> localDateMockedStatic = Mockito.mockStatic(LocalDate.class, Mockito.CALLS_REAL_METHODS);
final HsBookingItemEntity givenBookingItem = HsBookingItemEntity.builder() final HsBookingItemEntity givenBookingItem = HsBookingItemEntity.builder()
.project(TEST_PROJECT) .project(PROJECT_TEST_ENTITY)
.type(HsBookingItemType.CLOUD_SERVER) .type(HsBookingItemType.CLOUD_SERVER)
.caption("some caption") .caption("some caption")
.resources(Map.ofEntries( .resources(Map.ofEntries(

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.booking.item;
import io.hypersistence.utils.hibernate.type.range.Range; import io.hypersistence.utils.hibernate.type.range.Range;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealRepository;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
@ -42,7 +42,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
HsBookingItemRepository bookingItemRepo; HsBookingItemRepository bookingItemRepo;
@Autowired @Autowired
HsBookingProjectRepository projectRepo; HsBookingProjectRealRepository realProjectRepo;
@Autowired @Autowired
HsOfficeDebitorRepository debitorRepo; HsOfficeDebitorRepository debitorRepo;
@ -71,7 +71,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var count = bookingItemRepo.count(); final var count = bookingItemRepo.count();
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var givenProject = projectRepo.findAllByDebitorUuid(givenDebitor.getUuid()).get(0); final var givenProject = realProjectRepo.findAllByDebitorUuid(givenDebitor.getUuid()).get(0);
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
@ -102,7 +102,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
// when // when
attempt(em, () -> { attempt(em, () -> {
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);
final var givenProject = projectRepo.findAllByDebitorUuid(givenDebitor.getUuid()).get(0); final var givenProject = realProjectRepo.findAllByDebitorUuid(givenDebitor.getUuid()).get(0);
final var newBookingItem = HsBookingItemEntity.builder() final var newBookingItem = HsBookingItemEntity.builder()
.project(givenProject) .project(givenProject)
.type(MANAGED_WEBSPACE) .type(MANAGED_WEBSPACE)
@ -160,7 +160,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var projectUuid = debitorRepo.findDebitorByDebitorNumber(1000212).stream() final var projectUuid = debitorRepo.findDebitorByDebitorNumber(1000212).stream()
.map(d -> projectRepo.findAllByDebitorUuid(d.getUuid())) .map(d -> realProjectRepo.findAllByDebitorUuid(d.getUuid()))
.flatMap(List::stream) .flatMap(List::stream)
.findAny().orElseThrow().getUuid(); .findAny().orElseThrow().getUuid();
@ -185,7 +185,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
final var debitor = debitorRepo.findDebitorByDebitorNumber(1000111); final var debitor = debitorRepo.findDebitorByDebitorNumber(1000111);
context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-D-1000111defaultproject:OWNER"); context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-D-1000111defaultproject:OWNER");
final var projectUuid = debitor.stream() final var projectUuid = debitor.stream()
.map(d -> projectRepo.findAllByDebitorUuid(d.getUuid())) .map(d -> realProjectRepo.findAllByDebitorUuid(d.getUuid()))
.flatMap(List::stream) .flatMap(List::stream)
.findAny().orElseThrow().getUuid(); .findAny().orElseThrow().getUuid();
@ -329,7 +329,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
private HsBookingItemEntity givenSomeTemporaryBookingItem(final String projectCaption) { private HsBookingItemEntity givenSomeTemporaryBookingItem(final String projectCaption) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenProject = projectRepo.findByCaption(projectCaption).stream() final var givenProject = realProjectRepo.findByCaption(projectCaption).stream()
.findAny().orElseThrow(); .findAny().orElseThrow();
final var newBookingItem = HsBookingItemEntity.builder() final var newBookingItem = HsBookingItemEntity.builder()
.project(givenProject) .project(givenProject)

View File

@ -7,13 +7,13 @@ import java.time.LocalDate;
import java.util.Map; import java.util.Map;
import static java.util.Map.entry; import static java.util.Map.entry;
import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.TEST_PROJECT; import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.PROJECT_TEST_ENTITY;
@UtilityClass @UtilityClass
public class TestHsBookingItem { public class TestHsBookingItem {
public static final HsBookingItemEntity TEST_CLOUD_SERVER_BOOKING_ITEM = HsBookingItemEntity.builder() public static final HsBookingItemEntity TEST_CLOUD_SERVER_BOOKING_ITEM = HsBookingItemEntity.builder()
.project(TEST_PROJECT) .project(PROJECT_TEST_ENTITY)
.type(HsBookingItemType.CLOUD_SERVER) .type(HsBookingItemType.CLOUD_SERVER)
.caption("test cloud server booking item") .caption("test cloud server booking item")
.resources(Map.ofEntries( .resources(Map.ofEntries(
@ -26,7 +26,7 @@ public class TestHsBookingItem {
.build(); .build();
public static final HsBookingItemEntity TEST_MANAGED_SERVER_BOOKING_ITEM = HsBookingItemEntity.builder() public static final HsBookingItemEntity TEST_MANAGED_SERVER_BOOKING_ITEM = HsBookingItemEntity.builder()
.project(TEST_PROJECT) .project(PROJECT_TEST_ENTITY)
.type(HsBookingItemType.MANAGED_SERVER) .type(HsBookingItemType.MANAGED_SERVER)
.caption("test project booking item") .caption("test project booking item")
.resources(Map.ofEntries( .resources(Map.ofEntries(

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.booking.item.validators;
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.validation.ValidationException; import jakarta.validation.ValidationException;
@ -18,13 +18,13 @@ class HsBookingItemEntityValidatorUnitTest {
final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder() final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder()
.debitorNumber(12345) .debitorNumber(12345)
.build(); .build();
final HsBookingProjectEntity project = HsBookingProjectEntity.builder() final HsBookingProjectRealEntity project = HsBookingProjectRealEntity.builder()
.debitor(debitor) .debitor(debitor)
.caption("test project") .caption("test project")
.build(); .build();
@Test @Test
void validThrowsException() { void rejectsInvalidEntity() {
// given // given
final var cloudServerBookingItemEntity = HsBookingItemEntity.builder() final var cloudServerBookingItemEntity = HsBookingItemEntity.builder()
.type(CLOUD_SERVER) .type(CLOUD_SERVER)

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.booking.item.validators;
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Map; import java.util.Map;
@ -20,7 +20,7 @@ class HsCloudServerBookingItemValidatorUnitTest {
final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder() final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder()
.debitorNumber(12345) .debitorNumber(12345)
.build(); .build();
final HsBookingProjectEntity project = HsBookingProjectEntity.builder() final HsBookingProjectRealEntity project = HsBookingProjectRealEntity.builder()
.debitor(debitor) .debitor(debitor)
.caption("Test-Project") .caption("Test-Project")
.build(); .build();

View File

@ -2,8 +2,7 @@ package net.hostsharing.hsadminng.hs.booking.item.validators;
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -29,7 +28,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder() final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder()
.debitorNumber(12345) .debitorNumber(12345)
.build(); .build();
final HsBookingProjectEntity project = HsBookingProjectEntity.builder() final HsBookingProjectRealEntity project = HsBookingProjectRealEntity.builder()
.debitor(debitor) .debitor(debitor)
.caption("Test-Project") .caption("Test-Project")
.build(); .build();
@ -141,7 +140,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
entry("Traffic", 1000), entry("Traffic", 1000),
entry("Multi", 1) entry("Multi", 1)
)) ))
.relatedHostingAsset(HsHostingAssetRbacEntity.builder() .relatedHostingAsset(HsHostingAssetRealEntity.builder()
.type(HsHostingAssetType.MANAGED_WEBSPACE) .type(HsHostingAssetType.MANAGED_WEBSPACE)
.identifier("abc00") .identifier("abc00")
.subHostingAssets(concat( .subHostingAssets(concat(

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.booking.item.validators;
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Map; import java.util.Map;
@ -16,7 +16,7 @@ class HsManagedWebspaceBookingItemValidatorUnitTest {
final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder() final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder()
.debitorNumber(12345) .debitorNumber(12345)
.build(); .build();
final HsBookingProjectEntity project = HsBookingProjectEntity.builder() final HsBookingProjectRealEntity project = HsBookingProjectRealEntity.builder()
.debitor(debitor) .debitor(debitor)
.caption("Test-Project") .caption("Test-Project")
.build(); .build();

View File

@ -2,7 +2,7 @@ package net.hostsharing.hsadminng.hs.booking.item.validators;
import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static java.util.List.of; import static java.util.List.of;
@ -11,7 +11,7 @@ import static java.util.Map.ofEntries;
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.CLOUD_SERVER; import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.CLOUD_SERVER;
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.MANAGED_SERVER; import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.MANAGED_SERVER;
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.PRIVATE_CLOUD; import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.PRIVATE_CLOUD;
import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.TEST_PROJECT; import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.PROJECT_TEST_ENTITY;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
class HsPrivateCloudBookingItemValidatorUnitTest { class HsPrivateCloudBookingItemValidatorUnitTest {
@ -19,7 +19,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder() final HsBookingDebitorEntity debitor = HsBookingDebitorEntity.builder()
.debitorNumber(12345) .debitorNumber(12345)
.build(); .build();
final HsBookingProjectEntity project = HsBookingProjectEntity.builder() final HsBookingProjectRealEntity project = HsBookingProjectRealEntity.builder()
.debitor(debitor) .debitor(debitor)
.caption("Test-Project") .caption("Test-Project")
.build(); .build();
@ -29,7 +29,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
// given // given
final var privateCloudBookingItemEntity = HsBookingItemEntity.builder() final var privateCloudBookingItemEntity = HsBookingItemEntity.builder()
.type(PRIVATE_CLOUD) .type(PRIVATE_CLOUD)
.project(TEST_PROJECT) .project(PROJECT_TEST_ENTITY)
.caption("myPC") .caption("myPC")
.resources(ofEntries( .resources(ofEntries(
entry("CPU", 4), entry("CPU", 4),

View File

@ -32,10 +32,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
private Integer port; private Integer port;
@Autowired @Autowired
HsBookingProjectRepository bookingProjectRepo; HsBookingProjectRealRepository realProjectRepo;
@Autowired
HsBookingProjectRepository projectRepo;
@Autowired @Autowired
HsBookingDebitorRepository debitorRepo; HsBookingDebitorRepository debitorRepo;
@ -126,7 +123,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
@Test @Test
void globalAdmin_canGetArbitraryBookingProject() { void globalAdmin_canGetArbitraryBookingProject() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenBookingProjectUuid = bookingProjectRepo.findByCaption("D-1000111 default project").stream() final var givenBookingProjectUuid = realProjectRepo.findByCaption("D-1000111 default project").stream()
.findAny().orElseThrow().getUuid(); .findAny().orElseThrow().getUuid();
RestAssured // @formatter:off RestAssured // @formatter:off
@ -148,8 +145,8 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
@Test @Test
void normalUser_canNotGetUnrelatedBookingProject() { void normalUser_canNotGetUnrelatedBookingProject() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenBookingProjectUuid = bookingProjectRepo.findByCaption("D-1000212 default project").stream() final var givenBookingProjectUuid = realProjectRepo.findByCaption("D-1000212 default project").stream()
.map(HsBookingProjectEntity::getUuid) .map(HsBookingProject::getUuid)
.findAny().orElseThrow(); .findAny().orElseThrow();
RestAssured // @formatter:off RestAssured // @formatter:off
@ -165,7 +162,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
@Test @Test
void projectAgentUser_canGetRelatedBookingProject() { void projectAgentUser_canGetRelatedBookingProject() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenBookingProjectUuid = bookingProjectRepo.findByCaption("D-1000313 default project").stream() final var givenBookingProjectUuid = realProjectRepo.findByCaption("D-1000313 default project").stream()
.findAny().orElseThrow().getUuid(); .findAny().orElseThrow().getUuid();
RestAssured // @formatter:off RestAssured // @formatter:off
@ -217,7 +214,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
// finally, the bookingProject is actually updated // finally, the bookingProject is actually updated
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
assertThat(bookingProjectRepo.findByUuid(givenBookingProject.getUuid())).isPresent().get() assertThat(realProjectRepo.findByUuid(givenBookingProject.getUuid())).isPresent().get()
.matches(mandate -> { .matches(mandate -> {
assertThat(mandate.getDebitor().toString()).isEqualTo("booking-debitor(D-1000111: fir)"); assertThat(mandate.getDebitor().toString()).isEqualTo("booking-debitor(D-1000111: fir)");
return true; return true;
@ -243,7 +240,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
.statusCode(204); // @formatter:on .statusCode(204); // @formatter:on
// then the given bookingProject is gone // then the given bookingProject is gone
assertThat(bookingProjectRepo.findByUuid(givenBookingProject.getUuid())).isEmpty(); assertThat(realProjectRepo.findByUuid(givenBookingProject.getUuid())).isEmpty();
} }
@Test @Test
@ -261,21 +258,21 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean
.statusCode(404); // @formatter:on .statusCode(404); // @formatter:on
// then the given bookingProject is still there // then the given bookingProject is still there
assertThat(bookingProjectRepo.findByUuid(givenBookingProject.getUuid())).isNotEmpty(); assertThat(realProjectRepo.findByUuid(givenBookingProject.getUuid())).isNotEmpty();
} }
} }
private HsBookingProjectEntity givenSomeBookingProject(final int debitorNumber, final String caption) { private HsBookingProjectRealEntity givenSomeBookingProject(final int debitorNumber, final String caption) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findByDebitorNumber(debitorNumber).stream().findAny().orElseThrow(); final var givenDebitor = debitorRepo.findByDebitorNumber(debitorNumber).stream().findAny().orElseThrow();
final var newBookingProject = HsBookingProjectEntity.builder() final var newBookingProject = HsBookingProjectRealEntity.builder()
.uuid(UUID.randomUUID()) .uuid(UUID.randomUUID())
.debitor(givenDebitor) .debitor(givenDebitor)
.caption(caption) .caption(caption)
.build(); .build();
return bookingProjectRepo.save(newBookingProject); return realProjectRepo.save(newBookingProject);
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
} }

View File

@ -23,7 +23,7 @@ import static org.mockito.Mockito.lenient;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class HsBookingProjectEntityPatcherUnitTest extends PatchUnitTestBase< class HsBookingProjectEntityPatcherUnitTest extends PatchUnitTestBase<
HsBookingProjectPatchResource, HsBookingProjectPatchResource,
HsBookingProjectEntity HsBookingProject
> { > {
private static final UUID INITIAL_BOOKING_PROJECT_UUID = UUID.randomUUID(); private static final UUID INITIAL_BOOKING_PROJECT_UUID = UUID.randomUUID();
@ -38,13 +38,14 @@ class HsBookingProjectEntityPatcherUnitTest extends PatchUnitTestBase<
void initMocks() { void initMocks() {
lenient().when(em.getReference(eq(HsOfficeDebitorEntity.class), any())).thenAnswer(invocation -> lenient().when(em.getReference(eq(HsOfficeDebitorEntity.class), any())).thenAnswer(invocation ->
HsOfficeDebitorEntity.builder().uuid(invocation.getArgument(1)).build()); HsOfficeDebitorEntity.builder().uuid(invocation.getArgument(1)).build());
lenient().when(em.getReference(eq(HsBookingProjectEntity.class), any())).thenAnswer(invocation -> // FIXME
HsBookingProjectEntity.builder().uuid(invocation.getArgument(1)).build()); // lenient().when(em.getReference(eq(HsBookingProject.class), any())).thenAnswer(invocation ->
// HsBookingProject.builder().uuid(invocation.getArgument(1)).build());
} }
@Override @Override
protected HsBookingProjectEntity newInitialEntity() { protected HsBookingProject newInitialEntity() {
final var entity = new HsBookingProjectEntity(); final var entity = new HsBookingProject();
entity.setUuid(INITIAL_BOOKING_PROJECT_UUID); entity.setUuid(INITIAL_BOOKING_PROJECT_UUID);
entity.setDebitor(TEST_BOOKING_DEBITOR); entity.setDebitor(TEST_BOOKING_DEBITOR);
entity.setCaption(INITIAL_CAPTION); entity.setCaption(INITIAL_CAPTION);
@ -57,7 +58,7 @@ class HsBookingProjectEntityPatcherUnitTest extends PatchUnitTestBase<
} }
@Override @Override
protected HsBookingProjectEntityPatcher createPatcher(final HsBookingProjectEntity bookingProject) { protected HsBookingProjectEntityPatcher createPatcher(final HsBookingProject bookingProject) {
return new HsBookingProjectEntityPatcher(bookingProject); return new HsBookingProjectEntityPatcher(bookingProject);
} }
@ -68,7 +69,7 @@ class HsBookingProjectEntityPatcherUnitTest extends PatchUnitTestBase<
"caption", "caption",
HsBookingProjectPatchResource::setCaption, HsBookingProjectPatchResource::setCaption,
PATCHED_CAPTION, PATCHED_CAPTION,
HsBookingProjectEntity::setCaption) HsBookingProject::setCaption)
); );
} }
} }

View File

@ -2,26 +2,22 @@ package net.hostsharing.hsadminng.hs.booking.project;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static net.hostsharing.hsadminng.hs.booking.debitor.TestHsBookingDebitor.TEST_BOOKING_DEBITOR; import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.PROJECT_TEST_ENTITY;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
class HsBookingProjectEntityUnitTest { class HsBookingProjectEntityUnitTest {
final HsBookingProjectEntity givenBookingProject = HsBookingProjectEntity.builder()
.debitor(TEST_BOOKING_DEBITOR)
.caption("some caption")
.build();
@Test @Test
void toStringContainsAllPropertiesAndResourcesSortedByKey() { void toStringContainsAllPropertiesAndResourcesSortedByKey() {
final var result = givenBookingProject.toString(); final var result = PROJECT_TEST_ENTITY.toString();
assertThat(result).isEqualTo("HsBookingProjectEntity(D-1234500, some caption)"); assertThat(result).isEqualTo("HsBookingProject(D-1234500, test project)");
} }
@Test @Test
void toShortStringContainsOnlyMemberNumberAndCaption() { void toShortStringContainsOnlyMemberNumberAndCaption() {
final var result = givenBookingProject.toShortString(); final var result = PROJECT_TEST_ENTITY.toShortString();
assertThat(result).isEqualTo("D-1234500:some caption"); assertThat(result).isEqualTo("D-1234500:test project");
} }
} }

View File

@ -29,13 +29,13 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import({ Context.class, JpaAttempt.class }) @Import({ Context.class, JpaAttempt.class })
class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsBookingProjectRbacRepositoryIntegrationTest extends ContextBasedTestWithCleanup {
@Autowired @Autowired
HsBookingProjectRepository bookingProjectRepo; HsBookingProjectRealRepository realProjectRepo;
@Autowired @Autowired
HsBookingProjectRepository projectRepo; HsBookingProjectRbacRepository rbacProjectRepo;
@Autowired @Autowired
HsBookingDebitorRepository debitorRepo; HsBookingDebitorRepository debitorRepo;
@ -61,24 +61,24 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
@Test @Test
public void testHostsharingAdmin_withoutAssumedRole_canCreateNewBookingProject() { public void testHostsharingAdmin_withoutAssumedRole_canCreateNewBookingProject() {
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net"); // TODO.test: remove once we have a realDebitorRepo
final var count = bookingProjectRepo.count(); final var count = realProjectRepo.count();
final var givenDebitor = debitorRepo.findByDebitorNumber(1000111).get(0); final var givenDebitor = debitorRepo.findByDebitorNumber(1000111).get(0);
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newBookingProject = HsBookingProjectEntity.builder() final var newBookingProject = HsBookingProjectRbacEntity.builder()
.debitor(givenDebitor) .debitor(givenDebitor)
.caption("some new booking project") .caption("some new booking project")
.build(); .build();
return toCleanup(bookingProjectRepo.save(newBookingProject)); return toCleanup(rbacProjectRepo.save(newBookingProject));
}); });
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsBookingProjectEntity::getUuid).isNotNull(); assertThat(result.returnedValue()).isNotNull().extracting(HsBookingProject::getUuid).isNotNull();
assertThatBookingProjectIsPersisted(result.returnedValue()); assertThatBookingProjectIsPersisted(result.returnedValue());
assertThat(bookingProjectRepo.count()).isEqualTo(count + 1); assertThat(realProjectRepo.count()).isEqualTo(count + 1);
} }
@Test @Test
@ -93,11 +93,11 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
// when // when
attempt(em, () -> { attempt(em, () -> {
final var givenDebitor = debitorRepo.findByDebitorNumber(1000111).get(0); final var givenDebitor = debitorRepo.findByDebitorNumber(1000111).get(0);
final var newBookingProject = HsBookingProjectEntity.builder() final var newBookingProject = HsBookingProjectRbacEntity.builder()
.debitor(givenDebitor) .debitor(givenDebitor)
.caption("some new booking project") .caption("some new booking project")
.build(); .build();
return toCleanup(bookingProjectRepo.save(newBookingProject)); return toCleanup(rbacProjectRepo.save(newBookingProject));
}); });
// then // then
@ -135,9 +135,9 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
null)); null));
} }
private void assertThatBookingProjectIsPersisted(final HsBookingProjectEntity saved) { private void assertThatBookingProjectIsPersisted(final HsBookingProject saved) {
final var found = bookingProjectRepo.findByUuid(saved.getUuid()); final var found = rbacProjectRepo.findByUuid(saved.getUuid());
assertThat(found).isNotEmpty().map(HsBookingProjectEntity::toString).get().isEqualTo(saved.toString()); assertThat(found).isNotEmpty().map(HsBookingProject::toString).get().isEqualTo(saved.toString());
} }
} }
@ -152,12 +152,12 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
.findAny().orElseThrow().getUuid(); .findAny().orElseThrow().getUuid();
// when // when
final var result = bookingProjectRepo.findAllByDebitorUuid(debitorUuid); final var result = rbacProjectRepo.findAllByDebitorUuid(debitorUuid);
// then // then
allTheseBookingProjectsAreReturned( allTheseBookingProjectsAreReturned(
result, result,
"HsBookingProjectEntity(D-1000212, D-1000212 default project)"); "HsBookingProject(D-1000212, D-1000212 default project)");
} }
@Test @Test
@ -169,12 +169,12 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
.findAny().orElseThrow().getUuid(); .findAny().orElseThrow().getUuid();
// when: // when:
final var result = bookingProjectRepo.findAllByDebitorUuid(debitorUuid); final var result = rbacProjectRepo.findAllByDebitorUuid(debitorUuid);
// then: // then:
exactlyTheseBookingProjectsAreReturned( exactlyTheseBookingProjectsAreReturned(
result, result,
"HsBookingProjectEntity(D-1000111, D-1000111 default project)"); "HsBookingProject(D-1000111, D-1000111 default project)");
} }
} }
@ -182,29 +182,30 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
class UpdateBookingProject { class UpdateBookingProject {
@Test @Test
public void hostsharingAdmin_canUpdateArbitraryBookingProject() { public void bookingProjectAdmin_canUpdateArbitraryBookingProject() {
// given // given
final var givenBookingProjectUuid = givenSomeTemporaryBookingProject(1000111).getUuid(); final var givenBookingProjectUuid = givenSomeTemporaryBookingProject(1000111).getUuid();
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-sometempproject:ADMIN");
final var foundBookingProject = em.find(HsBookingProjectEntity.class, givenBookingProjectUuid); final var foundBookingProject = em.find(HsBookingProjectRbacEntity.class, givenBookingProjectUuid);
return toCleanup(bookingProjectRepo.save(foundBookingProject)); foundBookingProject.setCaption("updated caption");
return toCleanup(rbacProjectRepo.save(foundBookingProject));
}); });
// then // then
result.assertSuccessful(); result.assertSuccessful();
jpaAttempt.transacted(() -> { assertThat(result.returnedValue().getCaption()).isEqualTo("updated caption");
context("superuser-alex@hostsharing.net"); assertThatBookingProjectActuallyInDatabase(result.returnedValue());
assertThatBookingProjectActuallyInDatabase(result.returnedValue());
}).assertSuccessful();
} }
private void assertThatBookingProjectActuallyInDatabase(final HsBookingProjectEntity saved) { private void assertThatBookingProjectActuallyInDatabase(final HsBookingProject saved) {
final var found = bookingProjectRepo.findByUuid(saved.getUuid()); jpaAttempt.transacted(() -> {
assertThat(found).isNotEmpty().get().isNotSameAs(saved) final var found = realProjectRepo.findByUuid(saved.getUuid());
.extracting(Object::toString).isEqualTo(saved.toString()); assertThat(found).isNotEmpty().get().isNotSameAs(saved)
.extracting(Object::toString).isEqualTo(saved.toString());
}).assertSuccessful();
} }
} }
@ -220,14 +221,14 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
bookingProjectRepo.deleteByUuid(givenBookingProject.getUuid()); rbacProjectRepo.deleteByUuid(givenBookingProject.getUuid());
}); });
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(jpaAttempt.transacted(() -> { assertThat(jpaAttempt.transacted(() -> {
context("superuser-fran@hostsharing.net", null); context("superuser-fran@hostsharing.net", null);
return bookingProjectRepo.findByUuid(givenBookingProject.getUuid()); return rbacProjectRepo.findByUuid(givenBookingProject.getUuid());
}).assertSuccessful().returnedValue()).isEmpty(); }).assertSuccessful().returnedValue()).isEmpty();
} }
@ -239,9 +240,9 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-sometempproject:AGENT"); context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-sometempproject:AGENT");
assertThat(bookingProjectRepo.findByUuid(givenBookingProject.getUuid())).isPresent(); assertThat(rbacProjectRepo.findByUuid(givenBookingProject.getUuid())).isPresent();
bookingProjectRepo.deleteByUuid(givenBookingProject.getUuid()); rbacProjectRepo.deleteByUuid(givenBookingProject.getUuid());
}); });
// then // then
@ -250,7 +251,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
"[403] Subject ", " is not allowed to delete hs_booking_project"); "[403] Subject ", " is not allowed to delete hs_booking_project");
assertThat(jpaAttempt.transacted(() -> { assertThat(jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
return bookingProjectRepo.findByUuid(givenBookingProject.getUuid()); return rbacProjectRepo.findByUuid(givenBookingProject.getUuid());
}).assertSuccessful().returnedValue()).isPresent(); // still there }).assertSuccessful().returnedValue()).isPresent(); // still there
} }
@ -265,7 +266,7 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
return bookingProjectRepo.deleteByUuid(givenBookingProject.getUuid()); return rbacProjectRepo.deleteByUuid(givenBookingProject.getUuid());
}); });
// then // then
@ -295,32 +296,32 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
"[creating booking-project test-data 1000313, hs_booking_project, INSERT]"); "[creating booking-project test-data 1000313, hs_booking_project, INSERT]");
} }
private HsBookingProjectEntity givenSomeTemporaryBookingProject(final int debitorNumber) { private HsBookingProjectRealEntity givenSomeTemporaryBookingProject(final int debitorNumber) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findByDebitorNumber(debitorNumber).get(0); final var givenDebitor = debitorRepo.findByDebitorNumber(debitorNumber).get(0);
final var newBookingProject = HsBookingProjectEntity.builder() final var newBookingProject = HsBookingProjectRealEntity.builder()
.debitor(givenDebitor) .debitor(givenDebitor)
.caption("some temp project") .caption("some temp project")
.build(); .build();
return toCleanup(bookingProjectRepo.save(newBookingProject)); return toCleanup(realProjectRepo.save(newBookingProject));
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
void exactlyTheseBookingProjectsAreReturned( void exactlyTheseBookingProjectsAreReturned(
final List<HsBookingProjectEntity> actualResult, final List<HsBookingProjectRbacEntity> actualResult,
final String... bookingProjectNames) { final String... bookingProjectNames) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsBookingProjectEntity::toString) .extracting(HsBookingProject::toString)
.containsExactlyInAnyOrder(bookingProjectNames); .containsExactlyInAnyOrder(bookingProjectNames);
} }
void allTheseBookingProjectsAreReturned( void allTheseBookingProjectsAreReturned(
final List<HsBookingProjectEntity> actualResult, final List<HsBookingProjectRbacEntity> actualResult,
final String... bookingProjectNames) { final String... bookingProjectNames) {
assertThat(actualResult) assertThat(actualResult)
.extracting(HsBookingProjectEntity::toString) .extracting(HsBookingProject::toString)
.contains(bookingProjectNames); .contains(bookingProjectNames);
} }
} }

View File

@ -7,8 +7,7 @@ import static net.hostsharing.hsadminng.hs.booking.debitor.TestHsBookingDebitor.
@UtilityClass @UtilityClass
public class TestHsBookingProject { public class TestHsBookingProject {
public static final HsBookingProjectRealEntity PROJECT_TEST_ENTITY = HsBookingProjectRealEntity.builder()
public static final HsBookingProjectEntity TEST_PROJECT = HsBookingProjectEntity.builder()
.debitor(TEST_BOOKING_DEBITOR) .debitor(TEST_BOOKING_DEBITOR)
.caption("test project") .caption("test project")
.build(); .build();

View File

@ -7,7 +7,7 @@ import net.hostsharing.hsadminng.hash.HashGenerator;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealRepository;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
@ -59,7 +59,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
HsBookingItemRepository bookingItemRepo; HsBookingItemRepository bookingItemRepo;
@Autowired @Autowired
HsBookingProjectRepository projectRepo; HsBookingProjectRealRepository realProjectRepo;
@Autowired @Autowired
HsOfficeDebitorRepository debitorRepo; HsOfficeDebitorRepository debitorRepo;
@ -79,7 +79,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenProject = projectRepo.findByCaption("D-1000111 default project").stream() final var givenProject = realProjectRepo.findByCaption("D-1000111 default project").stream()
.findAny().orElseThrow(); .findAny().orElseThrow();
RestAssured // @formatter:off RestAssured // @formatter:off
@ -685,7 +685,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
final HsBookingItemType type, final String bookingItemCaption, final Map<String, Object> resources) { final HsBookingItemType type, final String bookingItemCaption, final Map<String, Object> resources) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var project = projectRepo.findByCaption(projectCaption).stream() final var project = realProjectRepo.findByCaption(projectCaption).stream()
.findAny().orElseThrow(); .findAny().orElseThrow();
final var bookingItem = HsBookingItemEntity.builder() final var bookingItem = HsBookingItemEntity.builder()
.project(project) .project(project)
@ -703,7 +703,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
final String bookingItemCaption) { final String bookingItemCaption) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var project = projectRepo.findByCaption(projectCaption).getFirst(); final var project = realProjectRepo.findByCaption(projectCaption).getFirst();
final var resources = switch (bookingItemType) { final var resources = switch (bookingItemType) {
case MANAGED_SERVER -> Map.<String, Object>ofEntries(entry("CPU", 1), case MANAGED_SERVER -> Map.<String, Object>ofEntries(entry("CPU", 1),
entry("RAM", 20), entry("RAM", 20),

View File

@ -4,7 +4,7 @@ import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRbacRepository;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.hsadminng.mapper.Array; import net.hostsharing.hsadminng.mapper.Array;
@ -51,7 +51,7 @@ class HsHostingAssetRbacRepositoryIntegrationTest extends ContextBasedTestWithCl
HsBookingItemRepository bookingItemRepo; HsBookingItemRepository bookingItemRepo;
@Autowired @Autowired
HsBookingProjectRepository projectRepo; HsBookingProjectRbacRepository projectRepo;
@Autowired @Autowired
RawRbacRoleRepository rawRoleRepo; RawRbacRoleRepository rawRoleRepo;

View File

@ -14,12 +14,12 @@ import static java.util.Map.entry;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.TEST_PROJECT; import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.PROJECT_TEST_ENTITY;
class HsManagedWebspaceHostingAssetValidatorUnitTest { class HsManagedWebspaceHostingAssetValidatorUnitTest {
final HsBookingItemEntity managedServerBookingItem = HsBookingItemEntity.builder() final HsBookingItemEntity managedServerBookingItem = HsBookingItemEntity.builder()
.project(TEST_PROJECT) .project(PROJECT_TEST_ENTITY)
.type(HsBookingItemType.MANAGED_SERVER) .type(HsBookingItemType.MANAGED_SERVER)
.caption("Test Managed-Server") .caption("Test Managed-Server")
.resources(Map.ofEntries( .resources(Map.ofEntries(
@ -126,7 +126,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
.type(MANAGED_WEBSPACE) .type(MANAGED_WEBSPACE)
.bookingItem(HsBookingItemEntity.builder() .bookingItem(HsBookingItemEntity.builder()
.type(HsBookingItemType.MANAGED_WEBSPACE) .type(HsBookingItemType.MANAGED_WEBSPACE)
.project(TEST_PROJECT) .project(PROJECT_TEST_ENTITY)
.caption("some ManagedWebspace") .caption("some ManagedWebspace")
.resources(Map.ofEntries(entry("SSD", 25), entry("Traffic", 250))) .resources(Map.ofEntries(entry("SSD", 25), entry("Traffic", 250)))
.build()) .build())

View File

@ -9,7 +9,7 @@ import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry;
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntitySaveProcessor; import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntitySaveProcessor;
@ -131,7 +131,7 @@ public class ImportHostingAssets extends ImportOfficeData {
record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference<HsHostingAssetRealEntity> serverRef) {} record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference<HsHostingAssetRealEntity> serverRef) {}
static Map<Integer, HsBookingProjectEntity> bookingProjects = new WriteOnceMap<>(); static Map<Integer, HsBookingProjectRealEntity> bookingProjects = new WriteOnceMap<>();
static Map<Integer, HsBookingItemEntity> bookingItems = new WriteOnceMap<>(); static Map<Integer, HsBookingItemEntity> bookingItems = new WriteOnceMap<>();
static Map<Integer, Hive> hives = new WriteOnceMap<>(); static Map<Integer, Hive> hives = new WriteOnceMap<>();
@ -158,7 +158,7 @@ public class ImportHostingAssets extends ImportOfficeData {
@Order(11010) @Order(11010)
void createBookingProjects() { void createBookingProjects() {
debitors.forEach((id, debitor) -> { debitors.forEach((id, debitor) -> {
bookingProjects.put(id, HsBookingProjectEntity.builder() bookingProjects.put(id, HsBookingProjectRealEntity.builder()
.caption(debitor.getDefaultPrefix() + " default project") .caption(debitor.getDefaultPrefix() + " default project")
.debitor(em.find(HsBookingDebitorEntity.class, debitor.getUuid())) .debitor(em.find(HsBookingDebitorEntity.class, debitor.getUuid()))
.build()); .build());
@ -1118,7 +1118,7 @@ public class ImportHostingAssets extends ImportOfficeData {
&& managedWebspace.getRelatedProject().getDebitor().getDebitorNumber() == 10000_00 ) { && managedWebspace.getRelatedProject().getDebitor().getDebitorNumber() == 10000_00 ) {
assertThat(managedWebspace.getIdentifier()).startsWith("xyz"); assertThat(managedWebspace.getIdentifier()).startsWith("xyz");
final var hshDebitor = managedWebspace.getBookingItem().getProject().getDebitor(); final var hshDebitor = managedWebspace.getBookingItem().getProject().getDebitor();
final var newProject = HsBookingProjectEntity.builder() final var newProject = HsBookingProjectRealEntity.builder()
.debitor(hshDebitor) .debitor(hshDebitor)
.caption(parentAsset.getIdentifier() + " Monitor") .caption(parentAsset.getIdentifier() + " Monitor")
.build(); .build();

View File

@ -20,6 +20,7 @@ import jakarta.persistence.*;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.regex.Pattern;
import static java.lang.System.out; import static java.lang.System.out;
import static java.util.Comparator.comparing; import static java.util.Comparator.comparing;
@ -290,6 +291,20 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
/**
* @return an array of all RBAC roles matching the given pattern
*/
protected String[] roleNames(final String sqlLikeExpression) {
final var pattern = Pattern.compile(sqlLikeExpression);
//noinspection unchecked
final List<Object[]> rows = (List<Object[]>) em.createNativeQuery("select * from rbacrole_ev where roleidname like 'hs_booking_project#%'")
.getResultList();
return rows.stream()
.map(row -> (row[0]).toString())
.filter(roleName -> pattern.matcher(roleName).matches())
.toArray(String[]::new);
}
/** /**
* Generates a diagram of the RBAC-Grants to the current subjects (user or assumed roles). * Generates a diagram of the RBAC-Grants to the current subjects (user or assumed roles).
*/ */

View File

@ -77,11 +77,11 @@ public class JpaAttempt {
public static class JpaResult<T> { public static class JpaResult<T> {
private final T result; private final T value;
private final RuntimeException exception; private final RuntimeException exception;
private JpaResult(final T result, final RuntimeException exception) { private JpaResult(final T value, final RuntimeException exception) {
this.result = result; this.value = value;
this.exception = exception; this.exception = exception;
} }
@ -102,7 +102,7 @@ public class JpaAttempt {
} }
public T returnedValue() { public T returnedValue() {
return result; return value;
} }
public ObjectAssert<T> assertThatResult() { public ObjectAssert<T> assertThatResult() {