The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit fb2f71e7 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Refactor DataProcessor to allow multiple required DataProcessors

parent 8c96cad0
......@@ -39,7 +39,7 @@ public class PedestrianEndTimeProcessorTestEnv extends ProcessorTestEnv<Pedestri
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock(1) {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(new Integer[]{3,4,7,6,8});
......@@ -54,7 +54,7 @@ public class PedestrianEndTimeProcessorTestEnv extends ProcessorTestEnv<Pedestri
}
});
states.add(new SimulationStateMock(2) {
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(new Integer[]{3,4,7,6,8,10, 12});
......@@ -72,7 +72,7 @@ public class PedestrianEndTimeProcessorTestEnv extends ProcessorTestEnv<Pedestri
}
});
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(new Integer[]{3,6,8,10, 12});
......@@ -87,7 +87,7 @@ public class PedestrianEndTimeProcessorTestEnv extends ProcessorTestEnv<Pedestri
}
});
states.add(new SimulationStateMock(4) {
addSimState(new SimulationStateMock(4) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(new Integer[]{8,10});
......
......@@ -16,21 +16,31 @@ import static org.mockito.Mockito.when;
public class PedestrianEvacuationTimeProcessorTestEnv extends ProcessorTestEnv<PedestrianIdKey, Double> {
DataProcessor pedStartTimeProc;
PedestrianStartTimeProcessorTestEnv pedStartTimeProcEnv;
PedestrianListBuilder b = new PedestrianListBuilder();
PedestrianEvacuationTimeProcessorTestEnv() {
PedestrianEvacuationTimeProcessorTestEnv(){this(1);}
PedestrianEvacuationTimeProcessorTestEnv(int nextProcesorId) {
testedProcessor = processorFactory.createDataProcessor(PedestrianEvacuationTimeProcessor.class);
testedProcessor.setId(nextProcessorId());
testedProcessor.setId(nextProcesorId);
this.nextProcessorId = nextProcesorId + 1;
DataProcessor pedStartTimeProc;
PedestrianStartTimeProcessorTestEnv pedStartTimeProcEnv;
int pedStartTimeProcId = nextProcessorId();
//add ProcessorId of required Processors to current Processor under test
AttributesPedestrianEvacuationTimeProcessor attr =
(AttributesPedestrianEvacuationTimeProcessor) testedProcessor.getAttributes();
attr.setPedestrianStartTimeProcessorId(99);
attr.setPedestrianStartTimeProcessorId(pedStartTimeProcId);
pedStartTimeProcEnv = new PedestrianStartTimeProcessorTestEnv(99);
//create required Processor enviroment and add it to current Processor under test
pedStartTimeProcEnv = new PedestrianStartTimeProcessorTestEnv(pedStartTimeProcId);
pedStartTimeProc = pedStartTimeProcEnv.getTestedProcessor();
Mockito.when(manager.getProcessor(99)).thenReturn(pedStartTimeProc);
Mockito.when(manager.getProcessor(pedStartTimeProcId)).thenReturn(pedStartTimeProc);
addRequiredProcessors(pedStartTimeProcEnv);
//setup output file with different VadereWriter impl for test
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
PedestrianIdKey.class,
testedProcessor.getId()
......@@ -41,7 +51,7 @@ public class PedestrianEvacuationTimeProcessorTestEnv extends ProcessorTestEnv<P
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock(1) {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
......@@ -54,11 +64,10 @@ public class PedestrianEvacuationTimeProcessorTestEnv extends ProcessorTestEnv<P
addToExpectedOutput(new PedestrianIdKey(3), 0.0);
addToExpectedOutput(new PedestrianIdKey(4), 0.0);
pedStartTimeProcEnv.addSimState(this);
}
});
states.add(new SimulationStateMock(2) {
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
......@@ -73,11 +82,10 @@ public class PedestrianEvacuationTimeProcessorTestEnv extends ProcessorTestEnv<P
addToExpectedOutput(new PedestrianIdKey(5), 0.0);
addToExpectedOutput(new PedestrianIdKey(8), 0.0);
pedStartTimeProcEnv.addSimState(this);
}
});
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
......@@ -90,12 +98,11 @@ public class PedestrianEvacuationTimeProcessorTestEnv extends ProcessorTestEnv<P
addToExpectedOutput(new PedestrianIdKey(5), 34.7 - 12.8);
addToExpectedOutput(new PedestrianIdKey(8), 34.7 - 12.8);
pedStartTimeProcEnv.addSimState(this);
}
});
states.add(new SimulationStateMock(4) {
addSimState(new SimulationStateMock(4) {
@Override
public void mockIt() {
......@@ -106,7 +113,6 @@ public class PedestrianEvacuationTimeProcessorTestEnv extends ProcessorTestEnv<P
addToExpectedOutput(new PedestrianIdKey(1), Double.NaN);
pedStartTimeProcEnv.addSimState(this);
}
});
}
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.mockito.Mockito;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.processor.AttributesPedestrianLastPositionProcessor;
......@@ -17,33 +18,35 @@ import static org.mockito.Mockito.when;
public class PedestrianLastPositionProcessorTestEnv extends ProcessorTestEnv<PedestrianIdKey, VPoint> {
PedestrianListBuilder b = new PedestrianListBuilder();
private int pedPosProcId;
private DataProcessor pedPosProc;
private PedestrianPositionProcessorTestEnv pedPosProcEnv;
PedestrianLastPositionProcessorTestEnv() {
testedProcessor = processorFactory.createDataProcessor(PedestrianLastPositionProcessor.class);
testedProcessor.setId(nextProcessorId());
DataProcessor pedPosProc;
PedestrianPositionProcessorTestEnv pedPosProcEnv;
int pedPosProcId = nextProcessorId();
//add ProcessorId of required Processors to current Processor under test
((AttributesPedestrianLastPositionProcessor) testedProcessor.getAttributes())
.setPedestrianPositionProcessorId(99);
pedPosProcId = 99;
.setPedestrianPositionProcessorId(pedPosProcId);
//create required Processor enviroment and add it to current Processor under test
pedPosProcEnv = new PedestrianPositionProcessorTestEnv(pedPosProcId);
pedPosProcEnv.init();
pedPosProc = pedPosProcEnv.getTestedProcessor();
Mockito.when(manager.getProcessor(pedPosProcId)).thenReturn(pedPosProc);
//setup output file with different VadereWriter impl for test
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
PedestrianIdKey.class,
testedProcessor.getId()
);
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
when(manager.getProcessor(pedPosProcId)).thenReturn(pedPosProc);
}
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock(1) {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
......@@ -56,12 +59,10 @@ public class PedestrianLastPositionProcessorTestEnv extends ProcessorTestEnv<Ped
addToExpectedOutput(new PedestrianIdKey(3), new VPoint(4.45, 1.2));
addToExpectedOutput(new PedestrianIdKey(5), new VPoint(3.546, 7.2342));
//also set this SimulstaionStateMock for all dependencies.
pedPosProcEnv.addSimState(this);
}
});
states.add(new SimulationStateMock(2) {
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(33.2, 3.22))
......@@ -74,18 +75,15 @@ public class PedestrianLastPositionProcessorTestEnv extends ProcessorTestEnv<Ped
addToExpectedOutput(new PedestrianIdKey(3), new VPoint(3.2, 22.3));
addToExpectedOutput(new PedestrianIdKey(7), new VPoint(1.2, 3.3));
pedPosProcEnv.addSimState(this);
}
});
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
b.clear();
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
//no Pedestrians left so nothing to add in this step.
pedPosProcEnv.addSimState(this);
}
});
}
......
......@@ -28,7 +28,7 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock(1) {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
......@@ -46,7 +46,7 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
}
});
states.add(new SimulationStateMock(2) {
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
......@@ -66,7 +66,7 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
}
});
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
......
......@@ -26,7 +26,7 @@ public class PedestrianPositionProcessorTestEnv extends ProcessorTestEnv<Timeste
super();
testedProcessor = processorFactory.createDataProcessor(PedestrianPositionProcessor.class);
testedProcessor.setId(processorId);
this.nextProcessorId = processorId++;
this.nextProcessorId = processorId + 1;
outputFile = outputFileFactory.createOutputfile(
TimestepPedestrianIdOutputFile.class,
......@@ -43,7 +43,7 @@ public class PedestrianPositionProcessorTestEnv extends ProcessorTestEnv<Timeste
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock() {
addSimState(new SimulationStateMock() {
@Override
public void mockIt() {
when(state.getStep()).thenReturn(1);
......@@ -57,7 +57,7 @@ public class PedestrianPositionProcessorTestEnv extends ProcessorTestEnv<Timeste
}
});
states.add(new SimulationStateMock() {
addSimState(new SimulationStateMock() {
@Override
public void mockIt() {
when(state.getStep()).thenReturn(2);
......@@ -69,7 +69,7 @@ public class PedestrianPositionProcessorTestEnv extends ProcessorTestEnv<Timeste
}
});
states.add(new SimulationStateMock() {
addSimState(new SimulationStateMock() {
@Override
public void mockIt() {
when(state.getStep()).thenReturn(3);
......
......@@ -40,7 +40,7 @@ public class PedestrianSourceIdProcessorTestEnv extends ProcessorTestEnv<Pedestr
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock(1) {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
List<Pedestrian> pedes = getPeds(new Integer[]{1, 5, 9, 6}, new Integer[]{3, 3, 1, 2});
......@@ -55,7 +55,7 @@ public class PedestrianSourceIdProcessorTestEnv extends ProcessorTestEnv<Pedestr
}
});
states.add(new SimulationStateMock(2) {
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
List<Pedestrian> pedes = getPeds(new Integer[]{1, 5, 9, 12}, new Integer[]{3, 4, 1, 1});
......
......@@ -43,7 +43,7 @@ public class PedestrianStartTimeProcessorTestEnv extends ProcessorTestEnv<Pedest
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock() {
addSimState(new SimulationStateMock() {
@Override
public void mockIt() {
......@@ -60,7 +60,7 @@ public class PedestrianStartTimeProcessorTestEnv extends ProcessorTestEnv<Pedest
}
});
states.add(new SimulationStateMock() {
addSimState(new SimulationStateMock() {
@Override
public void mockIt() {
......@@ -78,7 +78,7 @@ public class PedestrianStartTimeProcessorTestEnv extends ProcessorTestEnv<Pedest
}
});
states.add(new SimulationStateMock() {
addSimState(new SimulationStateMock() {
@Override
public void mockIt() {
......
......@@ -53,7 +53,7 @@ public class PedestrianStateProcessorTestEnv extends ProcessorTestEnv<TimestepPe
peds[id] = new Pedestrian(new AttributesAgent(id), new Random());
}
states.add(new SimulationStateMock(1) {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(1, 2, 3, 4, 5);
......@@ -65,7 +65,7 @@ public class PedestrianStateProcessorTestEnv extends ProcessorTestEnv<TimestepPe
});
states.add(new SimulationStateMock(2) {
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(1, 2, 3, 4, 5, 7, 8);
......@@ -77,7 +77,7 @@ public class PedestrianStateProcessorTestEnv extends ProcessorTestEnv<TimestepPe
}
});
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(4, 5, 7, 8, 9);
......
......@@ -39,7 +39,7 @@ public class PedestrianTargetIdProcessorTestEnv extends ProcessorTestEnv<Timeste
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock(1) {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(new Integer[]{12,33,40, 2}, new Integer[]{1,1,2, 2});
......@@ -53,7 +53,7 @@ public class PedestrianTargetIdProcessorTestEnv extends ProcessorTestEnv<Timeste
}
});
states.add(new SimulationStateMock(2) {
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(new Integer[]{12,33,40, 9}, new Integer[]{1,2,3, 1});
......@@ -67,7 +67,7 @@ public class PedestrianTargetIdProcessorTestEnv extends ProcessorTestEnv<Timeste
}
});
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
List<Pedestrian> peds = getPeds(new Integer[]{ 10, 9 }, new Integer[]{1, 1});
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.mockito.Mockito;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.processor.AttributesPedestrianVelocityProcessor;
......@@ -16,27 +17,32 @@ import static org.mockito.Mockito.when;
public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdKey, Double>{
private DataProcessor pedPosProc;
private PedestrianPositionProcessorTestEnv pedPosProcEnv;
PedestrianVelocityProcessorTestEnv(){
testedProcessor = processorFactory.createDataProcessor(PedestrianVelocityProcessor.class);
testedProcessor.setId(nextProcessorId());
DataProcessor pedPosProc;
PedestrianPositionProcessorTestEnv pedPosProcEnv;
int pedPosProcId = nextProcessorId();
//add ProcessorId of required Processors to current Processor under test
AttributesPedestrianVelocityProcessor attr =
(AttributesPedestrianVelocityProcessor) testedProcessor.getAttributes();
attr.setPedestrianPositionProcessorId(99);
attr.setPedestrianPositionProcessorId(pedPosProcId);
pedPosProcEnv = new PedestrianPositionProcessorTestEnv(99);
pedPosProcEnv.init();
//create required Processor enviroment and add it to current Processor under test
pedPosProcEnv = new PedestrianPositionProcessorTestEnv(pedPosProcId);
pedPosProc = pedPosProcEnv.getTestedProcessor();
Mockito.when(manager.getProcessor(pedPosProcId)).thenReturn(pedPosProc);
addRequiredProcessors(pedPosProcEnv);
//setup output file with different VadereWriter impl for test
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
TimestepPedestrianIdKey.class,
testedProcessor.getId()
);
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
when(manager.getProcessor(99)).thenReturn(pedPosProc);
}
PedestrianListBuilder b = new PedestrianListBuilder();
......@@ -44,14 +50,13 @@ public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<Timest
SimulationStateMock state2;
public void loadSimulationStateMocksWithBackstep2(){
states.clear();
pedPosProcEnv.getSimStates().clear();
clearStates();
states.add(state1);
addSimState(state1);
states.add(state2);
addSimState(state2);
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
......@@ -67,8 +72,6 @@ public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<Timest
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 5.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0);
pedPosProcEnv.addSimState(this);
}
});
}
......@@ -91,11 +94,9 @@ public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<Timest
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 0.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0);
pedPosProcEnv.addSimState(this);
}
};
states.add(state1);
addSimState(state1);
state2 = new SimulationStateMock(2) {
@Override
......@@ -113,13 +114,11 @@ public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<Timest
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 5.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0);
pedPosProcEnv.addSimState(this);
}
};
states.add(state2);
addSimState(state2);
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
......@@ -135,8 +134,6 @@ public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<Timest
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 0.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0);
pedPosProcEnv.addSimState(this);
}
});
}
......
......@@ -11,7 +11,7 @@ public class PedestrianWaitingEndTimeProcessorTest extends ProcessorTest {
@Before
public void setup(){
processorTestEnv = new PedestrianWaitingEndTimeProcessorEnv();
processorTestEnv = new PedestrianWaitingEndTimeProcessorTestEnv();
super.setup();
}
......
......@@ -9,9 +9,9 @@ import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
public class PedestrianWaitingEndTimeProcessorEnv extends ProcessorTestEnv<PedestrianIdKey, Double> {
public class PedestrianWaitingEndTimeProcessorTestEnv extends ProcessorTestEnv<PedestrianIdKey, Double> {
PedestrianWaitingEndTimeProcessorEnv(){
PedestrianWaitingEndTimeProcessorTestEnv(){
testedProcessor = processorFactory.createDataProcessor(PedestrianWaitingEndTimeProcessor.class);
testedProcessor.setId(nextProcessorId());
......
......@@ -35,7 +35,7 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
/**
* Ped 1,2,3 start within WaitingArea and 4 never enters Area.
*/
states.add(new SimulationStateMock(1) {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
......@@ -54,7 +54,7 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
}
});
states.add(new SimulationStateMock(2) {
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
......@@ -71,7 +71,7 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
}
});
states.add(new SimulationStateMock(3) {
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
......@@ -87,7 +87,7 @@ public class PedestrianWaitingTimeProcessorTestEnv extends ProcessorTestEnv<Pede
}
});
states.add(new SimulationStateMock(4) {
addSimState(new SimulationStateMock(4) {
@Override
public void mockIt() {
Map<Integer, VPoint> pedPosMap = new HashMap<>();
......
......@@ -12,6 +12,7 @@ import org.vadere.tests.reflection.ReflectionHelper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -33,7 +34,7 @@ public abstract class ProcessorTestEnv<K extends DataKey<K>, V> {
/**
* List of {@link SimulationState}s used for test. (mocked)