Search in sources :

Example 1 with TestCaseSummary

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);
    }
}
Also used : SynapseTestCase(org.apache.synapse.unittest.testcase.data.classes.SynapseTestCase) TestCase(org.apache.synapse.unittest.testcase.data.classes.TestCase) QName(javax.xml.namespace.QName) TestCaseSummary(org.apache.synapse.unittest.testcase.data.classes.TestCaseSummary) HttpResponse(org.apache.http.HttpResponse) MessageContext(org.apache.synapse.MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) IOException(java.io.IOException)

Example 2 with TestCaseSummary

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;
}
Also used : JsonArray(com.google.gson.JsonArray) TestCaseAssertionSummary(org.apache.synapse.unittest.testcase.data.classes.TestCaseAssertionSummary) TestCaseSummary(org.apache.synapse.unittest.testcase.data.classes.TestCaseSummary) JsonObject(com.google.gson.JsonObject)

Aggregations

TestCaseSummary (org.apache.synapse.unittest.testcase.data.classes.TestCaseSummary)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 HttpResponse (org.apache.http.HttpResponse)1 MessageContext (org.apache.synapse.MessageContext)1 SynapseTestCase (org.apache.synapse.unittest.testcase.data.classes.SynapseTestCase)1 TestCase (org.apache.synapse.unittest.testcase.data.classes.TestCase)1 TestCaseAssertionSummary (org.apache.synapse.unittest.testcase.data.classes.TestCaseAssertionSummary)1