better selection of test-data

This commit is contained in:
Michael Hoennig 2024-07-17 06:09:56 +02:00
parent 7d87a30d93
commit 731fa369ad
2 changed files with 123 additions and 47 deletions

View File

@ -139,6 +139,7 @@ public class CsvDataImport extends ContextBasedTest {
map.keySet().stream()
.map(id -> " " + id + "=" + map.get(id).toString())
.map(e -> e.replaceAll("\n ", " ").replace("\n", ""))
.sorted()
.collect(Collectors.joining(",\n")) +
"\n}\n";
}

View File

@ -17,10 +17,10 @@ import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import java.io.Reader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toMap;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.IPV4_NUMBER;
@ -78,9 +78,12 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ImportHostingAssets extends CsvDataImport {
private static final Integer IP_NUMBER_ID_OFFSET = 1000000;
private static final Integer PACKET_ID_OFFSET = 2000000;
private static final Integer HIVE_ID_OFFSET = 2000000;
private static final Integer PACKET_ID_OFFSET = 3000000;
record Hive(int hive_id, String hive_name, int inet_addr_id){};
record Hive(int hive_id, String hive_name, int inet_addr_id) {}
;
private static Map<Integer, HsBookingItemEntity> bookingItems = new WriteOnceMap<>();
private static Map<Integer, Hive> hives = new WriteOnceMap<>();
@ -103,13 +106,13 @@ public class ImportHostingAssets extends CsvDataImport {
assumeThatWeAreImportingControlledTestData();
// no contacts yet => mostly null values
assertThat(toFormattedString(firstOfType(5, hostingAssets, IPV4_NUMBER))).isEqualToIgnoringWhitespace("""
assertThat(firstOfEachType(5, IPV4_NUMBER)).isEqualToIgnoringWhitespace("""
{
1000333=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.4),
1000332=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.3),
1000331=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.2),
1000329=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.0),
1000330=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.1),
1000329=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.0)
1000331=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.2),
1000332=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.3),
1000333=HsHostingAssetEntity(IPV4_NUMBER, 83.223.95.4)
}
""");
}
@ -133,11 +136,11 @@ public class ImportHostingAssets extends CsvDataImport {
// no contacts yet => mostly null values
assertThat(toFormattedString(first(5, hives))).isEqualToIgnoringWhitespace("""
{
1=Hive[hive_id=1, hive_name=h01, inet_addr_id=358],
2=Hive[hive_id=2, hive_name=h02, inet_addr_id=359],
4=Hive[hive_id=4, hive_name=h03, inet_addr_id=360],
7=Hive[hive_id=7, hive_name=h04, inet_addr_id=361],
13=Hive[hive_id=13, hive_name=h05, inet_addr_id=430]
2000001=Hive[hive_id=1, hive_name=h01, inet_addr_id=358],
2000002=Hive[hive_id=2, hive_name=h02, inet_addr_id=359],
2000004=Hive[hive_id=4, hive_name=h03, inet_addr_id=360],
2000007=Hive[hive_id=7, hive_name=h04, inet_addr_id=361],
2000013=Hive[hive_id=13, hive_name=h05, inet_addr_id=430]
}
""");
}
@ -158,14 +161,34 @@ public class ImportHostingAssets extends CsvDataImport {
void verifyPackets() {
assumeThatWeAreImportingControlledTestData();
// no contacts yet => mostly null values
assertThat(toFormattedString(firstOfType(5, hostingAssets, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE))).isEqualToIgnoringWhitespace("""
assertThat(firstOfEachType(3, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE)).isEqualToIgnoringWhitespace("""
{
2000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000, D-???????-?:al000),
2000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, D-???????-?:ahr01),
2000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00, D-???????-?:aih00),
2000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, D-???????-?:ahr00),
2000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, D-???????-?:agu00)
3000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, D-???????-?:agu00),
3000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, D-???????-?:ahr00),
3000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, D-???????-?:ahr01),
3000964=HsHostingAssetEntity(MANAGED_SERVER, vm1064, D-???????-?:vm1064),
3000966=HsHostingAssetEntity(MANAGED_SERVER, vm1063, D-???????-?:vm1063),
3000967=HsHostingAssetEntity(MANAGED_SERVER, vm1062, D-???????-?:vm1062),
3023611=HsHostingAssetEntity(CLOUD_SERVER, vm2097, D-???????-?:vm2097),
3023612=HsHostingAssetEntity(CLOUD_SERVER, vm2062, D-???????-?:vm2062),
3023613=HsHostingAssetEntity(CLOUD_SERVER, vm2058, D-???????-?:vm2058)
}
""");
assertThat(firstOfEachType(
3,
HsBookingItemType.CLOUD_SERVER,
HsBookingItemType.MANAGED_SERVER,
HsBookingItemType.MANAGED_WEBSPACE)).isEqualToIgnoringWhitespace("""
{
3000003=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), agu00),
3000007=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), ahr00),
3000008=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), ahr01),
3000964=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1064),
3000966=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1063),
3000967=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1062),
3023611=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2097),
3023612=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2062),
3023613=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2058)
}
""");
}
@ -187,13 +210,48 @@ public class ImportHostingAssets extends CsvDataImport {
assumeThatWeAreImportingControlledTestData();
// no contacts yet => mostly null values
assertThat(toFormattedString(firstOfType(5, hostingAssets, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE))).isEqualToIgnoringWhitespace("""
assertThat(firstOfEachType(5, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE))
.isEqualToIgnoringWhitespace("""
{
2000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000, D-???????-?:al000),
2000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, D-???????-?:ahr01),
2000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00, D-???????-?:aih00),
2000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, D-???????-?:ahr00),
2000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, D-???????-?:agu00)
3000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, D-???????-?:agu00),
3000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, D-???????-?:ahr00),
3000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, D-???????-?:ahr01),
3000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00, D-???????-?:aih00),
3000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000, D-???????-?:al000),
3000964=HsHostingAssetEntity(MANAGED_SERVER, vm1064, D-???????-?:vm1064),
3000966=HsHostingAssetEntity(MANAGED_SERVER, vm1063, D-???????-?:vm1063),
3000967=HsHostingAssetEntity(MANAGED_SERVER, vm1062, D-???????-?:vm1062),
3000968=HsHostingAssetEntity(MANAGED_SERVER, vm1061, D-???????-?:vm1061),
3000969=HsHostingAssetEntity(MANAGED_SERVER, vm1060, D-???????-?:vm1060),
3023611=HsHostingAssetEntity(CLOUD_SERVER, vm2097, D-???????-?:vm2097),
3023612=HsHostingAssetEntity(CLOUD_SERVER, vm2062, D-???????-?:vm2062),
3023613=HsHostingAssetEntity(CLOUD_SERVER, vm2058, D-???????-?:vm2058),
3023614=HsHostingAssetEntity(CLOUD_SERVER, vm2055, D-???????-?:vm2055),
3023615=HsHostingAssetEntity(CLOUD_SERVER, vm2010, D-???????-?:vm2010)
}
""");
assertThat(firstOfEachType(
5,
HsBookingItemType.CLOUD_SERVER,
HsBookingItemType.MANAGED_SERVER,
HsBookingItemType.MANAGED_WEBSPACE))
.isEqualToIgnoringWhitespace("""
{
3000003=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), agu00, { "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 8192, "Traffic": 20}),
3000007=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), ahr00, { "Multi": 6, "SLA-Platform": "EXT24H", "SSD": 25600, "Traffic": 10}),
3000008=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), ahr01, { "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 5120, "Traffic": 10}),
3000009=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), aih00, { "HDD": 20480, "Multi": 2, "SLA-Platform": "BASIC", "SSD": 3072, "Traffic": 10}),
3000012=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), al000, { "HDD": 10240, "Multi": 3, "SLA-Platform": "BASIC", "SSD": 6144, "Traffic": 40}),
3000964=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1064, { "CPU": 2, "RAM": 4096, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT4H", "SLA-Web": true, "SSD": 76800, "Traffic": 500}),
3000966=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1063, { "CPU": 2, "HDD": 256000, "RAM": 8192, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT4H", "SLA-Web": true, "SSD": 51200, "Traffic": 250}),
3000967=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1062, { "CPU": 2, "HDD": 256000, "RAM": 12288, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT2H", "SLA-Web": true, "SSD": 102400, "Traffic": 250}),
3000968=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1061, { "CPU": 6, "HDD": 256000, "RAM": 14336, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "BASIC", "SLA-Web": true, "SSD": 384000, "Traffic": 250}),
3000969=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1060, { "CPU": 2, "RAM": 4096, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT2H", "SLA-Web": true, "SSD": 76800, "Traffic": 250}),
3023611=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2097, { "CPU": 8, "RAM": 12288, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023612=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2062, { "CPU": 10, "RAM": 65536, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023613=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2058, { "CPU": 1, "RAM": 8192, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023614=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2055, { "CPU": 8, "HDD": 256000, "RAM": 16384, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023615=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2010, { "CPU": 2, "RAM": 2048, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 51200, "Traffic": 250})
}
""");
}
@ -220,10 +278,11 @@ public class ImportHostingAssets extends CsvDataImport {
.map(row -> new Record(columns, row))
.forEach(rec -> {
final var hive_id = rec.getInteger("hive_id");
final var hive = new Hive(hive_id,
final var hive = new Hive(
hive_id,
rec.getString("hive_name"),
rec.getInteger("inet_addr_id"));
hives.put(hive_id, hive);
hives.put(HIVE_ID_OFFSET + hive_id, hive);
});
}
@ -250,17 +309,20 @@ public class ImportHostingAssets extends CsvDataImport {
case "SRV/CLD" -> HsBookingItemType.CLOUD_SERVER;
case "SRV/MGD" -> HsBookingItemType.MANAGED_SERVER;
case "PAC/WEB" -> HsBookingItemType.MANAGED_WEBSPACE;
default -> throw new IllegalArgumentException("unknown basepacket_code: " + rec.getString("basepacket_code"));
default -> throw new IllegalArgumentException(
"unknown basepacket_code: " + rec.getString("basepacket_code"));
})
.caption(packet_name)
.build();
bookingItems.put(PACKET_ID_OFFSET + packet_id, bookingItem);
final var asset = HsHostingAssetEntity.builder()
.type(switch (rec.getString("basepacket_code")) {
case "SRV/CLD" -> CLOUD_SERVER;
case "SRV/MGD" -> MANAGED_SERVER;
case "PAC/WEB" -> MANAGED_WEBSPACE;
default -> throw new IllegalArgumentException("unknown basepacket_code: " + rec.getString("basepacket_code"));
default -> throw new IllegalArgumentException(
"unknown basepacket_code: " + rec.getString("basepacket_code"));
})
.identifier(rec.getString("packet_name"))
.bookingItem(bookingItem)
@ -342,21 +404,34 @@ public class ImportHostingAssets extends CsvDataImport {
asset.getBookingItem().getResources().put(name, slaValue);
} else if (name.startsWith("SLA")) {
asset.getBookingItem().getResources().put(name, true);
} else {
} else if (quantity > 0) {
asset.getBookingItem().getResources().put(name, quantity);
}
});
}
private Map<Integer, Object> firstOfType(
private String firstOfEachType(
final int maxCount,
final Map<Integer, HsHostingAssetEntity> hostingAssets,
final HsHostingAssetType... types) {
final var typesList = Arrays.asList(types);
return hostingAssets.entrySet().stream()
.filter(ha -> typesList.contains(ha.getValue().getType()))
return toFormattedString(stream(types)
.flatMap(t ->
hostingAssets.entrySet().stream()
.filter(hae -> hae.getValue().getType() == t)
.limit(maxCount)
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
)
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
private String firstOfEachType(
final int maxCount,
final HsBookingItemType... types) {
return toFormattedString(stream(types)
.flatMap(t ->
bookingItems.entrySet().stream()
.filter(bie -> bie.getValue().getType() == t)
.limit(maxCount)
)
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
private Map<Integer, Object> first(