Skip to content

Commit 4381a45

Browse files
committed
Fixes tests and some missing documentation
1 parent eedf0c1 commit 4381a45

9 files changed

Lines changed: 62 additions & 61 deletions

File tree

core/src/main/java/edu/wpi/grip/core/Pipeline.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ public class Pipeline {
3737
public void clear() {
3838
// These streams are both collected into lists because streams cannot modify their source. Sending a
3939
// StepRemovedEvent or SourceRemovedEvent modifies this.steps or this.sources.
40-
this.steps.stream()
41-
.map(StepRemovedEvent::new)
42-
.collect(Collectors.toList())
43-
.forEach(this.eventBus::post);
40+
this.steps.stream().collect(Collectors.toList()).forEach(this::removeStep);
4441

4542
this.sources.stream()
4643
.map(SourceRemovedEvent::new)
@@ -138,15 +135,15 @@ public void onSourceRemoved(SourceRemovedEvent event) {
138135
}
139136
}
140137

141-
public synchronized void addStep(Step step, int index) {
138+
public synchronized void addStep(int index, Step step) {
142139
checkNotNull(step, "The step can not be null");
143140
this.steps.add(index, step);
144141
this.eventBus.register(step);
145142
this.eventBus.post(new StepAddedEvent(step, index));
146143
}
147144

148145
public synchronized void addStep(Step step) {
149-
addStep(step, this.steps.size());
146+
addStep(this.steps.size(), step);
150147
}
151148

152149
public synchronized void removeStep(Step step) {

core/src/test/java/edu/wpi/grip/core/MockStep.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.google.common.eventbus.EventBus;
44

5+
import java.util.Optional;
6+
57
public class MockStep extends Step {
68

79
public MockStep() {
8-
super(null, null, null, null);
10+
super(null, new InputSocket[0], new OutputSocket[0], Optional.empty());
911
}
1012

1113
public static Step createMockStepWithOperation(){

core/src/test/java/edu/wpi/grip/core/PipelineTest.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void testRemoveSource() throws URISyntaxException, IOException {
8585
public void testAddStep() {
8686
Step step = new MockStep();
8787

88-
eventBus.post(new StepAddedEvent(step));
88+
pipeline.addStep(step);
8989

9090
assertEquals(Collections.singletonList(step), pipeline.getSteps());
9191
}
@@ -96,8 +96,8 @@ public void testAddStepAtIndex() {
9696
Step step1 = new MockStep();
9797
Step step2 = new MockStep();
9898

99-
eventBus.post(new StepAddedEvent(step1));
100-
eventBus.post(new StepAddedEvent(step2, 0));
99+
pipeline.addStep(step1);
100+
pipeline.addStep(0, step2);
101101

102102
assertEquals(Arrays.asList(step2, step1), pipeline.getSteps());
103103
}
@@ -108,9 +108,9 @@ public void testRemoveFirstStep() {
108108
Step step1 = new MockStep();
109109
Step step2 = new MockStep();
110110

111-
eventBus.post(new StepAddedEvent(step1));
112-
eventBus.post(new StepAddedEvent(step2));
113-
eventBus.post(new StepRemovedEvent(step1));
111+
pipeline.addStep(step1);
112+
pipeline.addStep(step2);
113+
pipeline.removeStep(step1);
114114

115115
assertEquals(Collections.singletonList(step2), pipeline.getSteps());
116116
}
@@ -121,9 +121,9 @@ public void testRemoveSecondStep() {
121121
Step step1 = new MockStep();
122122
Step step2 = new MockStep();
123123

124-
eventBus.post(new StepAddedEvent(step1));
125-
eventBus.post(new StepAddedEvent(step2));
126-
eventBus.post(new StepRemovedEvent(step2));
124+
pipeline.addStep(step1);
125+
pipeline.addStep(step2);
126+
pipeline.removeStep(step2);
127127

128128
assertEquals(Collections.singletonList(step1), pipeline.getSteps());
129129
}
@@ -134,10 +134,10 @@ public void testMoveStep() {
134134
Step step2 = new MockStep();
135135
Step step3 = new MockStep();
136136

137-
eventBus.post(new StepAddedEvent(step1));
138-
eventBus.post(new StepAddedEvent(step2));
139-
eventBus.post(new StepAddedEvent(step3));
140-
eventBus.post(new StepMovedEvent(step1, +1));
137+
pipeline.addStep(step1);
138+
pipeline.addStep(step2);
139+
pipeline.addStep(step3);
140+
pipeline.moveStep(step1, +1);
141141

142142
assertEquals(Arrays.asList(step2, step1, step3), pipeline.getSteps());
143143
}
@@ -148,10 +148,10 @@ public void testMoveStepToBeginning() {
148148
Step step2 = new MockStep();
149149
Step step3 = new MockStep();
150150

151-
eventBus.post(new StepAddedEvent(step1));
152-
eventBus.post(new StepAddedEvent(step2));
153-
eventBus.post(new StepAddedEvent(step3));
154-
eventBus.post(new StepMovedEvent(step2, -10));
151+
pipeline.addStep(step1);
152+
pipeline.addStep(step2);
153+
pipeline.addStep(step3);
154+
pipeline.moveStep(step2, -10);
155155

156156
assertEquals("The step was not moved to the beginning of the pipeline", Arrays.asList(step2, step1, step3), pipeline.getSteps());
157157
}
@@ -162,10 +162,10 @@ public void testMoveStepToEnd() {
162162
Step step2 = new MockStep();
163163
Step step3 = new MockStep();
164164

165-
eventBus.post(new StepAddedEvent(step1));
166-
eventBus.post(new StepAddedEvent(step2));
167-
eventBus.post(new StepAddedEvent(step3));
168-
eventBus.post(new StepMovedEvent(step2, +10));
165+
pipeline.addStep(step1);
166+
pipeline.addStep(step2);
167+
pipeline.addStep(step3);
168+
pipeline.moveStep(step2, +10);
169169

170170
assertEquals("The step was not moved to the end of the pipeline", Arrays.asList(step1, step3, step2), pipeline.getSteps());
171171
}
@@ -206,8 +206,8 @@ public void testPipeline() {
206206
// sum2 = a2+b2
207207
// a2 = sum1
208208
// So, sum2 will be equal to a1+b1+b2
209-
eventBus.post(new StepAddedEvent(step1));
210-
eventBus.post(new StepAddedEvent(step2));
209+
pipeline.addStep(step1);
210+
pipeline.addStep(step2);
211211

212212
Connection connection = new Connection(eventBus, pipeline, sum1, a2);
213213
eventBus.register(connection);
@@ -234,8 +234,8 @@ public void testPipelineRemoved() {
234234

235235
a2.setValue(0.0);
236236

237-
eventBus.post(new StepAddedEvent(step1));
238-
eventBus.post(new StepAddedEvent(step2));
237+
pipeline.addStep(step1);
238+
pipeline.addStep(step2);
239239

240240
Connection connection = new Connection(eventBus, pipeline, sum1, a2);
241241
eventBus.post(new ConnectionAddedEvent(connection));
@@ -257,8 +257,8 @@ public void testCannotConnectBackwards() {
257257
InputSocket<Double> a1 = (InputSocket<Double>) step1.getInputSockets()[0];
258258
OutputSocket<Double> sum2 = (OutputSocket<Double>) step2.getOutputSockets()[0];
259259

260-
eventBus.post(new StepAddedEvent(step1));
261-
eventBus.post(new StepAddedEvent(step2));
260+
pipeline.addStep(step1);
261+
pipeline.addStep(step2);
262262
assertFalse("Should not be able to connect backwards", pipeline.canConnect(a1, sum2));
263263
}
264264

core/src/test/java/edu/wpi/grip/core/serialization/ProjectTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import edu.wpi.grip.core.events.ConnectionAddedEvent;
1010
import edu.wpi.grip.core.events.OperationAddedEvent;
1111
import edu.wpi.grip.core.events.SourceAddedEvent;
12-
import edu.wpi.grip.core.events.StepAddedEvent;
1312
import edu.wpi.grip.core.operations.PythonScriptOperation;
1413
import edu.wpi.grip.core.sources.ImageFileSource;
1514
import edu.wpi.grip.util.Files;
@@ -84,9 +83,9 @@ public void testSerializeEmptyPipeline() throws Exception {
8483

8584
@Test
8685
public void testSerializePipelineWithSteps() throws Exception {
87-
eventBus.post(new StepAddedEvent(stepFactory.create(additionOperation)));
88-
eventBus.post(new StepAddedEvent(stepFactory.create(pythonAdditionOperationFromSource)));
89-
eventBus.post(new StepAddedEvent(stepFactory.create(pythonAdditionOperationFromURL)));
86+
pipeline.addStep(stepFactory.create(additionOperation));
87+
pipeline.addStep(stepFactory.create(pythonAdditionOperationFromSource));
88+
pipeline.addStep(stepFactory.create(pythonAdditionOperationFromURL));
9089

9190
serializeAndDeserialize();
9291

@@ -113,8 +112,8 @@ public void testSerializePipelineWithStepsAndConnections() throws Exception {
113112
b1.setValue(34);
114113
b2.setValue(56);
115114

116-
eventBus.post(new StepAddedEvent(step1));
117-
eventBus.post(new StepAddedEvent(step2));
115+
pipeline.addStep(step1);
116+
pipeline.addStep(step2);
118117
eventBus.post(new ConnectionAddedEvent(connectionFactory.create(sum1, (InputSocket) a2)));
119118

120119
serializeAndDeserialize();
@@ -128,7 +127,7 @@ public void testSerializePipelineWithStepsAndConnections() throws Exception {
128127
@Test
129128
@SuppressWarnings("unchecked")
130129
public void testPerformSerializedStep() throws Exception {
131-
eventBus.post(new StepAddedEvent(stepFactory.create(additionOperation)));
130+
pipeline.addStep(stepFactory.create(additionOperation));
132131
serializeAndDeserialize();
133132

134133
InputSocket<Number> a = (InputSocket<Number>) pipeline.getSteps().get(0).getInputSockets()[0];
@@ -143,7 +142,7 @@ public void testPerformSerializedStep() throws Exception {
143142
@Test
144143
@SuppressWarnings("unchecked")
145144
public void testPerformSerializedPythonStepFromURL() throws Exception {
146-
eventBus.post(new StepAddedEvent(stepFactory.create(pythonAdditionOperationFromURL)));
145+
pipeline.addStep(stepFactory.create(pythonAdditionOperationFromURL));
147146
serializeAndDeserialize();
148147

149148
InputSocket<Number> a = (InputSocket<Number>) pipeline.getSteps().get(0).getInputSockets()[0];
@@ -158,7 +157,7 @@ public void testPerformSerializedPythonStepFromURL() throws Exception {
158157
@Test
159158
@SuppressWarnings("unchecked")
160159
public void testPerformSerializedPythonStepFromSource() throws Exception {
161-
eventBus.post(new StepAddedEvent(stepFactory.create(pythonAdditionOperationFromSource)));
160+
pipeline.addStep(stepFactory.create(pythonAdditionOperationFromSource));
162161
serializeAndDeserialize();
163162

164163
InputSocket<Number> a = (InputSocket<Number>) pipeline.getSteps().get(0).getInputSockets()[0];
@@ -175,8 +174,8 @@ public void testPerformSerializedPythonStepFromSource() throws Exception {
175174
public void testPerformSerializedPipeline() throws Exception {
176175
Step step1 = stepFactory.create(pythonAdditionOperationFromURL);
177176
Step step2 = stepFactory.create(pythonAdditionOperationFromSource);
178-
eventBus.post(new StepAddedEvent(step1));
179-
eventBus.post(new StepAddedEvent(step2));
177+
pipeline.addStep(step1);
178+
pipeline.addStep(step2);
180179
eventBus.post(new ConnectionAddedEvent(
181180
connectionFactory.create(
182181
(OutputSocket) step1.getOutputSockets()[0],
@@ -198,7 +197,7 @@ public void testPerformSerializedPipeline() throws Exception {
198197
@Test
199198
@SuppressWarnings("unchecked")
200199
public void testPerformSerializedPipelineWithMats() throws Exception {
201-
eventBus.post(new StepAddedEvent(stepFactory.create(opencvAddOperation)));
200+
pipeline.addStep(stepFactory.create(opencvAddOperation));
202201
serializeAndDeserialize();
203202

204203
Step step1 = pipeline.getSteps().get(0);

ui/src/main/java/edu/wpi/grip/ui/pipeline/PipelineController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public final class PipelineController {
6565
/**
6666
* Add initial views for the stuff in the pipeline at the time this controller is created
6767
*/
68+
@FXML
6869
public void initialize() throws Exception {
6970
stepsMapManager = new NodeControllerManager<>(stepBox.getChildren());
7071
sourceMapManager = new NodeControllerManager<>(sourcesBox.getChildren());

ui/src/main/java/edu/wpi/grip/ui/pipeline/SocketHandleView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public class SocketHandleView extends Button {
3535
private static final PseudoClass CONNECTING_PSEUDO_CLASS = PseudoClass.getPseudoClass("connecting");
3636
private static final PseudoClass CONNECTED_PSEUDO_CLASS = PseudoClass.getPseudoClass("connected");
3737

38+
/**
39+
* Provides a singleton object to assign the socket being dragged from during dragging to allow for a
40+
* connection to be made.
41+
*/
3842
@Singleton
3943
protected static final class SocketHandleDraggingSocketService {
4044
private Optional<Socket> draggingSocket = Optional.empty();

ui/src/main/java/edu/wpi/grip/ui/pipeline/StepController.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package edu.wpi.grip.ui.pipeline;
22

3-
import com.google.common.eventbus.EventBus;
43
import com.google.inject.assistedinject.Assisted;
54
import edu.wpi.grip.core.InputSocket;
65
import edu.wpi.grip.core.OutputSocket;
@@ -35,7 +34,6 @@ public class StepController implements Controller {
3534
@FXML private VBox inputs;
3635
@FXML private VBox outputs;
3736

38-
private final EventBus eventBus;
3937
private final Pipeline pipeline;
4038
private final InputSocketControllerFactory inputSocketControllerFactory;
4139
private final OutputSocketController.Factory outputSocketControllerFactory;
@@ -54,15 +52,15 @@ public interface Factory {
5452
}
5553

5654
@Inject
57-
StepController(EventBus eventBus, Pipeline pipeline, InputSocketControllerFactory inputSocketControllerFactory, OutputSocketController.Factory outputSocketControllerFactory, @Assisted Step step) {
58-
this.eventBus = eventBus;
55+
StepController(Pipeline pipeline, InputSocketControllerFactory inputSocketControllerFactory, OutputSocketController.Factory outputSocketControllerFactory, @Assisted Step step) {
5956
this.pipeline = pipeline;
6057
this.inputSocketControllerFactory = inputSocketControllerFactory;
6158
this.outputSocketControllerFactory = outputSocketControllerFactory;
6259
this.step = step;
6360
}
6461

65-
public void initialize() {
62+
@FXML
63+
private void initialize() {
6664
inputSocketMapManager = new NodeControllerManager<>(inputs.getChildren());
6765
outputSocketMapManager = new NodeControllerManager<>(outputs.getChildren());
6866

@@ -83,15 +81,13 @@ public void initialize() {
8381
/**
8482
* @return An unmodifiable collection of {@link InputSocketController}s corresponding to the input sockets of this step
8583
*/
86-
@SuppressWarnings("unchecked")
8784
public Collection<InputSocketController> getInputSockets() {
8885
return inputSocketMapManager.keySet();
8986
}
9087

9188
/**
9289
* @return An unmodifiable collection of {@link InputSocketController}s corresponding to the output sockets of this step
9390
*/
94-
@SuppressWarnings("unchecked")
9591
public Collection<OutputSocketController> getOutputSockets() {
9692
return outputSocketMapManager.keySet();
9793
}

ui/src/main/java/edu/wpi/grip/ui/pipeline/source/SourceControllerFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package edu.wpi.grip.ui.pipeline.source;
22

33
import com.google.inject.Inject;
4+
import com.google.inject.Singleton;
45
import edu.wpi.grip.core.Source;
56
import edu.wpi.grip.core.sources.CameraSource;
67
import edu.wpi.grip.core.sources.MultiImageFileSource;
78

89
/**
910
* BaseSourceControllerFactory for creating views to control sources.
1011
*/
11-
public final class SourceControllerFactory {
12+
@Singleton
13+
public class SourceControllerFactory {
1214
@Inject private CameraSourceController.Factory cameraControllerFactory;
1315
@Inject private MultiImageFileSourceController.Factory multiImageFileSourceControllerFactory;
1416
@Inject private SourceController.BaseSourceControllerFactory<Source> baseSourceControllerFactory;

ui/src/test/java/edu/wpi/grip/ui/pipeline/PipelineUITest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import com.google.inject.Guice;
66
import com.google.inject.Injector;
77
import edu.wpi.grip.core.*;
8-
import edu.wpi.grip.core.events.StepAddedEvent;
9-
import edu.wpi.grip.core.events.StepMovedEvent;
108
import edu.wpi.grip.ui.GRIPUIModule;
119
import edu.wpi.grip.ui.util.StyleClassNameUtility;
1210
import edu.wpi.grip.ui.util.TestAnnotationFXMLLoader;
@@ -37,11 +35,13 @@ public class PipelineUITest extends ApplicationTest {
3735
private AdditionOperation additionOperation;
3836
private SubtractionOperation subtractionOperation;
3937
private PipelineController pipelineController;
38+
private Pipeline pipeline;
4039

4140
@Override
4241
public void start(Stage stage) throws Exception {
4342
injector = Guice.createInjector(new GRIPCoreModule(), new GRIPUIModule());
4443
eventBus = injector.getInstance(EventBus.class);
44+
pipeline = injector.getInstance(Pipeline.class);
4545
additionOperation = new AdditionOperation();
4646
subtractionOperation = new SubtractionOperation();
4747
pipelineController = injector.getInstance(PipelineController.class);
@@ -77,10 +77,10 @@ public void testMoveOperation() {
7777
final Step step2 = MockStep.createMockStepWithOperation();
7878
final Step step3 = MockStep.createMockStepWithOperation();
7979

80-
eventBus.post(new StepAddedEvent(step1));
81-
eventBus.post(new StepAddedEvent(step2));
82-
eventBus.post(new StepAddedEvent(step3));
83-
eventBus.post(new StepMovedEvent(step2, +1));
80+
pipeline.addStep(step1);
81+
pipeline.addStep(step2);
82+
pipeline.addStep(step3);
83+
pipeline.moveStep(step2, +1);
8484

8585
//sleep(1, TimeUnit.SECONDS);
8686
WaitForAsyncUtils.waitForFxEvents();
@@ -127,7 +127,7 @@ private void addAdditionOperation() {
127127

128128
private Step addOperation(int count, Operation operation) {
129129
final Step step = new Step.Factory(eventBus).create(operation);
130-
eventBus.post(new StepAddedEvent(step));
130+
pipeline.addStep(step);
131131

132132
// Wait for the event to propagate to the UI
133133
sleep(1, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)