View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.support.wsrm;
14  
15  import java.util.HashMap;
16  
17  import com.eviware.soapui.config.WsrmVersionTypeConfig;
18  import com.eviware.soapui.impl.wsdl.WsdlRequest;
19  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
20  import com.eviware.soapui.impl.wsdl.support.wsmc.WsmcInjection;
21  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
22  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
23  import com.eviware.soapui.model.testsuite.TestCaseRunContext;
24  import com.eviware.soapui.model.testsuite.TestCaseRunner;
25  import com.eviware.soapui.model.testsuite.TestRunListener;
26  import com.eviware.soapui.model.testsuite.TestStep;
27  import com.eviware.soapui.model.testsuite.TestStepResult;
28  
29  public class WsrmTestRunListener implements TestRunListener
30  {
31  
32  	private HashMap<String, WsrmSequence> wsrmMap;
33  
34  	public void afterRun( TestCaseRunner testRunner, TestCaseRunContext runContext )
35  	{
36  
37  		if( wsrmMap != null )
38  		{
39  			for( String endpoint : wsrmMap.keySet() )
40  			{
41  				WsrmSequence sequence = wsrmMap.get( endpoint );
42  				WsrmUtils utils = new WsrmUtils( sequence.getSoapVersion() );
43  				utils.closeSequence( endpoint, sequence.getSoapVersion(), sequence.getWsrmNameSpace(), sequence.getUuid(),
44  						sequence.getIdentifier(), sequence.getLastMsgNumber(), sequence.getOperation() );
45  			}
46  		}
47  
48  		wsrmMap = null;
49  	}
50  
51  	public void afterStep( TestCaseRunner testRunner, TestCaseRunContext runContext, TestStepResult result )
52  	{
53  		// TestStep currentStep = runContext.getCurrentStep();
54  		// WsdlTestCase testCase = (WsdlTestCase) runContext.getTestCase();
55  		// if (currentStep instanceof WsdlTestRequestStep
56  		// && testCase.getWsrmEnabled()) {
57  		// if (wsrmMap == null) {
58  		// wsrmMap = new HashMap<String, WsrmSequence>();
59  		// }
60  		// WsdlTestRequestStep requestStep = (WsdlTestRequestStep) currentStep;
61  		// String endpoint = requestStep.getHttpRequest().getEndpoint();
62  		// if (wsrmMap.containsKey(endpoint)) {
63  		// SoapVersion soapVersion = requestStep.getOperation()
64  		// .getInterface().getSoapVersion();
65  		//
66  		// WsrmSequence sequence = wsrmMap.get(endpoint);
67  		//
68  		// WsmcUtils wsmcUtils = new WsmcUtils();
69  		// wsmcUtils.sendMakeConnectionRequest(endpoint, soapVersion,
70  		// requestStep.getOperation(), sequence.getUuid());
71  		//
72  		// }
73  		//
74  		// }
75  	}
76  
77  	public void beforeRun( TestCaseRunner testRunner, TestCaseRunContext runContext )
78  	{
79  	}
80  
81  	public void beforeStep( TestCaseRunner testRunner, TestCaseRunContext runContext )
82  	{
83  	}
84  
85  	public void beforeStep( TestCaseRunner testRunner, TestCaseRunContext runContext, TestStep testStep )
86  	{
87  		TestStep currentStep = testStep;
88  		WsdlTestCase testCase = ( WsdlTestCase )runContext.getTestCase();
89  		if( currentStep instanceof WsdlTestRequestStep && testCase.getWsrmEnabled() )
90  		{
91  			if( wsrmMap == null )
92  			{
93  				wsrmMap = new HashMap<String, WsrmSequence>();
94  			}
95  			WsdlTestRequestStep requestStep = ( WsdlTestRequestStep )currentStep;
96  			String endpoint = requestStep.getHttpRequest().getEndpoint();
97  			SoapVersion soapVersion = requestStep.getOperation().getInterface().getSoapVersion();
98  			if( !wsrmMap.containsKey( endpoint ) )
99  			{
100 
101 				WsrmUtils utils = new WsrmUtils( soapVersion );
102 				WsrmSequence sequence = utils.createSequence( endpoint, soapVersion, testCase.getWsrmVersionNamespace(),
103 						testCase.getWsrmAckTo(), testCase.getWsrmExpires(), requestStep.getOperation(), null );
104 
105 				wsrmMap.put( endpoint, sequence );
106 			}
107 
108 			WsrmSequence sequence = wsrmMap.get( endpoint );
109 			WsdlRequest wsdlRequest = ( WsdlRequest )requestStep.getHttpRequest();
110 
111 			wsdlRequest.getWsrmConfig().setVersion( testCase.getWsrmVersion() );
112 			wsdlRequest.getWsrmConfig().setSequenceIdentifier( sequence.getIdentifier() );
113 			wsdlRequest.getWsrmConfig().setLastMessageId( sequence.incrementLastMsgNumber() );
114 			wsdlRequest.getWsrmConfig().setUuid( sequence.getUuid() );
115 			wsdlRequest.getWsrmConfig().setWsrmEnabled( true );
116 
117 			if( testCase.getWsrmVersion() != WsrmVersionTypeConfig.X_1_0.toString() )
118 			{
119 				WsmcInjection injection = new WsmcInjection( wsdlRequest.getEndpoint(), wsdlRequest.getOperation(),
120 						soapVersion, wsdlRequest.getWsrmConfig().getUuid() );
121 				wsdlRequest.setAfterRequestInjection( injection );
122 			}
123 
124 		}
125 
126 	}
127 
128 }