How to use getFileType method of org.cerberus.crud.entity.TestCaseExecutionFile class

Best Cerberus-source code snippet using org.cerberus.crud.entity.TestCaseExecutionFile.getFileType

Source:ReadTestCaseExecutionMedia.java Github

copy

Full Screen

...143 pathString = parameterService.getParameterStringByKey("cerberus_exeautomedia_path", "", "");144 } else {145 pathString = parameterService.getParameterStringByKey("cerberus_exemanualmedia_path", "", "");146 }147 switch (tceFile.getFileType()) {148 case "JPG":149 case "JPEG":150 if (autoContentType) {151 response.setContentType("image/jpeg");152 }153 returnImage(request, response, tceFile, pathString);154 break;155 case "PNG":156 if (autoContentType) {157 response.setContentType("image/png");158 }159 returnImage(request, response, tceFile, pathString);160 break;161 case "GIF":162 if (autoContentType) {163 response.setContentType("image/gif");164 }165 returnImage(request, response, tceFile, pathString);166 break;167 case "HTML":168 if (autoContentType) {169 response.setContentType("text/html");170 }171 returnFile(request, response, tceFile, pathString);172 break;173 case "XML":174 if (autoContentType) {175 response.setContentType("application/xml");176 }177 returnFile(request, response, tceFile, pathString);178 break;179 case "JSON":180 if (autoContentType) {181 response.setContentType("application/json");182 }183 returnFile(request, response, tceFile, pathString);184 break;185 case "TXT":186 returnFile(request, response, tceFile, pathString);187 break;188 case "PDF":189 returnPDF(request, response, tceFile, pathString);190 default:191 returnNotSupported(request, response, tceFile, pathString);192 }193 }194 }195 private void returnImage(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) throws IOException {196 int width = (!StringUtils.isEmpty(request.getParameter("w"))) ? Integer.valueOf(request.getParameter("w")) : 150;197 int height = (!StringUtils.isEmpty(request.getParameter("h"))) ? Integer.valueOf(request.getParameter("h")) : 100;198 Boolean real = request.getParameter("r") != null;199 BufferedImage image = null;200 BufferedImage b = null;201 filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator);202 File picture = new File(filePath + tc.getFileName());203 LOG.debug("Accessing File : " + picture.getAbsolutePath());204 try {205 if (real) {206 b = ImageIO.read(picture);207 ImageIO.write(b, "png", response.getOutputStream());208 } else {209 image = ImageIO.read(picture);210 // 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.211 if ((image.getHeight() * width / image.getWidth() < 10) || (image.getWidth() * height / image.getHeight() < 15)) {212 LOG.debug("Image is too big of thin. Target Height : " + image.getHeight() * width / image.getWidth() + " Target Width : " + image.getWidth() * height / image.getHeight());213 b = ImageIO.read(picture);214 int minwidth = width;215 if (width > image.getWidth()) {216 minwidth = image.getWidth();217 }218 int minheight = height;219 if (height > image.getHeight()) {220 minheight = image.getHeight();221 }222 BufferedImage crop = ((BufferedImage) b).getSubimage(0, 0, minwidth, minheight);223 b = crop;224 response.setHeader("Format-Status", "ERROR");225 response.setHeader("Format-Status-Message", "Image Crop from : " + image.getWidth() + "X" + image.getHeight() + " to : " + minwidth + "X" + minheight);226 } else {227 ResampleOp rop = new ResampleOp(DimensionConstrain.createMaxDimension(width, height, true));228 rop.setNumberOfThreads(4);229 b = rop.filter(image, null);230 response.setHeader("Format-Status", "OK");231 }232 }233 } catch (IOException e) {234 }235 response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());236 response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());237 response.setHeader("Type", "PNG");238 response.setHeader("Description", tc.getFileDesc());239 ImageIO.write(b, "png", response.getOutputStream());240 }241 private void returnPDF(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {242 File pdfFile = null;243 filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator);244 pdfFile = new File(filePath + tc.getFileName());245 response.setContentType("application/pdf");246 response.setContentLength((int) pdfFile.length());247 try {248 Files.copy(pdfFile, response.getOutputStream());249 } catch (IOException e) {250 Log.warn(e);251 }252 }253 private void returnFile(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {254 String everything = "";255 filePath = StringUtil.addSuffixIfNotAlready(filePath, File.separator);256 LOG.debug("Accessing File : " + filePath + tc.getFileName());257 try (FileInputStream inputStream = new FileInputStream(filePath + tc.getFileName())) {258 everything = IOUtils.toString(inputStream);259 response.getWriter().print(everything);260 } catch (FileNotFoundException e) {261 } catch (IOException e) {262 }263 response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());264 response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());265 response.setHeader("Type", tc.getFileType());266 response.setHeader("Description", tc.getFileDesc());267 }268 private void returnText(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {269 response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());270 response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());271 response.setHeader("Type", tc.getFileType());272 response.setHeader("Description", tc.getFileDesc());273 }274 private void returnNotSupported(HttpServletRequest request, HttpServletResponse response, TestCaseExecutionFile tc, String filePath) {275 response.setHeader("Last-Modified", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());276 response.setHeader("Expires", DateUtils.addDays(Calendar.getInstance().getTime(), 2 * 360).toGMTString());277 response.setHeader("Type", tc.getFileType());278 }279 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">280 /**281 * Handles the HTTP <code>GET</code> method.282 *283 * @param request servlet request284 * @param response servlet response285 * @throws ServletException if a servlet-specific error occurs286 * @throws IOException if an I/O error occurs287 */288 @Override289 protected void doGet(HttpServletRequest request, HttpServletResponse response)290 throws ServletException, IOException {291 try {...

Full Screen

Full Screen

getFileType

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecutionFile2import org.cerberus.engine.entity.MessageGeneral3import org.cerberus.engine.execution.impl.Test4import org.cerberus.crud.entity.TestCaseExecution5import org.cerberus.crud.entity.TestCaseStepActionControl6import org.cerberus.crud.entity.TestCaseStepActionControlExecution7import org.cerberus.crud.entity.TestCaseStepActionExecution8import org.cerberus.engine.entity.MessageEvent9import org.cerberus.engine.entity.MessageGeneralEnum10import org.cerberus.crud.factory.IFactoryTestCaseExecutionFile11import org.cerberus.crud.service.ITestCaseExecutionFileService12import org.cerberus.engine.entity.Identifier13import org.cerberus.engine.execution.IRecorderService14import org.cerberus.engine.execution.IVariableService15import org.cerberus.engine.execution.impl.Test16import org.cerberus.engine.groovy.impl.GroovyStepActionControl17import org.cerberus.engine.groovy.impl.GroovyTestCase18import org.cerberus.engine.groovy.impl.GroovyTestCaseStepAction19import org.cerberus.engine.groovy.impl.GroovyTestCaseStepActionControl20import org.cerberus.engine.groovy.impl.GroovyTestCaseStepActionControlExecution21import org.cerberus.engine.groovy.impl.GroovyTestCaseStepActionExecution22import org.cerberus.enums.MessageEventEnum23import org.cerberus.enums.MessageGeneralEnum24import org.cerberus.exception.CerberusEventException25import org.cerberus.exception.CerberusException26import org.cerberus.exception.CerberusException27import org.cerberus.log.MyLog

Full Screen

Full Screen

getFileType

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecutionFile;2import org.cerberus.crud.entity.TestCaseExecutionFile.FileTypeEnum;3FileTypeEnum fileType = null;4String fileExtension = null;5String fileName = "test.txt";6String fileContentType = "text/plain";7fileType = TestCaseExecutionFile.getFileType(fileName, fileContentType);8System.out.println("FileType: " + fileType);9fileType = TestCaseExecutionFile.getFileType(fileName, null);10System.out.println("FileType: " + fileType);11fileName = "test.xml";12fileContentType = "text/xml";13fileType = TestCaseExecutionFile.getFileType(fileName, fileContentType);14System.out.println("FileType: " + fileType);15fileType = TestCaseExecutionFile.getFileType(fileName, null);16System.out.println("FileType: " + fileType);17fileName = "test.html";18fileContentType = "text/html";19fileType = TestCaseExecutionFile.getFileType(fileName, fileContentType);20System.out.println("FileType: " + fileType);21fileType = TestCaseExecutionFile.getFileType(fileName, null);22System.out.println("FileType: " + fileType);23fileName = "test.png";24fileContentType = "image/png";25fileType = TestCaseExecutionFile.getFileType(fileName, fileContentType);26System.out.println("FileType: " + fileType);27fileType = TestCaseExecutionFile.getFileType(fileName, null);28System.out.println("FileType: " + fileType);29fileName = "test.pdf";30fileContentType = "application/pdf";31fileType = TestCaseExecutionFile.getFileType(fileName, fileContentType);32System.out.println("FileType: " + fileType);33fileType = TestCaseExecutionFile.getFileType(fileName, null);34System.out.println("FileType: " + fileType);35fileName = "test";36fileContentType = "application/pdf";37fileType = TestCaseExecutionFile.getFileType(fileName, fileContentType);38System.out.println("FileType: " + fileType);39fileType = TestCaseExecutionFile.getFileType(fileName, null);40System.out.println("FileType: " + fileType);41import org.cerberus.crud.entity.TestCaseExecutionFile;42import org.cerberus.crud.entity.TestCaseExecutionFile.FileTypeEnum;43FileTypeEnum fileType = null;

Full Screen

Full Screen

getFileType

Using AI Code Generation

copy

Full Screen

1import org.cerberus.crud.entity.TestCaseExecutionFile;2import org.cerberus.crud.entity.TestCaseExecutionFile.FileType;3String file = "c:/temp/MyFile.txt";4String fileExtension = getFileExtension(file);5if (fileExtension.equals(FileType.TXT.toString().toLowerCase())) {6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful