Search in sources :

Example 56 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class ExecutionCheckService method compareRevision.

private int compareRevision(String rev1, String rev2, String system) {
    try {
        BuildRevisionInvariant r1 = buildRevisionInvariantService.convert(buildRevisionInvariantService.readByKey(system, 2, rev1));
        BuildRevisionInvariant r2 = buildRevisionInvariantService.convert(buildRevisionInvariantService.readByKey(system, 2, rev2));
        return r1.getSeq().compareTo(r2.getSeq());
    } catch (CerberusException e) {
        throw new NumberFormatException();
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) BuildRevisionInvariant(org.cerberus.crud.entity.BuildRevisionInvariant)

Example 57 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class ExecutionCheckService method checkRangeBuildRevision.

private boolean checkRangeBuildRevision(TestCaseExecution tCExecution) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking if test can be executed in this build and revision");
    }
    TestCase tc = tCExecution.getTestCaseObj();
    CountryEnvParam env = tCExecution.getCountryEnvParam();
    String tcFromSprint = ParameterParserUtil.parseStringParam(tc.getFromBuild(), "");
    String tcToSprint = ParameterParserUtil.parseStringParam(tc.getToBuild(), "");
    String tcFromRevision = ParameterParserUtil.parseStringParam(tc.getFromRev(), "");
    String tcToRevision = ParameterParserUtil.parseStringParam(tc.getToRev(), "");
    String sprint = ParameterParserUtil.parseStringParam(env.getBuild(), "");
    String revision = ParameterParserUtil.parseStringParam(env.getRevision(), "");
    int dif = -1;
    if (!tcFromSprint.isEmpty() && sprint != null) {
        try {
            if (sprint.isEmpty()) {
                message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_NOTDEFINED);
                return false;
            } else {
                dif = this.compareBuild(sprint, tcFromSprint, env.getSystem());
            }
            if (dif == 0) {
                if (!tcFromRevision.isEmpty() && revision != null) {
                    if (revision.isEmpty()) {
                        message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_NOTDEFINED);
                        return false;
                    } else if (this.compareRevision(revision, tcFromRevision, env.getSystem()) < 0) {
                        message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_DIFFERENT);
                        return false;
                    }
                }
            } else if (dif < 0) {
                message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_DIFFERENT);
                return false;
            }
        } catch (NumberFormatException exception) {
            message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_WRONGFORMAT);
            return false;
        } catch (CerberusException ex) {
            message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_BADLYDEFINED);
            return false;
        }
    }
    if (!tcToSprint.isEmpty() && sprint != null) {
        try {
            if (sprint.isEmpty()) {
                message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_NOTDEFINED);
                return false;
            } else {
                dif = this.compareBuild(tcToSprint, sprint, env.getSystem());
            }
            if (dif == 0) {
                if (!tcToRevision.isEmpty() && revision != null) {
                    if (revision.isEmpty()) {
                        message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_NOTDEFINED);
                        return false;
                    } else if (this.compareRevision(tcToRevision, revision, env.getSystem()) < 0) {
                        message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_DIFFERENT);
                        return false;
                    }
                }
            } else if (dif < 0) {
                message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_DIFFERENT);
                return false;
            }
        } catch (NumberFormatException exception) {
            message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_WRONGFORMAT);
            return false;
        } catch (CerberusException ex) {
            message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_BADLYDEFINED);
            return false;
        }
    }
    return true;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) TestCase(org.cerberus.crud.entity.TestCase) CountryEnvParam(org.cerberus.crud.entity.CountryEnvParam)

Example 58 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseLabelService method compareListAndUpdateInsertDeleteElements.

@Override
public Answer compareListAndUpdateInsertDeleteElements(String test, String testCase, List<TestCaseLabel> newList) {
    Answer ans = new Answer(null);
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer finalAnswer = new Answer(msg1);
    List<TestCaseLabel> oldList = new ArrayList();
    try {
        oldList = this.convert(this.readByTestTestCase(test, testCase));
    } catch (CerberusException ex) {
        LOG.error(ex);
    }
    /**
     * Update and Create all objects database Objects from newList
     */
    List<TestCaseLabel> listToUpdateOrInsert = new ArrayList(newList);
    listToUpdateOrInsert.removeAll(oldList);
    List<TestCaseLabel> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
    for (TestCaseLabel objectDifference : listToUpdateOrInsertToIterate) {
        for (TestCaseLabel objectInDatabase : oldList) {
            if (objectDifference.hasSameKey(objectInDatabase)) {
                ans = this.update(objectDifference);
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                listToUpdateOrInsert.remove(objectDifference);
            }
        }
    }
    /**
     * Delete all objects database Objects that do not exist from newList
     */
    List<TestCaseLabel> listToDelete = new ArrayList(oldList);
    listToDelete.removeAll(newList);
    List<TestCaseLabel> listToDeleteToIterate = new ArrayList(listToDelete);
    for (TestCaseLabel tcsDifference : listToDeleteToIterate) {
        for (TestCaseLabel tcsInPage : newList) {
            if (tcsDifference.hasSameKey(tcsInPage)) {
                listToDelete.remove(tcsDifference);
            }
        }
    }
    if (!listToDelete.isEmpty()) {
        ans = this.deleteList(listToDelete);
        finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
    }
    // We insert only at the end (after deletion of all potencial enreg - linked with #1281)
    if (!listToUpdateOrInsert.isEmpty()) {
        ans = this.createList(listToUpdateOrInsert);
        finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
    }
    return finalAnswer;
}
Also used : Answer(org.cerberus.util.answer.Answer) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) ArrayList(java.util.ArrayList)

Example 59 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class RecorderService method recordTestDataLibProperty.

@Override
public TestCaseExecutionFile recordTestDataLibProperty(Long runId, String property, int propertyIndex, List<HashMap<String, String>> result) {
    TestCaseExecutionFile object = null;
    // Used for logging purposes
    String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
    try {
        JSONArray jsonResult = null;
        jsonResult = dataLibService.convertToJSONObject(result);
        // RESULT.
        Recorder recorder = this.initFilenames(runId, null, null, null, null, null, null, property, propertyIndex, "result", "json", false);
        recordFile(recorder.getFullPath(), recorder.getFileName(), jsonResult.toString());
        // Index file created to database.
        object = testCaseExecutionFileFactory.create(0, runId, recorder.getLevel(), "Result", recorder.getRelativeFilenameURL(), "JSON", "", null, "", null);
        testCaseExecutionFileService.save(object);
    } catch (CerberusException | JSONException ex) {
        LOG.error(logPrefix + "TestDataLib file was not saved due to unexpected error." + ex.toString());
    }
    return object;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) JSONArray(org.json.JSONArray) Recorder(org.cerberus.engine.entity.Recorder) JSONException(org.json.JSONException) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 60 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class RecorderService method recordPageSource.

@Override
public TestCaseExecutionFile recordPageSource(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control) {
    // Used for logging purposes
    String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
    LOG.debug(logPrefix + "Starting to save Page Source File.");
    TestCaseExecutionFile object = null;
    String test = testCaseExecution.getTest();
    String testCase = testCaseExecution.getTestCase();
    String step = String.valueOf(testCaseStepActionExecution.getStep());
    String index = String.valueOf(testCaseStepActionExecution.getIndex());
    String sequence = String.valueOf(testCaseStepActionExecution.getSequence());
    String controlString = control.equals(0) ? null : String.valueOf(control);
    try {
        Recorder recorder = this.initFilenames(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getId(), test, testCase, step, index, sequence, controlString, null, 0, "pagesource", "html", false);
        File dir = new File(recorder.getFullPath());
        dir.mkdirs();
        File file = new File(recorder.getFullFilename());
        try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
            fileOutputStream.write(this.webdriverService.getPageSource(testCaseExecution.getSession()).getBytes());
            fileOutputStream.close();
            // Index file created to database.
            object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Page Source", recorder.getRelativeFilenameURL(), "HTML", "", null, "", null);
            testCaseExecutionFileService.save(object);
        } catch (FileNotFoundException ex) {
            LOG.error(logPrefix + ex.toString());
        } catch (IOException ex) {
            LOG.error(logPrefix + ex.toString());
        }
        LOG.debug(logPrefix + "Page Source file saved in : " + recorder.getRelativeFilenameURL());
    } catch (CerberusException ex) {
        LOG.error(logPrefix + ex.toString());
    }
    return object;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Recorder(org.cerberus.engine.entity.Recorder) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile) IOException(java.io.IOException) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) File(java.io.File) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Aggregations

CerberusException (org.cerberus.exception.CerberusException)159 MessageEvent (org.cerberus.engine.entity.MessageEvent)64 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)58 ApplicationContext (org.springframework.context.ApplicationContext)58 JSONObject (org.json.JSONObject)54 JSONException (org.json.JSONException)53 Connection (java.sql.Connection)48 SQLException (java.sql.SQLException)48 PreparedStatement (java.sql.PreparedStatement)47 AnswerItem (org.cerberus.util.answer.AnswerItem)41 ArrayList (java.util.ArrayList)37 IOException (java.io.IOException)35 PolicyFactory (org.owasp.html.PolicyFactory)35 ILogEventService (org.cerberus.crud.service.ILogEventService)34 Answer (org.cerberus.util.answer.Answer)34 ServletException (javax.servlet.ServletException)26 ResultSet (java.sql.ResultSet)18 TestCase (org.cerberus.crud.entity.TestCase)16 JSONArray (org.json.JSONArray)16 HashMap (java.util.HashMap)12