use of com.qasymphony.ci.plugin.model.AutomationAttachment in project jenkin-qtest-plugin by QASymphony.
the class CommonParsingUtils method processAttachment.
/**
* Process attachment
*
* @param map automationTestResultMap
*/
private static Map<String, AutomationTestResult> processAttachment(Map<String, AutomationTestResult> map) throws Exception {
Iterator<String> keys = map.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
AutomationTestResult testLog = map.get(key);
int totalAttachments = testLog.getAttachments().size();
if (totalAttachments > LIMIT_TXT_FILES) {
File zipFile = File.createTempFile(testLog.getName(), Extension.ZIP_FILE);
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFile));
Map<String, Integer> attachmentNames = new HashMap<>();
for (int i = 0; i < totalAttachments; i++) {
AutomationAttachment attachment = testLog.getAttachments().get(i);
String attachmentName = attachment.getName();
if (attachmentNames.containsKey(attachment.getName())) {
Integer count = attachmentNames.get(attachment.getName());
attachmentName = attachmentName.replace(Extension.TEXT_FILE, "_" + count + Extension.TEXT_FILE);
attachmentNames.put(attachment.getName(), ++count);
} else {
attachmentNames.put(attachment.getName(), 1);
}
zipOutputStream.putNextEntry(new ZipEntry(attachmentName));
zipOutputStream.write(attachment.getData().getBytes());
zipOutputStream.closeEntry();
}
zipOutputStream.close();
// get zipFile stream
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(zipFile));
int zipFileLength = (int) zipFile.length();
byte[] zipFileBytes = new byte[zipFileLength];
bufferedInputStream.read(zipFileBytes, 0, zipFileLength);
bufferedInputStream.close();
AutomationAttachment attachment = new AutomationAttachment();
attachment.setData(Base64.encodeBase64String(zipFileBytes));
attachment.setContentType(CONTENT_TYPE_ZIP);
attachment.setName(testLog.getName() + Extension.ZIP_FILE);
// add zip file
testLog.setAttachments(Arrays.asList(attachment));
// remove zip tmp file
zipFile.delete();
} else {
for (int i = 0; i < totalAttachments; i++) {
AutomationAttachment attachment = testLog.getAttachments().get(i);
attachment.setContentType(CONTENT_TYPE_TEXT);
attachment.setData(Base64.encodeBase64String(attachment.getData().getBytes()));
}
}
}
return map;
}
use of com.qasymphony.ci.plugin.model.AutomationAttachment in project jenkin-qtest-plugin by QASymphony.
the class CommonParsingUtils method useTestMethodAsTestCase.
/**
* Each method as a testCase in qTest
*
* @param request parse request
* @param testResults testResults
* @param startTime start build time
* @return
* @throws Exception
*/
private static List<AutomationTestResult> useTestMethodAsTestCase(ParseRequest request, List<TestResult> testResults, Date startTime) throws Exception {
Map<String, AutomationTestResult> map = new HashMap<>();
int currentTestLogOrder = 0;
for (TestResult testResult : testResults) {
for (SuiteResult suite : testResult.getSuites()) {
if (suite.getCases() == null) {
continue;
}
Date startDate = JsonUtils.parseTimestamp(suite.getTimestamp());
startDate = startDate == null ? startTime : startDate;
for (CaseResult caseResult : suite.getCases()) {
String automationContent = caseResult.getClassName() + "#" + caseResult.getName();
if (!map.containsKey(automationContent)) {
AutomationTestResult testLog = new AutomationTestResult();
testLog.setOrder(currentTestLogOrder++);
testLog.setAutomationContent(automationContent);
testLog.setExecutedStartDate(startDate);
testLog.setExecutedEndDate(computeEndTime(startDate, caseResult.getDuration()));
testLog.addTestStepLog(new AutomationTestStepLog(caseResult), request.getOverwriteExistingTestSteps());
if (caseResult.isFailed()) {
try {
AutomationAttachment attachment = new AutomationAttachment(caseResult);
attachment.setData(Base64.encodeBase64String(attachment.getData().getBytes()));
testLog.addAttachment(attachment);
} catch (Exception e) {
LoggerUtils.formatError(request.getListener().getLogger(), "Error while build attachment: %s, %s", e.getMessage(), e.getStackTrace());
}
}
map.put(automationContent, testLog);
}
}
}
}
return new ArrayList<>(map.values());
}
use of com.qasymphony.ci.plugin.model.AutomationAttachment in project jenkin-qtest-plugin by QASymphony.
the class CommonParsingUtils method useClassNameAsTestCase.
/**
* Class name as a testCase in qTest
*
* @param request parse request
* @param testResults testResults
* @param startTime start build time
* @return
* @throws Exception
*/
private static List<AutomationTestResult> useClassNameAsTestCase(ParseRequest request, List<TestResult> testResults, Date startTime) throws Exception {
Map<String, AutomationTestResult> map = new HashMap<>();
int currentTestLogOrder = 0;
for (TestResult testResult : testResults) {
for (SuiteResult suite : testResult.getSuites()) {
if (suite.getCases() == null) {
continue;
}
Date startDate = JsonUtils.parseTimestamp(suite.getTimestamp());
startDate = startDate == null ? startTime : startDate;
for (CaseResult caseResult : suite.getCases()) {
AutomationTestResult testLog = null;
if (map.containsKey(caseResult.getClassName())) {
testLog = map.get(caseResult.getClassName());
} else {
testLog = new AutomationTestResult();
testLog.setOrder(currentTestLogOrder++);
testLog.setAutomationContent(caseResult.getClassName());
testLog.setExecutedStartDate(startDate);
testLog.setExecutedEndDate(computeEndTime(startDate, suite.getDuration()));
map.put(caseResult.getClassName(), testLog);
}
testLog.addTestStepLog(new AutomationTestStepLog(caseResult), request.getOverwriteExistingTestSteps());
if (caseResult.isFailed()) {
testLog.addAttachment(new AutomationAttachment(caseResult));
}
}
}
}
map = processAttachment(map);
return new ArrayList<>(map.values());
}
Aggregations