use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class ReadTestCaseExecutionMedia method returnPDF.
private void returnPDF(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {
File pdfFile = null;
filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator);
pdfFile = new File(filePath + tc.getFileName());
response.setContentType("application/pdf");
response.setContentLength((int) pdfFile.length());
try {
Files.copy(pdfFile, response.getOutputStream());
} catch (IOException e) {
Log.warn(e);
}
}
use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class ReadTestCaseExecutionMedia method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
* @throws CerberusException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException {
String charset = request.getCharacterEncoding();
boolean auto = ParameterParserUtil.parseBooleanParam(request.getParameter("auto"), true);
String type = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("type"), "", charset);
String test = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("test"), "", charset);
String testcase = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testcase"), "", charset);
String fileName = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("filename"), "", charset);
String fileType = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("filetype"), "", charset);
String fileDesc = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("filedesc"), "", charset);
int step = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("step"), 0, charset);
int index = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("index"), 1, charset);
int sequence = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("sequence"), 0, charset);
int sequenceControl = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("sequenceControl"), 0, charset);
int iterator = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("iterator"), 0, charset);
boolean autoContentType = ParameterParserUtil.parseBooleanParam(request.getParameter("autoContentType"), true);
long id = ParameterParserUtil.parseLongParamAndDecode(request.getParameter("id"), 0, charset);
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IParameterService parameterService = appContext.getBean(IParameterService.class);
BufferedImage b = null;
AnswerList al = new AnswerList<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));
TestCaseExecutionFile tceFile = null;
if (!(fileName.equals(""))) {
IFactoryTestCaseExecutionFile factoryTestCaseExecutionFile = appContext.getBean(IFactoryTestCaseExecutionFile.class);
tceFile = factoryTestCaseExecutionFile.create(0, 0, "", fileDesc, fileName, fileType, "", null, "", null);
} else {
ITestCaseExecutionFileService testCaseExecutionFileService = appContext.getBean(ITestCaseExecutionFileService.class);
String levelFile = "";
if (type.equals("action")) {
levelFile = test + "-" + testcase + "-" + step + "-" + index + "-" + sequence;
} else if (type.equals("control")) {
levelFile = test + "-" + testcase + "-" + step + "-" + index + "-" + sequence + "-" + sequenceControl;
}
al = testCaseExecutionFileService.readByVarious(id, levelFile);
if (al.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && !al.getDataList().isEmpty()) {
Iterator i = al.getDataList().iterator();
int indexIterator = -1;
while (i.hasNext() && indexIterator != iterator) {
indexIterator++;
TestCaseExecutionFile tctemp = (TestCaseExecutionFile) i.next();
if (indexIterator == iterator) {
tceFile = tctemp;
}
}
} else {
// If previous read failed we try without index. (that can be removed few moths after step index has been introduced in Jan 2017)
if (type.equals("action")) {
levelFile = test + "-" + testcase + "-" + step + "-" + sequence;
} else if (type.equals("control")) {
levelFile = test + "-" + testcase + "-" + step + "-" + sequence + "-" + sequenceControl;
}
al = testCaseExecutionFileService.readByVarious(id, levelFile);
if (al.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && !al.getDataList().isEmpty()) {
Iterator i = al.getDataList().iterator();
int indexIterator = -1;
while (i.hasNext() && indexIterator != iterator) {
indexIterator++;
TestCaseExecutionFile tctemp = (TestCaseExecutionFile) i.next();
if (indexIterator == iterator) {
tceFile = tctemp;
}
}
}
}
}
if (tceFile != null) {
String pathString = "";
if (auto) {
pathString = parameterService.getParameterStringByKey("cerberus_exeautomedia_path", "", "");
} else {
pathString = parameterService.getParameterStringByKey("cerberus_exemanualmedia_path", "", "");
}
switch(tceFile.getFileType()) {
case "JPG":
case "JPEG":
if (autoContentType) {
response.setContentType("image/jpeg");
}
returnImage(request, response, tceFile, pathString);
break;
case "PNG":
if (autoContentType) {
response.setContentType("image/png");
}
returnImage(request, response, tceFile, pathString);
break;
case "GIF":
if (autoContentType) {
response.setContentType("image/gif");
}
returnImage(request, response, tceFile, pathString);
break;
case "HTML":
if (autoContentType) {
response.setContentType("text/html");
}
returnFile(request, response, tceFile, pathString);
break;
case "XML":
if (autoContentType) {
response.setContentType("application/xml");
}
returnFile(request, response, tceFile, pathString);
break;
case "JSON":
if (autoContentType) {
response.setContentType("application/json");
}
returnFile(request, response, tceFile, pathString);
break;
case "TXT":
returnFile(request, response, tceFile, pathString);
break;
case "PDF":
returnPDF(request, response, tceFile, pathString);
default:
returnNotSupported(request, response, tceFile, pathString);
}
}
}
use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class ReadTestCaseExecutionMedia method returnImage.
private void returnImage(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) throws IOException {
int width = (!StringUtils.isEmpty(request.getParameter("w"))) ? Integer.valueOf(request.getParameter("w")) : 150;
int height = (!StringUtils.isEmpty(request.getParameter("h"))) ? Integer.valueOf(request.getParameter("h")) : 100;
Boolean real = request.getParameter("r") != null;
BufferedImage image = null;
BufferedImage b = null;
filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator);
File picture = new File(filePath + tc.getFileName());
LOG.debug("Accessing File : " + picture.getAbsolutePath());
try {
if (real) {
b = ImageIO.read(picture);
ImageIO.write(b, "png", response.getOutputStream());
} else {
image = ImageIO.read(picture);
// We test if file is too thin or too long. That prevent 500 error in case files are not compatible with resize. In that case, we crop the file.
if ((image.getHeight() * width / image.getWidth() < 10) || (image.getWidth() * height / image.getHeight() < 15)) {
LOG.debug("Image is too big of thin. Target Height : " + image.getHeight() * width / image.getWidth() + " Target Width : " + image.getWidth() * height / image.getHeight());
b = ImageIO.read(picture);
int minwidth = width;
if (width > image.getWidth()) {
minwidth = image.getWidth();
}
int minheight = height;
if (height > image.getHeight()) {
minheight = image.getHeight();
}
BufferedImage crop = ((BufferedImage) b).getSubimage(0, 0, minwidth, minheight);
b = crop;
response.setHeader("Format-Status", "ERROR");
response.setHeader("Format-Status-Message", "Image Crop from : " + image.getWidth() + "X" + image.getHeight() + " to : " + minwidth + "X" + minheight);
} else {
ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(width, height, true));
rop.setNumberOfThreads(4);
b = rop.filter(image, null);
response.setHeader("Format-Status", "OK");
}
}
} catch (IOException e) {
}
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
sdf.applyPattern("dd MMM yyyy HH:mm:ss z");
response.setHeader("Last-Modified", sdf.format(DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360)));
response.setHeader("Expires", sdf.format(DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360)));
response.setHeader("Type", "PNG");
response.setHeader("Description", tc.getFileDesc());
ImageIO.write(b, "png", response.getOutputStream());
}
use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class FactoryTestCaseStepActionExecution method create.
@Override
public TestCaseStepActionExecution create(long id, String test, String testCase, int step, int index, int sequence, int sort, String returnCode, String returnMessage, String conditionOper, String conditionVal1Init, String conditionVal2Init, String conditionVal1, String conditionVal2, String action, String value1Init, String value2Init, String value1, String value2, String forceExeStatus, long start, long end, long startLong, long endLong, MessageEvent resultMessage, String description, TestCaseStepAction testCaseStepAction, TestCaseStepExecution testCaseStepExecution) {
TestCaseStepActionExecution testCaseStepActionExecution = new TestCaseStepActionExecution();
testCaseStepActionExecution.setAction(action);
testCaseStepActionExecution.setEnd(end);
testCaseStepActionExecution.setEndLong(endLong);
testCaseStepActionExecution.setId(id);
testCaseStepActionExecution.setConditionOper(conditionOper);
testCaseStepActionExecution.setConditionVal1Init(conditionVal1Init);
testCaseStepActionExecution.setConditionVal2Init(conditionVal2Init);
testCaseStepActionExecution.setConditionVal1(conditionVal1);
testCaseStepActionExecution.setConditionVal2(conditionVal2);
testCaseStepActionExecution.setValue1(value1);
testCaseStepActionExecution.setValue2(value2);
testCaseStepActionExecution.setValue1Init(value1Init);
testCaseStepActionExecution.setValue2Init(value2Init);
testCaseStepActionExecution.setForceExeStatus(forceExeStatus);
testCaseStepActionExecution.setReturnCode(returnCode);
testCaseStepActionExecution.setReturnMessage(returnMessage);
testCaseStepActionExecution.setSequence(sequence);
testCaseStepActionExecution.setSort(sort);
testCaseStepActionExecution.setStart(start);
testCaseStepActionExecution.setStartLong(startLong);
testCaseStepActionExecution.setStep(step);
testCaseStepActionExecution.setIndex(index);
testCaseStepActionExecution.setTest(test);
testCaseStepActionExecution.setTestCase(testCase);
testCaseStepActionExecution.setActionResultMessage(resultMessage);
testCaseStepActionExecution.setTestCaseStepAction(testCaseStepAction);
testCaseStepActionExecution.setTestCaseStepExecution(testCaseStepExecution);
testCaseStepActionExecution.setDescription(description);
// List objects
List<TestCaseExecutionFile> objectFileList = new ArrayList<>();
testCaseStepActionExecution.setFileList(objectFileList);
List<TestCaseStepActionControlExecution> testCaseStepActionControlExecution = new ArrayList<>();
testCaseStepActionExecution.setTestCaseStepActionControlExecutionList(testCaseStepActionControlExecution);
return testCaseStepActionExecution;
}
use of org.cerberus.crud.entity.TestCaseExecutionFile in project cerberus-source by cerberustesting.
the class ControlService method takeScreenshot.
private MessageEvent takeScreenshot(TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
MessageEvent message;
if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
TestCaseExecutionFile file = recorderService.recordScreenshot(tCExecution, testCaseStepActionExecution, testCaseStepActionControlExecution.getControlSequence());
testCaseStepActionControlExecution.addFileList(file);
message = new MessageEvent(MessageEventEnum.CONTROL_SUCCESS_TAKESCREENSHOT);
return message;
}
message = new MessageEvent(MessageEventEnum.CONTROL_NOTEXECUTED_NOTSUPPORTED_FOR_APPLICATION);
message.setDescription(message.getDescription().replace("%CONTROL%", "takeScreenShot"));
message.setDescription(message.getDescription().replace("%APPLICATIONTYPE%", testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType()));
return message;
}
Aggregations