Skip to content

Commit

Permalink
Record a file at control lavel was saving it at action level #2412
Browse files Browse the repository at this point in the history
Fixed #2412
  • Loading branch information
vertigo17 committed Aug 5, 2023
1 parent f1e6318 commit dc97c72
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.cerberus.core.enums.MessageGeneralEnum;
import org.cerberus.core.exception.CerberusException;
import org.cerberus.core.crud.service.ITestCaseExecutionFileService;
import org.cerberus.core.util.StringUtil;
import org.cerberus.core.util.answer.Answer;
import org.cerberus.core.util.answer.AnswerItem;
import org.cerberus.core.util.answer.AnswerList;
Expand Down Expand Up @@ -76,7 +77,7 @@ public AnswerList<TestCaseExecutionFile> readByVarious(long ExeId, String level)
}

@Override
public List<TestCaseExecutionFile> getListByFileDesc(long exeId, String fileDesc) throws CerberusException{
public List<TestCaseExecutionFile> getListByFileDesc(long exeId, String fileDesc) throws CerberusException {
return testCaseExecutionFileDAO.getListByFileDesc(exeId, fileDesc);
}

Expand All @@ -98,13 +99,13 @@ public boolean exist(long exeId, String level, String fileDesc) {
AnswerItem objectAnswer = readByKey(exeId, level, fileDesc);
return (objectAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) && (objectAnswer.getItem() != null); // Call was successfull and object was found.
}

@Override
public boolean exist(long exeId, String level) {
AnswerItem objectAnswer = readByKey(exeId, level, null);
return (objectAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) && (objectAnswer.getItem() != null); // Call was successfull and object was found.
}

@Override
public Answer create(TestCaseExecutionFile object) {
return testCaseExecutionFileDAO.create(object);
Expand All @@ -128,70 +129,73 @@ public Answer save(TestCaseExecutionFile object) {
return create(object);
}
}

@Override
public void deleteFile(String root, String fileName) {
File currentFile = new File(root + File.separator +fileName);
currentFile.delete();
File currentFile = new File(root + File.separator + fileName);
currentFile.delete();
}

@Override
public Answer saveManual(TestCaseExecutionFile object) {
if(this.exist(object.getId())) {
return update(object);
}else {
return create(object);
}
if (this.exist(object.getId())) {
return update(object);
} else {
return create(object);
}
}

/**
* this function allow to check if extension exist in invariants table
*/

@Override
public String checkExtension(String fileName, String extension) {
if(extension.isEmpty() || (extension == null ? fileName.substring(fileName.lastIndexOf('.')+1, fileName.length()) != null : !extension.equals(fileName.substring(fileName.lastIndexOf('.')+1, fileName.length())))) {
if(fileName.contains(".")) {
extension = fileName.substring(fileName.lastIndexOf('.')+1, fileName.length());
extension = extension.trim().toUpperCase();
}else {
extension = "BIN";
}

switch(extension) {
case TestCaseExecutionFile.FILETYPE_JPG:
extension = "JPG";
break;
case TestCaseExecutionFile.FILETYPE_PNG:
extension = "PNG";
break;
case TestCaseExecutionFile.FILETYPE_JPEG:
extension = "JPG";
break;
case TestCaseExecutionFile.FILETYPE_PDF:
extension = "PDF";
break;
case TestCaseExecutionFile.FILETYPE_JSON:
extension = "JSON";
break;
case TestCaseExecutionFile.FILETYPE_XML:
extension = "XML";
break;
case TestCaseExecutionFile.FILETYPE_TXT:
extension = "TXT";
break;
case TestCaseExecutionFile.FILETYPE_BIN:
extension = "BIN";
break;
default:
extension = "BIN";
break;
}
if (extension.isEmpty() || (extension == null ? fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length()) != null : !extension.equals(fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length())))) {
if (fileName.contains(".")) {
extension = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());
extension = extension.trim().toUpperCase();
} else {
if (StringUtil.isEmptyOrNullValue(extension)) {

extension = "BIN";

}
}

switch (extension) {
case TestCaseExecutionFile.FILETYPE_JPG:
extension = "JPG";
break;
case TestCaseExecutionFile.FILETYPE_PNG:
extension = "PNG";
break;
case TestCaseExecutionFile.FILETYPE_JPEG:
extension = "JPG";
break;
case TestCaseExecutionFile.FILETYPE_PDF:
extension = "PDF";
break;
case TestCaseExecutionFile.FILETYPE_JSON:
extension = "JSON";
break;
case TestCaseExecutionFile.FILETYPE_XML:
extension = "XML";
break;
case TestCaseExecutionFile.FILETYPE_TXT:
extension = "TXT";
break;
case TestCaseExecutionFile.FILETYPE_BIN:
extension = "BIN";
break;
default:
extension = "BIN";
break;
}
}
return extension;

return extension;
}



@Override
public TestCaseExecutionFile convert(AnswerItem<TestCaseExecutionFile> answerItem) throws CerberusException {
if (answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public AnswerItem<TestCaseExecutionFile> recordManuallyFile(TestCaseStepActionEx
step = String.valueOf(controlExecution.getStepId());
index = String.valueOf(controlExecution.getIndex());
sequence = String.valueOf(controlExecution.getActionId());
controlString = controlNumber.equals(0) ? null : String.valueOf(controlNumber);
controlString = String.valueOf(controlNumber);
}
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - [" + test + " - " + testCase + " - step: " + step + " action: " + sequence + "] ";
Expand All @@ -227,10 +227,8 @@ public AnswerItem<TestCaseExecutionFile> recordManuallyFile(TestCaseStepActionEx
File dir = null;
if (file != null) {
name = file.getName();
extension = name.substring(name.lastIndexOf('.') + 1);
extension = extension.toUpperCase();
extension = testCaseExecutionFileService.checkExtension(name, extension);
recorder = this.initFilenames(myExecution, test, testCase, step, index, sequence, controlString, null, 0, name.substring(0, name.lastIndexOf('.')), extension, true);
recorder = this.initFilenames(myExecution, test, testCase, step, index, sequence, controlString, null, 0, name, extension, true);
dir = new File(recorder.getFullPath());
} else {
name = fileName;
Expand Down Expand Up @@ -1053,9 +1051,9 @@ public void addFileToTestCaseExecution(TestCaseExecution tce, Recorder recorder,
/**
* Auxiliary method that saves a file
*
* @param path - directory path
* @param path - directory path
* @param fileName - name of the file
* @param content -content of the file
* @param content -content of the file
*/
private void recordFile(String path, String fileName, String content, HashMap<String, String> secrets) {
LOG.debug("Starting to save File (recordFile) : {} {}", path, fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re

ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
IRecorderService recorderService = appContext.getBean(IRecorderService.class);
TestCaseStepActionExecution testCaseStepActionExecution = null;
TestCaseStepActionControlExecution testCaseStepActionControlExecution = null;
TestCaseStepActionExecution executionAction = null;
TestCaseStepActionControlExecution executionControl = null;
JSONArray obj = null;
if (action) {
obj = new JSONArray(fileData.get("action"));
testCaseStepActionExecution = updateTestCaseStepActionExecutionFromJsonArray(obj, appContext);
executionAction = updateTestCaseStepActionExecutionFromJsonArray(obj, appContext);
} else {
obj = new JSONArray(fileData.get("control"));
testCaseStepActionControlExecution = updateTestCaseStepActionControlExecutionFromJsonArray(obj, appContext);
executionControl = updateTestCaseStepActionControlExecutionFromJsonArray(obj, appContext);
}

if (description.isEmpty()) {
Expand All @@ -147,7 +147,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
.replace("%REASON%", "desc is missing!"));
ans.setResultMessage(msg);
} else {
ans = recorderService.recordManuallyFile(testCaseStepActionExecution, testCaseStepActionControlExecution, extension, description, file, idex, fileName, fileID);
ans = recorderService.recordManuallyFile(executionAction, executionControl, extension, description, file, idex, fileName, fileID);
}

if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Fixed impossibility to delete all property with the same name. #2454
* Fixed the Job that CANCELLED execution queue entries so that it does not not consider the timeout from the time it was inserted to the queue but the time when the execution was triggered. #2472
* Service Call JSON now display the proper Kafka Filter Header path and value #2465
* Record a file at control lavel was saving it at action level #2412

*Improvements / New features*
[square]
Expand Down

0 comments on commit dc97c72

Please sign in to comment.