use of org.apache.synapse.unittest.testcase.data.classes.TestCase in project wso2-synapse by wso2.
the class SynapseTestcaseDataReader method readAndStoreTestCaseData.
/**
* Read test-case data from the descriptor data.
* Append test-case data into the test data holder object
*
* @return testCaseDataHolder object with test case data
*/
TestCaseData readAndStoreTestCaseData() {
TestCaseData testCaseDataHolder = new TestCaseData();
// Set test case count as zero
int testCasesCount = 0;
// Read test cases from descriptor data
QName qualifiedTestCases = new QName("", TEST_CASES, "");
OMElement testCasesNode = importXMLFile.getFirstChildWithName(qualifiedTestCases);
// Iterate through test-cases in descriptor data
Iterator<?> testCaseIterator = Collections.emptyIterator();
if (testCasesNode != null) {
testCaseIterator = testCasesNode.getChildElements();
}
while (testCaseIterator.hasNext()) {
TestCase testCase = new TestCase();
OMElement testCaseNode = (OMElement) (testCaseIterator.next());
String testCaseName = testCaseNode.getAttributeValue(new QName(NAME_ATTRIBUTE));
testCase.setTestCaseName(testCaseName);
// Read input child from test-case node
QName qualifiedInput = new QName("", TEST_CASE_INPUT, "");
OMElement testCaseInputNode = testCaseNode.getFirstChildWithName(qualifiedInput);
// Read input node data of payload and properties if not null
if (testCaseInputNode != null) {
readTestCaseInputData(testCaseInputNode, testCase);
}
// Read assertions of test-case node
QName qualifiedAssertions = new QName("", TEST_CASE_ASSERTIONS, "");
OMElement testCaseAssertionNode = testCaseNode.getFirstChildWithName(qualifiedAssertions);
ArrayList<AssertEqual> assertEquals = new ArrayList<>();
ArrayList<AssertNotNull> assertNotNulls = new ArrayList<>();
readTestCaseAssertions(testCaseAssertionNode, assertEquals, assertNotNulls);
// set assertion values in testCase object
testCase.setAssertEquals(assertEquals);
testCase.setAssertNotNull(assertNotNulls);
// set testCase object in testCase data holder
testCaseDataHolder.setTestCases(testCase);
testCasesCount++;
}
// Set test case count in test data holder
testCaseDataHolder.setTestCaseCount(testCasesCount);
log.info("Test case data from descriptor data read successfully");
return testCaseDataHolder;
}
use of org.apache.synapse.unittest.testcase.data.classes.TestCase 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);
}
}
Aggregations