package com.comapny.osb.test; import static org.junit.Assert.assertTrue; import java.io.File; import java.util.List; import org.apache.log4j.Logger; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import com.eviware.soapui.impl.WorkspaceImpl; import com.eviware.soapui.model.project.Project; import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils; import com.eviware.soapui.model.testsuite.TestCase; import com.eviware.soapui.model.testsuite.TestCaseRunner; import com.eviware.soapui.model.testsuite.TestProperty; import com.eviware.soapui.model.testsuite.TestStepResult; import com.eviware.soapui.model.testsuite.TestSuite; import com.eviware.soapui.support.types.StringToObjectMap; import com.eviware.soapui.support.types.StringToStringMap; public class TestMiddleware { private static Logger log = Logger.getLogger(TestMiddleware.class); private static WorkspaceImpl workspace; @BeforeClass public static void setUpBeforeClass() throws Exception { workspace = new WorkspaceImpl("default-soapui-workspace.xml", new StringToStringMap()); PropertyExpansionUtils.getGlobalProperties().addProperty("hashKey").setValue("password"); File soapuiLogFile = new File("soapui.log"); if (!soapuiLogFile.delete()) { log.error("failed to delete " + soapuiLogFile.getCanonicalPath()); } File soapuiErrorsLogFile = new File("soapui-errors.log"); if (!soapuiErrorsLogFile.delete()) { log.error("failed to delete " + soapuiErrorsLogFile.getCanonicalPath()); } // In to ensure the mock services are up correctly //Thread.sleep(5000); } @AfterClass public static void tearDownAfterClass() throws Exception { workspace.release(); } private boolean runTestCase(TestCase tC, StringToObjectMap map, List tProps) { boolean tcOK = false; log.info("Running Test Case:" + tC.getName()); TestCaseRunner testCaseRunner = tC.run(map, false); tcOK = (testCaseRunner.getStatus() == TestCaseRunner.Status.FINISHED); log.info("Test Case:" + tC.getName() + (tcOK ? " - PASSED" : " - FAILED")); if (!tcOK) { log.error(testCaseRunner.getTestCase().getTestStepList().get(0).getProperty("Request").getValue()); log.error(testCaseRunner.getTestCase().getTestStepList().get(0).getProperty("Response").getValue()); List results = testCaseRunner.getResults(); for (TestStepResult testStepResult : results) { String[] messages = testStepResult.getMessages(); for (String message : messages) { log.error(message); } } } return (tcOK); } @Test public void testConnectionMessageValidation() { Project project = workspace.getProjectByName("ConnectionMessageValidation"); TestSuite tSuite = project.getTestSuiteByName("MeterRequestBinding TestSuite"); StringToObjectMap map = new StringToObjectMap(); log.info("Running " + project.getName() + ":" + tSuite.getName()); tSuite.setPropertyValue("MeterRequestId", String.valueOf(Math.random()).substring(2,12)); TestCase reco = tSuite.getTestCaseByName("RECONNECT"); assertTrue(this.runTestCase(reco, map, tSuite.getPropertyList())); TestCase disco = tSuite.getTestCaseByName("DISCONNECT"); assertTrue(this.runTestCase(disco, map, tSuite.getPropertyList())); TestCase relayStatus = tSuite.getTestCaseByName("RELAY_STATUS"); assertTrue(this.runTestCase(relayStatus, map, tSuite.getPropertyList())); TestCase cancelDisco = tSuite.getTestCaseByName("CANCEL DISCONNECT"); assertTrue(this.runTestCase(cancelDisco, map, tSuite.getPropertyList())); TestCase recoReplay = tSuite.getTestCaseByName("RECONNECT - REPLAY"); assertTrue(this.runTestCase(recoReplay, map, tSuite.getPropertyList())); TestCase recoDuplicate = tSuite.getTestCaseByName("RECONNECT - DUPLICATE"); assertTrue(this.runTestCase(recoDuplicate, map, tSuite.getPropertyList())); TestCase recoFailSignature = tSuite.getTestCaseByName("RECONNECT - Fail Signature Validation"); assertTrue(this.runTestCase(recoFailSignature, map, tSuite.getPropertyList())); TestCase recoFailXMLValidation = tSuite.getTestCaseByName("RECONNECT - Fail XML Validation"); assertTrue(this.runTestCase(recoFailXMLValidation, map, tSuite.getPropertyList())); } @Test public void testUpdateServiceRequestStatus() { Project project = workspace.getProjectByName("AIFServiceRequest"); TestSuite tSuite = project.getTestSuiteByName("UpdateServiceRequestStatus TestSuite"); StringToObjectMap map = new StringToObjectMap(); log.info("Running " + project.getName() + ":" + tSuite.getName()); TestCase update = tSuite.getTestCaseByName("UpdateServiceRequestStatus"); assertTrue(this.runTestCase(update, map, tSuite.getPropertyList())); TestCase updateFail = tSuite.getTestCaseByName("UpdateServiceRequestStatus XML Fail"); assertTrue(this.runTestCase(updateFail, map, tSuite.getPropertyList())); } @Test public void testGetServiceRequest() { Project project = workspace.getProjectByName("AIFServiceRequest"); TestSuite tSuite = project.getTestSuiteByName("GetRequest TestSuite"); StringToObjectMap map = new StringToObjectMap(); log.info("Running " + project.getName() + ":" + tSuite.getName()); TestCase get = tSuite.getTestCaseByName("GetRequest"); assertTrue(this.runTestCase(get, map, tSuite.getPropertyList())); TestCase getNoResult = tSuite.getTestCaseByName("GetRequest No Result"); assertTrue(this.runTestCase(getNoResult, map, tSuite.getPropertyList())); TestCase getXMLFail = tSuite.getTestCaseByName("GetRequest XML Fail"); assertTrue(this.runTestCase(getXMLFail, map, tSuite.getPropertyList())); } @Test public void testCreateServiceRequest() { Project project = workspace.getProjectByName("AIFServiceRequest"); TestSuite tSuite = project.getTestSuiteByName("CreateServiceRequest TestSuite"); StringToObjectMap map = new StringToObjectMap(); log.info("Running " + project.getName() + ":" + tSuite.getName()); TestCase create = tSuite.getTestCaseByName("createServiceRequest TestCase"); assertTrue(this.runTestCase(create, map, tSuite.getPropertyList())); TestCase createFail = tSuite.getTestCaseByName("createServiceRequest TestCase XML Fail"); assertTrue(this.runTestCase(createFail, map, tSuite.getPropertyList())); } @Test public void testCloseServiceRequest() { Project project = workspace.getProjectByName("AIFServiceRequest"); TestSuite tSuite = project.getTestSuiteByName("CloseServiceRequest TestSuite"); StringToObjectMap map = new StringToObjectMap(); log.info("Running " + project.getName() + ":" + tSuite.getName()); TestCase close = tSuite.getTestCaseByName("CloseServiceRequest"); assertTrue(this.runTestCase(close, map, tSuite.getPropertyList())); TestCase closeFail = tSuite.getTestCaseByName("CloseServiceRequest XML Fail"); assertTrue(this.runTestCase(closeFail, map, tSuite.getPropertyList())); } @Test public void testAMIConnectionServices() { Project project = workspace.getProjectByName("AMIConnectionServices"); TestSuite tSuite = project.getTestSuiteByName("ConnectionRequestTestSuite"); StringToObjectMap map = new StringToObjectMap(); log.info("Running " + project.getName() + ":" + tSuite.getName()); TestCase disco = tSuite.getTestCaseByName("DISCONNECT"); assertTrue(this.runTestCase(disco, map, tSuite.getPropertyList())); TestCase reco = tSuite.getTestCaseByName("RECONNECT"); assertTrue(this.runTestCase(reco, map, tSuite.getPropertyList())); TestCase recoXMLFail = tSuite.getTestCaseByName("RECONNECT XML Fail"); assertTrue(this.runTestCase(recoXMLFail, map, tSuite.getPropertyList())); } @Test public void testConnectionNotificationService() { Project project = workspace.getProjectByName("ConnectionNotificationService"); TestSuite tSuite = project.getTestSuiteByName("ConnectionNotificationSOAP TestSuite"); StringToObjectMap map = new StringToObjectMap(); log.info("Running " + project.getName() + ":" + tSuite.getName()); TestCase ok = tSuite.getTestCaseByName("SUCCESS"); assertTrue(this.runTestCase(ok, map, tSuite.getPropertyList())); TestCase sigFail = tSuite.getTestCaseByName("Invalid Signature"); assertTrue(this.runTestCase(sigFail, map, tSuite.getPropertyList())); TestCase fail = tSuite.getTestCaseByName("Failed"); assertTrue(this.runTestCase(fail, map, tSuite.getPropertyList())); TestCase xmlFail = tSuite.getTestCaseByName("Failed XML Validation"); assertTrue(this.runTestCase(xmlFail, map, tSuite.getPropertyList())); } @Test public void testProvisionMessageValidation() { Project project = workspace.getProjectByName("ProvisionMessageValidation"); TestSuite tSuite = project.getTestSuiteByName("ServiceRequestBinding TestSuite"); StringToObjectMap map = new StringToObjectMap(); tSuite.setPropertyValue("ServiceRequestId", String.valueOf(Math.random()).substring(2,12)); log.info("Running " + project.getName() + ":" + tSuite.getName()); TestCase prov = tSuite.getTestCaseByName("PROVISION"); assertTrue(this.runTestCase(prov, map, tSuite.getPropertyList())); TestCase act = tSuite.getTestCaseByName("ACTIVATE"); assertTrue(this.runTestCase(act, map, tSuite.getPropertyList())); TestCase deact = tSuite.getTestCaseByName("DEACTIVATE"); assertTrue(this.runTestCase(deact, map, tSuite.getPropertyList())); TestCase actXMLFail = tSuite.getTestCaseByName("ACTIVATION - Fail XML Validation"); assertTrue(this.runTestCase(actXMLFail, map, tSuite.getPropertyList())); TestCase provXMLFail = tSuite.getTestCaseByName("PROVISION - Fail Signature Validation"); assertTrue(this.runTestCase(provXMLFail, map, tSuite.getPropertyList())); TestCase provFault = tSuite.getTestCaseByName("PROVISION - SOAP Fault"); assertTrue(this.runTestCase(provFault, map, tSuite.getPropertyList())); TestCase actReplay = tSuite.getTestCaseByName("ACTIVATE - REPLAY"); assertTrue(this.runTestCase(actReplay, map, tSuite.getPropertyList())); TestCase actDup = tSuite.getTestCaseByName("ACTIVATE - DUPLICATE"); assertTrue(this.runTestCase(actDup, map, tSuite.getPropertyList())); } @Test public void testProvisionNotificationService() { Project project = workspace.getProjectByName("ProvisionNotificationService"); TestSuite tSuite = project.getTestSuiteByName("ProvisionNotificationSOAP TestSuite"); StringToObjectMap map = new StringToObjectMap(); log.info("Running " + project.getName() + ":" + tSuite.getName()); TestCase ok = tSuite.getTestCaseByName("SUCCESS"); assertTrue(this.runTestCase(ok, map, tSuite.getPropertyList())); TestCase sigFail = tSuite.getTestCaseByName("Invalid Signature"); assertTrue(this.runTestCase(sigFail, map, tSuite.getPropertyList())); TestCase fail = tSuite.getTestCaseByName("Failed"); assertTrue(this.runTestCase(fail, map, tSuite.getPropertyList())); TestCase xmlFail = tSuite.getTestCaseByName("Failed XML Validation"); assertTrue(this.runTestCase(xmlFail, map, tSuite.getPropertyList())); } }