Show TOC

Generating Test DataLocate this document in the navigation structure

Context

You use custom operations for validations and complex business logic that you must code manually. In this example, the custom operation generates dummy data and saves it in the local database. This is required in order to have meaningful searches in case the synchronization with the Data Orchestration Engine (DOE) is not yet set up completely. Setting up synchronization with the DOE is explained in Starting and Configuring SAP NetWeaver Developer Studio .

Procedure

  1. In the Services Explorer , in the context menu of OrderService , choose Add Operation .
  2. For Operation Type , select Custom . For Name , enter generateTestData . For Description , enter This method generates test data for orders .
  3. Choose Next .
  4. Choose Finish to close the wizard
  5. Choose Save .
  6. In the Services Explorer , in the context menu of OrderService , choose Start of the navigation path Open with Next navigation step Java Editor End of the navigation path.
  7. Scroll to the method generateTestData or use the Outline view (by default in the bottom left of the NWDS window) to navigate to it.
  8. Enter custom code between the tags //@@begin implementation and //@@end to generate test orders. The completed code should be the same as the example below (you can copy and paste this example code into the editor):

    public void generateTestData() {

    //@@begin implementation

    if( !(((order_srvModel)OcaRoot. getInstance ().getModel(order_srvModel.class)).getOrderOrderheaders().size() > 0))

    {

    OrderOrderheader order =

    ((order_srvModel)OcaRoot.getInstance().getModel(order_srvModel. class )).createOrderOrderheader();

    order.setOrderid("0023378");

    order.setLongtext("Repair front door");

    order.setServiceunit("SU01");

    order.setCreatedOn(Date. valueOf ("2008-06-30"));

    order.setCreatedAt(Time. valueOf ("08:45:00"));

    order =

    ((order_srvModel)OcaRoot. getInstance ().getModel(order_srvModel. class )).createOrderOrderheader();

    order.setOrderid("0024897");

    order.setLongtext("Analyse malfunction");

    order.setServiceunit("SU01");

    order.setCreatedOn(Date. valueOf ("2008-07-01"));

    order.setCreatedAt(Time. valueOf ("09:00:00"));

    order =

    ((order_srvModel)OcaRoot. getInstance ().getModel(order_srvModel. class e)).createOrderOrderheader();

    order.setOrderid("0034534");

    order.setLongtext("Repair escalator");

    order.setServiceunit("SU03");

    order.setCreatedOn(Date. valueOf ("2008-07-03"));

    order.setCreatedAt(Time. valueOf ("19:45:00"));

    order =

    ((order_srvModel)OcaRoot. getInstance ().getModel(order_srvModel. class )).createOrderOrderheader();

    order.setOrderid("0024589");

    order.setLongtext("Analyse computer problem");

    order.setServiceunit("SU04");

    order.setCreatedOn(Date. valueOf ("2008-07-01"));

    order.setCreatedAt(Time. valueOf ("15:45:00"));

    order =

    ((order_srvModel)OcaRoot. getInstance ().getModel(order_srvModel. class )).createOrderOrderheader();

    order.setOrderid("0027890");

    order.setLongtext("Repair door lock");

    order.setServiceunit("SU03");

    order.setCreatedOn(Date. valueOf ("2008-07-05"));

    order.setCreatedAt(Time. valueOf ("10:00:00"));

    OcaRoot. getInstance ().commit();

    }

    //@@end

  9. Save your work.