1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.teststeps;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.impl.support.components.ModelItemXmlEditor;
17 import com.eviware.soapui.impl.wsdl.panels.request.AbstractWsdlRequestDesktopPanel;
18 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
19 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext;
20 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
21 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
22 import com.eviware.soapui.impl.wsdl.teststeps.actions.AddAssertionAction;
23 import com.eviware.soapui.model.ModelItem;
24 import com.eviware.soapui.model.iface.Request.SubmitException;
25 import com.eviware.soapui.model.iface.Submit;
26 import com.eviware.soapui.model.iface.SubmitContext;
27 import com.eviware.soapui.model.testsuite.Assertable.AssertionStatus;
28 import com.eviware.soapui.model.testsuite.AssertionError;
29 import com.eviware.soapui.model.testsuite.*;
30 import com.eviware.soapui.monitor.support.TestMonitorListenerAdapter;
31 import com.eviware.soapui.support.ListDataChangeListener;
32 import com.eviware.soapui.support.UISupport;
33 import com.eviware.soapui.support.components.JComponentInspector;
34 import com.eviware.soapui.support.components.JInspectorPanel;
35 import com.eviware.soapui.support.components.JInspectorPanelFactory;
36 import com.eviware.soapui.support.components.JXToolBar;
37 import com.eviware.soapui.support.log.JLogList;
38
39 import javax.swing.*;
40 import java.beans.PropertyChangeEvent;
41 import java.text.SimpleDateFormat;
42 import java.util.Date;
43
44 /***
45 * DesktopPanel for WsdlTestRequest. Essentially a copy of
46 * WsdlRequestDesktopPanel with assertions.
47 *
48 * @author Ole.Matzura
49 */
50
51 public class WsdlTestRequestDesktopPanel extends AbstractWsdlRequestDesktopPanel<WsdlTestRequestStep, WsdlTestRequest>
52 {
53 private JLogList logArea;
54 private InternalTestMonitorListener testMonitorListener = new InternalTestMonitorListener();
55 private JButton addAssertionButton;
56 protected boolean updatingRequest;
57 private AssertionsPanel assertionsPanel;
58 private JInspectorPanel inspectorPanel;
59 private JComponentInspector<?> assertionInspector;
60 private JComponentInspector<?> logInspector;
61 private InternalAssertionsListener assertionsListener = new InternalAssertionsListener();
62 private long startTime;
63 private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
64
65 public WsdlTestRequestDesktopPanel(WsdlTestRequestStep requestStep)
66 {
67 super(requestStep, requestStep.getTestRequest());
68
69 SoapUI.getTestMonitor().addTestMonitorListener(testMonitorListener);
70 setEnabled(!SoapUI.getTestMonitor().hasRunningTest(requestStep.getTestCase()));
71
72 requestStep.getTestRequest().addAssertionsListener(assertionsListener);
73 }
74
75 protected JComponent buildLogPanel()
76 {
77 logArea = new JLogList("Request Log");
78
79 logArea.getLogList().getModel().addListDataListener(new ListDataChangeListener()
80 {
81
82 public void dataChanged(ListModel model)
83 {
84 logInspector.setTitle("Request Log (" + model.getSize() + ")");
85 }
86 });
87
88 return logArea;
89 }
90
91 protected AssertionsPanel buildAssertionsPanel()
92 {
93 return new AssertionsPanel(getRequest())
94 {
95 protected void selectError(AssertionError error)
96 {
97 ModelItemXmlEditor<?, ?> editor = (ModelItemXmlEditor<?, ?>) getResponseEditor();
98 editor.requestFocus();
99 }
100 };
101 }
102
103 public void setContent(JComponent content)
104 {
105 inspectorPanel.setContentComponent(content);
106 }
107
108 public void removeContent(JComponent content)
109 {
110 inspectorPanel.setContentComponent(null);
111 }
112
113 protected String getHelpUrl()
114 {
115 return HelpUrls.TESTREQUESTEDITOR_HELP_URL;
116 }
117
118 protected JComponent buildContent()
119 {
120 JComponent component = super.buildContent();
121
122 inspectorPanel = JInspectorPanelFactory.build(component);
123 assertionsPanel = buildAssertionsPanel();
124
125 assertionInspector = new JComponentInspector<JComponent>(assertionsPanel, "Assertions ("
126 + getModelItem().getAssertionCount() + ")", "Assertions for this Test Request", true);
127
128 inspectorPanel.addInspector(assertionInspector);
129
130 logInspector = new JComponentInspector<JComponent>(buildLogPanel(), "Request Log (0)", "Log of requests", true);
131 inspectorPanel.addInspector(logInspector);
132 inspectorPanel.setDefaultDividerLocation(0.6F);
133 inspectorPanel.setCurrentInspector("Assertions");
134
135 updateStatusIcon();
136
137 return inspectorPanel.getComponent();
138 }
139
140 private void updateStatusIcon()
141 {
142 AssertionStatus status = getModelItem().getTestRequest().getAssertionStatus();
143 switch (status)
144 {
145 case FAILED:
146 {
147 assertionInspector.setIcon(UISupport.createImageIcon("/failed_assertion.gif"));
148 inspectorPanel.activate(assertionInspector);
149 break;
150 }
151 case UNKNOWN:
152 {
153 assertionInspector.setIcon(UISupport.createImageIcon("/unknown_assertion.gif"));
154 break;
155 }
156 case VALID:
157 {
158 assertionInspector.setIcon(UISupport.createImageIcon("/valid_assertion.gif"));
159 inspectorPanel.deactivate();
160 break;
161 }
162 }
163 }
164
165 protected JComponent buildToolbar()
166 {
167 addAssertionButton = createActionButton(new AddAssertionAction(getRequest()), true);
168 return super.buildToolbar();
169 }
170
171 protected void insertButtons(JXToolBar toolbar)
172 {
173 toolbar.add(addAssertionButton);
174 super.insertButtons(toolbar);
175 }
176
177 public void setEnabled(boolean enabled)
178 {
179 if (enabled == true)
180 enabled = !SoapUI.getTestMonitor().hasRunningLoadTest(getModelItem().getTestCase());
181
182 super.setEnabled(enabled);
183 addAssertionButton.setEnabled(enabled);
184 assertionsPanel.setEnabled(enabled);
185
186 if (SoapUI.getTestMonitor().hasRunningLoadTest(getRequest().getTestCase()))
187 {
188 getRequest().removeSubmitListener(this);
189 }
190 else
191 {
192 getRequest().addSubmitListener(this);
193 }
194 }
195
196 protected Submit doSubmit() throws SubmitException
197 {
198 return getRequest().submit(new WsdlTestRunContext(getModelItem()), true);
199 }
200
201 private final class InternalAssertionsListener implements AssertionsListener
202 {
203 public void assertionAdded(TestAssertion assertion)
204 {
205 assertionInspector.setTitle("Assertions (" + getModelItem().getAssertionCount() + ")");
206 }
207
208 public void assertionRemoved(TestAssertion assertion)
209 {
210 assertionInspector.setTitle("Assertions (" + getModelItem().getAssertionCount() + ")");
211 }
212 }
213
214 public boolean beforeSubmit(Submit submit, SubmitContext context)
215 {
216 boolean result = super.beforeSubmit(submit, context);
217 startTime = System.currentTimeMillis();
218 return result;
219 }
220
221 protected void logMessages(String message, String infoMessage)
222 {
223 super.logMessages(message, infoMessage);
224 logArea.addLine(sdf.format(new Date(startTime)) + " - " + message);
225 }
226
227 @Override
228 public void afterSubmit(Submit submit, SubmitContext context)
229 {
230 super.afterSubmit(submit, context);
231 if( !isHasClosed() )
232 updateStatusIcon();
233 }
234
235 public boolean onClose(boolean canCancel)
236 {
237 if (super.onClose(canCancel))
238 {
239 assertionsPanel.release();
240 SoapUI.getTestMonitor().removeTestMonitorListener(testMonitorListener);
241 logArea.release();
242 getModelItem().getTestRequest().removeAssertionsListener(assertionsListener);
243 return true;
244 }
245
246 return false;
247 }
248
249 public boolean dependsOn(ModelItem modelItem)
250 {
251 return modelItem == getRequest() || modelItem == getModelItem() || modelItem == getRequest().getOperation()
252 || modelItem == getRequest().getOperation().getInterface()
253 || modelItem == getRequest().getOperation().getInterface().getProject()
254 || modelItem == getModelItem().getTestCase() || modelItem == getModelItem().getTestCase().getTestSuite();
255 }
256
257 private class InternalTestMonitorListener extends TestMonitorListenerAdapter
258 {
259 public void loadTestFinished(LoadTestRunner runner)
260 {
261 setEnabled(!SoapUI.getTestMonitor().hasRunningTest(getModelItem().getTestCase()));
262 }
263
264 public void loadTestStarted(LoadTestRunner runner)
265 {
266 if (runner.getLoadTest().getTestCase() == getModelItem().getTestCase())
267 setEnabled(false);
268 }
269
270 public void testCaseFinished(TestRunner runner)
271 {
272 setEnabled(!SoapUI.getTestMonitor().hasRunningTest(getModelItem().getTestCase()));
273 }
274
275 public void testCaseStarted(TestRunner runner)
276 {
277 if (runner.getTestCase() == getModelItem().getTestCase())
278 setEnabled(false);
279 }
280 }
281
282 public void propertyChange(PropertyChangeEvent evt)
283 {
284 super.propertyChange(evt);
285
286 if (evt.getPropertyName().equals(WsdlTestRequest.STATUS_PROPERTY))
287 updateStatusIcon();
288 }
289 }