001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.panels.teststeps;
014:
015: import java.awt.BorderLayout;
016: import java.awt.Component;
017: import java.text.SimpleDateFormat;
018: import java.util.Date;
019:
020: import javax.swing.JButton;
021: import javax.swing.JComponent;
022: import javax.swing.JPanel;
023: import javax.swing.JSplitPane;
024: import javax.swing.JTabbedPane;
025: import javax.swing.JToolBar;
026:
027: import com.eviware.soapui.SoapUI;
028: import com.eviware.soapui.impl.wsdl.panels.request.AbstractWsdlRequestDesktopPanel;
029: import com.eviware.soapui.impl.wsdl.panels.request.components.SoapMessageXmlEditor;
030: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
031: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext;
032: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
033: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
034: import com.eviware.soapui.impl.wsdl.teststeps.actions.AddAssertionAction;
035: import com.eviware.soapui.impl.wsdl.teststeps.assertions.AssertionError;
036: import com.eviware.soapui.model.ModelItem;
037: import com.eviware.soapui.model.iface.Submit;
038: import com.eviware.soapui.model.iface.SubmitContext;
039: import com.eviware.soapui.model.iface.Request.SubmitException;
040: import com.eviware.soapui.model.testsuite.LoadTestRunner;
041: import com.eviware.soapui.model.testsuite.TestRunner;
042: import com.eviware.soapui.monitor.support.TestMonitorListenerAdapter;
043: import com.eviware.soapui.support.UISupport;
044: import com.eviware.soapui.support.log.JLogList;
045:
046: /**
047: * DesktopPanel for WsdlTestRequest. Essentially a copy of WsdlRequestDesktopPanel with assertions.
048: *
049: * @author Ole.Matzura
050: */
051:
052: public class WsdlTestRequestDesktopPanel
053: extends
054: AbstractWsdlRequestDesktopPanel<WsdlTestRequestStep, WsdlTestRequest> {
055: private JLogList logArea;
056: private InternalTestMonitorListener testMonitorListener = new InternalTestMonitorListener();
057: private JButton addAssertionButton;
058: protected boolean updatingRequest;
059: private WsdlTestRequestDesktopPanel.InternalSubmitListener submitListener;
060: private AssertionsPanel assertionsPanel;
061: private JSplitPane outerSplit;
062:
063: public WsdlTestRequestDesktopPanel(WsdlTestRequestStep requestStep) {
064: super (requestStep);
065:
066: init(requestStep.getTestRequest());
067:
068: SoapUI.getTestMonitor().addTestMonitorListener(
069: testMonitorListener);
070: setEnabled(!SoapUI.getTestMonitor().hasRunningTest(
071: requestStep.getTestCase()));
072: }
073:
074: private Component buildLogPanel() {
075: JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.RIGHT);
076: tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
077:
078: logArea = new JLogList("Request Log");
079:
080: JPanel panel = new JPanel(new BorderLayout());
081: panel.add(logArea, BorderLayout.CENTER);
082:
083: tabbedPane.addTab("Assertions", buildAssertionsPanel());
084: tabbedPane.addTab("Request Log", panel);
085: return UISupport.createTabPanel(tabbedPane, true);
086: }
087:
088: private Component buildAssertionsPanel() {
089: assertionsPanel = new AssertionsPanel(getRequest()) {
090: protected void selectError(AssertionError error) {
091: SoapMessageXmlEditor editor = getResponseEditor();
092: editor.requestFocus();
093: }
094: };
095:
096: return assertionsPanel;
097: }
098:
099: public void setContent(JComponent content) {
100: outerSplit.setTopComponent(content);
101: }
102:
103: public void removeContent(JComponent content) {
104: outerSplit.setTopComponent(null);
105: }
106:
107: protected String getHelpUrl() {
108: return HelpUrls.TESTREQUESTEDITOR_HELP_URL;
109: }
110:
111: protected JComponent buildContent() {
112: JComponent component = super .buildContent();
113:
114: outerSplit = UISupport.createVerticalSplit();
115: outerSplit.setTopComponent(component);
116: outerSplit.setBottomComponent(buildLogPanel());
117: outerSplit.setDividerLocation(350);
118: outerSplit.setResizeWeight(0.9);
119: outerSplit.setBorder(null);
120:
121: return outerSplit;
122: }
123:
124: protected SoapMessageXmlEditor buildRequestEditor() {
125: SoapMessageXmlEditor editor = super .buildRequestEditor();
126: return editor;
127: }
128:
129: protected SoapMessageXmlEditor buildResponseEditor() {
130: SoapMessageXmlEditor editor = super .buildResponseEditor();
131: return editor;
132: }
133:
134: protected JComponent buildToolbar() {
135: addAssertionButton = createActionButton(new AddAssertionAction(
136: getRequest()), true);
137: return super .buildToolbar();
138: }
139:
140: protected void insertButtons(JToolBar toolbar) {
141: toolbar.add(addAssertionButton);
142: }
143:
144: public void setEnabled(boolean enabled) {
145: if (enabled == true)
146: enabled = !SoapUI.getTestMonitor().hasRunningLoadTest(
147: getModelItem().getTestCase());
148:
149: super .setEnabled(enabled);
150: addAssertionButton.setEnabled(enabled);
151: assertionsPanel.setEnabled(enabled);
152:
153: if (SoapUI.getTestMonitor().hasRunningLoadTest(
154: getRequest().getTestCase())) {
155: getRequest().removeSubmitListener(submitListener);
156: } else {
157: getRequest().addSubmitListener(submitListener);
158: }
159: }
160:
161: protected Submit doSubmit() throws SubmitException {
162: return getRequest().submit(
163: new WsdlTestRunContext(getModelItem()), true);
164: }
165:
166: protected InternalSubmitListener createSubmitListener() {
167: submitListener = new InternalSubmitListener();
168: return submitListener;
169: }
170:
171: private class InternalSubmitListener extends
172: AbstractWsdlRequestDesktopPanel.InternalSubmitListener {
173: private long startTime;
174: private SimpleDateFormat sdf;
175:
176: private InternalSubmitListener() {
177: super ();
178: sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
179: }
180:
181: public boolean beforeSubmit(Submit submit, SubmitContext context) {
182: boolean result = super .beforeSubmit(submit, context);
183: startTime = System.currentTimeMillis();
184: return result;
185: }
186:
187: protected void logMessages(String message, String infoMessage) {
188: super .logMessages(message, infoMessage);
189: logArea.addLine(sdf.format(new Date(startTime)) + " - "
190: + message);
191: }
192: }
193:
194: public boolean onClose(boolean canCancel) {
195: if (super .onClose(canCancel)) {
196: assertionsPanel.release();
197: SoapUI.getTestMonitor().removeTestMonitorListener(
198: testMonitorListener);
199: logArea.release();
200: return true;
201: }
202:
203: return false;
204: }
205:
206: public boolean dependsOn(ModelItem modelItem) {
207: return modelItem == getRequest()
208: || modelItem == getModelItem()
209: || modelItem == getRequest().getOperation()
210: || modelItem == getRequest().getOperation()
211: .getInterface()
212: || modelItem == getRequest().getOperation()
213: .getInterface().getProject()
214: || modelItem == getModelItem().getTestCase()
215: || modelItem == getModelItem().getTestCase()
216: .getTestSuite();
217: }
218:
219: private class InternalTestMonitorListener extends
220: TestMonitorListenerAdapter {
221: public void loadTestFinished(LoadTestRunner runner) {
222: setEnabled(!SoapUI.getTestMonitor().hasRunningTest(
223: getModelItem().getTestCase()));
224: }
225:
226: public void loadTestStarted(LoadTestRunner runner) {
227: if (runner.getLoadTest().getTestCase() == getModelItem()
228: .getTestCase())
229: setEnabled(false);
230: }
231:
232: public void testCaseFinished(TestRunner runner) {
233: setEnabled(!SoapUI.getTestMonitor().hasRunningTest(
234: getModelItem().getTestCase()));
235: }
236:
237: public void testCaseStarted(TestRunner runner) {
238: if (runner.getTestCase() == getModelItem().getTestCase())
239: setEnabled(false);
240: }
241: }
242:
243: @Override
244: public String getDescription() {
245: return "TestRequest: [" + getModelItem().getName() + "] - "
246: + getModelItem().getTestStepTitle();
247: }
248:
249: public String getTitle() {
250: return getModelItem().getTestCase().getName()
251: + " - "
252: + getModelItem().getName()
253: + " ("
254: + getModelItem().getTestRequest().getOperation()
255: .getName() + ")";
256: }
257: }
|