1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.panels.teststeps.amf;
13
14 import com.eviware.soapui.SoapUI;
15 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
16 import com.eviware.soapui.impl.wsdl.teststeps.AMFRequestTestStep;
17 import com.eviware.soapui.model.testsuite.TestCaseRunContext;
18 import com.eviware.soapui.model.testsuite.TestCaseRunner;
19 import com.eviware.soapui.model.testsuite.TestRunListener;
20 import com.eviware.soapui.model.testsuite.TestStep;
21 import com.eviware.soapui.model.testsuite.TestStepResult;
22 import com.eviware.soapui.support.StringUtils;
23
24 import flex.messaging.io.amf.client.exceptions.ClientStatusException;
25 import flex.messaging.io.amf.client.exceptions.ServerStatusException;
26
27 public class AMFTestRunListener implements TestRunListener
28 {
29 private AMFCredentials amfCredentials;
30
31 public void afterRun( TestCaseRunner testRunner, TestCaseRunContext runContext )
32 {
33 if( amfCredentials != null && runContext.getProperty( AMFSubmit.AMF_CONNECTION ) != null
34 && runContext.getProperty( AMFSubmit.AMF_CONNECTION ) instanceof SoapUIAMFConnection )
35 {
36 if( amfCredentials.isLoggedIn() )
37 amfCredentials.logout();
38 }
39 }
40
41 public void beforeRun( TestCaseRunner testRunner, TestCaseRunContext runContext )
42 {
43 if( testRunner.getTestCase() instanceof WsdlTestCase )
44 {
45 try
46 {
47 WsdlTestCase wsdlTestCase = ( WsdlTestCase )testRunner.getTestCase();
48
49 if( wsdlTestCase.getConfig().getAmfAuthorisation() )
50 {
51 if( noAMFTestSteps( wsdlTestCase ) )
52 return;
53
54 String endpoint = runContext.expand( wsdlTestCase.getConfig().getAmfEndpoint() );
55 String username = runContext.expand( wsdlTestCase.getConfig().getAmfLogin() );
56 String password = runContext.expand( wsdlTestCase.getConfig().getAmfPassword() );
57
58 SoapUIAMFConnection amfConnection = null;
59
60 if( StringUtils.hasContent( endpoint ) )
61 {
62 if( StringUtils.hasContent( username ) )
63 {
64 amfCredentials = new AMFCredentials( endpoint, username, password, runContext );
65 amfConnection = amfCredentials.login();
66 }
67 else
68 {
69 amfConnection = new SoapUIAMFConnection();
70 amfConnection.connect( runContext.expand( endpoint ) );
71 }
72
73 runContext.setProperty( AMFSubmit.AMF_CONNECTION, amfConnection );
74 }
75 }
76 }
77 catch( ClientStatusException e )
78 {
79 SoapUI.logError( e );
80 }
81 catch( ServerStatusException e )
82 {
83 SoapUI.logError( e );
84 }
85 }
86 }
87
88 /***
89 * check if there is no amf test steps in test case then disable amf
90 * authorisation and return true otherwise return false
91 *
92 * @param wsdlTestCase
93 * @return boolean
94 */
95 private static boolean noAMFTestSteps( WsdlTestCase wsdlTestCase )
96 {
97 if( wsdlTestCase.getTestStepsOfType( AMFRequestTestStep.class ).isEmpty() )
98 {
99
100
101
102
103
104 return true;
105 }
106 return false;
107 }
108
109 public void beforeStep( TestCaseRunner testRunner, TestCaseRunContext runContext )
110 {
111 }
112
113 public void beforeStep( TestCaseRunner testRunner, TestCaseRunContext runContext, TestStep testStep )
114 {
115 }
116
117 public void afterStep( TestCaseRunner testRunner, TestCaseRunContext runContext, TestStepResult result )
118 {
119 }
120 }