Test the Model

Calling applications can launch the Configurator Runtime Model Test service using any SOAP client. The instructions here describe the process for creating a web service proxy and data control to run the service within the context of a jUnit test case for Oracle JDeveloper.

The required process is:

  1. Create a web service proxy.

  2. Create a web service data control.

  3. Create a jUnit.

The details for these steps follow.

Creating a Web Service Proxy

The first step is to create a web service proxy using the Oracle JDeveloper Web Service Proxy wizard. Using a web service's WSDL, this wizard creates all the necessary Java objects for the serialization and deserialization of the request and response payloads and calling the web service.

To create a web service proxy:

  1. Create a generic application and project in Oracle JDeveloper.

  2. Select the project in your application and click File > New.

  3. Search for the Web Service Proxy project technology, select it and click OK.

  4. Click Next on the wizard's overview page.

  5. Leave the Client Style as JAX-WS Style and click Next.

  6. Enter the URL to the Web Services Description Language (WSDL) endpoint on the host where the Configurator Runtime Test Model service is deployed (in a cloud deployment this would be on the HTTPS port) then click Next.

  7. On the Specify Default Mapping Options step, deselect the Generate As Async option (because asynchronous invocation isn't supported) and click Next twice, to navigate through the steps related to port endpoints without changing the options

  8. On the Asynchronous Methods step, be sure to select the Don't generate any asynchronous methods option, then click Next.

  9. On the Policy step, wait for the list of policies to be populated. Select oracle/wss11_username_token_with_message_protection_client_policy from the list. Click Next.

  10. On the Defined Handlers step, click Next. Finally, click Finish.

  11. The wizard creates all the necessary Java objects needed for constructing the request and response payloads needed to interact with the web service. See the description of creating a jUnit for an example of how these objects can be used.

Creating a Web Service Data Control

A web service data control is an effective way to create a connection using the connection factory object in order to interact with a web service. A data control encapsulates the security policies, credentials and the data model needed when calling the service. With a properly prepared data control, all that's required for a client to call the web service is to retrieve a service connection using its Java Naming and Directory Interface (JNDI) name. See the description of creating a jUnit for an example of how to call a web service using the service connection factory.

To create a web service data control:

  1. Create and select a project where the web service data controls will be created, then click File New.

  2. Search for the Web Service Data Control project technology, select it, then click OK.

  3. Enter a name for the data source, which will later be used as the JNDI name for looking up this web service connection. Provide the URL to the WSDL endpoint on the host where the Configurator Runtime Test Model service is deployed (in a cloud deployment this would be on the HTTPS port) then click Next.

  4. On the Data Control Operations step, select and move the testModel operation from the Available operations list to the Selected operations list. Click Next.

  5. On the Response Format step, click Next.

  6. On the Endpoint Authentication step, select ConfiguratorRuntimeServiceSoapHttpPort, then enter the user name and password for the web service. Click Next.

  7. Click Finish. The web service data control wizard creates all the type XML files and adds a connection reference in the connections.xml file of the calling application.

Creating a jUnit

There are many ways to call a web service. Here, the vehicle described for calling the Configurator Runtime Model Test service is a jUnit. jUnits are an effective way to perform repeatable tests for this service. Also, Oracle JDeveloper has full support for the Apache jUnit 4 framework.

To build a simple jUnit in Oracle JDeveloper,

  1. Select an existing project, or create a new project, in your application where you want to create the jUnit.

    Note: Ensure that the web service proxy and web service data control projects that you previously created are in this project's library path. It's essential that your jUnit have access to the object in those projects.
  2. Search for and select the Test Case project technology. Click OK.

  3. In the Class Under Test list, select <None>. Click Next.

  4. Enter a name and package for the jUnit. Select the standard jUnit setup and tear-down methods to be generated. Click Next to continue.

  5. Click Finish. The test case wizard creates the jUnit Java class in your project.

  6. The content of the jUnit should be similar to the following code example.

    package oracle.apps.scm.cz;
    import org.junit.After;
    import org.junit.AfterClass;
    import static org.junit.Assert.*;
    import org.junit.Before;
    import org.junit.BeforeClass;
    
    public class MyServiceTest {
        public MyServiceTest() {
        }
    
        @Before
        public void setUp() throws Exception {
        }
    
        @After
        public void tearDown() throws Exception {
        }
    
        @BeforeClass
        public static void setUpBeforeClass() throws Exception {
        }
    
        @AfterClass
        public static void tearDownAfterClass() throws Exception {
        }
    }
  7. Add a test method to the jUnit that's similar to the following code example.

    @Test
    public void testMyTest() {
        ConfiguratorRuntimeService_Service configuratorRuntimeService_Service;
        // Insert the name of the file that includes the model test request XML
        File testModelFile = new File("filename.xml");
    
        TestModelResponse response = null;
        try {
            // 1. Lookup the web service connection using its JNDI name
            Context ctxnew = ADFContext.getCurrent().getConnectionsContext();
            WebServiceConnection wsc =
             (WebServiceConnection)ctxnew.lookup("WebServiceJNDIName");
            
            // 2. Get a reference to the web service port 
            configuratorRuntimeService_Service =
                    new ConfiguratorRuntimeService_Service();
            ConfiguratorRuntimeService configuratorRuntimeService =
                wsc.getJaxWSPort(ConfiguratorRuntimeService.class);
    
            // 3. Create a test model request using JAXB
            JAXBContext jaxbContext = JAXBContext.newInstance(TestModel.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            TestModel testModel =
                (TestModel)jaxbUnmarshaller.unmarshal(testModelFile);
    
            // 4. Call the web service method
            TestModelResponse testModelResponse = new TestModelResponse();
            testModelResponse =
                    configuratorRuntimeService.testModel(testModel);
    
        } catch (Exception e) {
            Assert.fail(e.getMessage());
        }
        
        // 5. Introspect the response object as needed
        JAXBElement<String> status = response.getResult().getTestStatus();
        if (!"SUCCESS".equalsIgnoreCase(status.getValue()))
            Assert.fail(response.getResult().getTestFailureMessage().getValue());
    
    }
  8. Be sure to provide the relative path to the model test request XML file and the correct JNDI name to look up the web service connection. The JNDI name is the name you provided when you created the web service data control.

  9. Run the Java class as a jUnit within Oracle JDeveloper.

Developer Testing Recommendations

The Configurator Runtime Model Test service is an autonomous SOAP-based web service; it can be called from any SOAP client.

Because the Configurator Runtime Model Test service is deployed as an external service in the cloud environment, the exposed port will be enabled for SSL (Secure Sockets Layer) by default. We strongly recommend that you build and test client applications using the SSL port.

To ensure that the initial SSL handshake between the Java client application (such as jUnit) and the web service is established, you must import the SSL certificate where the Configurator Runtime Model Test service is hosted into the local Java key store where the Java client application is running.

To ensure that the proper SSL certificate for the Configurator Runtime Model Test service is available during the client-server SSL handshake, perform the following steps:

  1. Access the Configurator Runtime Model Test service on the SSL port from a standard browser. For an example using Firefox:

    1. Select Tools > Options > Security

    2. Click View Certificate.

  2. Export the server SSL certificate as a certificate in the PEM (Privacy-Enhanced Mail) security format.

    1. On the Details tab of the Certificate Viewer dialog box, click Export.

    2. Save the PEM file to a desired location.

      
                      my_server_com.PEM
  3. Using the Java keytool utility, import the certificate file to the local Java keystore where the Java client application is running.

    keytool -import -trustcacerts
      -file my_server_com.PEM
      -keystore $JAVA_HOME/lib/DemoTrust.jks