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();
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations