Skip to content

Commit

Permalink
JSON-File wird f. manuelle Kontrolle exportiert
Browse files Browse the repository at this point in the history
  • Loading branch information
oboehm committed Dec 7, 2024
1 parent 47a53d3 commit aff6b4e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/src/test/java/gdv/xport/util/JsonFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
package gdv.xport.util;

import gdv.xport.Datenpaket;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hamcrest.MatcherAssert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;

import static org.hamcrest.Matchers.startsWith;

Expand All @@ -37,12 +41,20 @@
public final class JsonFormatterTest extends AbstractFormatterTest {

private static final Logger LOG = LogManager.getLogger(JsonFormatterTest.class);
private static final File TARGET_DIR = new File("target", "json");

@Override
protected AbstractFormatter createFormatter() {
return new JsonFormatter();
}

@BeforeClass
public static void setUpTargetDir() {
if (!TARGET_DIR.exists() && TARGET_DIR.mkdirs()) {
LOG.info("Verzeichnis '{}' wurde angelegt.", TARGET_DIR);
}
}

/**
* Tested den Export eines Datenpakets als JSON.
*
Expand Down Expand Up @@ -70,11 +82,14 @@ public void testWriteDatenpaket() throws IOException {
}

private void checkWrite(Datenpaket datenpaket) throws IOException {
File exportFile = new File(TARGET_DIR, String.format("datenpaket%03d.json", datenpaket.getDatensaetze().size()));
try (StringWriter swriter = new StringWriter()) {
JsonFormatter formatter = new JsonFormatter(swriter);
formatter.write(datenpaket);
swriter.flush();
String jsonString = swriter.toString().trim();
FileUtils.writeStringToFile(exportFile, jsonString, StandardCharsets.UTF_8);
LOG.info("{} wurde zur manuellen Pruefung in '{}' abgelegt", datenpaket, exportFile);
MatcherAssert.assertThat(jsonString, startsWith("{"));
LOG.info("{} wurde nach JSON formatiert.", datenpaket);
}
Expand Down

0 comments on commit aff6b4e

Please sign in to comment.