Search in sources :

Example 36 with TestCaseStepActionControlExecution

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

the class TestCaseStepActionControlExecutionService method readByVarious1WithDependency.

@Override
public AnswerList readByVarious1WithDependency(long executionId, String test, String testcase, int step, int index, int sequence) {
    AnswerList controls = this.readByVarious1(executionId, test, testcase, step, index, sequence);
    AnswerList response = null;
    List<TestCaseStepActionControlExecution> tcsaceList = new ArrayList();
    for (Object control : controls.getDataList()) {
        TestCaseStepActionControlExecution tcsace = (TestCaseStepActionControlExecution) control;
        AnswerList files = testCaseExecutionFileService.readByVarious(executionId, tcsace.getTest() + "-" + tcsace.getTestCase() + "-" + tcsace.getStep() + "-" + tcsace.getIndex() + "-" + tcsace.getSequence() + "-" + tcsace.getControlSequence());
        tcsace.setFileList((List<TestCaseExecutionFile>) files.getDataList());
        tcsaceList.add(tcsace);
    }
    response = new AnswerList(tcsaceList, controls.getTotalRows());
    return response;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) ArrayList(java.util.ArrayList) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 37 with TestCaseStepActionControlExecution

use of org.cerberus.crud.entity.TestCaseStepActionControlExecution 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)

Example 38 with TestCaseStepActionControlExecution

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

the class CreateUpdateTestCaseExecutionFile method createTestCaseStepActionControlExecution.

// create a TestCaseStepActionControlExecution with the parameters
private TestCaseStepActionControlExecution createTestCaseStepActionControlExecution(long id, String test, String testCase, int step, int index, int sequence, int controlSequence, int sort, String returnCode, String returnMessage, String conditionOper, String conditionVal1Init, String conditionVal2Init, String conditionVal1, String conditionVal2, String control, String value1Init, String value2Init, String value1, String value2, String fatal, long start, long end, long startLong, long endLong, String description, TestCaseStepActionExecution testCaseStepActionExecution, MessageEvent resultMessage) {
    TestCaseStepActionControlExecution testCaseStepActionControlExecution = new TestCaseStepActionControlExecution();
    testCaseStepActionControlExecution.setId(id);
    testCaseStepActionControlExecution.setTest(test);
    testCaseStepActionControlExecution.setTestCase(testCase);
    testCaseStepActionControlExecution.setStep(step);
    testCaseStepActionControlExecution.setIndex(index);
    testCaseStepActionControlExecution.setSequence(sequence);
    testCaseStepActionControlExecution.setControlSequence(controlSequence);
    testCaseStepActionControlExecution.setSort(sort);
    testCaseStepActionControlExecution.setReturnCode(returnCode);
    testCaseStepActionControlExecution.setReturnMessage(returnMessage);
    testCaseStepActionControlExecution.setConditionOper(conditionOper);
    testCaseStepActionControlExecution.setConditionVal1Init(conditionVal1Init);
    testCaseStepActionControlExecution.setConditionVal2Init(conditionVal2Init);
    testCaseStepActionControlExecution.setConditionVal1(conditionVal1);
    testCaseStepActionControlExecution.setConditionVal2(conditionVal2);
    testCaseStepActionControlExecution.setControl(control);
    testCaseStepActionControlExecution.setValue1(value1);
    testCaseStepActionControlExecution.setValue2(value2);
    testCaseStepActionControlExecution.setValue1Init(value1Init);
    testCaseStepActionControlExecution.setValue2Init(value2Init);
    testCaseStepActionControlExecution.setFatal(fatal);
    testCaseStepActionControlExecution.setStart(start);
    testCaseStepActionControlExecution.setEnd(end);
    testCaseStepActionControlExecution.setStartLong(startLong);
    testCaseStepActionControlExecution.setEndLong(endLong);
    testCaseStepActionControlExecution.setTestCaseStepActionExecution(testCaseStepActionExecution);
    testCaseStepActionControlExecution.setControlResultMessage(resultMessage);
    testCaseStepActionControlExecution.setDescription(description);
    return testCaseStepActionControlExecution;
}
Also used : TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution)

Example 39 with TestCaseStepActionControlExecution

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

the class CreateUpdateTestCaseExecutionFile method updateTestCaseStepActionControlExecutionFromJsonArray.

// </editor-fold>
/**
 * update control execution with testCaseStepActionControlJson
 * @param JSONObject testCaseJson
 * @param ApplicationContext appContext
 * @throws JSONException
 * @throws IOException
 */
TestCaseStepActionControlExecution updateTestCaseStepActionControlExecutionFromJsonArray(JSONArray controlArray, ApplicationContext appContext) throws JSONException, IOException {
    JSONObject currentControl = controlArray.getJSONObject(0);
    long id = currentControl.getLong("id");
    String test = currentControl.getString("test");
    String testCase = currentControl.getString("testcase");
    int step = currentControl.getInt("step");
    int index = currentControl.getInt("index");
    int sort = currentControl.getInt("sort");
    int sequence = currentControl.getInt("sequence");
    int controlSequence = currentControl.getInt("control");
    String conditionOper = currentControl.getString("conditionOper");
    String conditionVal1Init = currentControl.getString("conditionVal1Init");
    String conditionVal2Init = currentControl.getString("conditionVal2Init");
    String conditionVal1 = currentControl.getString("conditionVal1");
    String conditionVal2 = currentControl.getString("conditionVal2");
    String control = currentControl.getString("controlType");
    String value1Init = currentControl.getString("value1init");
    String value2Init = currentControl.getString("value2init");
    String value1 = currentControl.getString("value1");
    String value2 = currentControl.getString("value2");
    String fatal = currentControl.getString("fatal");
    String description = currentControl.getString("description");
    String returnCode = currentControl.getString("returnCode");
    // String wrote by the user
    String returnMessage = StringUtil.sanitize(currentControl.getString("returnMessage"));
    if (// default message unchanged
    returnMessage.equals("Control executed manually"))
        returnMessage = "Control executed manually";
    long start = currentControl.getLong("start");
    long end = currentControl.getLong("end");
    // currentAction.getLong("fullStart");
    long fullStart = 0;
    // currentAction.getLong("fullEnd");
    long fullEnd = 0;
    // create this TestCaseStepActionControlExecution and update the bdd with it
    TestCaseStepActionControlExecution currentTestCaseStepActionControlExecution = createTestCaseStepActionControlExecution(id, test, testCase, step, index, sequence, controlSequence, sort, returnCode, returnMessage, conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, control, value1Init, value2Init, value1, value2, fatal, start, end, fullStart, fullEnd, description, null, null);
    return currentTestCaseStepActionControlExecution;
}
Also used : JSONObject(org.json.JSONObject) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution)

Aggregations

TestCaseStepActionControlExecution (org.cerberus.crud.entity.TestCaseStepActionControlExecution)39 TestCaseStepActionExecution (org.cerberus.crud.entity.TestCaseStepActionExecution)29 TestCaseStepExecution (org.cerberus.crud.entity.TestCaseStepExecution)26 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)5 IFactoryTestCaseStepActionControlExecution (org.cerberus.crud.factory.IFactoryTestCaseStepActionControlExecution)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 AnswerItem (org.cerberus.util.answer.AnswerItem)2 Ignore (org.junit.Ignore)2 Gson (com.google.gson.Gson)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 FileItem (org.apache.commons.fileupload.FileItem)1