1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.request;
14
15 import java.awt.event.ActionEvent;
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import javax.swing.AbstractAction;
20 import javax.swing.Action;
21 import javax.swing.JOptionPane;
22
23 import com.eviware.soapui.SoapUI;
24 import com.eviware.soapui.impl.wsdl.WsdlProject;
25 import com.eviware.soapui.impl.wsdl.WsdlRequest;
26 import com.eviware.soapui.impl.wsdl.WsdlTestCase;
27 import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
28 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
29 import com.eviware.soapui.model.testsuite.TestSuite;
30
31 /***
32 * Adds a WsdlRequest to a WsdlTestCase
33 *
34 * @author Ole.Matzura
35 */
36
37 public class AddToTestCaseAction extends AbstractAction
38 {
39 private final WsdlRequest request;
40
41 public AddToTestCaseAction( WsdlRequest request )
42 {
43 super( "Add to Testcase" );
44 this.request = request;
45 putValue( Action.SHORT_DESCRIPTION, "Adds this request to a test-case" );
46 putValue( Action.SMALL_ICON, SoapUI.createImageIcon("/addToTestCase.gif" ));
47 }
48
49 public void actionPerformed(ActionEvent e)
50 {
51 WsdlProject project = (WsdlProject) request.getOperation().getInterface().getProject();
52
53 List<WsdlTestCase> testCases = new ArrayList<WsdlTestCase>();
54 List<String> testCaseNames = new ArrayList<String>();
55 WsdlTestCase testCase = null;
56
57 if( project.getTestSuiteCount() == 0 )
58 {
59 String name = JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(), "Missing Test-suite in project, enter name to create",
60 "Create Test-Suite", JOptionPane.QUESTION_MESSAGE );
61 if( name == null ) return;
62
63 WsdlTestSuite testSuite = project.addNewTestSuite( name );
64 SoapUI.getInstance().selectModelItem( testSuite );
65
66 name = JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(), "Enter name for test-case create",
67 "Create Test-Case", JOptionPane.QUESTION_MESSAGE );
68 if( name == null ) return;
69
70 String stepName = JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(), "Enter name for test step",
71 request.getName(), JOptionPane.QUESTION_MESSAGE );
72 if( stepName == null ) return;
73
74 testCase = testSuite.addNewTestCase( name );
75 WsdlTestRequestStep test = testCase.addTestRequestStep( request, stepName );
76
77 SoapUI.getInstance().selectModelItem( test );
78 SoapUI.getInstance().showTab( test );
79 }
80 else
81 {
82 for( int c = 0; c < project.getTestSuiteCount(); c++ )
83 {
84 TestSuite testSuite = project.getTestSuiteAt( c );
85 for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
86 {
87 testCase = (WsdlTestCase) testSuite.getTestCaseAt( i );
88 testCases.add( testCase );
89 testCaseNames.add( (testCaseNames.size()+1) + ": " + testSuite.getName() + " - " + testCase.getName() );
90 }
91 }
92
93 if( testCases.size() == 0 )
94 {
95 List<String> testSuiteNames = new ArrayList<String>();
96
97 for( int c = 0; c < project.getTestSuiteCount(); c++ )
98 {
99 TestSuite testSuite = project.getTestSuiteAt( c );
100 testSuiteNames.add( (testSuiteNames.size()+1) + ": " + testSuite.getName() );
101 }
102
103 String selection = (String) JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(),
104 "Select test-suite", "Select test-suite to create test-case in",
105 JOptionPane.QUESTION_MESSAGE, null, testSuiteNames.toArray(), null );
106 if( selection == null ) return;
107
108 WsdlTestSuite testSuite = (WsdlTestSuite) project.getTestSuiteAt( testSuiteNames.indexOf( selection ));
109
110 String name = JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(), "Enter name for test-case create",
111 "Create Test-Case", JOptionPane.QUESTION_MESSAGE );
112 if( name == null ) return;
113
114 testCase = testSuite.addNewTestCase( name );
115 }
116 else
117 {
118 String selection = (String) JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(),
119 "Select test-case", "Select test-case", JOptionPane.QUESTION_MESSAGE, null, testCaseNames.toArray(), null );
120 if( selection == null ) return;
121
122 testCase = testCases.get( testCaseNames.indexOf( selection ));
123 }
124
125 String name = JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(), "Specify name of test step",
126 request.getName() );
127 if( name == null ) return;
128
129 WsdlTestRequestStep test = testCase.addTestRequestStep( request, name );
130
131 SoapUI.getInstance().selectModelItem( test );
132 SoapUI.getInstance().showTab( test );
133 }
134 }
135 }