use of org.apache.synapse.unittest.testcase.data.holders.TestCaseData 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.holders.TestCaseData in project wso2-synapse by wso2.
the class RequestHandler method preProcessingData.
/**
* Processed received message data and stores those data in relevant data holders.
* Uses configModifier if there are some mock services to start
*
* @param receivedMessage received synapseTestcase data message as String
* @return SynapaseTestCase object contains artifact, test cases and mock services data
*/
private SynapseTestCase preProcessingData(String receivedMessage) {
try {
// Read relevant data from the received message and add to the relevant data holders
SynapseTestcaseDataReader synapseTestcaseDataReader = new SynapseTestcaseDataReader(receivedMessage);
ArtifactData readArtifactData = synapseTestcaseDataReader.readAndStoreArtifactData();
TestCaseData readTestCaseData = synapseTestcaseDataReader.readAndStoreTestCaseData();
MockServiceData readMockServiceData = synapseTestcaseDataReader.readAndStoreMockServiceData();
// configure connector resources if exists
if (!readArtifactData.getConnectorResources().isEmpty()) {
ConnectorDeployer.deployConnectorResources(readArtifactData.getConnectorResources());
}
// store registry resources into mock registry in synapse configuration
if (!readArtifactData.getRegistryResources().isEmpty()) {
addRegistryResourcesToMockRegistry(readArtifactData.getRegistryResources());
}
// configure the artifact if there are mock-services to append
String exceptionWhileMocking = null;
if (readMockServiceData.getMockServicesCount() > 0) {
exceptionWhileMocking = ConfigModifier.mockServiceLoader(readMockServiceData);
}
// check is there any error occurred while mocking endpoints if yes stop the testing and return the exception
if (exceptionWhileMocking != null) {
exception = exceptionWhileMocking;
return null;
}
// wrap the artifact data, testcase data and mock service data as one
SynapseTestCase synapseTestCases = new SynapseTestCase();
synapseTestCases.setArtifacts(readArtifactData);
synapseTestCases.setTestCases(readTestCaseData);
return synapseTestCases;
} catch (Exception e) {
log.error("Error while reading data from received message", e);
exception = CommonUtils.stackTraceToString(e);
return null;
}
}
Aggregations