AbstractCloneable implements WorkflowBean { @Override public AbstractCloneable clone() { return cloneWorkflowBean(this); }  @Override AbstractCloneable clone(); static T cloneWorkflowBean(T obj); Scufl2Tools getTools(); URITools getUriTools();  }
@Test public void cloneBundle() throws Exception { AbstractCloneable clone = originalWfBundle.clone(); List<WorkflowBean> stillOriginalBeans = AllBeansVisitor .allBeansFrom(originalWfBundle); System.out.println(stillOriginalBeans); assertEquals(originalBeans.size(), stillOriginalBeans.size()); assertEquals(originalBeans.size(), findCommonById(originalBeans, stillOriginalBeans).size()); List<WorkflowBean> clonedBeans = AllBeansVisitor.allBeansFrom(clone); List<WorkflowBean> common = findCommonById(originalBeans, clonedBeans); assertTrue("Found some common beans: " + common, common.isEmpty()); checkParents(originalBeans); checkParents(stillOriginalBeans); checkParents(clonedBeans); }
@Test public void cloneWorkflow() throws Exception { Workflow original = originalWfBundle.getMainWorkflow(); assertEquals(originalWfBundle, original.getParent()); Workflow clone = (Workflow) original.clone(); assertNull(clone.getParent()); assertEquals(original.getName(), clone.getName()); assertNotSame(original.getProcessors().getByName("Hello"), clone .getProcessors().getByName("Hello")); assertNotSame(original.getCurrentRevision(), clone.getCurrentRevision()); assertEquals(original.getCurrentRevision(), clone.getCurrentRevision()); }
@Test public void cloneProfile() throws Exception { Profile original = originalWfBundle.getMainProfile(); assertEquals(originalWfBundle, original.getParent()); Profile clone = (Profile) original.clone(); assertNull(clone.getParent()); assertEquals(original.getName(), clone.getName()); ProcessorBinding originalBinding = original.getProcessorBindings() .getByName("Hello"); ProcessorBinding cloneBinding = clone.getProcessorBindings().getByName( "Hello"); assertNotSame(originalBinding, cloneBinding); assertNotSame(originalBinding.getBoundActivity(), cloneBinding.getBoundActivity()); assertSame(originalBinding.getBoundProcessor(), cloneBinding.getBoundProcessor()); }
@Test public void cloneProcessor() throws Exception { Workflow wf = originalWfBundle.getMainWorkflow(); Processor original = wf.getProcessors().getByName("Hello"); Processor clone = (Processor) original.clone(); assertEquals(clone.getName(), original.getName()); assertNotNull(original.getParent()); assertNull(clone.getParent()); wf.getProcessors().addWithUniqueName(clone); assertTrue(!clone.getName().equals(original.getName())); clone.setParent(wf); assertSame(original, wf.getProcessors().getByName("Hello")); assertSame(clone, wf.getProcessors().getByName(clone.getName())); }
@Test public void nullParentNotCopied() throws Exception { Workflow wf = new Workflow(); Processor orphan = new Processor(); orphan.setName("orphan"); wf.getProcessors().add(orphan); assertNull(orphan.getParent()); Workflow clone = (Workflow) wf.clone(); assertTrue(clone.getProcessors().isEmpty()); orphan.setParent(wf); Workflow clone2 = (Workflow) wf.clone(); assertEquals(Collections.singleton("orphan"), clone2.getProcessors() .getNames()); }