Pipeline implements ConnectionValidator, SettingsProvider, StepIndexer { public void addStep(int index, Step step) { checkNotNull(step, "The step can not be null"); checkArgument(!step.removed(), "The step must not have been disabled already"); writeStepsSafelyConsume(steps -> steps.add(index, step)); this.eventBus.register(step); this.eventBus.post(new StepAddedEvent(step, index)); }  void clear(); final ImmutableList<Source> getSources(); final ImmutableList<Step> getSteps(); Set<Connection> getConnections(); @Override ProjectSettings getProjectSettings(); @Override AppSettings getAppSettings(); @Override CodeGenerationSettings getCodeGenerationSettings(); @SuppressWarnings("unchecked") @Override boolean canConnect(OutputSocket<?> outputSocket, InputSocket<?> inputSocket); @Subscribe void onSourceAdded(SourceAddedEvent event); @Subscribe void onSourceRemoved(SourceRemovedEvent event); void addStepBetween(Step stepToAdd, @Nullable Step lower, @Nullable Step higher); void moveStepBetween(Step toMove, @Nullable Step lower, @Nullable Step higher); void addStep(int index, Step step); void addStep(Step step); void removeStep(Step step); synchronized void moveStep(Step step, int delta); @Override int indexOf(Step step); @Subscribe void onConnectionAdded(ConnectionAddedEvent event); @Subscribe void onConnectionRemoved(ConnectionRemovedEvent event); @Subscribe void onProjectSettingsChanged(ProjectSettingsChangedEvent event); @Subscribe void onAppSettingsChanged(AppSettingsChangedEvent event); @Subscribe void onCodeGenerationSettingsChanged(CodeGenerationSettingsChangedEvent event);  }
@Test @SuppressWarnings("unchecked") public void testAddStep() { Step step = new MockStep(); pipeline.addStep(step); assertEquals("The step was not added to the pipeline", Collections.singletonList(step), pipeline.getSteps()); }
@Test @SuppressWarnings("unchecked") public void testPipeline() { Step step1 = stepFactory.create(new OperationMetaData(AdditionOperation.DESCRIPTION, () -> new AdditionOperation(isf, osf))); Step step2 = stepFactory.create(new OperationMetaData(AdditionOperation.DESCRIPTION, () -> new AdditionOperation(isf, osf))); final InputSocket<Double> a1 = step1.getInputSockets().get(0); final InputSocket<Double> b1 = step1.getInputSockets().get(1); final OutputSocket<Double> sum1 = step1.getOutputSockets().get(0); final InputSocket<Double> a2 = step2.getInputSockets().get(0); final InputSocket<Double> b2 = step2.getInputSockets().get(1); final OutputSocket<Double> sum2 = step2.getOutputSockets().get(0); pipeline.addStep(step1); pipeline.addStep(step2); Connection connection = new Connection(eventBus, pipeline, sum1, a2); eventBus.register(connection); eventBus.post(new ConnectionAddedEvent(connection)); ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); a1.setValue(123.0); b1.setValue(456.0); b2.setValue(789.0); runner.runPipeline(); assertEquals((Double) 1368.0, sum2.getValue().get()); }
@Test @SuppressWarnings("unchecked") public void testPipelineRemoved() { Step step1 = stepFactory.create(new OperationMetaData(AdditionOperation.DESCRIPTION, () -> new AdditionOperation(isf, osf))); Step step2 = stepFactory.create(new OperationMetaData(AdditionOperation.DESCRIPTION, () -> new AdditionOperation(isf, osf))); final InputSocket<Double> a1 = step1.getInputSockets().get(0); final InputSocket<Double> b1 = step1.getInputSockets().get(1); final OutputSocket<Double> sum1 = step1.getOutputSockets().get(0); final InputSocket<Double> a2 = step2.getInputSockets().get(0); final InputSocket<Double> b2 = step2.getInputSockets().get(1); final OutputSocket<Double> sum2 = step2.getOutputSockets().get(0); a2.setValue(0.0); pipeline.addStep(step1); pipeline.addStep(step2); Connection connection = new Connection(eventBus, pipeline, sum1, a2); eventBus.post(new ConnectionAddedEvent(connection)); eventBus.post(new ConnectionRemovedEvent(connection)); ManualPipelineRunner runner = new ManualPipelineRunner(eventBus, pipeline); a1.setValue(123.0); b1.setValue(456.0); b2.setValue(789.0); runner.runPipeline(); assertEquals((Double) 789.0, sum2.getValue().get()); }
@Test public void testCompareSteps() { Step a = MockStep.createMockStepWithOperation(); Step b = MockStep.createMockStepWithOperation(); pipeline.addStep(a); pipeline.addStep(b); assertEquals("a should be 1 behind b", -1, pipeline.compare(a, b)); assertEquals("b should be 1 ahead of a", 1, pipeline.compare(b, a)); }