Commit 346d2ed0 authored by hengwen's avatar hengwen
Browse files

Activate tests

parent 14aad27c
Pipeline #188330 passed with stages
in 13 minutes and 41 seconds
......@@ -3,12 +3,19 @@ package server.restful.service;
import junit.framework.TestCase;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.restful.dao.MapDAO;
import server.restful.dao.ScenarioDAO;
import server.restful.dao.SimulationDAO;
import server.restful.model.Dataframe;
import server.restful.model.ScenarioModel;
import server.restful.registry.RegistryFactory;
import server.restful.util.Util;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Properties;
public class SimulationServiceTest extends TestCase {
......@@ -23,38 +30,38 @@ public class SimulationServiceTest extends TestCase {
*
* @throws FileNotFoundException
*/
// @Test
// public void testSimulation() throws Exception {
// Logger logger = LoggerFactory.getLogger(SimulationServiceTest.class);
// ScenarioModel scenario = ScenarioService.saveScenario(
// new FileInputStream(getClass().getResource("/chargingstation.sim").getPath()),
// "uploaded.sim"
// );
// int mapID = MapDAO.create("chargingstation.osm", getClass().getResource("/chargingstation.osm").getPath());
// int simID = SimulationDAO.create(scenario.getId(), 1);
// SimulationService sim = new SimulationService(simID);
//
// sim.startSimulation(RegistryFactory.getZookeeperRegistry());
//
// // wait for battery to be charged from 19% to 100%, it will take some time...
// // if we can set the charging battery target to a lower value rather than 100%,
// // it will be much quicker.
// while(!sim.isSimulationFinished()){
// logger.info("Waiting for simulation result...");
// Thread.sleep(5000);
// }
//
// List<Dataframe> frames = sim.getResult().get(0).getFrames();
//
// // expect 1 vehicle
// assertEquals(1, sim.getResult().size());
// assertTrue(frames.size() > 0);
//
// double initialBattery = frames.get(0).getBattery();
// double finalBattery = frames.get(frames.size() - 1).getBattery();
// // after charging, final battery percentage should be higher than initial
// assertTrue(finalBattery > initialBattery);
// }
@Test
public void testSimulation() throws Exception {
Logger logger = LoggerFactory.getLogger(SimulationServiceTest.class);
ScenarioModel scenario = ScenarioService.saveScenario(
new FileInputStream(getClass().getResource("/chargingstation.sim").getPath()),
"uploaded.sim"
);
int mapID = MapDAO.create("chargingstation.osm", getClass().getResource("/chargingstation.osm").getPath());
int simID = SimulationDAO.create(scenario.getId(), 1);
SimulationService sim = new SimulationService(simID);
sim.startSimulation(RegistryFactory.getZookeeperRegistry());
// wait for battery to be charged from 19% to 100%, it will take some time...
// if we can set the charging battery target to a lower value rather than 100%,
// it will be much quicker.
while(!sim.isSimulationFinished()){
logger.info("Waiting for simulation result...");
Thread.sleep(5000);
}
List<Dataframe> frames = sim.getResult().get(0).getFrames();
// expect 1 vehicle
assertEquals(1, sim.getResult().size());
assertTrue(frames.size() > 0);
double initialBattery = frames.get(0).getBattery();
double finalBattery = frames.get(frames.size() - 1).getBattery();
// after charging, final battery percentage should be higher than initial
assertTrue(finalBattery > initialBattery);
}
@Test
public void testConfig() {
......@@ -67,14 +74,14 @@ public class SimulationServiceTest extends TestCase {
}
// @Test
// public void testGetScenario() throws FileNotFoundException {
// ScenarioModel scenario = ScenarioService.saveScenario(
// new FileInputStream(getClass().getResource("/straight.sim").getPath()),
// "my-uploaded-scenario.sim"
// );
// int mapID = MapDAO.create("straight.osm", getClass().getResource("/straight.osm").getPath());
// int simID = SimulationDAO.create(scenario.getId(), 2);
// SimulationService sim = new SimulationService(simID);
// sim.getScenario();
// }
public void testGetScenario() throws FileNotFoundException {
ScenarioModel scenario = ScenarioService.saveScenario(
new FileInputStream(getClass().getResource("/straight.sim").getPath()),
"my-uploaded-scenario.sim"
);
int mapID = MapDAO.create("straight.osm", getClass().getResource("/straight.osm").getPath());
int simID = SimulationDAO.create(scenario.getId(), 2);
SimulationService sim = new SimulationService(simID);
sim.getScenario();
}
}
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