This chapter explains how to extend the Oracle Communications Services Gatekeeper Platform Test Environment (PTE) by adding and testing custom client modules. Client modules serve as the application-facing interfaces for communication services. Client modules are displayed in the PTE GUI when you select the Clients item in the tools selection panel. An example unit test is included with this release that you can use as a model for your own customization.
For instructions on how to create and deploy new client modules (application-facing), network protocol simulators (network-facing), and communication services, see "Extending the ATE and the PTE" in Services Gatekeeper Extension Developer's Guide.
This section explains how to verify that your new or modified client modules are functioning correctly.
Unit tests are an essential part of creating or changing a Services Gatekeeper communication service. You add known data to the system, run tests on it, and confirm that the test results are what you expect, all programmatically.
You use the Unit Test Framework to create PTE unit tests. Its main tools include:
The OCSGBaseTestCase
abstract class (located in Middleware_home/ocsg_pds/lib/wlng/pte_api.jar where Middleware_home is the Middleware home where Services Gatekeeper is installed) manages the mechanics of using JMX and JMS to connect to the PTE.
The test.properties file (located in Middleware_home/ocsg_pds/lib/wlng/pte_api.jar where Middleware_home is the middleware home where Services Gatekeeper is installed) defines the commonly changed properties of the test.
Figure 3-1 An Example SMS Unit Test Workflow
The workflow of the SMS unit test is as follows:
The test client calls execute
on the PTE Module Management MBean. The mechanics of the JMX call are taken care of by the base class.
The MBean calls execute
on the specified module; in this case, sendSMS
. This request includes a request for delivery receipts.
The sendSMS
module sends the request to Services Gatekeeper.
Services Gatekeeper processes the request and submits it to the network simulator module; in this case, the SMPP module.
The simulator module returns a delivery receipt to Services Gatekeeper
Services Gatekeeper sends the receipt on to the Notification module (which represents the client web Service implementation).
The test client retrieves the result of Services Gatekeeper's submit
from the SMPP simulator.
The test client retrieves the delivery receipt from the Notification module.
To help you understand how unit tests work, PTE includes an example unit test (TestSendData.java), which tests an example communication service using the example clients and simulator. The default location for this file is Middleware_home/ocsg_pds/example/unit_test/src/oracle/ocsg/et/example/TestSendData.java where Middleware_home is the middleware home where Services Gatekeeper is installed. Example 3-1 shows the TestSendData.java file example communication service test.
Example 3-1 A Unit Test for the Example Communication Service
package oracle.ocsg.et.example; import oracle.ocsg.pte.api.OCSGBaseTestCase; import java.util.List; import java.util.Map; /** * This class illustrates how to use the Unit Test Framework to * test the Communication Service Example. A few things are assumed before * running this class: * - the OCSG should be running and configured properly * - the CS example should be deployed and ready * Note: this example uses also the wlngJmx to be able to access the OCSG * MBeans to ask the CS example plugin to connect to the Netex simulator. * */ public class TestSendData extends OCSGBaseTestCase { private static final String SEND_DATA_MBEAN = "com.bea.wlcp.wlng.pte:group=traffic,name=example_application_initiated"; private static final String NETWORK_TRIGGERED_MBEAN = "com.bea.wlcp.wlng.pte:group=traffic,name=example_network_triggered"; private static final String NOTIF_MANAGER_MBEAN = "com.bea.wlcp.wlng.pte:group=client,name=example_notif_manager"; private static final String NOTIF_MBEAN = "com.bea.wlcp.wlng.pte:group=client,name=example_notif"; private static final String NETEX_SIMULATOR_MBEAN = "com.bea.wlcp.wlng.pte:group=netex,name=example_simulator"; // Make sure the InstanceName correspond to the instance name provided // in the PluginManager Mbean when creating the plugin instance. private static final String EXAMPLE_PLUGIN_MBEAN = "com.bea.wlcp.wlng:AppName=example_enabler#4.0," + "InstanceName=example_1," + "Type=com.acompany.plugin.example.netex.management.ExampleMBean"; public TestSendData() throws Exception { } @Override protected void setUp() throws Exception { super.setUp(); ocsgJmx.open("localhost", 8001, "weblogic", "weblogic"); start(NETEX_SIMULATOR_MBEAN); } @Override protected void tearDown() throws Exception { ocsgJmx.close(); stop(NETEX_SIMULATOR_MBEAN); super.tearDown(); } public void testSendData() throws Exception { assertTrue(isRunning(NETEX_SIMULATOR_MBEAN)); resetStatistics(NETEX_SIMULATOR_MBEAN); ocsgJmx.invokeOperation(EXAMPLE_PLUGIN_MBEAN, "connect"); String data = "Hello at " + System.currentTimeMillis(); String to = "tel:1234"; putParameter(SEND_DATA_MBEAN, "url", "http://localhost:8001/example/SendData"); putParameter(SEND_DATA_MBEAN, "data.data", data); putParameter(SEND_DATA_MBEAN, "data.address", to); start(SESSION_MBEAN); assertTrue(isRunning(SESSION_MBEAN)); execute(SEND_DATA_MBEAN); Thread.sleep(2000); stop(SESSION_MBEAN); Map<String,String> stats = listAllStatistics(NETEX_SIMULATOR_MBEAN); System.out.println("Simulator statistics: "+stats); assertEquals("MessageReceived", "1", stats.get("MessageReceived")); assertEquals("MessageSent", "0", stats.get("MessageSent")); public void testSendNetworkTriggeredData() throws Exception { String data = "Hello at " + System.currentTimeMillis(); String from = "tel:1234"; String to = "tel:7878"; String correlator = "1234567890"; assertTrue(isRunning(NETEX_SIMULATOR_MBEAN)); resetStatistics(NETEX_SIMULATOR_MBEAN); ocsgJmx.invokeOperation(EXAMPLE_PLUGIN_MBEAN, "connect"); start(SESSION_MBEAN); assertTrue(isRunning(SESSION_MBEAN)); putParameter(NOTIF_MANAGER_MBEAN, "url", "http://localhost:8001/example/NotificationManager"); putParameter(NOTIF_MANAGER_MBEAN, "start.address", "tel:7878"); putParameter(NOTIF_MANAGER_MBEAN, "start.correlator", correlator); putParameter(NOTIF_MANAGER_MBEAN, "start.endpoint", "http://localhost:13444/jaxws/NetexNotification"); putParameter(NOTIF_MANAGER_MBEAN, "stop.correlator", correlator); start(NOTIF_MANAGER_MBEAN); start(NOTIF_MBEAN); putParameter(NETWORK_TRIGGERED_MBEAN, "data", data); putParameter(NETWORK_TRIGGERED_MBEAN, "fromAddress", from); putParameter(NETWORK_TRIGGERED_MBEAN, "toAddress", to); clearResults(NOTIF_MBEAN); execute(NETWORK_TRIGGERED_MBEAN); Thread.sleep(2000); stop(NOTIF_MBEAN); stop(NOTIF_MANAGER_MBEAN); stop(SESSION_MBEAN); } Map<String,String> stats = listAllStatistics(NETEX_SIMULATOR_MBEAN); System.out.println("Simulator statistics: "+stats); assertEquals("MessageReceived", "0", stats.get("MessageReceived")); assertEquals("MessageSent", "1", stats.get("MessageSent")); List<Map<String,String>> results = listAllResults(NOTIF_MBEAN); System.out.println("Notification results: "+results); assertEquals("Correlator", correlator, results.get(0).get("Correlator")); assertEquals("From Address", from, results.get(0).get("From Address")); assertEquals("Data", data, results.get(0).get("Data")); }
To create and run a PTE unit test:
Note:
The PTE should be running in console (non-GUI) mode when you run your test. See "Starting the PTE" for instructions on starting the PTE in console mode.Create any necessary client or simulator modules for the PTE using the required SPI and XML configuration files. See "Adding Custom PTE Client Modules to the PTE" for information.
Implement a test class based on the OCSGBaseTestCase
abstract class.
Add the test class to the PTE. For information, see "Extending the ATE and the PTE" in Services Gatekeeper Extension Developer's Guide.
Start the PTE and make sure the modules are correctly loaded. For information on starting PTE, see "Starting the PTE". If your new module is correctly loaded, it appears in the PTE GUI.
Run the test class. See "Using the PTE to Test Services Gatekeeper" for information.
Figure 3-1 shows the workflow of a typical unit test; in this case an SMS communication service unit test.