use of org.cerberus.crud.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class GetStepUsedAsLibraryInOtherTestCasePerApplication method processRequest.
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 echo = policy.sanitize(request.getParameter("sEcho"));
String system = policy.sanitize(request.getParameter("System"));
JSONObject jsonResponse = new JSONObject();
try {
JSONArray data = new JSONArray();
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseStepService stepService = appContext.getBean(ITestCaseStepService.class);
for (TestCaseStep tcs : stepService.getStepLibraryBySystem(system)) {
JSONArray row = new JSONArray();
StringBuilder testLink = new StringBuilder();
testLink.append("<a href=\"TestCaseList.jsp?test=");
testLink.append(tcs.getTest());
testLink.append("\">");
testLink.append(tcs.getTest());
testLink.append("</a>");
row.put(testLink.toString());
StringBuilder testcaseLink = new StringBuilder();
testcaseLink.append("<a href=\"TestCaseScript.jsp?test=");
testcaseLink.append(tcs.getTest());
testcaseLink.append("&testcase=");
testcaseLink.append(tcs.getTestCase());
testcaseLink.append("\">");
testcaseLink.append(tcs.getTestCase());
testcaseLink.append("</a>");
row.put(testcaseLink.toString());
row.put(tcs.getStep());
row.put(tcs.getDescription());
data.put(row);
}
// data that will be shown in the table
jsonResponse.put("aaData", data);
jsonResponse.put("sEcho", echo);
jsonResponse.put("iTotalRecords", data.length());
jsonResponse.put("iTotalDisplayRecords", data.length());
response.setContentType("application/json");
response.getWriter().print(jsonResponse.toString());
} catch (JSONException ex) {
LOG.warn(ex.toString());
} catch (CerberusException ex) {
LOG.warn(ex);
}
}
use of org.cerberus.crud.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class ReadTestCaseStep method getStepUsesByKey.
private JSONObject getStepUsesByKey(String test, String testcase, int step, ApplicationContext appContext, HttpServletResponse response) throws JSONException {
JSONObject jsonResponse = new JSONObject();
ITestCaseStepService stepService = appContext.getBean(TestCaseStepService.class);
AnswerList answer = stepService.readByLibraryUsed(test, testcase, step);
JSONArray res = new JSONArray();
for (Object obj : answer.getDataList()) {
TestCaseStep testCaseStep = (TestCaseStep) obj;
Gson gson = new Gson();
JSONObject result = new JSONObject(gson.toJson(testCaseStep));
res.put(result);
}
jsonResponse.put("step", res);
return jsonResponse;
}
use of org.cerberus.crud.service.ITestCaseStepService 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.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class UpdateTestCaseWithDependencies 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
* @throws org.cerberus.exception.CerberusException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
String initialTest = request.getParameter("informationInitialTest");
String initialTestCase = request.getParameter("informationInitialTestCase");
String test = request.getParameter("informationTest");
String testCase = request.getParameter("informationTestCase");
TestCase tc = getTestCaseFromParameter(request, appContext, test, testCase);
boolean duplicate = false;
ITestService tService = appContext.getBean(ITestService.class);
ITestCaseService tcService = appContext.getBean(ITestCaseService.class);
ITestCaseCountryService tccService = appContext.getBean(ITestCaseCountryService.class);
ITestCaseCountryPropertiesService tccpService = appContext.getBean(ITestCaseCountryPropertiesService.class);
ITestCaseStepService tcsService = appContext.getBean(ITestCaseStepService.class);
ITestCaseStepActionService tcsaService = appContext.getBean(ITestCaseStepActionService.class);
ITestCaseStepActionControlService tcsacService = appContext.getBean(ITestCaseStepActionControlService.class);
IInvariantService invariantService = appContext.getBean(IInvariantService.class);
IUserService userService = appContext.getBean(IUserService.class);
IUserGroupService userGroupService = appContext.getBean(IUserGroupService.class);
/**
* Get User and Groups of this user
*/
User user = userService.findUserByKey(request.getUserPrincipal().getName());
// List<UserGroup> userGroupList = groupService.findGroupByUser(user);
List<UserGroup> userGroupList = userGroupService.convert(userGroupService.readByUser(user.getLogin()));
List<String> groupList = new ArrayList();
for (UserGroup group : userGroupList) {
groupList.add(group.getGroup());
}
/**
* Verify the Test is the same than initialTest If it is the same > Do
* nothing If it is not the same > Verify if test already exists If not
* exist > create it If exist > do nothing
*/
if (!tc.getTest().equals(initialTest)) {
if (tService.findTestByKey(tc.getTest()) == null) {
if (groupList.contains("TestAdmin")) {
Test newTest = tService.findTestByKey(initialTest);
newTest.setTest(tc.getTest());
tService.convert(tService.create(newTest));
} else {
response.sendError(403, MessageGeneralEnum.GUI_TEST_CREATION_NOT_HAVE_RIGHT.getDescription());
return;
}
}
}
if (!tc.getTest().equals(initialTest) || !tc.getTestCase().equals(initialTestCase)) {
duplicate = true;
}
/**
* If the testcase is a duplication, set the creator as the one which
* duplicate the testcase and the status in the initial one.
*/
if (duplicate) {
tc.setUsrCreated(user.getLogin());
// TODO: handle if the response does not turn ok
AnswerList answer = invariantService.readByIdname("TCSTATUS");
tc.setStatus(((List<Invariant>) answer.getDataList()).get(0).getValue());
}
/**
* If not duplicate and test in Working status and user with no admin
* right, raise an error
*/
if (!duplicate && "WORKING".equals(tc.getStatus()) && !groupList.contains("TestAdmin")) {
response.sendError(403, MessageGeneralEnum.GUI_TESTCASE_NON_ADMIN_SAVE_WORKING_TESTCASE.getDescription());
return;
}
/**
* Verify testcase is the same than initialTestCase If it is the same >
* update If it is not the same, > verify if testcase already exist If
* it already exist > Send Error If it do not already exists > Create it
*/
if (!duplicate) {
tcService.updateTestCase(tc);
} else if (tcService.findTestCaseByKey(tc.getTest(), tc.getTestCase()) != null) {
response.sendError(403, MessageGeneralEnum.GUI_TESTCASE_DUPLICATION_ALREADY_EXISTS.getDescription());
return;
} else {
tcService.createTestCase(tc);
}
/**
* For the list of testcase country verify it exists. If it does not
* exists > create it If it exist, verify if it's the
*/
List<TestCaseCountry> tccFromPage = getTestCaseCountryFromParameter(request, appContext, test, testCase);
List<TestCaseCountry> tccFromDtb = tccService.findTestCaseCountryByTestTestCase(initialTest, initialTestCase);
/**
* Iterate on (TestCaseCountry From Page - TestCaseCountry From
* Database) If TestCaseCountry in Database has same key : Update and
* remove from the list. If TestCaseCountry in database does ot exist :
* Insert it.
*/
List<TestCaseCountry> tccToUpdateOrInsert = new ArrayList(tccFromPage);
tccToUpdateOrInsert.removeAll(tccFromDtb);
List<TestCaseCountry> tccToUpdateOrInsertToIterate = new ArrayList(tccToUpdateOrInsert);
for (TestCaseCountry tccDifference : tccToUpdateOrInsertToIterate) {
for (TestCaseCountry tccInDatabase : tccFromDtb) {
if (tccDifference.hasSameKey(tccInDatabase)) {
tccToUpdateOrInsert.remove(tccDifference);
}
}
}
tccService.insertListTestCaseCountry(tccToUpdateOrInsert);
/**
* Iterate on (TestCaseCountry From Database - TestCaseCountry From
* Page). If TestCaseCountry in Page has same key : remove from the
* list. Then delete the list of TestCaseCountry
*/
if (!duplicate) {
List<TestCaseCountry> tccToDelete = new ArrayList(tccFromDtb);
tccToDelete.removeAll(tccFromPage);
List<TestCaseCountry> tccToDeleteToIterate = new ArrayList(tccToDelete);
for (TestCaseCountry tccDifference : tccToDeleteToIterate) {
for (TestCaseCountry tccInPage : tccFromPage) {
if (tccDifference.hasSameKey(tccInPage)) {
tccToDelete.remove(tccDifference);
}
}
}
tccService.deleteListTestCaseCountry(tccToDelete);
}
/**
* For the list of testcase country verify it exists. If it does not
* exists > create it If it exist, verify if it's the
*/
List<TestCaseCountryProperties> tccpFromPage = getTestCaseCountryPropertiesFromParameter(request, appContext, test, testCase);
List<TestCaseCountryProperties> tccpFromDtb = tccpService.findListOfPropertyPerTestTestCase(initialTest, initialTestCase);
/**
* Iterate on (TestCaseCountryProperties From Page -
* TestCaseCountryProperties From Database) If TestCaseCountryProperties
* in Database has same key : Update and remove from the list. If
* TestCaseCountryProperties in database does ot exist : Insert it.
*/
List<TestCaseCountryProperties> tccpToUpdateOrInsert = new ArrayList(tccpFromPage);
tccpToUpdateOrInsert.removeAll(tccpFromDtb);
List<TestCaseCountryProperties> tccpToUpdateOrInsertToIterate = new ArrayList(tccpToUpdateOrInsert);
for (TestCaseCountryProperties tccpDifference : tccpToUpdateOrInsertToIterate) {
for (TestCaseCountryProperties tccpInDatabase : tccpFromDtb) {
if (tccpDifference.hasSameKey(tccpInDatabase)) {
tccpService.updateTestCaseCountryProperties(tccpDifference);
tccpToUpdateOrInsert.remove(tccpDifference);
}
}
}
tccpService.insertListTestCaseCountryProperties(tccpToUpdateOrInsert);
/**
* Iterate on (TestCaseCountryProperties From Database -
* TestCaseCountryProperties From Page). If TestCaseCountryProperties in
* Page has same key : remove from the list. Then delete the list of
* TestCaseCountryProperties
*/
if (!duplicate) {
List<TestCaseCountryProperties> tccpToDelete = new ArrayList(tccpFromDtb);
tccpToDelete.removeAll(tccpFromPage);
List<TestCaseCountryProperties> tccpToDeleteToIterate = new ArrayList(tccpToDelete);
for (TestCaseCountryProperties tccpDifference : tccpToDeleteToIterate) {
for (TestCaseCountryProperties tccpInPage : tccpFromPage) {
if (tccpDifference.hasSameKey(tccpInPage)) {
tccpToDelete.remove(tccpDifference);
}
}
}
tccpService.deleteListTestCaseCountryProperties(tccpToDelete);
}
/*
* Get steps, actions and controls from page by:
* - generating a new step, action or control number,
* - setting the correct related step and action for action or control
*/
List<TestCaseStep> tcsFromPage = getTestCaseStepFromParameter(request, appContext, test, testCase, duplicate);
List<TestCaseStepAction> tcsaFromPage = new ArrayList();
List<TestCaseStepActionControl> tcsacFromPage = new ArrayList();
int nextStepNumber = getMaxStepNumber(tcsFromPage);
for (TestCaseStep tcs : tcsFromPage) {
if (tcs.getStep() == -1) {
tcs.setStep(++nextStepNumber);
}
if (tcs.getTestCaseStepAction() != null) {
int nextSequenceNumber = getMaxSequenceNumber(tcs.getTestCaseStepAction());
for (TestCaseStepAction tcsa : tcs.getTestCaseStepAction()) {
if (tcsa.getSequence() == -1) {
tcsa.setSequence(++nextSequenceNumber);
}
tcsa.setStep(tcs.getStep());
if (tcsa.getTestCaseStepActionControl() != null) {
int nextControlNumber = getMaxControlNumber(tcsa.getTestCaseStepActionControl());
for (TestCaseStepActionControl tscac : tcsa.getTestCaseStepActionControl()) {
if (tscac.getControlSequence() == -1) {
tscac.setControlSequence(++nextControlNumber);
}
tscac.setStep(tcs.getStep());
tscac.setSequence(tcsa.getSequence());
}
tcsacFromPage.addAll(tcsa.getTestCaseStepActionControl());
}
}
tcsaFromPage.addAll(tcs.getTestCaseStepAction());
}
}
/*
* Create, update or delete step, action and control according to the needs
*/
List<TestCaseStep> tcsFromDtb = new ArrayList(tcsService.getListOfSteps(initialTest, initialTestCase));
tcsService.compareListAndUpdateInsertDeleteElements(tcsFromPage, tcsFromDtb, duplicate);
List<TestCaseStepAction> tcsaFromDtb = new ArrayList(tcsaService.findTestCaseStepActionbyTestTestCase(initialTest, initialTestCase));
tcsaService.compareListAndUpdateInsertDeleteElements(tcsaFromPage, tcsaFromDtb, duplicate);
List<TestCaseStepActionControl> tcsacFromDtb = new ArrayList(tcsacService.findControlByTestTestCase(initialTest, initialTestCase));
tcsacService.compareListAndUpdateInsertDeleteElements(tcsacFromPage, tcsacFromDtb, duplicate);
/**
* Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateTestCase", "UPDATE", "Update testcase : ['" + tc.getTest() + "'|'" + tc.getTestCase() + "']", request);
String encodedTest = URLEncoder.encode(tc.getTest(), "UTF-8");
String encodedTestCase = URLEncoder.encode(tc.getTestCase(), "UTF-8");
response.sendRedirect(response.encodeRedirectURL("TestCase.jsp?Load=Load&Test=" + encodedTest + "&TestCase=" + encodedTestCase));
}
use of org.cerberus.crud.service.ITestCaseStepService in project cerberus-source by cerberustesting.
the class UseTestCaseStep 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());
ITestCaseStepActionService testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);
IFactoryTestCaseStep testCaseStepFactory = appContext.getBean(IFactoryTestCaseStep.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 loop = request.getParameter("Loop");
String conditionOper = request.getParameter("ConditionOper");
String conditionVal1 = request.getParameter("ConditionVal1");
String conditionVal2 = request.getParameter("ConditionVal2");
String description = request.getParameter("Description");
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");
}
TestCaseStep tcs = testCaseStepFactory.create(test, testCase, step, step, loop, conditionOper, conditionVal1, conditionVal2, description, "Y", fromTest, fromTestCase, fromStep, null);
/**
* Import Step, properties
*/
LOG.debug("Use Step");
testCaseStepService.create(tcs);
if (importProperty.equalsIgnoreCase("Y")) {
/**
* 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);
}
/**
* For the country defined in the destination testcase, insert the
* properties of the origine testcase
*/
// retrieve list of property name used in the step
List<String> propertyNamesOfStep = new ArrayList<String>();
List<TestCaseStepAction> testCaseStepActions = testCaseStepActionService.getListOfAction(fromTest, fromTestCase, fromStep);
for (TestCaseStepAction action : testCaseStepActions) {
if (!propertyNamesOfStep.contains(action.getValue2())) {
propertyNamesOfStep.add(action.getValue2());
}
}
LOG.debug("Rewrite TestCaseCountryProperties");
if (tccListString != null) {
tccListString.retainAll(tccFromListString);
if (tccListString.size() > 0 && propertyNamesOfStep.size() > 0) {
List<TestCaseCountryProperties> tccpToImport = new ArrayList();
for (String country : tccListString) {
tccpList = testCaseCountryProperties.findListOfPropertyPerTestTestCaseCountry(fromTest, fromTestCase, country);
for (TestCaseCountryProperties tccp : tccpList) {
// only add property of the test case if it is used by the step
if (propertyNamesOfStep.contains(tccp.getProperty())) {
tccp.setTest(test);
tccp.setTestCase(testCase);
tccpToImport.add(tccp);
}
}
}
// if the list of property to import is not empty, insert them.
if (!tccpToImport.isEmpty()) {
testCaseCountryProperties.insertListTestCaseCountryProperties(tccpToImport);
}
}
}
}
response.sendRedirect("TestCase.jsp?Load=Load&Test=" + test + "&TestCase=" + testCase);
}
Aggregations