1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface;
14
15 import java.awt.event.ActionEvent;
16
17 import javax.swing.AbstractAction;
18 import javax.swing.Action;
19
20 import com.eviware.soapui.impl.wsdl.WsdlInterface;
21 import com.eviware.soapui.impl.wsdl.WsdlOperation;
22 import com.eviware.soapui.impl.wsdl.WsdlProject;
23 import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
24 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
25 import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory;
26 import com.eviware.soapui.model.support.ModelSupport;
27 import com.eviware.soapui.support.UISupport;
28 import com.eviware.x.form.XFormDialog;
29 import com.eviware.x.form.support.ADialogBuilder;
30 import com.eviware.x.form.support.AField;
31 import com.eviware.x.form.support.AForm;
32 import com.eviware.x.form.support.AField.AFieldType;
33
34 public class GenerateTestSuiteAction extends AbstractAction
35 {
36 private final WsdlInterface iface;
37 private XFormDialog dialog;
38
39 public GenerateTestSuiteAction( WsdlInterface iface )
40 {
41 super( "Generate TestSuite" );
42
43 putValue( Action.SHORT_DESCRIPTION, "Generates TestSuite with TestCase(s) for all Operations in this Interface");
44 this.iface = iface;
45 }
46
47 public void actionPerformed( ActionEvent e )
48 {
49 if( dialog == null )
50 dialog = ADialogBuilder.buildDialog( GenerateForm.class );
51
52 WsdlProject project = ( WsdlProject ) iface.getProject();
53 String[] testSuites = ModelSupport.getNames( new String[] {"<create>"}, project.getTestSuites());
54 dialog.setOptions( GenerateForm.TESTSUITE, testSuites );
55
56 if( dialog.show() )
57 {
58 String testSuiteName = dialog.getValue( GenerateForm.TESTSUITE );
59
60 if( testSuiteName.equals( "<create>" ))
61 testSuiteName = UISupport.prompt( "Enter name of TestSuite to create", "Generate TestSuite", iface.getName() + " TestSuite" );
62
63 if( testSuiteName != null && testSuiteName.trim().length() > 0)
64 {
65 WsdlTestSuite testSuite = ( WsdlTestSuite ) project.getTestSuiteByName( testSuiteName );
66
67 if( testSuite == null )
68 {
69 testSuite = ( WsdlTestSuite ) project.addNewTestSuite( testSuiteName );
70 }
71
72 int style = dialog.getValueIndex( GenerateForm.STYLE );
73 if( style == 0 )
74 generateMulipleTestCases( testSuite );
75 else if( style == 1 )
76 generateSingleTestCase( testSuite );
77 }
78 }
79 }
80
81 private void generateSingleTestCase( WsdlTestSuite testSuite )
82 {
83 WsdlTestCase testCase = testSuite.addNewTestCase( iface.getName() + " TestSuite" );
84
85 for( int i = 0; i < iface.getOperationCount(); i++ )
86 {
87 WsdlOperation operation = ( WsdlOperation ) iface.getOperationAt( i );
88 testCase.addTestStep( WsdlTestRequestStepFactory.createConfig( operation, operation.getName() ) );
89 }
90
91 UISupport.showDesktopPanel( testCase );
92 }
93
94 private void generateMulipleTestCases( WsdlTestSuite testSuite )
95 {
96 for( int i = 0; i < iface.getOperationCount(); i++ )
97 {
98 WsdlOperation operation = ( WsdlOperation ) iface.getOperationAt( i );
99 WsdlTestCase testCase = testSuite.addNewTestCase( operation.getName() + " TestCase" );
100 testCase.addTestStep( WsdlTestRequestStepFactory.createConfig( operation, operation.getName() ) );
101 }
102
103 UISupport.showDesktopPanel( testSuite );
104 }
105
106 @AForm( name="Generate TestSuite", description = "Generates TestSuite with TestCase(s) for all Operations in this Interface")
107 private class GenerateForm
108 {
109 @AField(name = "TestSuite", description = "The TestSuite to create or use", type = AFieldType.ENUMERATION )
110 public final static String TESTSUITE = "TestSuite";
111
112 @AField(name = "Style", description = "Select the style of TestCases to create",
113 type = AFieldType.ENUMERATION, values = { "One TestCase for each Operation", "Single TestCase with one Request for each Operation"} )
114 public final static String STYLE = "Style";
115 }
116 }