use of org.cerberus.crud.entity.TestCaseStepActionControl in project cerberus-source by cerberustesting.
the class TestCaseService method findTestCaseByKeyWithDependency.
@Override
public TestCase findTestCaseByKeyWithDependency(String test, String testCase) throws CerberusException {
TestCase newTcase;
newTcase = findTestCaseByKey(test, testCase);
if (newTcase == null) {
// TODO:FN temporary debug messages
LOG.warn("test case is null - test: " + test + " testcase: " + testCase);
} else {
List<TestCaseCountry> testCaseCountry = testCaseCountryService.findTestCaseCountryByTestTestCase(test, testCase);
List<TestCaseCountry> testCaseCountryToAdd = new ArrayList();
for (TestCaseCountry tcc : testCaseCountry) {
List<TestCaseCountryProperties> properties = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCaseCountry(test, testCase, tcc.getCountry());
tcc.setTestCaseCountryProperty(properties);
testCaseCountryToAdd.add(tcc);
}
newTcase.setTestCaseCountry(testCaseCountryToAdd);
String initialTest = test;
String initialTc = testCase;
List<TestCaseStep> tcs = testCaseStepService.getListOfSteps(test, testCase);
List<TestCaseStep> tcsToAdd = new ArrayList();
for (TestCaseStep step : tcs) {
int stepNumber = step.getStep();
int initialStep = step.getStep();
if (step.getUseStep().equals("Y")) {
test = step.getUseStepTest();
testCase = step.getUseStepTestCase();
stepNumber = step.getUseStepStep();
}
List<TestCaseStepAction> tcsa = testCaseStepActionService.getListOfAction(test, testCase, stepNumber);
List<TestCaseStepAction> tcsaToAdd = new ArrayList();
for (TestCaseStepAction action : tcsa) {
List<TestCaseStepActionControl> tcsac = testCaseStepActionControlService.findControlByTestTestCaseStepSequence(test, testCase, stepNumber, action.getSequence());
List<TestCaseStepActionControl> tcsacToAdd = new ArrayList();
for (TestCaseStepActionControl control : tcsac) {
control.setTest(initialTest);
control.setTestCase(initialTc);
control.setStep(initialStep);
tcsacToAdd.add(control);
}
action.setTestCaseStepActionControl(tcsacToAdd);
action.setTest(initialTest);
action.setTestCase(initialTc);
action.setStep(initialStep);
tcsaToAdd.add(action);
}
step.setTestCaseStepAction(tcsaToAdd);
tcsToAdd.add(step);
}
newTcase.setTestCaseStep(tcsToAdd);
}
return newTcase;
}
use of org.cerberus.crud.entity.TestCaseStepActionControl in project cerberus-source by cerberustesting.
the class TestCaseStepActionControlService method compareListAndUpdateInsertDeleteElements.
@Override
public void compareListAndUpdateInsertDeleteElements(List<TestCaseStepActionControl> newList, List<TestCaseStepActionControl> oldList, boolean duplicate) throws CerberusException {
/**
* Iterate on (TestCaseStepActionControl From Page -
* TestCaseStepActionControl From Database) If TestCaseStepActionControl
* in Database has same key : Update and remove from the list. If
* TestCaseStepActionControl in database does ot exist : Insert it.
*/
List<TestCaseStepActionControl> tcsacToUpdateOrInsert = new ArrayList(newList);
tcsacToUpdateOrInsert.removeAll(oldList);
List<TestCaseStepActionControl> tcsacToUpdateOrInsertToIterate = new ArrayList(tcsacToUpdateOrInsert);
for (TestCaseStepActionControl tcsacDifference : tcsacToUpdateOrInsertToIterate) {
for (TestCaseStepActionControl tcsacInDatabase : oldList) {
if (tcsacDifference.hasSameKey(tcsacInDatabase)) {
this.updateTestCaseStepActionControl(tcsacDifference);
tcsacToUpdateOrInsert.remove(tcsacDifference);
}
}
}
/**
* Iterate on (TestCaseStep From Database - TestCaseStep From Page). If
* TestCaseStep in Page has same key : remove from the list. Then delete
* the list of TestCaseStep
*/
if (!duplicate) {
List<TestCaseStepActionControl> tcsacToDelete = new ArrayList(oldList);
tcsacToDelete.removeAll(newList);
List<TestCaseStepActionControl> tcsacToDeleteToIterate = new ArrayList(tcsacToDelete);
for (TestCaseStepActionControl tcsacDifference : tcsacToDeleteToIterate) {
for (TestCaseStepActionControl tcsacInPage : newList) {
if (tcsacDifference.hasSameKey(tcsacInPage)) {
tcsacToDelete.remove(tcsacDifference);
}
}
}
this.deleteListTestCaseStepActionControl(tcsacToDelete);
}
// We insert only at the end (after deletion of all potencial enreg - linked with #1281)
this.insertListTestCaseStepActionControl(tcsacToUpdateOrInsert);
}
use of org.cerberus.crud.entity.TestCaseStepActionControl in project cerberus-source by cerberustesting.
the class ReadTestCase method findTestCaseWithStep.
private AnswerItem findTestCaseWithStep(ApplicationContext appContext, HttpServletRequest request, String test, String testCase) throws JSONException {
AnswerItem item = new AnswerItem();
JSONObject object = new JSONObject();
HashMap<String, JSONObject> hashProp = new HashMap<String, JSONObject>();
JSONObject jsonResponse = new JSONObject();
testCaseService = appContext.getBean(ITestCaseService.class);
testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
testCaseStepService = appContext.getBean(ITestCaseStepService.class);
testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);
ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
// finds the testcase
AnswerItem answer = testCaseService.readByKey(test, testCase);
AnswerList testCaseCountryList = testCaseCountryService.readByTestTestCase(null, test, testCase);
AnswerList testCaseStepList = testCaseStepService.readByTestTestCase(test, testCase);
AnswerList testCaseStepActionList = testCaseStepActionService.readByTestTestCase(test, testCase);
AnswerList testCaseStepActionControlList = testCaseStepActionControlService.readByTestTestCase(test, testCase);
if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// if the service returns an OK message then we can get the item and convert it to JSONformat
TestCase tc = (TestCase) answer.getItem();
object = convertToJSONObject(tc);
object.put("countryList", new JSONObject());
jsonResponse.put("hasPermissionsDelete", testCaseService.hasPermissionsDelete(tc, request));
jsonResponse.put("hasPermissionsUpdate", testCaseService.hasPermissionsUpdate(tc, request));
jsonResponse.put("hasPermissionsStepLibrary", (request.isUserInRole("TestStepLibrary")));
}
for (TestCaseCountry country : (List<TestCaseCountry>) testCaseCountryList.getDataList()) {
object.getJSONObject("countryList").put(country.getCountry(), country.getCountry());
}
JSONArray stepList = new JSONArray();
Gson gson = new Gson();
for (TestCaseStep step : (List<TestCaseStep>) testCaseStepList.getDataList()) {
step = testCaseStepService.modifyTestCaseStepDataFromUsedStep(step);
JSONObject jsonStep = new JSONObject(gson.toJson(step));
// Fill JSON with step info
jsonStep.put("objType", "step");
// Add a JSON array for Action List from this step
jsonStep.put("actionList", new JSONArray());
if (step.getUseStep().equals("Y")) {
// If this step is imported from library, we call the service to retrieve actions
TestCaseStep usedStep = testCaseStepService.findTestCaseStep(step.getUseStepTest(), step.getUseStepTestCase(), step.getUseStepStep());
List<TestCaseStepAction> actionList = testCaseStepActionService.getListOfAction(step.getUseStepTest(), step.getUseStepTestCase(), step.getUseStepStep());
List<TestCaseStepActionControl> controlList = testCaseStepActionControlService.findControlByTestTestCaseStep(step.getUseStepTest(), step.getUseStepTestCase(), step.getUseStepStep());
List<TestCaseCountryProperties> properties = testCaseCountryPropertiesService.findDistinctPropertiesOfTestCase(step.getUseStepTest(), step.getUseStepTestCase());
// Get the used step sort
jsonStep.put("useStepStepSort", usedStep.getSort());
// retrieve the inherited properties
for (TestCaseCountryProperties prop : properties) {
JSONObject propertyFound = new JSONObject();
propertyFound.put("fromTest", prop.getTest());
propertyFound.put("fromTestCase", prop.getTestCase());
propertyFound.put("property", prop.getProperty());
propertyFound.put("description", prop.getDescription());
propertyFound.put("type", prop.getType());
propertyFound.put("database", prop.getDatabase());
propertyFound.put("value1", prop.getValue1());
propertyFound.put("value2", prop.getValue2());
propertyFound.put("length", prop.getLength());
propertyFound.put("rowLimit", prop.getRowLimit());
propertyFound.put("nature", prop.getNature());
List<String> countriesSelected = testCaseCountryPropertiesService.findCountryByProperty(prop);
JSONArray countries = new JSONArray();
for (String country : countriesSelected) {
countries.put(country);
}
propertyFound.put("country", countries);
hashProp.put(prop.getTest() + "_" + prop.getTestCase() + "_" + prop.getProperty(), propertyFound);
}
for (TestCaseStepAction action : actionList) {
if (action.getStep() == step.getUseStepStep()) {
JSONObject jsonAction = new JSONObject(gson.toJson(action));
jsonAction.put("objType", "action");
jsonAction.put("controlList", new JSONArray());
// We fill the action with the corresponding controls
for (TestCaseStepActionControl control : controlList) {
if (control.getStep() == step.getUseStepStep() && control.getSequence() == action.getSequence()) {
JSONObject jsonControl = new JSONObject(gson.toJson(control));
jsonControl.put("objType", "control");
jsonAction.getJSONArray("controlList").put(jsonControl);
}
}
// we put the action in the actionList for the corresponding step
jsonStep.getJSONArray("actionList").put(jsonAction);
}
}
} else {
// else, we fill the actionList with the action from this step
for (TestCaseStepAction action : (List<TestCaseStepAction>) testCaseStepActionList.getDataList()) {
if (action.getStep() == step.getStep()) {
JSONObject jsonAction = new JSONObject(gson.toJson(action));
jsonAction.put("objType", "action");
jsonAction.put("controlList", new JSONArray());
// We fill the action with the corresponding controls
for (TestCaseStepActionControl control : (List<TestCaseStepActionControl>) testCaseStepActionControlList.getDataList()) {
if (control.getStep() == step.getStep() && control.getSequence() == action.getSequence()) {
JSONObject jsonControl = new JSONObject(gson.toJson(control));
jsonControl.put("objType", "control");
jsonAction.getJSONArray("controlList").put(jsonControl);
}
}
// we put the action in the actionList for the corresponding step
jsonStep.getJSONArray("actionList").put(jsonAction);
}
}
}
stepList.put(jsonStep);
}
jsonResponse.put("info", object);
jsonResponse.put("stepList", stepList);
jsonResponse.put("inheritedProp", hashProp.values());
item.setItem(jsonResponse);
item.setResultMessage(answer.getResultMessage());
return item;
}
use of org.cerberus.crud.entity.TestCaseStepActionControl in project cerberus-source by cerberustesting.
the class ReadTestCaseStep method getStepByKey.
private JSONObject getStepByKey(String test, String testcase, int step, ApplicationContext appContext, HttpServletResponse response) throws JSONException {
JSONObject jsonResponse = new JSONObject();
ITestCaseStepService stepService = appContext.getBean(TestCaseStepService.class);
ITestCaseStepActionService stepActionService = appContext.getBean(TestCaseStepActionService.class);
ITestCaseStepActionControlService stepActionControlService = appContext.getBean(TestCaseStepActionControlService.class);
TestCaseStep testCaseStep = stepService.findTestCaseStep(test, testcase, step);
Gson gson = new Gson();
JSONObject result = new JSONObject(gson.toJson(testCaseStep));
jsonResponse.put("step", result);
// jsonResponse.put("step", testCaseStep);
List<TestCaseStepAction> tcsActionList = stepActionService.getListOfAction(test, testcase, step);
if (tcsActionList != null) {
JSONArray list = new JSONArray();
for (TestCaseStepAction t : tcsActionList) {
JSONObject obj = new JSONObject(gson.toJson(t));
obj.put("controlList", new JSONArray());
obj.put("objType", "action");
list.put(obj);
}
jsonResponse.put("tcsActionList", list);
}
List<TestCaseStepActionControl> tcsActionControlList = stepActionControlService.findControlByTestTestCaseStep(test, testcase, step);
if (tcsActionControlList != null) {
JSONArray list2 = new JSONArray();
for (TestCaseStepActionControl t : tcsActionControlList) {
JSONObject obj = new JSONObject(gson.toJson(t));
list2.put(obj);
}
jsonResponse.put("tcsActionControlList", list2);
}
return jsonResponse;
}
use of org.cerberus.crud.entity.TestCaseStepActionControl in project cerberus-source by cerberustesting.
the class UpdateTestCaseWithDependencies method getTestCaseStepActionControlFromParameter.
private List<TestCaseStepActionControl> getTestCaseStepActionControlFromParameter(HttpServletRequest request, ApplicationContext appContext, String test, String testCase, String stepInc, String actionInc) {
List<TestCaseStepActionControl> testCaseStepActionControl = new ArrayList();
String[] stepActionControl_increment = getParameterValuesIfExists(request, "control_increment_" + stepInc + "_" + actionInc);
IFactoryTestCaseStepActionControl testCaseStepActionControlFactory = appContext.getBean(IFactoryTestCaseStepActionControl.class);
if (stepActionControl_increment != null) {
for (String inc : stepActionControl_increment) {
String delete = getParameterIfExists(request, "control_delete_" + stepInc + "_" + actionInc + "_" + inc);
int controlsequence = getParameterIfExists(request, "control_technical_control_" + stepInc + "_" + actionInc + "_" + inc) == null ? 0 : Integer.parseInt(getParameterIfExists(request, "control_technical_control_" + stepInc + "_" + actionInc + "_" + inc));
int sort = getParameterIfExists(request, "control_controlsequence_" + stepInc + "_" + actionInc + "_" + inc) == null ? 0 : Integer.parseInt(getParameterIfExists(request, "control_controlsequence_" + stepInc + "_" + actionInc + "_" + inc));
String conditionOper = getParameterIfExists(request, "control_conditionoper_" + stepInc + "_" + actionInc + "_" + inc);
String conditionVal1 = getParameterIfExists(request, "control_conditionval1_" + stepInc + "_" + actionInc + "_" + inc);
conditionVal1 = conditionVal1 != null ? conditionVal1.replaceAll("\"", "\\\"") : null;
String conditionVal2 = getParameterIfExists(request, "control_conditionval2_" + stepInc + "_" + actionInc + "_" + inc);
conditionVal2 = conditionVal2 != null ? conditionVal2.replaceAll("\"", "\\\"") : null;
String control = getParameterIfExists(request, "control_control_" + stepInc + "_" + actionInc + "_" + inc);
String value1 = getParameterIfExists(request, "control_value1_" + stepInc + "_" + actionInc + "_" + inc);
value1 = value1 != null ? value1.replaceAll("\"", "\\\"") : null;
String value2 = getParameterIfExists(request, "control_value2_" + stepInc + "_" + actionInc + "_" + inc);
value2 = value2 != null ? value2.replaceAll("\"", "\\\"") : null;
String fatal = getParameterIfExists(request, "control_fatal_" + stepInc + "_" + actionInc + "_" + inc);
String description = getParameterIfExists(request, "control_description_" + stepInc + "_" + actionInc + "_" + inc);
String screenshot = getParameterIfExists(request, "control_screenshot_" + stepInc + "_" + actionInc + "_" + inc);
if (delete == null) {
testCaseStepActionControl.add(testCaseStepActionControlFactory.create(test, testCase, -1, -1, controlsequence, sort, conditionOper, conditionVal1, conditionVal2, control, value1, value2, fatal, description, screenshot));
}
}
}
return testCaseStepActionControl;
}
Aggregations