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