Show TOC

Creating Mock ServicesLocate this document in the navigation structure

Use

Creating and using a mock service allows you to replace a back-end service needed by a composed service with a simulation. This allows you to test the behavior of the composed service as if it is using the back-end service. The mock service can be directly deployed and consumed by your composite application. This allows you to continue development even if you do not have a back-end service in place.

Figure 1: Using Mock Services

You can create mock services in two ways:

  • Basic usage - allows you to directly create a mock service from a WSDL.

    You can use it as a dummy implementation of services. This approach automatically creates a dummy result for every operation. You can attach a SOAP response XML as mock data.

  • Service Component Architecture (SCA) usage - allows you to create a mock service for a Service Reference . Note that this is possible only for composed services' service references.

    This approach automatically creates a Mock Service Group , so that no configuration is required after deployment.

Prerequisites
  • The back-end service must be located on a different server than the client server you want to use.

  • You can create mock services only for service operations of type document/literal .

  • You have created a composed service in the Service Composer perspective and generated it.

Procedure

Creating a Mock Service for a WSDL (Basic Usage)

  1. Open the context menu of the WSDL file you want to use.

  2. Choose Start of the navigation path Service Mocking Next navigation step Generate Mock Service Implementation End of the navigation path.

  3. In the dialog that appears, specify the development component (DC) that will hold the newly created mock service in the EJB Module DC dropdown menu.

  4. Specify the Enterprise Application DC that will pack the EJB. Choose Next .

  5. The available service operations are displayed. You can generate or use an external file as output (that is, the SOAP response) for the service operations of the mock service.

  6. Mark the Open in Editor checkbox to directly open for editing the SOAP response after completing this wizard.

  7. Choose Finish .

    The mock service is generated in the EJB DC you have chosen. You can now deploy the mock service and start testing.

Creating a Mock Service for a Service Reference (SCA Based Usage)

Caution

The Enterprise Application DC, which contains the EJB DC of the mock service must be different from the application of the mock client.

Caution

The automatic Smart Configuration during deployment will not work if you have several Service Implementations with the same Service Interface names (PortType Name) running on the same Application Server Java (AS Java) as the mock service. In such case, you can manually assign your service group to the implementation you want. For more information, see Configuring Groups of Web Service Clients . You can check the Smart Configuration settings using the SAP NetWeaver Administrator, under SOA Management .

  1. Create a new Enterprise Application DC that will contain the mock service.

    For more information, see Creating Development Components .

  2. In the composed service project, open the diagram editor of the composed service.

    To do that, navigate to Start of the navigation path Service Composition Next navigation step Composed Services Next navigation step <Name of the composed service for which you want to create a mock service> End of the navigation path and double-click the service operation. The diagram editor opens.

  3. Select the service operation in the diagram with the secondary mouse button and choose Start of the navigation path Service Mocking Next navigation step Replace with Mock Service End of the navigation path.

  4. In the dialog that appears, specify the development component (DC) that will hold the newly created mock service in the EJB Module DC dropdown menu.

  5. Specify the Enterprise Application DC that will pack the EJB. Choose Next .

  6. The available service operations are displayed. You can generate or use an external file as output (that is the SOAP response) for the service operations of the mock service.

  7. Mark the Open in Editor checkbox to directly open for editing the SOAP response after completing this wizard.

  8. Choose Finish .

    The mock service is generated in the EJB DC you have chosen. Deploy the mock service and the client and start testing.

Reverting the Usage of a Mock Service

To stop using the mock service and use again the original back-end service:

  1. In the composed service project, open the diagram editor of the composed service.

    To do that, navigate to Start of the navigation path Service Composition Next navigation step Composed Services Next navigation step <Name of the composed service for which you created the mock service for> End of the navigation path and double-click the service operation. The diagram editor opens.

  2. Select the service operation in the diagram with the secondary mouse button and choose Start of the navigation path Service Mocking Next navigation step Revert to Original Service End of the navigation path.

  3. Build and deploy the client.

  4. Configure the binding to the original back-end service. For more information, see Configuring Web Service Clients .

    Your client is using the original back-end service again.