use of org.cerberus.crud.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class ImportTestCaseStep method processRequest.
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException {
response.setContentType("text/html;charset=UTF-8");
appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);
ITestCaseStepActionService testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
ITestCaseStepActionControlService testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);
ITestCaseCountryService testCaseCountry = appContext.getBean(ITestCaseCountryService.class);
ITestCaseCountryPropertiesService testCaseCountryProperties = appContext.getBean(ITestCaseCountryPropertiesService.class);
this.database = appContext.getBean(DatabaseSpring.class);
/**
* Get Parameters Test : Target Test TestCase : Target TestCase Step :
* Target Step fromTest : from Test fromTestCase : from TestCase
* fromStep : from Step
*/
String test = request.getParameter("Test");
String testCase = request.getParameter("TestCase");
Integer step = Integer.valueOf(request.getParameter("Step"));
String fromTest = request.getParameter("FromTest");
String fromTestCase = request.getParameter("FromTestCase");
Integer fromStep = Integer.valueOf(request.getParameter("FromStep"));
String importProperty = "N";
if (request.getParameter("ImportProperty") != null) {
LOG.debug(request.getParameter("ImportProperty"));
importProperty = request.getParameter("ImportProperty");
}
/**
* Get TestCaseStep, List of TestCaseStepAction and List of
* TestCaseStepActionControl from Test, Testcase, Step
*/
TestCaseStep fromTcs = testCaseStepService.findTestCaseStep(fromTest, fromTestCase, fromStep);
List<TestCaseStepAction> fromTcsa = testCaseStepActionService.getListOfAction(fromTest, fromTestCase, fromStep);
List<TestCaseStepActionControl> fromTcsac = testCaseStepActionControlService.findControlByTestTestCaseStep(fromTest, fromTestCase, fromStep);
/**
* Get List of Country of the origin testcase and the destination
* Testcase
*/
List<String> tccListString = null;
List<String> tccFromListString = null;
List<TestCaseCountryProperties> tccpList = null;
if (importProperty.equalsIgnoreCase("Y")) {
tccListString = testCaseCountry.findListOfCountryByTestTestCase(test, testCase);
tccFromListString = testCaseCountry.findListOfCountryByTestTestCase(test, testCase);
}
/**
* Modify the object with the target test, testcase, step, country
*/
LOG.debug("Rewrite TestCaseStep");
fromTcs.setTest(test);
fromTcs.setTestCase(testCase);
fromTcs.setStep(step);
LOG.debug("Rewrite TestCaseStepAction");
List<TestCaseStepAction> tcsaToImport = new ArrayList();
// retrieve list of property name used in the step
List<String> propertyNamesOfStep = new ArrayList<String>();
for (TestCaseStepAction tcsa : fromTcsa) {
tcsa.setTest(test);
tcsa.setTestCase(testCase);
tcsa.setStep(step);
tcsaToImport.add(tcsa);
if (!propertyNamesOfStep.contains(tcsa.getValue2())) {
propertyNamesOfStep.add(tcsa.getValue2());
}
}
LOG.debug("Rewrite TestCaseStepActionControl");
List<TestCaseStepActionControl> tcsacToImport = new ArrayList();
for (TestCaseStepActionControl tcsac : fromTcsac) {
tcsac.setTest(test);
tcsac.setTestCase(testCase);
tcsac.setStep(step);
tcsacToImport.add(tcsac);
}
/**
* For the country defined in the destination testcase, insert the
* properties of the origine testcase
*/
List<TestCaseCountryProperties> tccpToImport = new ArrayList();
if (importProperty.equalsIgnoreCase("Y")) {
LOG.debug("Rewrite TestCaseCountryProperties");
if (tccListString != null) {
tccListString.retainAll(tccFromListString);
if (!tccListString.isEmpty()) {
for (String country : tccListString) {
tccpList = testCaseCountryProperties.findListOfPropertyPerTestTestCaseCountry(fromTest, fromTestCase, country);
for (TestCaseCountryProperties tccp : tccpList) {
if (propertyNamesOfStep.contains(tccp.getProperty())) {
tccp.setTest(test);
tccp.setTestCase(testCase);
tccpToImport.add(tccp);
}
}
}
}
}
}
/**
* Import Step, List of testcasestepaction, List of
* testcasestepactioncontrol
*/
LOG.debug("Import Step");
testCaseStepService.create(fromTcs);
testCaseStepActionService.insertListTestCaseStepAction(tcsaToImport);
testCaseStepActionControlService.insertListTestCaseStepActionControl(tcsacToImport);
if (importProperty.equalsIgnoreCase("Y")) {
// testCaseCountry.insertListTestCaseCountry(tccToImport);
testCaseCountryProperties.insertListTestCaseCountryProperties(tccpToImport);
}
response.sendRedirect("TestCase.jsp?Load=Load&Test=" + test + "&TestCase=" + testCase);
}
use of org.cerberus.crud.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class DeleteTestCaseFromTestPage 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
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
String[] tcToDelete = request.getParameterValues("test_testcase_delete");
String testToDelete = policy.sanitize(request.getParameter("test_of_page"));
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseService tcService = appContext.getBean(ITestCaseService.class);
ITestCaseStepService tcsService = appContext.getBean(ITestCaseStepService.class);
try {
for (String ttd : tcToDelete) {
TestCase testCase = tcService.findTestCaseByKey(testToDelete, ttd);
if (testCase != null) {
List<TestCaseStep> tcsList = tcsService.getTestCaseStepUsingTestCaseInParamter(testCase.getTest(), testCase.getTestCase());
if (tcsList != null && !tcsList.isEmpty()) {
response.sendError(403, MessageGeneralEnum.GUI_TESTCASE_DELETE_USED_STEP.getDescription());
return;
}
tcService.deleteTestCase(testCase);
} else {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
}
} catch (CerberusException ex) {
LOG.warn(ex);
}
response.sendRedirect("Test.jsp?stestbox=" + testToDelete);
}
use of org.cerberus.crud.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class DuplicateTestCase method processRequest.
// </editor-fold>
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException, CerberusException {
JSONObject jsonResponse = new JSONObject();
Answer ans = new Answer();
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");
// Calling Servlet Transversal Util.
ServletUtil.servletStart(request);
/**
* Parsing and securing all required parameters.
*/
String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");
String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), "");
String originalTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");
String originalTestCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTestCase"), null);
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(test) || StringUtil.isNullOrEmpty(testCase) || StringUtil.isNullOrEmpty(originalTest) || originalTestCase != null) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case").replace("%OPERATION%", "Duplicate").replace("%REASON%", "mandatory fields are missing."));
ans.setResultMessage(msg);
} else {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
ITestCaseCountryService testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);
ITestCaseStepActionService testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
ITestCaseStepActionControlService testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);
ITestCaseLabelService testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
AnswerItem originalTestAI = testCaseService.readByKey(originalTest, originalTestCase);
AnswerItem targetTestAI = testCaseService.readByKey(test, testCase);
TestCase originalTC = (TestCase) originalTestAI.getItem();
TestCase targetTC = (TestCase) targetTestAI.getItem();
if (!(originalTestAI.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && originalTestAI.getItem() != null)) {
/**
* Object could not be found. We stop here and report the error.
*/
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "TestCase does not exist."));
ans.setResultMessage(msg);
} else /**
* The service was able to perform the query and confirm the object
* exist, then we can update it.
*/
if (!request.isUserInRole("Test")) {
// We cannot update the testcase if the user is not at least in Test role.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "Not enought privilege to duplicate the testcase. You must belong to Test Privilege."));
ans.setResultMessage(msg);
} else if (targetTC != null) {
// If target Test Case already exists.
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "The test case you try to create already exists. Please define a test/testcase that is not already existing."));
ans.setResultMessage(msg);
} else {
getInfo(request, originalTC);
// Update object with new testcase id and insert it in db
originalTC.setTest(test);
originalTC.setTestCase(testCase);
ans = testCaseService.create(originalTC);
List<TestCaseCountry> countryList = new ArrayList();
countryList = testCaseCountryService.findTestCaseCountryByTestTestCase(originalTest, originalTestCase);
boolean success = true;
if (!countryList.isEmpty()) {
ans = testCaseCountryService.duplicateList(countryList, test, testCase);
}
// List<TestCaseCountry> countryList = getCountryList(test, testCase, request);
// boolean success = false;
// if (countryList.isEmpty()) {
// success = true;
// } else {
// success = testCaseCountryService.insertListTestCaseCountry(countryList);
// }
List<TestCaseCountryProperties> tccpList = new ArrayList();
if (!countryList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tccpList = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCase(originalTest, originalTestCase);
if (!tccpList.isEmpty()) {
ans = testCaseCountryPropertiesService.duplicateList(tccpList, test, testCase);
}
}
List<TestCaseStep> tcsList = new ArrayList();
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tcsList = testCaseStepService.getListOfSteps(originalTest, originalTestCase);
if (!tcsList.isEmpty()) {
ans = testCaseStepService.duplicateList(tcsList, test, testCase);
}
}
List<TestCaseStepAction> tcsaList = new ArrayList();
if (!tcsList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
tcsaList = testCaseStepActionService.findTestCaseStepActionbyTestTestCase(originalTest, originalTestCase);
if (!tcsaList.isEmpty()) {
ans = testCaseStepActionService.duplicateList(tcsaList, test, testCase);
}
}
if (!tcsList.isEmpty() && !tcsaList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
List<TestCaseStepActionControl> tcsacList = testCaseStepActionControlService.findControlByTestTestCase(originalTest, originalTestCase);
if (!tcsacList.isEmpty()) {
ans = testCaseStepActionControlService.duplicateList(tcsacList, test, testCase);
}
}
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
List<TestCaseLabel> tclList = testCaseLabelService.readByTestTestCase(originalTest, originalTestCase).getDataList();
if (!tclList.isEmpty()) {
ans = testCaseLabelService.duplicateList(tclList, test, testCase);
}
}
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate"));
ans.setResultMessage(msg);
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/DuplicateTestCase", "CREATE", "Create testcase : ['" + test + "'|'" + testCase + "']", 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();
}
use of org.cerberus.crud.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class GetStepInLibrary 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
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException {
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
// String system = policy.sanitize(request.getParameter("system"));
String system = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("system"), null);
String test = policy.sanitize(request.getParameter("test"));
String testCase = policy.sanitize(request.getParameter("testCase"));
String withTestCase = policy.sanitize(request.getParameter("withTestCase"));
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);
ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
JSONArray array = new JSONArray();
JSONObject jsonObject = new JSONObject();
try {
List<TestCaseStep> tcsList;
if (test.equals("") && testCase.equals("")) {
tcsList = testCaseStepService.getStepLibraryBySystem(system);
} else if (testCase.equals("")) {
tcsList = testCaseStepService.getStepLibraryBySystemTest(system, test);
} else {
tcsList = testCaseStepService.getStepLibraryBySystemTestTestCase(system, test, testCase);
}
for (TestCaseStep list : tcsList) {
JSONObject tcs = new JSONObject();
tcs.put("test", list.getTest());
tcs.put("testCase", list.getTestCase());
tcs.put("step", list.getStep());
tcs.put("sort", list.getSort());
tcs.put("description", list.getDescription());
if (list.getTestCaseObj() != null) {
tcs.put("tcdesc", list.getTestCaseObj().getDescription());
tcs.put("tcapp", list.getTestCaseObj().getApplication());
}
array.put(tcs);
}
jsonObject.put("testCaseStepList", array);
response.setContentType("application/json");
response.getWriter().print(jsonObject.toString());
} catch (JSONException exception) {
LOG.warn(exception.toString());
}
}
use of org.cerberus.crud.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class DeleteTest method externallyUsedTestCaseSteps.
/**
* Get {@link TestCaseStep} which are using an other {@link TestCaseStep} from the given {@link Test} but which are NOT included into this {@link Test}
*
* @param test the {@link Test} from which getting externally used {@link TestCaseStep}s
* @return a {@link Collection} of {@link TestCaseStep} which are using an other {@link TestCaseStep} from the given {@link Test} but which are NOT included into this {@link Test}
* @throws CerberusException if an unexpected error occurred
*/
private Collection<TestCaseStep> externallyUsedTestCaseSteps(final Test test) throws CerberusException {
// Get the associated ApplicationContext to this servlet
final ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
// Get all TestCaseSteps which are using an other TestCaseSteps from given Test
final ITestCaseStepService testCaseStepService = applicationContext.getBean(ITestCaseStepService.class);
final List<TestCaseStep> stepsInUse = testCaseStepService.getTestCaseStepsUsingTestInParameter(test.getTest());
// Filter the retrieved list to only retain those which are not included from the given Test
return Collections2.filter(stepsInUse, new Predicate<TestCaseStep>() {
@Override
public boolean apply(@Nullable final TestCaseStep input) {
return !input.getTest().equals(test.getTest());
}
@Override
public boolean test(TestCaseStep t) {
// To change body of generated methods, choose Tools | Templates.
return Predicate.super.test(t);
}
});
}
Aggregations