1   /*
2    *  soapUI, copyright (C) 2004-2009 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.mocksuite;
14  
15  import com.eviware.soapui.impl.WsdlInterfaceFactory;
16  import com.eviware.soapui.impl.wsdl.WsdlInterface;
17  import com.eviware.soapui.impl.wsdl.WsdlOperation;
18  import com.eviware.soapui.impl.wsdl.WsdlProject;
19  import com.eviware.soapui.impl.wsdl.WsdlRequest;
20  import com.eviware.soapui.impl.wsdl.WsdlSubmitContext;
21  import com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation;
22  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
23  import com.eviware.soapui.impl.wsdl.mock.WsdlMockService;
24  import com.eviware.soapui.model.iface.Response;
25  import com.eviware.soapui.support.TestCaseWithJetty;
26  
27  public class MockServiceTestCase extends TestCaseWithJetty
28  {
29  	public void testMockOperation() throws Exception
30  	{
31  		WsdlProject project = new WsdlProject();
32  		WsdlInterface iface = WsdlInterfaceFactory.importWsdl( project, "http://localhost:8082/test8/TestService.wsdl", true )[0];
33  		
34  		WsdlMockService mockService = ( WsdlMockService ) project.addNewMockService( "MockService 1" );
35  		
36  		mockService.setPort( 9081 );
37  		mockService.setPath( "/testmock" );
38  		
39  		WsdlOperation operation = ( WsdlOperation ) iface.getOperationAt( 0 );
40  		WsdlMockOperation mockOperation = ( WsdlMockOperation ) mockService.addNewMockOperation( operation );
41  		WsdlMockResponse mockResponse = mockOperation.addNewMockResponse( "Test Response", true );
42  		mockResponse.setResponseContent( "Tjohoo!" );
43  		
44  		mockService.start();
45  		
46  		iface.addEndpoint( "/testmock" );
47  		WsdlRequest request = ( WsdlRequest ) operation.getRequestAt(  0 );
48  		
49  		request.setEndpoint( "http://localhost:9081/testmock" );
50  		Response response = request.submit( new WsdlSubmitContext(null), false ).getResponse();
51  		
52  		assertEquals( response.getContentAsString(), mockResponse.getResponseContent() );
53  	}
54  }