cleanup-todos (#31)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/31 Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
@ -121,7 +121,7 @@ public class ArchitectureTest {
|
||||
.should().onlyBeAccessed().byClassesThat()
|
||||
.resideInAnyPackage(
|
||||
"..hs.office.(*)..",
|
||||
"..rbac.rbacgrant" // TODO: just because of RbacGrantsDiagramServiceIntegrationTest
|
||||
"..rbac.rbacgrant" // TODO.test: just because of RbacGrantsDiagramServiceIntegrationTest
|
||||
);
|
||||
|
||||
@ArchTest
|
||||
|
@ -27,12 +27,12 @@ import static org.mockito.Mockito.verify;
|
||||
class ContextUnitTest {
|
||||
|
||||
private static final String DEFINE_CONTEXT_QUERY_STRING = """
|
||||
call defineContext(
|
||||
cast(:currentTask as varchar),
|
||||
cast(:currentRequest as varchar),
|
||||
cast(:currentUser as varchar),
|
||||
cast(:assumedRoles as varchar));
|
||||
""";
|
||||
call defineContext(
|
||||
cast(:currentTask as varchar(127)),
|
||||
cast(:currentRequest as text),
|
||||
cast(:currentUser as varchar(63)),
|
||||
cast(:assumedRoles as varchar(1023)));
|
||||
""";
|
||||
|
||||
@Nested
|
||||
class WithoutHttpRequest {
|
||||
@ -71,7 +71,7 @@ class ContextUnitTest {
|
||||
context.define("current-user");
|
||||
|
||||
verify(em).createNativeQuery(DEFINE_CONTEXT_QUERY_STRING);
|
||||
verify(nativeQuery).setParameter("currentRequest", "");
|
||||
verify(nativeQuery).setParameter("currentRequest", null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,8 +142,8 @@ class ContextUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shortensCurrentTaskTo96Chars() throws IOException {
|
||||
givenRequest("GET", "http://localhost:9999/api/endpoint/" + "0123456789".repeat(10),
|
||||
void shortensCurrentTaskToMaxLength() throws IOException {
|
||||
givenRequest("GET", "http://localhost:9999/api/endpoint/" + "0123456789".repeat(13),
|
||||
Map.ofEntries(
|
||||
Map.entry("current-user", "given-user"),
|
||||
Map.entry("content-type", "application/json"),
|
||||
@ -153,26 +153,7 @@ class ContextUnitTest {
|
||||
context.define("current-user");
|
||||
|
||||
verify(em).createNativeQuery(DEFINE_CONTEXT_QUERY_STRING);
|
||||
verify(nativeQuery).setParameter(eq("currentTask"), argThat((String t) -> t.length() == 96));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shortensCurrentRequestTo512Chars() throws IOException {
|
||||
givenRequest("GET", "http://localhost:9999/api/endpoint",
|
||||
Map.ofEntries(
|
||||
Map.entry("current-user", "given-user"),
|
||||
Map.entry("content-type", "application/json"),
|
||||
Map.entry("user-agent", "given-user-agent")),
|
||||
"""
|
||||
{
|
||||
"dummy": "%s"
|
||||
}
|
||||
""".formatted("0123456789".repeat(60)));
|
||||
|
||||
context.define("current-user");
|
||||
|
||||
verify(em).createNativeQuery(DEFINE_CONTEXT_QUERY_STRING);
|
||||
verify(nativeQuery).setParameter(eq("currentRequest"), argThat((String t) -> t.length() == 512));
|
||||
verify(nativeQuery).setParameter(eq("currentTask"), argThat((String t) -> t.length() == 127));
|
||||
}
|
||||
|
||||
private void givenRequest(final String method, final String url, final Map<String, String> headers, final String body)
|
||||
|
@ -1,11 +1,10 @@
|
||||
package net.hostsharing.hsadminng.hs.office.test;
|
||||
|
||||
import net.hostsharing.hsadminng.context.ContextBasedTest;
|
||||
import net.hostsharing.hsadminng.persistence.HasUuid;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
|
||||
import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantRepository;
|
||||
import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantsDiagramService;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
|
||||
import net.hostsharing.hsadminng.rbac.rbacrole.RbacRoleEntity;
|
||||
import net.hostsharing.hsadminng.rbac.rbacrole.RbacRoleRepository;
|
||||
import net.hostsharing.test.JpaAttempt;
|
||||
@ -66,7 +65,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
|
||||
return merged;
|
||||
}
|
||||
|
||||
public UUID toCleanup(final Class<? extends HasUuid> entityClass, final UUID uuidToCleanup) {
|
||||
public UUID toCleanup(final Class<? extends RbacObject> entityClass, final UUID uuidToCleanup) {
|
||||
out.println("toCleanup(" + entityClass.getSimpleName() + ", " + uuidToCleanup);
|
||||
entitiesToCleanup.put(uuidToCleanup, entityClass);
|
||||
return uuidToCleanup;
|
||||
@ -81,7 +80,7 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected void cleanupAllNew(final Class<? extends HasUuid> entityClass) {
|
||||
protected void cleanupAllNew(final Class<? extends RbacObject> entityClass) {
|
||||
if (initialRbacObjects == null) {
|
||||
out.println("skipping cleanupAllNew: " + entityClass.getSimpleName());
|
||||
return; // TODO: seems @AfterEach is called without any @BeforeEach
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.test;
|
||||
|
||||
import net.hostsharing.hsadminng.persistence.HasUuid;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -8,7 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EntityList {
|
||||
|
||||
public static <E extends HasUuid> E one(final List<E> entities) {
|
||||
public static <E extends RbacObject> E one(final List<E> entities) {
|
||||
assertThat(entities).hasSize(1);
|
||||
return entities.stream().findFirst().orElseThrow();
|
||||
}
|
||||
|
@ -130,7 +130,6 @@ public class JpaAttempt {
|
||||
final Class<? extends RuntimeException> expectedExceptionClass,
|
||||
final String... expectedRootCauseMessages) {
|
||||
assertThat(wasSuccessful()).as("wasSuccessful").isFalse();
|
||||
// TODO: also check the expected exception class itself
|
||||
final String firstRootCauseMessageLine = firstRootCauseMessageLineOf(caughtException(expectedExceptionClass));
|
||||
for (String expectedRootCauseMessage : expectedRootCauseMessages) {
|
||||
assertThat(firstRootCauseMessageLine).contains(expectedRootCauseMessage);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.hostsharing.test;
|
||||
|
||||
import net.hostsharing.hsadminng.persistence.HasUuid;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
|
||||
import net.hostsharing.hsadminng.mapper.EntityPatcher;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -233,7 +233,7 @@ public abstract class PatchUnitTestBase<R, E> {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class JsonNullableProperty<R, RV, E extends HasUuid, EV> extends Property<R, RV, E, EV> {
|
||||
protected static class JsonNullableProperty<R, RV, E extends RbacObject, EV> extends Property<R, RV, E, EV> {
|
||||
|
||||
private final BiConsumer<R, JsonNullable<RV>> resourceSetter;
|
||||
public final RV givenPatchValue;
|
||||
|
Reference in New Issue
Block a user