test-data-cleanup-via-raw-tables-and-fix-arc-tests #39

Merged
hsh-michaelhoennig merged 6 commits from test-data-cleanup-via-raw-tables-and-fix-arc-tests into master 2024-04-13 13:55:28 +02:00
3 changed files with 16 additions and 32 deletions
Showing only changes of commit 9f0af9274f - Show all commits

View File

@ -218,7 +218,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
.reference("test ref")
.build());
}).assertSuccessful().assertNotNull().returnedValue();
toCleanup(HsOfficeCoopAssetsTransactionRawEntity.class, givenTransaction.getUuid());
toCleanup(HsOfficeCoopAssetsTransactionEntity.class, givenTransaction.getUuid());
final var location = RestAssured // @formatter:off
.given()
@ -267,7 +267,7 @@ class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBased
final var newAssetTxUuid = UUID.fromString(
location.substring(location.lastIndexOf('/') + 1));
assertThat(newAssetTxUuid).isNotNull();
toCleanup(HsOfficeCoopAssetsTransactionRawEntity.class, newAssetTxUuid);
toCleanup(HsOfficeCoopAssetsTransactionEntity.class, newAssetTxUuid);
}
@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;
}
// TODO.test: back to `Class<? extends RbacObject> entityClass` but delete on raw table
// 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 + ")");
entitiesToCleanup.put(uuidToCleanup, entityClass);
return uuidToCleanup;
@ -178,16 +177,19 @@ public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
}
private void cleanupTemporaryTestData() {
entitiesToCleanup.forEach((uuid, entityClass) -> {
final var caughtException = jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null);
em.remove(em.getReference(entityClass, uuid));
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " generated");
}).caughtException();
if (caughtException != null) {
out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + " failed: " + caughtException);
}
});
jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null);
entitiesToCleanup.reversed().forEach((uuid, entityClass) -> {
final var rvTableName = entityClass.getAnnotation(Table.class).name();
if ( !rvTableName.endsWith("_rv") ) {
throw new IllegalStateException();
}
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() {