/** * @return a new instance of ConnectMergedDatalinkEdit constructed from the * provided parameters. * * @param merge * a Merge instance * @param sourcePort * the source port from which a link is to be created. * @param sinkPort * the sink port to which the link is to be created. */ public Edit<Merge> getConnectMergedDatalinkEdit(Merge merge, EventForwardingOutputPort sourcePort, EventHandlingInputPort sinkPort) { return new ConnectMergedDatalinkEdit(merge, sourcePort, sinkPort); }
/** * @return a new instance of ConnectMergedDatalinkEdit constructed from the * provided parameters. * * @param merge * a Merge instance * @param sourcePort * the source port from which a link is to be created. * @param sinkPort * the sink port to which the link is to be created. */ public Edit<Merge> getConnectMergedDatalinkEdit(Merge merge, EventForwardingOutputPort sourcePort, EventHandlingInputPort sinkPort) { return new ConnectMergedDatalinkEdit(merge, sourcePort, sinkPort); }
/** * @return a new instance of ConnectMergedDatalinkEdit constructed from the * provided parameters. * * @param merge * a Merge instance * @param sourcePort * the source port from which a link is to be created. * @param sinkPort * the sink port to which the link is to be created. */ public Edit<Merge> getConnectMergedDatalinkEdit(Merge merge, EventForwardingOutputPort sourcePort, EventHandlingInputPort sinkPort) { return new ConnectMergedDatalinkEdit(merge, sourcePort, sinkPort); }
@Test(expected=RuntimeException.class) public void nullMerge() throws Exception { new ConnectMergedDatalinkEdit(null,sourcePort,sinkPort); }
@Test(expected=RuntimeException.class) public void nullSourcePort() throws Exception { Merge merge = new MergeImpl("merge"); new ConnectMergedDatalinkEdit(merge,sourcePort,null); }
@Test(expected=RuntimeException.class) public void nullSinkPort() throws Exception { Merge merge = new MergeImpl("merge"); new ConnectMergedDatalinkEdit(merge,null,sinkPort); }
@Test(expected=EditException.class) public void invalidSinkPort() throws Exception { Edit<Merge> theEdit = new ConnectMergedDatalinkEdit(merge,sourcePort,sinkPort); theEdit.doEdit(); ProcessorImpl p2=new ProcessorImpl(); ProcessorInputPortImpl sinkPort2=new ProcessorInputPortImpl(p2,"sink_port2",0); theEdit = new ConnectMergedDatalinkEdit(merge,sourcePort,sinkPort2); theEdit.doEdit(); } }
/** * Check that the outgoing link to the sink port is retained when undoing a second merged input. */ @Test public void undoSecond() throws Exception { Edit<Merge> theEdit = new ConnectMergedDatalinkEdit(merge,sourcePort,sinkPort); theEdit.doEdit(); ProcessorImpl p3=new ProcessorImpl(); ProcessorOutputPortImpl sourcePort2=new ProcessorOutputPortImpl(p3,"source_port2",0,0); Edit<Merge> theEdit2 = new ConnectMergedDatalinkEdit(merge,sourcePort2,sinkPort); theEdit2.doEdit(); theEdit2.undo(); assertEquals(1,merge.getInputPorts().size()); assertEquals(1,merge.getOutputPort().getOutgoingLinks().size()); }
@Test public void undo() throws Exception { Edit<Merge> theEdit = new ConnectMergedDatalinkEdit(merge,sourcePort,sinkPort); theEdit.doEdit(); theEdit.undo(); assertEquals(0,merge.getInputPorts().size()); assertEquals(0,merge.getOutputPort().getOutgoingLinks().size()); assertEquals(0,sourcePort.getOutgoingLinks().size()); assertNull(sinkPort.getIncomingLink()); }
@Test public void redo() throws Exception { Edit<Merge> theEdit = new ConnectMergedDatalinkEdit(merge,sourcePort,sinkPort); theEdit.doEdit(); theEdit.undo(); theEdit.doEdit(); assertEquals(1,merge.getInputPorts().size()); assertTrue(merge.getInputPorts().get(0) instanceof MergeInputPort); assertSame(sourcePort,merge.getInputPorts().get(0).getIncomingLink().getSource()); assertEquals(1,merge.getOutputPort().getOutgoingLinks().size()); assertSame(sinkPort,merge.getOutputPort().getOutgoingLinks().toArray(new Datalink[]{})[0].getSink()); assertEquals(1,sourcePort.getOutgoingLinks().size()); assertTrue(sourcePort.getOutgoingLinks().toArray(new Datalink[]{})[0].getSink() instanceof MergeInputPort); assertTrue(sinkPort.getIncomingLink().getSource() instanceof MergeOutputPort); assertSame(merge.getInputPorts().get(0),sourcePort.getOutgoingLinks().toArray(new Datalink[]{})[0].getSink()); assertSame(sinkPort.getIncomingLink().getSource(),merge.getOutputPort()); }
@Test public void applyEdit() throws Exception { Edit<Merge> theEdit = new ConnectMergedDatalinkEdit(merge,sourcePort,sinkPort); assertEquals(0,merge.getInputPorts().size()); assertNotNull(merge.getOutputPort()); ProcessorOutputPortImpl sourcePort2=new ProcessorOutputPortImpl(p3,"source_port2",0,0); Edit<Merge> theEdit2 = new ConnectMergedDatalinkEdit(merge,sourcePort2,sinkPort); theEdit2.doEdit(); assertEquals(1,merge.getOutputPort().getOutgoingLinks().size());