MergeProcesses { public static BPMNDiagram mergeProcesses(Collection<BPMNDiagram> models, boolean removeEnt, String algorithm, double threshold, double... param) { if (models.isEmpty()) { return BPMNDiagramFactory.newBPMNDiagram("Empty diagram"); } else if (models.size() == 1) { return BPMNDiagramFactory.cloneBPMNDiagram(models.iterator().next()); } Iterator<BPMNDiagram> diagramIterator = models.iterator(); IdGeneratorHelper idGenerator = new IdGeneratorHelper(); BPMNDiagram d1 = diagramIterator.next(); Graph m1 = ModelParser.readModel(d1); if(m1.getGraphLabel() == null) m1.name = d1.getLabel(); m1.setIdGenerator(idGenerator); m1.removeEmptyNodes(); m1.reorganizeIDs(); BPMNDiagram d2 = diagramIterator.next(); Graph m2 = ModelParser.readModel(d2); if(m2.getGraphLabel() == null) m2.name = d2.getLabel(); m2.setIdGenerator(idGenerator); m2.removeEmptyNodes(); m2.reorganizeIDs(); m1.addLabelsToUnNamedEdges(); m2.addLabelsToUnNamedEdges(); Graph merged = MergeModels.mergeModels(m1, m2, idGenerator, removeEnt, algorithm, param); while (diagramIterator.hasNext()) { BPMNDiagram d3 = diagramIterator.next(); Graph m3 = ModelParser.readModel(d3); if(m3.getGraphLabel() == null) m3.name = d3.getLabel(); m3.setIdGenerator(idGenerator); m3.removeEmptyNodes(); m3.reorganizeIDs(); m3.addLabelsToUnNamedEdges(); merged = MergeModels.mergeModels(merged, m3, idGenerator, removeEnt, algorithm, param); } return ModelParser.writeModel(merged, idGenerator); }  static BPMNDiagram mergeProcesses(Collection<BPMNDiagram> models, boolean removeEnt, String algorithm,
            double threshold, double... param);  }
@Test public void testMergeProcesses_two_simple_models() { try { List<BPMNDiagram> diagrams = Arrays.asList(new BPMNDiagram[] {read_one_task_A(), read_one_task_B()}); BPMNDiagram merge = MergeProcesses.mergeProcesses(diagrams, false, "Greedy", 0.6, 0.6, 0.75, 1.0, 1.0, 1.0); Assert.assertEquals(6, merge.getNodes().size()); Assert.assertEquals(6, merge.getEdges().size()); BPMNDiagramSupport bpmnSupport = new BPMNDiagramSupport(merge); BPMNNode node = bpmnSupport.getStartEvent(); node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isXORSplitGateway(node)); Collection<BPMNNode> nodes = bpmnSupport.getTargets(node); node = nodes.iterator().next(); Assert.assertEquals(true, node.getLabel().equals("A") || node.getLabel().equals("B")); node = nodes.iterator().next(); Assert.assertEquals(true, node.getLabel().equals("A") || node.getLabel().equals("B")); node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isXORJoinGateway(node)); node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isEndEvent(node)); } catch (Exception e) { fail("Exception occurred: " + e.getMessage()); } }
@Test public void testMergeProcesses_three_simple_models() { try { List<BPMNDiagram> diagrams = Arrays.asList(new BPMNDiagram[] {read_one_task_A(), read_one_task_B(), read_one_task_C()}); BPMNDiagram merge = MergeProcesses.mergeProcesses(diagrams, false, "Greedy", 0.6, 0.6, 0.75, 1.0, 1.0, 1.0); Assert.assertEquals(7, merge.getNodes().size()); Assert.assertEquals(8, merge.getEdges().size()); BPMNDiagramSupport bpmnSupport = new BPMNDiagramSupport(merge); BPMNNode node = bpmnSupport.getStartEvent(); node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isXORSplitGateway(node)); Collection<BPMNNode> nodes = bpmnSupport.getTargets(node); node = nodes.iterator().next(); Assert.assertEquals(true, node.getLabel().equals("A") || node.getLabel().equals("B") || node.getLabel().equals("C")); node = nodes.iterator().next(); Assert.assertEquals(true, node.getLabel().equals("A") || node.getLabel().equals("B") || node.getLabel().equals("C")); node = nodes.iterator().next(); Assert.assertEquals(true, node.getLabel().equals("A") || node.getLabel().equals("B") || node.getLabel().equals("C")); node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isXORJoinGateway(node)); node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isEndEvent(node)); } catch (Exception e) { fail("Exception occurred: " + e.getMessage()); } }
@Test public void testMergeProcesses_merge_in_middle() { try { List<BPMNDiagram> diagrams = Arrays.asList(new BPMNDiagram[] {read_one_task_B(), read_two_tasks_sequence_AB()}); BPMNDiagram merge = MergeProcesses.mergeProcesses(diagrams, false, "Greedy", 0.6, 0.6, 0.75, 1.0, 1.0, 1.0); Assert.assertEquals(6, merge.getNodes().size()); Assert.assertEquals(6, merge.getEdges().size()); BPMNDiagramSupport bpmnSupport = new BPMNDiagramSupport(merge); BPMNNode node = bpmnSupport.getStartEvent(); node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isXORSplitGateway(node)); Collection<BPMNNode> nodes = bpmnSupport.getTargets(node); node = nodes.iterator().next(); Assert.assertEquals(true, node.getLabel().equals("A") || bpmnSupport.isXORJoinGateway(node)); node = nodes.iterator().next(); Assert.assertEquals(true, node.getLabel().equals("A") || bpmnSupport.isXORJoinGateway(node)); if (node.getLabel().equals("A")) { node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isXORJoinGateway(node)); } node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, node.getLabel().equals("B")); node = bpmnSupport.getTargets(node).iterator().next(); Assert.assertEquals(true, bpmnSupport.isEndEvent(node)); } catch (Exception e) { fail("Exception occurred: " + e.getMessage()); } }