add first 3-letters of asset-transaction-type to toShortString

This commit is contained in:
Michael Hoennig 2024-04-11 13:47:12 +02:00
parent f5de2a8850
commit 9f0af9274f
3 changed files with 16 additions and 32 deletions

View File

@ -218,7 +218,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
.reference("test ref") .reference("test ref")
.build()); .build());
}).assertSuccessful().assertNotNull().returnedValue(); }).assertSuccessful().assertNotNull().returnedValue();
toCleanup(HsOfficeCoopAssetsTransactionRawEntity.class, givenTransaction.getUuid()); toCleanup(HsOfficeCoopAssetsTransactionEntity.class, givenTransaction.getUuid());
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -267,7 +267,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
final var newAssetTxUuid = UUID.fromString( final var newAssetTxUuid = UUID.fromString(
location.substring(location.lastIndexOf('/') + 1)); location.substring(location.lastIndexOf('/') + 1));
assertThat(newAssetTxUuid).isNotNull(); assertThat(newAssetTxUuid).isNotNull();
toCleanup(HsOfficeCoopAssetsTransactionRawEntity.class, newAssetTxUuid); toCleanup(HsOfficeCoopAssetsTransactionEntity.class, newAssetTxUuid);
} }
@Test @Test

View File

@ -1,18 +0,0 @@
package net.hostsharing.hsadminng.hs.office.coopassets;
import lombok.NoArgsConstructor;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.UUID;
@Entity
@Table(name = "hs_office_coopassetstransaction")
@NoArgsConstructor
public class HsOfficeCoopAssetsTransactionRawEntity {
@Id
private UUID uuid;
}

View File

@ -64,9 +64,8 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
return merged; return merged;
} }
// TODO.test: back to `Class<? extends RbacObject> entityClass` but delete on raw table
// remove HsOfficeCoopAssetsTransactionRawEntity, which is not needed anymore after this change // remove HsOfficeCoopAssetsTransactionRawEntity, which is not needed anymore after this change
public UUID toCleanup(final Class entityClass, final UUID uuidToCleanup) { public UUID toCleanup(final Class<? extends RbacObject> entityClass, final UUID uuidToCleanup) {
out.println("toCleanup(" + entityClass.getSimpleName() + ", " + uuidToCleanup + ")"); out.println("toCleanup(" + entityClass.getSimpleName() + ", " + uuidToCleanup + ")");
entitiesToCleanup.put(uuidToCleanup, entityClass); entitiesToCleanup.put(uuidToCleanup, entityClass);
return uuidToCleanup; return uuidToCleanup;
@ -178,16 +177,19 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
} }
private void cleanupTemporaryTestData() { private void cleanupTemporaryTestData() {
entitiesToCleanup.forEach((uuid, entityClass) -> { jpaAttempt.transacted(() -> {
final var caughtException = jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net", null);
context.define("superuser-alex@hostsharing.net", null); entitiesToCleanup.reversed().forEach((uuid, entityClass) -> {
em.remove(em.getReference(entityClass, uuid)); final var rvTableName = entityClass.getAnnotation(Table.class).name();
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " generated"); if ( !rvTableName.endsWith("_rv") ) {
}).caughtException(); throw new IllegalStateException();
if (caughtException != null) { }
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " failed: " + caughtException); final var rawTableName = rvTableName.substring(0, rvTableName.length() - "_rv".length());
} final var deletedRows = em.createNativeQuery("DELETE FROM " + rawTableName + " WHERE uuid=:uuid")
}); .setParameter("uuid", uuid).executeUpdate();
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " deleted " + deletedRows + " rows");
});
}).assertSuccessful();
} }
private long assertNoNewRbacObjectsRolesAndGrantsLeaked() { private long assertNoNewRbacObjectsRolesAndGrantsLeaked() {