use of org.apache.synapse.unittest.testcase.data.classes.TestCaseSummary in project wso2-synapse by wso2.
the class TestingAgent method processTestCases.
/**
* Check artifact type and pass the test case data to the relevant mediation.
*
* @param synapseTestCase test cases data received from client
*/
void processTestCases(SynapseTestCase synapseTestCase, TestSuiteSummary testSuiteSummary) {
int testCaseCount = synapseTestCase.getTestCases().getTestCaseCount();
log.info(testCaseCount + " Test case(s) ready to execute");
String currentTestCaseName = null;
try {
// execute test cases with synapse configurations and test data
for (int i = 0; i < testCaseCount; i++) {
TestCaseSummary testSummary = new TestCaseSummary();
TestCase currentTestCase = synapseTestCase.getTestCases().getTestCase(i);
currentTestCaseName = currentTestCase.getTestCaseName();
testSummary.setTestCaseName(currentTestCaseName);
testSuiteSummary.setRecentTestCaseName(currentTestCaseName);
switch(mainTestArtifactType) {
case TYPE_SEQUENCE:
Map.Entry<Boolean, MessageContext> mediateResult = TestCasesMediator.sequenceMediate(currentTestCase, synapseConfiguration, key);
testSuiteSummary.setMediationStatus(Constants.PASSED_KEY);
Boolean mediationResult = mediateResult.getKey();
MessageContext resultedMessageContext = mediateResult.getValue();
// check whether mediation is success or not
checkAssertionWithSequenceMediation(mediationResult, resultedMessageContext, currentTestCase, testSummary);
break;
case TYPE_PROXY:
Map.Entry<String, HttpResponse> invokedProxyResult = TestCasesMediator.proxyServiceExecutor(currentTestCase, proxyTransportMethod, key);
testSuiteSummary.setMediationStatus(Constants.PASSED_KEY);
checkAssertionWithProxyMediation(invokedProxyResult, currentTestCase, testSummary);
break;
case TYPE_API:
String context = artifactNode.getAttributeValue(new QName(API_CONTEXT));
String resourceMethod = currentTestCase.getRequestMethod();
String protocolType = currentTestCase.getProtocolType();
if (protocolType == null || protocolType.isEmpty()) {
protocolType = HTTP_KEY;
}
Map.Entry<String, HttpResponse> invokedApiResult = TestCasesMediator.apiResourceExecutor(currentTestCase, context, resourceMethod, protocolType);
testSuiteSummary.setMediationStatus(Constants.PASSED_KEY);
checkAssertionWithAPIMediation(invokedApiResult, currentTestCase, testSummary);
break;
default:
break;
}
testSuiteSummary.addTestCaseSumamry(testSummary);
}
} catch (Exception e) {
log.error("Error occurred while running test cases", e);
exception = CommonUtils.stackTraceToString(e);
testSuiteSummary.setRecentTestCaseName(currentTestCaseName);
testSuiteSummary.setMediationStatus(Constants.FAILED_KEY);
testSuiteSummary.setMediationException(exception);
}
}
use of org.apache.synapse.unittest.testcase.data.classes.TestCaseSummary in project wso2-synapse by wso2.
the class RequestHandler method createResponseJSON.
/**
* Create a json response message including all the details of the test suite.
*
* @return json message
*/
private JsonObject createResponseJSON(TestSuiteSummary testSummary) {
JsonObject jsonResponse = new JsonObject();
jsonResponse.addProperty(Constants.DEPLOYMENT_STATUS, testSummary.getDeploymentStatus());
jsonResponse.addProperty(Constants.DEPLOYMENT_EXCEPTION, testSummary.getDeploymentException());
jsonResponse.addProperty(Constants.DEPLOYMENT_DESCRIPTION, testSummary.getDescription());
jsonResponse.addProperty(Constants.MEDIATION_STATUS, testSummary.getMediationStatus());
jsonResponse.addProperty(Constants.CURRENT_TESTCASE, testSummary.getRecentTestCaseName());
jsonResponse.addProperty(Constants.MEDIATION_EXCEPTION, testSummary.getMediationException());
JsonArray jsonArray = new JsonArray();
for (TestCaseSummary summary : testSummary.getTestCaseSumamryList()) {
JsonObject testObject = new JsonObject();
testObject.addProperty(Constants.TEST_CASE_NAME, summary.getTestCaseName());
testObject.addProperty(Constants.MEDIATION_STATUS, summary.getMediationStatus());
testObject.addProperty(Constants.ASSERTION_STATUS, summary.getAssertionStatus());
testObject.addProperty(Constants.ASSERTION_EXCEPTION, summary.getTestException());
JsonArray jsonFailedAssertionArray = new JsonArray();
for (TestCaseAssertionSummary assertionFailure : summary.getTestCaseAssertionList()) {
JsonObject failedAssertionObject = new JsonObject();
failedAssertionObject.addProperty(Constants.ASSERTION_TYPE, assertionFailure.getAssertionType());
failedAssertionObject.addProperty(Constants.ASSERTION_EXPRESSION, assertionFailure.getAssertionExpression());
failedAssertionObject.addProperty(Constants.ASSERTION_ACTUAL, assertionFailure.getAssertionActualValue());
failedAssertionObject.addProperty(Constants.ASSERTION_EXPECTED, assertionFailure.getAssertionExpectedValue());
failedAssertionObject.addProperty(Constants.ASSERTION_DESCRIPTION, assertionFailure.getAssertionDescription());
failedAssertionObject.addProperty(Constants.ASSERTION_MESSAGE, assertionFailure.getAssertionErrorMessage());
jsonFailedAssertionArray.add(failedAssertionObject);
}
if (jsonFailedAssertionArray.size() > 0) {
testObject.add(Constants.FAILURE_ASSERTIONS, jsonFailedAssertionArray);
}
jsonArray.add(testObject);
}
jsonResponse.add("testCases", jsonArray);
return jsonResponse;
}
Aggregations