Unit tests are a core part of any testing cycle. Data are input into the system and the results are retrieved from the system and compared to expected values, all programmatically. This chapter describes the PTE Unit Test Framework. It consists of:
The Unit Test Framework allows you to create unit tests for the PTE easily. You implement your test class based on the abstract class WlngBaseTestCase
and it manages the mechanics of using JMX and JMS to connect to the PTE for you. A test.properties
file located in the same directory can be used to define commonly changed properties of the test.
Note: | The WlngBaseTestCase class is located in <bea_home>/wlng_pds400/lib/wlng/pte_api.jar . |
There are five basic steps to creating a unit test for the PTE:
WlngBaseTestCase
Note: | The PTE should be running in Console (non-GUI) mode when you run your test. See Installing and Running the Platform Test Environment for more information on starting in Console mode. |
The test sequence flow is as follows:
execute
on the PTE’s Module Management MBean. The mechanics of the JMX call are taken care of by the base class.execute
on the specified Module, in this case sendSMS.
This request includes a request for delivery receipts.sendSMS
Module sends the request to Gatekeeper. submit
from the SMPP simulator
To help you understand more clearly how all this works, there is an example unit test, which tests the example communication service, using the example clients and simulator. In standard installations, it is located in <bea_home>/wlng_pds400/example/unit_test/src/com/bea/wlcp/wlng/pds/example
. See Listing 4-1 below.
package com.bea.wlcp.wlng.et.example;
import com.bea.wlcp.wlng.et.api.WlngBaseTestCase;
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 Services Gatekeeper 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 Services Gatekeeper
* MBeans to ask the CS example plugin to connect to the Netex simulator.
*
*/
public class TestSendData extends WlngBaseTestCase {
private static final String SEND_DATA_MBEAN = "com.bea.wlcp.wlng.pte:group=traffic,name=SendData";
private static final String NETWORK_TRIGGERED_MBEAN = "com.bea.wlcp.wlng.pte:group=traffic,name=NetworkTriggered";
private static final String NOTIF_MANAGER_MBEAN = "com.bea.wlcp.wlng.pte:group=client,name=NotificationManager";
private static final String NOTIF_MBEAN = "com.bea.wlcp.wlng.pte:group=client,name=Notification";
private static final String NETEX_SIMULATOR_MBEAN = "com.bea.wlcp.wlng.pte:group=netex,name=Simulator";
private static final String EXAMPLE_PLUGIN_MBEAN =
"com.bea.wlcp.wlng:AppName=es_example_nt#4.0," +
"InstanceName=example_netex_plugin," +
"Type=com.acompany.plugin.example.netex.management.ExampleMBean";
public TestSendData() throws Exception {
}
@Override
protected void setUp() throws Exception {
super.setUp();
wlngJmx.open("localhost", 8001, "weblogic", "weblogic");
start(NETEX_SIMULATOR_MBEAN);
}
@Override
protected void tearDown() throws Exception {
wlngJmx.close();
stop(NETEX_SIMULATOR_MBEAN);
super.tearDown();
}
public void testSendData() throws Exception {
assertTrue(isRunning(NETEX_SIMULATOR_MBEAN));
resetStatistics(NETEX_SIMULATOR_MBEAN);
wlngJmx.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);
wlngJmx.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/axis/services/Notification");
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"));
}
}