Revert "BAEL-4134"
This commit is contained in:
committed by
GitHub
parent
4a35b97bad
commit
7ab2f437ee
+35
-24
@@ -7,48 +7,59 @@ import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
|
||||
public class CsvUnitTest {
|
||||
|
||||
private File csvFromJson;
|
||||
private File jsonFromCsv;
|
||||
private File formattedCsvFromJson;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
csvFromJson = new File("src/main/resources/csv/csvFromJson.csv");
|
||||
jsonFromCsv = new File("src/main/resources/csv/jsonFromCsv.json");
|
||||
formattedCsvFromJson = new File("src/main/resources/csv/formattedCsvFromJson.csv");
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
csvFromJson.deleteOnExit();
|
||||
jsonFromCsv.deleteOnExit();
|
||||
formattedCsvFromJson.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenJsonInput_thenWriteCsv() throws JsonParseException, JsonMappingException, IOException {
|
||||
JsonCsvConverter.JsonToCsv(new File("src/main/resources/csv/orderLines.json"),
|
||||
new File("src/main/resources/csv/csvFromJson.csv"));
|
||||
|
||||
assertEquals(readFile("src/main/resources/csv/csvFromJson.csv"),
|
||||
readFile("src/test/resources/csv/expectedCsvFromJson.csv"));
|
||||
JsonCsvConverter.JsonToCsv(new File("src/main/resources/csv/orderLines.json"), csvFromJson);
|
||||
|
||||
assertEquals(readFile(csvFromJson.getAbsolutePath()), readFile("src/test/resources/csv/expectedCsvFromJson.csv"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenCsvInput_thenWritesJson() throws JsonParseException, JsonMappingException, IOException {
|
||||
JsonCsvConverter.csvToJson(new File("src/main/resources/csv/orderLines.csv"),
|
||||
new File("src/main/resources/csv/jsonFromCsv.json"));
|
||||
|
||||
assertEquals(readFile("src/main/resources/csv/jsonFromCsv.json"),
|
||||
readFile("src/test/resources/csv/expectedJsonFromCsv.json"));
|
||||
|
||||
JsonCsvConverter.csvToJson(new File("src/main/resources/csv/orderLines.csv"), jsonFromCsv);
|
||||
|
||||
assertEquals(readFile(jsonFromCsv.getAbsolutePath()), readFile("src/test/resources/csv/expectedJsonFromCsv.json"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenJsonInput_thenWriteFormattedCsvOutput() throws JsonParseException, JsonMappingException, IOException {
|
||||
JsonCsvConverter.JsonToFormattedCsv(new File("src/main/resources/csv/orderLines.json"),
|
||||
new File("src/main/resources/csv/formattedCsvFromJson.csv"));
|
||||
JsonCsvConverter.JsonToFormattedCsv(new File("src/main/resources/csv/orderLines.json"), formattedCsvFromJson);
|
||||
|
||||
assertEquals(readFile(formattedCsvFromJson.getAbsolutePath()), readFile("src/test/resources/csv/expectedFormattedCsvFromJson.csv"));
|
||||
|
||||
assertEquals(readFile("src/main/resources/csv/formattedCsvFromJson.csv"),
|
||||
readFile("src/test/resources/csv/expectedFormattedCsvFromJson.csv"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<String> readFile(String filename) throws IOException {
|
||||
return Files.readLines(new File(filename), Charset.forName("utf-8"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
};
|
||||
+10
-2
@@ -12,6 +12,7 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -25,12 +26,19 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
|
||||
|
||||
public class YamlUnitTest {
|
||||
private ObjectMapper mapper;
|
||||
private File orderOutput;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mapper = new ObjectMapper(new YAMLFactory().disable(Feature.WRITE_DOC_START_MARKER));
|
||||
mapper.findAndRegisterModules();
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
orderOutput = new File("src/test/resources/yaml/orderOutput.yaml");
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
orderOutput.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,9 +61,9 @@ public class YamlUnitTest {
|
||||
LocalDate.parse("2019-04-18", DateTimeFormatter.ISO_DATE),
|
||||
"Customer, Jane",
|
||||
lines);
|
||||
mapper.writeValue(new File("src/test/resources/yaml/orderOutput.yaml"), order);
|
||||
mapper.writeValue(orderOutput, order);
|
||||
|
||||
File outputYaml = new File("src/test/resources/yaml/orderOutput.yaml");
|
||||
File outputYaml = new File(orderOutput.getAbsolutePath());
|
||||
assertTrue(outputYaml.exists());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user