improve validation after import

This commit is contained in:
Michael Hoennig 2024-08-09 11:19:15 +02:00
parent ee26cb6476
commit 9e04c800d0

View File

@ -574,10 +574,82 @@ public class ImportHostingAssets extends ImportOfficeData {
@Test @Test
@Order(18020) @Order(18020)
void validateHostingAssets() { void validateIpNumberAssets() {
validateHostingAssets(ipNumberAssets); validateHostingAssets(ipNumberAssets);
} }
@Test
@Order(18021)
void validateServerAndWebspaceAssets() {
validateHostingAssets(packetAssets);
}
@Test
@Order(18022)
void validateUnixUserAssets() {
validateHostingAssets(unixUserAssets);
}
@Test
@Order(18023)
void validateEmailAliasAssets() {
validateHostingAssets(emailAliasAssets);
}
@Test
@Order(18030)
void validateDbInstanceAssets() {
validateHostingAssets(dbInstanceAssets);
}
@Test
@Order(18031)
void validateDbUserAssets() {
validateHostingAssets(dbUserAssets);
}
@Test
@Order(18032)
void validateDbAssets() {
validateHostingAssets(dbAssets);
}
@Test
@Order(18040)
void validateDomainSetupAssets() {
validateHostingAssets(domainSetupAssets);
}
@Test
@Order(18041)
void validateDomainDnsSetupAssets() {
validateHostingAssets(domainDnsSetupAssets);
}
@Test
@Order(18042)
void validateDomainHttpSetupAssets() {
validateHostingAssets(domainHttpSetupAssets);
}
@Test
@Order(18043)
void validateDomainSmtpSetupAssets() {
validateHostingAssets(domainSmtpSetupAssets);
}
@Test
@Order(18044)
void validateDomainMBoxSetupAssets() {
validateHostingAssets(domainMBoxSetupAssets);
}
@Test
@Order(18050)
void validateEmailAddressAssets() {
validateHostingAssets(emailAddressAssets);
}
void validateHostingAssets(final Map<Integer, HsHostingAssetRealEntity> assets) { void validateHostingAssets(final Map<Integer, HsHostingAssetRealEntity> assets) {
assets.forEach((id, ha) -> { assets.forEach((id, ha) -> {
try { try {
@ -793,8 +865,15 @@ public class ImportHostingAssets extends ImportOfficeData {
.getSingleResult(); .getSingleResult();
assertThat(haCount).isGreaterThan(isImportingControlledTestData() ? 40 : 15000); assertThat(haCount).isGreaterThan(isImportingControlledTestData() ? 40 : 15000);
verifyActuallyPersistedHostingAssetCount(CLOUD_SERVER, 1, 50);
verifyActuallyPersistedHostingAssetCount(MANAGED_SERVER, 4, 100);
verifyActuallyPersistedHostingAssetCount(MANAGED_WEBSPACE, 4, 100);
verifyActuallyPersistedHostingAssetCount(UNIX_USER, 14, 100);
verifyActuallyPersistedHostingAssetCount(EMAIL_ALIAS, 9, 1400); verifyActuallyPersistedHostingAssetCount(EMAIL_ALIAS, 9, 1400);
verifyActuallyPersistedHostingAssetCount(EMAIL_ADDRESS, 70, 30000); verifyActuallyPersistedHostingAssetCount(PGSQL_DATABASE, 8, 100);
verifyActuallyPersistedHostingAssetCount(MARIADB_DATABASE, 8, 100);
verifyActuallyPersistedHostingAssetCount(DOMAIN_SETUP, 9, 100);
verifyActuallyPersistedHostingAssetCount(EMAIL_ADDRESS, 71, 30000);
} }
// ============================================================================================ // ============================================================================================
@ -836,10 +915,10 @@ public class ImportHostingAssets extends ImportOfficeData {
.filter(entry -> type == null || type == entry.getValue().getType()) .filter(entry -> type == null || type == entry.getValue().getType())
.toList(); .toList();
final var chunkSize = isImportingControlledTestData() ? 10 : 500; final var chunkSize = isImportingControlledTestData() ? 10 : 500;
ListUtils.partition(assetsOfType, chunkSize).forEach(chunk -> { ListUtils.partition(assetsOfType, chunkSize).forEach(chunk ->
chunk.forEach(entry -> {
jpaAttempt.transacted(() -> { jpaAttempt.transacted(() -> {
context(rbacSuperuser); context(rbacSuperuser);
chunk.forEach(entry ->
logError(() -> logError(() ->
new HostingAssetEntitySaveProcessor(em, entry.getValue()) new HostingAssetEntitySaveProcessor(em, entry.getValue())
.preprocessEntity() .preprocessEntity()
@ -847,23 +926,27 @@ public class ImportHostingAssets extends ImportOfficeData {
.prepareForSave() .prepareForSave()
.saveUsing(entity -> persist(entry.getKey(), entity)) .saveUsing(entity -> persist(entry.getKey(), entity))
.validateContext() .validateContext()
); ));
}).assertSuccessful();
});
} }
).assertSuccessful()
); );
} }
private void verifyActuallyPersistedHostingAssetCount( private void verifyActuallyPersistedHostingAssetCount(
final HsHostingAssetType assetType, final HsHostingAssetType assetType,
final int minExpectedInTestData, final int expectedCountInTestDataCount,
final int minExpectedInProdData) { final int minCountExpectedInProdData) {
final var q = em.createNativeQuery( final var q = em.createNativeQuery(
"select count(*) from hs_hosting_asset where type = cast(:type as HsHostingAssetType)", "select count(*) from hs_hosting_asset where type = cast(:type as HsHostingAssetType)",
Integer.class); Integer.class);
q.setParameter("type", assetType.name()); q.setParameter("type", assetType.name());
final var count = (Integer) q.getSingleResult(); final var count = (Integer) q.getSingleResult();
assertThat(count).isGreaterThan(isImportingControlledTestData() ? minExpectedInTestData : minExpectedInProdData); if (isImportingControlledTestData()) {
assertThat(count).isEqualTo(expectedCountInTestDataCount);
} else {
assertThat(count).isGreaterThanOrEqualTo(minCountExpectedInProdData);
}
} }
private void importIpNumbers(final String[] header, final List<String[]> records) { private void importIpNumbers(final String[] header, final List<String[]> records) {