Calling a service with a workspace context from a Java based client or JUnit test case

You can specify a workspace context when you call an HCL Commerce service from a Java based client, or a JUnit test case.

About this task

Test your services with different workspace context data to ensure they work properly for all workspaces.
Note: The Management Center Web application includes business context data by default in its service requests. You do not need to modify the Management Center to include this data.

Procedure

  1. Create a workspace, task, or task group to use for testing.
  2. Include Java code similar to the following sample (from a JUnit test case) to set the business context in your client code:
    // set the business context intent
    businessContext.setIntent("Authoring"); 
    // add the workspace context data to the business context
    ContextDataType contextData = CommerceFoundationFactory.eINSTANCE.createContextDataType();
    contextData.setName("workspace.name");
    contextData.setValue("W_10001");
    businessContext.getContextData().add(contextData);
    	
    contextData = CommerceFoundationFactory.eINSTANCE.createContextDataType();
    contextData.setName("workspace.taskGroup");
    contextData.setValue("G_10001");
    businessContext.getContextData().add(contextData);
    	
    contextData = CommerceFoundationFactory.eINSTANCE.createContextDataType();
    contextData.setName("workspace.task");
    contextData.setValue("T_10002");
    businessContext.getContextData().add(contextData);
    
    In the preceding example:
    • W_10001 is the workspace name
    • G_10001 is the task group name
    • T_10002 is the task name