Commit 13d81d2d authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

add identity test for scenarios

parent 1dac1eb2
......@@ -26,6 +26,27 @@
{
"type": "org.vadere.simulator.projects.dataprocessing.processor.PedestrianGroupIDProcessor",
"id": 3
},
{
"type": "org.vadere.simulator.projects.dataprocessing.processor.AreaDensityVoronoiProcessor",
"id": 4,
"attributesType": "org.vadere.state.attributes.processor.AttributesAreaDensityVoronoiProcessor",
"attributes": {
"measurementArea": {
"x": 0.0,
"y": 0.0,
"width": 1.0,
"height": 1.0,
"type": "RECTANGLE"
},
"voronoiArea": {
"x": 0.0,
"y": 0.0,
"width": 1.0,
"height": 1.0,
"type": "RECTANGLE"
}
}
}
],
"isTimestamped": true
......
......@@ -8,16 +8,13 @@
"processWriters": {
"files": {
"*": {
"type": "processWriters.files[&1].&",
"filename": "processWriters.files[&1].&",
"processors": "processWriters.files[&1].&"
"*": "processWriters.files[&1].&"
}
},
"processors": {
"*": {
// &1 is the index
"type": "processWriters.processors[&1].type",
"id": "processWriters.processors[&1].id"
// first '*' array, second '*' childen in object
"*": "processWriters.processors[&1].&0"
}
},
"isTimestamped": "&1.&0"
......
package org.vadere.simulator.projects.migration;
import com.bazaarvoice.jolt.Chainr;
import com.bazaarvoice.jolt.Diffy;
import com.bazaarvoice.jolt.JsonUtils;
import java.util.List;
public class JoltTest {
public static void main(String[] args) {
new JoltTest().run2();
}
public void run() {
// String s = getClass().getResourceAsStream("simpleTestSpec.json").toString();
// System.out.println(s);
// org.vadere.state.attributes.models.
int i = 0;
List chainrSpecJson = JsonUtils.classpathToList("/simpleTestSpec.json");
Chainr chainr = Chainr.fromSpec(chainrSpecJson);
Object inputJson = JsonUtils.classpathToObject("/testJson.json");
Object transformedOutput = chainr.transform(inputJson);
System.out.println(JsonUtils.toPrettyJsonString(transformedOutput));
}
public void run2() {
List chainrSpecJson = JsonUtils.classpathToList("/transfrom_v2_to_v3.json");
Chainr chainr = Chainr.fromSpec(chainrSpecJson);
Object inputJson = JsonUtils.classpathToObject("/scenario_test.json");
Object transformedOutput = chainr.transform(inputJson);
String in = JsonUtils.toPrettyJsonString(inputJson);
String out = JsonUtils.toPrettyJsonString(transformedOutput);
System.out.println(out);
String[] inarr = in.split(System.getProperty("line.separator"));
String[] outarr = out.split(System.getProperty("line.separator"));
Diffy diffy = new Diffy();
Diffy.Result res = diffy.diff(inputJson, transformedOutput);
System.out.println(res.toString());
//todo leere Attribute
//
}
}
package org.vadere.simulator.projects.migration;
import com.bazaarvoice.jolt.Chainr;
import com.bazaarvoice.jolt.Diffy;
import com.bazaarvoice.jolt.JsonUtils;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.LinkedList;
import java.util.List;
import static org.junit.Assert.*;
public class JoltIdentityTransformationTest {
@Test
public void testExistingScenarioFiles() throws IOException {
List<Path> scenarioFiles = getScenarioFiles(Paths.get("../VadereModelTests").toRealPath(LinkOption.NOFOLLOW_LINKS).toAbsolutePath());
for (Path scenarioFile : scenarioFiles) {
List chainrSpecJson = JsonUtils.classpathToList("/transfrom_v2_to_v3.json");
Chainr chainr = Chainr.fromSpec(chainrSpecJson);
Object inputJson = JsonUtils.filepathToObject(scenarioFile.toString());
Object transformedOutput = chainr.transform(inputJson);
Diffy diffy = new Diffy();
Diffy.Result res = diffy.diff(inputJson, transformedOutput);
System.out.printf("###Test Jolt Identity on Scenario: %s | Transformation Match: %s%n",
scenarioFile.getFileName().toString(), res.isEmpty());
if (!res.isEmpty()) {
System.out.println(res.toString());
System.out.println("######");
System.out.println(JsonUtils.toPrettyJsonString(transformedOutput));
}
}
}
private List<Path> getScenarioFiles(Path vadereModelTest) {
LinkedList<Path> scenarioFiles = new LinkedList<>();
FileVisitor<Path> visitor = new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
if (dir.endsWith("output") || dir.endsWith("TestSFM")) {
return FileVisitResult.SKIP_SUBTREE;
} else {
return FileVisitResult.CONTINUE;
}
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith("scenario")) {
scenarioFiles.add(file);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return null;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (Files.exists(dir.resolve(".git"))) {
return FileVisitResult.CONTINUE;
} else {
return FileVisitResult.SKIP_SUBTREE;
}
}
};
try {
Files.walkFileTree(vadereModelTest, visitor);
} catch (IOException e) {
e.printStackTrace();
}
return scenarioFiles;
}
}
\ No newline at end of file
......@@ -3,7 +3,9 @@ package org.vadere.util.factory.processors;
import org.vadere.util.factory.BaseFactory;
import java.util.HashMap;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public class ProcessorBaseFactory<T> extends BaseFactory<T, ProcessorFactoryObject<T>> {
......@@ -16,4 +18,8 @@ public class ProcessorBaseFactory<T> extends BaseFactory<T, ProcessorFactoryObje
supplierMap.forEach((s, factoryObject) -> out.put(factoryObject.getLabel(), s));
return out;
}
public List<String> getProcessors() {
return supplierMap.keySet().stream().collect(Collectors.toList());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment