Search in sources :

Example 36 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class ControlServiceTest method testDoControlIntegerGreaterWhenPropertyNotNumeric.

@Test
public void testDoControlIntegerGreaterWhenPropertyNotNumeric() {
    String property = "ten";
    String value = "5";
    String msg = "At least one of the Properties is not numeric, can not compare properties!";
    TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();
    tcsace.setControl("verifyNumericGreater");
    tcsace.setValue1(property);
    tcsace.setValue2(value);
    tcsace.setFatal("Y");
    TestCaseStepExecution tcse = new TestCaseStepExecution();
    tcse.settCExecution(tCExecution);
    TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();
    tcsae.setTestCaseStepExecution(tcse);
    tcsace.setTestCaseStepActionExecution(tcsae);
    this.controlService.doControl(tcsace);
    Assert.assertEquals("KO", tcsace.getReturnCode());
    Assert.assertEquals("Y", tcsace.getFatal());
}
Also used : TestCaseStepExecution(org.cerberus.crud.entity.TestCaseStepExecution) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) Test(org.junit.Test)

Example 37 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class ControlServiceTest method testDoControlIntegerEqualsWhenSuccess.

@Test
public void testDoControlIntegerEqualsWhenSuccess() {
    String property = "5";
    String value = "5";
    String msg = "'" + property + "' is equal to '" + value + "'.";
    TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();
    tcsace.setControl("verifyNumericEquals");
    tcsace.setValue1(property);
    tcsace.setValue2(value);
    TestCaseStepExecution tcse = new TestCaseStepExecution();
    tcse.settCExecution(tCExecution);
    TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();
    tcsae.setTestCaseStepExecution(tcse);
    tcsace.setTestCaseStepActionExecution(tcsae);
    this.controlService.doControl(tcsace);
    Assert.assertEquals("OK", tcsace.getReturnCode());
}
Also used : TestCaseStepExecution(org.cerberus.crud.entity.TestCaseStepExecution) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) Test(org.junit.Test)

Example 38 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class ControlServiceTest method testDoControlElementNotPresentWhenPropertyNull.

// @Ignore
// @Test
// public void testDoControlElementPresentWhenWebDriverException() {
// String property = "id=test";
// String value = "null";
// String msg = "The test case is canceled due to lost connection to Selenium Server! Detailed error : .*";
// Identifier identifier = new Identifier();
// identifier.setIdentifier("id");
// identifier.setLocator("test");
// 
// TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();
// tcsace.setControl("verifyElementPresent");
// tcsace.setValue1(property);
// tcsace.setValue2(value);
// tcsace.setFatal("Y");
// tCExecution.setSession(session);
// TestCaseStepExecution tcse = new TestCaseStepExecution();
// tcse.settCExecution(tCExecution);
// TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();
// tcsae.setTestCaseStepExecution(tcse);
// tcsace.setTestCaseStepActionExecution(tcsae);
// 
// when(webdriverService.isElementPresent(tCExecution.getSession(), identifier)).thenThrow(new WebDriverException());
// 
// this.controlService.doControl(tcsace);
// 
// Assert.assertTrue( tcsace.getControlResultMessage().getDescription().matches(msg));
// Assert.assertEquals("CA", tcsace.getReturnCode());
// Assert.assertEquals("Y", tcsace.getFatal());
// }
// @Ignore
// @Test
// public void testDoControlElementNotPresentWhenSuccess() {
// String property = "id=test";
// String value = "null";
// String msg = "Element '" + property + "' is not present on the page.";
// Identifier identifier = new Identifier();
// identifier.setIdentifier("id");
// identifier.setLocator("test");
// 
// TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();
// tcsace.setControl("verifyElementNotPresent");
// tcsace.setValue1(property);
// tcsace.setValue2(value);
// TestCaseStepExecution tcse = new TestCaseStepExecution();
// tcse.settCExecution(tCExecution);
// TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();
// tcsae.setTestCaseStepExecution(tcse);
// tcsace.setTestCaseStepActionExecution(tcsae);
// 
// when(webdriverService.isElementPresent(session, identifier)).thenReturn(false);
// 
// this.controlService.doControl(tcsace);
// 
// Assert.assertEquals(msg, tcsace.getControlResultMessage().getDescription());
// Assert.assertEquals("OK", tcsace.getReturnCode());
// }
// @Ignore
// @Test
// public void testDoControlElementNotPresentWhenFail() {
// String property = "id=test";
// String value = "null";
// String msg = "Element '" + property + "' is present on the page.";
// Identifier identifier = new Identifier();
// identifier.setIdentifier("id");
// identifier.setLocator("test");
// 
// TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();
// tcsace.setControl("verifyElementNotPresent");
// tcsace.setValue1(property);
// tcsace.setValue2(value);
// tcsace.setFatal("Y");
// TestCaseStepExecution tcse = new TestCaseStepExecution();
// tcse.settCExecution(tCExecution);
// TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();
// tcsae.setTestCaseStepExecution(tcse);
// tcsace.setTestCaseStepActionExecution(tcsae);
// 
// when(webdriverService.isElementPresent(session, identifier)).thenReturn(true);
// 
// this.controlService.doControl(tcsace);
// 
// Assert.assertEquals(msg, tcsace.getControlResultMessage().getDescription());
// Assert.assertEquals("KO", tcsace.getReturnCode());
// Assert.assertEquals("Y", tcsace.getFatal());
// }
@Ignore
@Test
public void testDoControlElementNotPresentWhenPropertyNull() {
    String property = "null";
    String value = "id=test";
    String msg = "Object is 'null'. This is mandatory in order to perform the control verify element not present";
    TestCaseStepActionControlExecution tcsace = new TestCaseStepActionControlExecution();
    tcsace.setControl("verifyElementNotPresent");
    tcsace.setValue1(property);
    tcsace.setValue2(value);
    tcsace.setFatal("Y");
    TestCaseStepExecution tcse = new TestCaseStepExecution();
    tcse.settCExecution(tCExecution);
    TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();
    tcsae.setTestCaseStepExecution(tcse);
    tcsace.setTestCaseStepActionExecution(tcsae);
    this.controlService.doControl(tcsace);
    Assert.assertEquals(msg, tcsace.getControlResultMessage().getDescription());
    Assert.assertEquals("KO", tcsace.getReturnCode());
    Assert.assertEquals("Y", tcsace.getFatal());
}
Also used : TestCaseStepExecution(org.cerberus.crud.entity.TestCaseStepExecution) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 39 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class SaveManualExecutionPicture method doPost.

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // using commons-fileupload http://commons.apache.org/proper/commons-fileupload/using.html
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    // Collection<Part> parts = req.getParts(); //for sevlet 3.0, in glassfish 2.x does not work
    TestCaseStepActionExecution tcsae = new TestCaseStepActionExecution();
    FileItem uploadedFile = null;
    // if is multipart we need to handle the upload data
    IParameterService parameterService = appContext.getBean(IParameterService.class);
    IRecorderService recorderService = appContext.getBean(IRecorderService.class);
    DiskFileItemFactory factory = new DiskFileItemFactory();
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    Integer imgPathMaxSize = parameterService.getParameterIntegerByKey("cerberus_screenshot_max_size", "", UPLOAD_PICTURE_MAXSIZE);
    // Set overall request size constraint
    // max size for the file
    upload.setFileSizeMax(imgPathMaxSize);
    try {
        // Parse the request
        List<FileItem> items = upload.parseRequest(req);
        // Process the uploaded items
        Iterator<FileItem> iter = items.iterator();
        while (iter.hasNext()) {
            FileItem item = iter.next();
            if (item.isFormField()) {
                tcsae = processFormField(tcsae, item);
            } else {
                // uploadFileName = processUploadedFile(item);
                uploadedFile = item;
            }
        }
    // this handles an action each time
    } catch (FileSizeLimitExceededException ex) {
        LOG.warn("File size exceed the limit: " + ex.toString());
    } catch (FileUploadException ex) {
        LOG.warn("Exception occurred while uploading file: " + ex.toString());
    }
    if (uploadedFile != null) {
        if (uploadedFile.getContentType().startsWith("image/")) {
            // TODO:FN verify if this is the best approach or if we should
            // check if the mime types for images can be configured in the web.xml and then obtain the valid mime types from the servletContext
            // getServletContext().getMimeType(fileName);
            recorderService.recordUploadedFile(tcsae.getId(), tcsae, uploadedFile);
        } else {
            LOG.warn("Problem with the file you're trying to upload. It is not an image." + "Name: " + uploadedFile.getName() + "; Content-type: " + uploadedFile.getContentType());
        }
    }
// old version : TODO to be deleted after testing
// Collection<Part> parts = req.getParts();
// String runId = req.getParameter("runId");
// String test = req.getParameter("picTest");
// String testCase = req.getParameter("picTestCase");
// String step = req.getParameter("pictStep");
// String action = req.getParameter("pictAction");
// String control = req.getParameter("pictControl") == null ? "" : req.getParameter("pictControl");
// String returnCode = req.getParameter("returnCode");
// 
// ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
// IParameterService parameterService = appContext.getBean(IParameterService.class);
// //        ITestCaseStepExecutionService testCaseStepExecutionService = appContext.getBean(ITestCaseStepExecutionService.class);
// //        ITestCaseStepActionExecutionService testCaseStepActionExecutionService = appContext.getBean(ITestCaseStepActionExecutionService.class);
// 
// try {
// String imgPath = parameterService.findParameterByKey("cerberus_exeautomedia_path", "").getValue();
// 
// File dir = new File(imgPath + runId);
// dir.mkdirs();
// 
// int seq = 1;
// long runID = ParameterParserUtil.parseLongParam(runId, 0);
// //TestCaseStepActionExecution testCaseStepActionExecution = new TestCaseStepActionExecution();
// for (Part p : parts) {
// if (p.getName().equalsIgnoreCase("files[]")) {
// if (seq == 1) {
// //                        TestCaseStepExecution tcse = new TestCaseStepExecution();
// //                        tcse.setId(runID);
// //                        tcse.setTest(test);
// //                        tcse.setTestCase(testCase);
// //                        tcse.setStep(1);
// //                        testCaseStepExecutionService.insertTestCaseStepExecution(tcse);
// }
// 
// InputStream inputStream = p.getInputStream();
// String controlName = control.equals("") ? "" : "Ct"+control;
// String name = test + "-" + testCase + "-St"+step+"Sq" + action + controlName + ".jpg";
// OutputStream outputStream = new FileOutputStream(new File(this.buildScreenshotPath(imgPath, runId, name)));
// 
// int read;
// byte[] bytes = new byte[1024];
// while ((read = inputStream.read(bytes)) != -1) {
// outputStream.write(bytes, 0, read);
// }
// outputStream.close();
// 
// Date now = new Date();
// 
// //create action
// //                    testCaseStepActionExecution.setId(runID);
// //                    testCaseStepActionExecution.setTest(test);
// //                    testCaseStepActionExecution.setTestCase(testCase);
// //                    testCaseStepActionExecution.setStep(1);
// //                    testCaseStepActionExecution.setSequence(seq);
// //                    testCaseStepActionExecution.setReturnCode(returnCode);
// //                    testCaseStepActionExecution.setReturnMessage("");
// //                    testCaseStepActionExecution.setAction("screenshot");
// //                    testCaseStepActionExecution.setObject("");
// //                    testCaseStepActionExecution.setProperty("");
// //                    testCaseStepActionExecution.setStart(now.getTime());
// //                    testCaseStepActionExecution.setEnd(now.getTime());
// //                    testCaseStepActionExecution.setStartLong(now.getTime());
// //                    testCaseStepActionExecution.setEndLong(now.getTime());
// //                    testCaseStepActionExecutionService.insertTestCaseStepActionExecution(testCaseStepActionExecution);
// //
// //                    seq++;
// }
// }
// 
// } catch (CerberusException e) {
// MyLogger.log(SaveManualExecutionPicture.class.getName(), Level.ERROR, e.toString());
// }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ApplicationContext(org.springframework.context.ApplicationContext) IRecorderService(org.cerberus.engine.execution.IRecorderService) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileSizeLimitExceededException(org.apache.commons.fileupload.FileUploadBase.FileSizeLimitExceededException) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) IParameterService(org.cerberus.crud.service.IParameterService) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Example 40 with TestCaseStepActionExecution

use of org.cerberus.crud.entity.TestCaseStepActionExecution in project cerberus-source by cerberustesting.

the class CreateUpdateTestCaseExecutionFile 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 org.cerberus.exception.CerberusException
 * @throws org.json.JSONException
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
    JSONObject jsonResponse = new JSONObject();
    Answer ans = new Answer();
    Gson gson = new Gson();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    response.setContentType("application/json");
    String charset = request.getCharacterEncoding();
    Map<String, String> fileData = new HashMap<String, String>();
    FileItem file = null;
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    try {
        List<FileItem> fields = upload.parseRequest(request);
        Iterator<FileItem> it = fields.iterator();
        if (!it.hasNext()) {
            return;
        }
        while (it.hasNext()) {
            FileItem fileItem = it.next();
            boolean isFormField = fileItem.isFormField();
            if (isFormField) {
                fileData.put(fileItem.getFieldName(), fileItem.getString("UTF-8"));
            } else {
                file = fileItem;
            }
        }
    } catch (FileUploadException e) {
        e.printStackTrace();
    }
    /**
     * Parsing and securing all required parameters
     */
    // Parameter that needs to be secured --> We SECURE+DECODE them
    String description = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("desc"), null, charset);
    String extension = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("type"), "", charset);
    String fileName = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(fileData.get("fileName"), null, charset);
    Integer fileID = ParameterParserUtil.parseIntegerParam(fileData.get("fileID"), 0);
    Integer idex = ParameterParserUtil.parseIntegerParam(fileData.get("idex"), 0);
    boolean action = fileData.get("action") != null ? true : false;
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IRecorderService recorderService = appContext.getBean(IRecorderService.class);
    TestCaseStepActionExecution testCaseStepActionExecution = null;
    TestCaseStepActionControlExecution testCaseStepActionControlExecution = null;
    JSONArray obj = null;
    if (action) {
        obj = new JSONArray(fileData.get("action"));
        testCaseStepActionExecution = updateTestCaseStepActionExecutionFromJsonArray(obj, appContext);
    } else {
        obj = new JSONArray(fileData.get("control"));
        testCaseStepActionControlExecution = updateTestCaseStepActionControlExecutionFromJsonArray(obj, appContext);
    }
    if (description.isEmpty()) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "manual testcase execution file").replace("%OPERATION%", "Create/Update").replace("%REASON%", "desc is missing!"));
        ans.setResultMessage(msg);
    } else {
        ans = recorderService.recordManuallyFile(testCaseStepActionExecution, testCaseStepActionControlExecution, extension, description, file, idex, fileName, fileID);
    }
    if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        /**
         * Object created. Adding Log entry.
         */
        ILogEventService logEventService = appContext.getBean(LogEventService.class);
        logEventService.createForPrivateCalls("/CreateUpdateTestCaseExecutionFile", "CREATE", "Create execution file", request);
    }
    /**
     * Formating and returning the json result.
     */
    jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", ans.getResultMessage().getDescription());
    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
}
Also used : PolicyFactory(org.owasp.html.PolicyFactory) HashMap(java.util.HashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) FileItemFactory(org.apache.commons.fileupload.FileItemFactory) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) Answer(org.cerberus.util.answer.Answer) FileItem(org.apache.commons.fileupload.FileItem) ApplicationContext(org.springframework.context.ApplicationContext) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) IRecorderService(org.cerberus.engine.execution.IRecorderService) JSONObject(org.json.JSONObject) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) ILogEventService(org.cerberus.crud.service.ILogEventService) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Aggregations

TestCaseStepActionExecution (org.cerberus.crud.entity.TestCaseStepActionExecution)40 TestCaseStepActionControlExecution (org.cerberus.crud.entity.TestCaseStepActionControlExecution)29 TestCaseStepExecution (org.cerberus.crud.entity.TestCaseStepExecution)28 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)6 IFactoryTestCaseStepActionExecution (org.cerberus.crud.factory.IFactoryTestCaseStepActionExecution)5 TestCaseExecutionFile (org.cerberus.crud.entity.TestCaseExecutionFile)4 MessageEvent (org.cerberus.engine.entity.MessageEvent)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 AnswerList (org.cerberus.util.answer.AnswerList)3 JSONObject (org.json.JSONObject)3 FileItem (org.apache.commons.fileupload.FileItem)2 FileUploadException (org.apache.commons.fileupload.FileUploadException)2 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)2 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)2 IRecorderService (org.cerberus.engine.execution.IRecorderService)2 AnswerItem (org.cerberus.util.answer.AnswerItem)2