Java Unit Tests
Test Suite Java API allows you to create pure JUnit test cases that can provide the same features that a user interface driven codeless test cases do.
The change when creating a Test Suite JUnit test case from the traditional test case is that the implementing class extends com.wm.ps.test.WmTestCase instead of junit.framework.TestCase. com.wm.ps.test.WmTestCase does extend the junit.framework.TestCase. The two important methods that are needed for creating test cases using the java API are:
invokeService – The method to invoke a service on the server
mockService – There are various variants of this method that allow the user to setup a mock for a service on the server.
A sample JUnit test case is provided here:
package com.wm.ps.serviceMock.samples;
import com.wm.data.*;
import com.wm.ps.test.*;
public class DuplicateCheckTest extends WmTestCase
{
public void testDupCheckCatchBlock() throws Exception
{
IData input = IDataFactory.create(new Object[][]{
{"lienType", "1"},
{"borrowerSSN", "111-11-1111"},
{"propertyAddress", "937 S Meyer"},
{"propertyZip", "85701"}
});
String exceptionText = "Bad argument";
mockService("wmServiceMockSamples.data.services", "getPotentialDuplicates", new
IllegalArgumentException(exceptionText));
try
{
invokeService("wmServiceMockSamples.services", "getDuplicateLoans", input);
assertFalse(true); //Control getting here means failure
}
catch (Exception e)
{
assertTrue(e.getMessage().endsWith(exceptionText));
}
}
public void testDupCheckSucessWithResults() throws Exception
{
IData input = IDataFactory.create(new Object[][]{
{"lienType", "1"},
{"borrowerSSN", "111-11-1111"},
{"propertyAddress", "937 S Meyer"},
{"propertyZip", "85701"}
});
IData mockOutput =
WmTestSuiteUtils.getIDataFromFile("resources/test/data/mockDupCheckOutputResults.xml");
mockService("wmServiceMockSamples.data.services", "getPotentialDuplicates",
mockOutput);
IData output = invokeService("wmServiceMockSamples.services", "getDuplicateLoans",
input);
IDataCursor outCursor = output.getCursor();
IData response = IDataUtil.getIData(outCursor, "response");
IDataCursor responseCursor = response.getCursor();
String creationTime = IDataUtil.getString(responseCursor, "@creationTime");
assertNotNull(creationTime);
assertEquals(28, creationTime.length());
IData[] duplicateLoans = IDataUtil.getIDataArray(responseCursor, "duplicateLoans");
assertEquals(duplicateLoans.length, 1);
}
}