1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.panels.testcase;
13
14 import java.text.SimpleDateFormat;
15 import java.util.Date;
16
17 import com.eviware.soapui.SoapUI;
18 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner;
19 import com.eviware.soapui.model.support.TestRunListenerAdapter;
20 import com.eviware.soapui.model.testsuite.TestCaseRunContext;
21 import com.eviware.soapui.model.testsuite.TestCaseRunner;
22 import com.eviware.soapui.model.testsuite.TestStepResult;
23
24 public class TestRunLogTestRunListener extends TestRunListenerAdapter
25 {
26 protected SimpleDateFormat dateFormat;
27 protected final JTestRunLog runLog;
28 protected final boolean clearOnRun;
29
30 public TestRunLogTestRunListener( JTestRunLog runLog, boolean clearOnRun )
31 {
32 this.runLog = runLog;
33 this.clearOnRun = clearOnRun;
34 dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.SSS" );
35 }
36
37 public void beforeRun( TestCaseRunner testRunner, TestCaseRunContext runContext )
38 {
39 if( SoapUI.getTestMonitor().hasRunningLoadTest( testRunner.getTestCase() ) )
40 return;
41
42 if( clearOnRun )
43 runLog.clear();
44
45 String testCaseName = testRunner.getTestCase().getName();
46 runLog.addBoldText( "TestCase [" + testCaseName + "] started at " + dateFormat.format( new Date() ) );
47 runLog.setStepIndex( 0 );
48 }
49
50 public void afterRun( TestCaseRunner testRunner, TestCaseRunContext runContext )
51 {
52 if( SoapUI.getTestMonitor().hasRunningLoadTest( testRunner.getTestCase() ) )
53 return;
54
55 WsdlTestCaseRunner wsdlRunner = ( WsdlTestCaseRunner )testRunner;
56
57 String testCaseName = testRunner.getTestCase().getName();
58 if( testRunner.getStatus() == TestCaseRunner.Status.CANCELED )
59 runLog.addText( "TestCase [" + testCaseName + "] canceled [" + testRunner.getReason() + "], time taken = "
60 + wsdlRunner.getTimeTaken() );
61 else if( testRunner.getStatus() == TestCaseRunner.Status.FAILED )
62 {
63 String msg = wsdlRunner.getReason();
64 if( wsdlRunner.getError() != null )
65 {
66 if( msg != null )
67 msg += ":";
68
69 msg += wsdlRunner.getError();
70 }
71
72 runLog.addText( "TestCase [" + testCaseName + "] failed [" + msg + "], time taken = "
73 + wsdlRunner.getTimeTaken() );
74 }
75 else
76 runLog.addText( "TestCase [" + testCaseName + "] finished with status [" + testRunner.getStatus()
77 + "], time taken = " + wsdlRunner.getTimeTaken() );
78 }
79
80 public void afterStep( TestCaseRunner testRunner, TestCaseRunContext runContext, TestStepResult stepResult )
81 {
82 if( SoapUI.getTestMonitor().hasRunningLoadTest( testRunner.getTestCase() ) )
83 return;
84
85 runLog.addTestStepResult( stepResult );
86 }
87 }