{
String targetProjectName = dialog.getValue( Form.PROJECT );
String targetTestSuiteName = dialog.getValue( Form.TESTSUITE );
String name = dialog.getValue( Form.NAME );
WsdlProject project = testCase.getTestSuite().getProject();
WsdlTestSuite targetTestSuite = null;
Set<Interface> requiredInterfaces = new HashSet<Interface>();
// to another project project?
if( !targetProjectName.equals( project.getName() ) )
{
// get required interfaces
for( int y = 0; y < testCase.getTestStepCount(); y++ )
{
WsdlTestStep testStep = testCase.getTestStepAt( y );
requiredInterfaces.addAll( testStep.getRequiredInterfaces() );
}
project = ( WsdlProject )workspace.getProjectByName( targetProjectName );
if( project == null )
{
targetProjectName = UISupport.prompt( "Enter name for new Project", "Clone TestCase", "" );
if( targetProjectName == null )
return;
try
{
project = workspace.createProject( targetProjectName, null );
}
catch( SoapUIException e )
{
UISupport.showErrorMessage( e );
}
if( project == null )
return;
}
if( requiredInterfaces.size() > 0 && project.getInterfaceCount() > 0 )
{
Map<String, Interface> bindings = new HashMap<String, Interface>();
for( Interface iface : requiredInterfaces )
{
bindings.put( iface.getTechnicalId(), iface );
}
for( Interface iface : project.getInterfaceList() )
{
bindings.remove( iface.getTechnicalId() );
}
requiredInterfaces.retainAll( bindings.values() );
}
if( requiredInterfaces.size() > 0 )
{
String msg = "Target project [" + targetProjectName + "] is missing required Interfaces;\r\n\r\n";
for( Interface iface : requiredInterfaces )
{
msg += iface.getName() + " [" + iface.getTechnicalId() + "]\r\n";
}
msg += "\r\nShould these will be cloned to the targetProject as well?";
Boolean result = UISupport.confirmOrCancel( msg, "Clone TestCase" );
if( result == null )
return;
if( result )
{
for( Interface iface : requiredInterfaces )
{
project.importInterface( ( AbstractInterface<?> )iface, true, true );
}
}
}
}
targetTestSuite = project.getTestSuiteByName( targetTestSuiteName );
if( targetTestSuite == null )
{
targetTestSuiteName = UISupport.prompt( "Specify name for new TestSuite", "Clone TestCase", "Copy of "
+ testCase.getTestSuite().getName() );
if( targetTestSuiteName == null )
return;
targetTestSuite = project.addNewTestSuite( targetTestSuiteName );
}
boolean move = dialog.getBooleanValue( Form.MOVE );
WsdlTestCase newTestCase = targetTestSuite.importTestCase( testCase, name, -1,
dialog.getBooleanValue( Form.CLONE_LOADTESTS ), dialog.getBooleanValue( Form.CLONE_SECURITYTESTS ),