How to use returnNotSupported method of org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionMedia class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.ReadTestCaseExecutionMedia.returnNotSupported

Source:ReadTestCaseExecutionMedia.java Github

copy

Full Screen

...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 @Override...

Full Screen

Full Screen

returnNotSupported

Using AI Code Generation

copy

Full Screen

1public class ReadTestCaseExecutionMedia implements ICerberusServlet {2 public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {3 boolean error = false;4 String message = new String();5 JSONObject jsonResponse = new JSONObject();6 String test = request.getParameter("test");7 String testcase = request.getParameter("testcase");8 String country = request.getParameter("country");9 String tag = request.getParameter("tag");10 if (StringUtil.isNullOrEmpty(test) || StringUtil.isNullOrEmpty(testcase) || StringUtil.isNullOrEmpty(country)) {11 error = true;12 message = "Missing parameter.";13 }14 if (!error) {15 try {16 TestCaseExecutionMedia testCaseExecutionMedia = testCaseExecutionMediaService.findTestCaseExecutionMediaByKey(test, testcase, country, tag);17 if (testCaseExecutionMedia != null) {18 byte[] mediaFile = testCaseExecutionMediaService.getMediaFile(testCaseExecutionMedia);19 if (mediaFile != null) {20 response.setContentType(testCaseExecutionMedia.getFiletype());21 response.getOutputStream().write(mediaFile);

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why does DevOps recommend shift-left testing principles?

Companies are using DevOps to quickly respond to changing market dynamics and customer requirements.

QA Innovation &#8211; Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

[LambdaTest Spartans Panel Discussion]: What Changed For Testing &#038; QA Community And What Lies Ahead

The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.

Six Agile Team Behaviors to Consider

Are members of agile teams different from members of other teams? Both yes and no. Yes, because some of the behaviors we observe in agile teams are more distinct than in non-agile teams. And no, because we are talking about individuals!

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