fix allowed licenses, do version upgrades upgrade and improve test coverage #112

Merged
hsh-michaelhoennig merged 8 commits from fix-checks into master 2024-10-10 09:31:46 +02:00
2 changed files with 15 additions and 17 deletions
Showing only changes of commit 83d949c7da - Show all commits

View File

@ -15,6 +15,7 @@ import org.opentest4j.AssertionFailedError;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.Resource;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
@ -24,7 +25,6 @@ import jakarta.validation.ValidationException;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
@ -33,6 +33,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -123,13 +124,10 @@ public class CsvDataImport extends ContextBasedTest {
} }
} }
protected String resourceAsString(@NotNull final String resourcePath) { @SneakyThrows
try (InputStream inputStream = requireNonNull(getClass().getClassLoader().getResourceAsStream(resourcePath)); protected String resourceAsString(final Resource resource) {
final var reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { final var lines = Files.readAllLines(resource.getFile().toPath(), StandardCharsets.UTF_8);
return reader.lines().collect(Collectors.joining(System.lineSeparator())); return String.join("\n", lines);
} catch (Exception exc) {
throw new AssertionFailedError("cannot open '" + resourcePath + "'");
}
} }
protected List<String[]> withoutHeader(final List<String[]> records) { protected List<String[]> withoutHeader(final List<String[]> records) {

View File

@ -2,6 +2,7 @@ package net.hostsharing.hsadminng.hs.migration;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hash.HashGenerator; import net.hostsharing.hsadminng.hash.HashGenerator;
import net.hostsharing.hsadminng.hash.HashGenerator.Algorithm; import net.hostsharing.hsadminng.hash.HashGenerator.Algorithm;
@ -26,10 +27,9 @@ import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.reflections.Reflections;
import org.reflections.scanners.ResourcesScanner;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.test.annotation.Commit; import org.springframework.test.annotation.Commit;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
@ -46,7 +46,6 @@ import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function; import java.util.function.Function;
import java.util.regex.Pattern;
import static java.util.Arrays.stream; import static java.util.Arrays.stream;
import static java.util.Map.entry; import static java.util.Map.entry;
@ -497,13 +496,14 @@ public class ImportHostingAssets extends BaseOfficeDataImport {
@Test @Test
@Order(16020) @Order(16020)
@SneakyThrows
void importZonenfiles() { void importZonenfiles() {
final var reflections = new Reflections(MIGRATION_DATA_PATH + "/hosting/zonefiles", new ResourcesScanner()); final var resolver = new PathMatchingResourcePatternResolver();
final var zonefileFiles = reflections.getResources(Pattern.compile(".*\\.json")).stream().sorted().toList(); final var resources = resolver.getResources("/" + MIGRATION_DATA_PATH + "/hosting/zonefiles/*.json");
zonefileFiles.forEach(zonenfileName -> { for (var resource : resources) {
System.out.println("Processing zonenfile: " + zonenfileName); System.out.println("Processing zonenfile: " + resource);
importZonefiles(vmName(zonenfileName), resourceAsString(zonenfileName)); importZonefiles(vmName(resource.getFilename()), resourceAsString(resource));
}); }
} }
@Test @Test