Commit 2e8e0ee7 authored by Jakob Schöttl's avatar Jakob Schöttl
Browse files

Reimplement JSON tests

parent 07801a88
package org.vadere.gui.vadere; package org.vadere.gui.vadere;
import org.junit.BeforeClass; import org.apache.commons.io.IOUtils;
import org.junit.Test; import org.junit.Test;
import org.vadere.simulator.projects.ScenarioRunManager; import org.vadere.simulator.projects.ScenarioRunManager;
import org.vadere.simulator.projects.VadereProject; import org.vadere.simulator.projects.io.JsonConverter;
import static org.junit.Assert.*;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap; import java.io.InputStream;
import java.util.concurrent.ConcurrentMap; import java.io.UncheckedIOException;
public class TestVadereTestProject { public class TestVadereTestProject {
private static VadereProject testProject;
private static String testProjectName = "testprojectname";
private static String testName = "testname";
@BeforeClass
public static void setUpBeforeClass() throws Exception {
ConcurrentMap<String, ScenarioRunManager> tests = new ConcurrentHashMap<>();
tests.put(testName + "1", new ScenarioRunManager(testName + "1"));
tests.put(testName + "2", new ScenarioRunManager(testName + "2"));
tests.put(testName + "3", new ScenarioRunManager(testName + "3"));
// testProject = new VadereProject(testProjectName, tests); // TODO [priority=medium] [task=test] fix test
}
@Test @Test
public void testToJSON() throws IOException { public void testToJson() throws IOException {
final String scenarioJson = loadTestScenarioJson();
final ScenarioRunManager srm = JsonConverter.deserializeScenarioRunManager(scenarioJson);
final String serializedJson = JsonConverter.serializeScenarioRunManager(srm);
// TODO implement json test // TODO implement json test
/*
* String json = IOUtils.toPrettyPrintJson(IOVadere.toJson(testProject));
* // System.out.println(json);
*
* Map<String, Object> store = fromJson(json, Map.class);
*
* assertEquals(testProject.getName(), store.get("name"));
*
* List<Map<Object, String>> tests = (List<Map<Object, String>>) store.get("scenarios");
* assertEquals(IOVadere.toJson(testProject.getScenario(0)),
* IOVadere.toJson(IOVadere.fromJson(IOUtils.toJson(tests.get(0)))));
* assertEquals(IOVadere.toJson(testProject.getScenario(1)),
* IOVadere.toJson(IOVadere.fromJson(IOUtils.toJson(tests.get(1)))));
* assertEquals(IOVadere.toJson(testProject.getScenario(2)),
* IOVadere.toJson(IOVadere.fromJson(IOUtils.toJson(tests.get(2)))));
*/
} }
@Test @Test
public void testFromJSON() throws IOException { public void testFromJson() throws IOException {
// TODO implement json test final String scenarioJson = loadTestScenarioJson();
/* final ScenarioRunManager srm = JsonConverter.deserializeScenarioRunManager(scenarioJson);
* String json = IOUtils.toPrettyPrintJson(IOVadere.toJson(testProject));
* VadereProject testInstanceNew = IOVadere.projectFromJson(json); assertEquals("Neues_Szenario", srm.getName());
* assertEquals(3, srm.getAttributesModel().size());
* assertEquals(IOVadere.toJson(testProject), IOVadere.toJson(testInstanceNew)); assertEquals(21, srm.getDataProcessingJsonManager().getDataProcessors().size());
*/ assertEquals(6, srm.getDataProcessingJsonManager().getOutputFiles().size());
assertTrue(srm.getAttributesPedestrian() != null);
assertTrue(srm.getAttributesSimulation() != null);
assertTrue(srm.getTopography() != null);
}
private String loadTestScenarioJson() {
try {
final InputStream resourceAsStream = getClass().getResourceAsStream("/test-scenario.scenario");
return IOUtils.toString(resourceAsStream);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
} }
} }
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