use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class GetPropertiesForTestCase 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");
PrintWriter out = response.getWriter();
try {
String test = request.getParameter("test");
String testcase = request.getParameter("testcase");
String property = request.getParameter("property");
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
JSONArray propertyList = new JSONArray();
List<TestCaseCountryProperties> properties = testCaseCountryPropertiesService.findDistinctPropertiesOfTestCase(test, testcase);
for (TestCaseCountryProperties prop : properties) {
if (property == null || "".equals(property.trim()) || property.equals(prop.getProperty())) {
JSONObject propertyFound = new JSONObject();
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());
propertyFound.put("retryNb", prop.getRetryNb());
propertyFound.put("retryPeriod", prop.getRetryPeriod());
propertyFound.put("cacheExpire", prop.getCacheExpire());
List<String> countriesSelected = testCaseCountryPropertiesService.findCountryByProperty(prop);
JSONArray countries = new JSONArray();
for (String country : countriesSelected) {
countries.put(country);
}
propertyFound.put("country", countries);
propertyList.put(propertyFound);
}
}
response.setContentType("application/json");
response.getWriter().print(propertyList.toString());
} catch (JSONException ex) {
LOG.warn(ex.toString());
} finally {
out.close();
}
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class UpdateTestCaseWithDependencies1 method getTestCaseCountryPropertiesFromParameter.
private List<TestCaseCountryProperties> getTestCaseCountryPropertiesFromParameter(HttpServletRequest request, ApplicationContext appContext, String test, String testCase, JSONArray properties) throws JSONException {
List<TestCaseCountryProperties> testCaseCountryProp = new ArrayList();
// String[] testcase_properties_increment = getParameterValuesIfExists(request, "property_increment");
IFactoryTestCaseCountryProperties testCaseCountryPropertiesFactory = appContext.getBean(IFactoryTestCaseCountryProperties.class);
for (int i = 0; i < properties.length(); i++) {
JSONObject propJson = properties.getJSONObject(i);
boolean delete = propJson.getBoolean("toDelete");
String property = propJson.getString("property");
String description = propJson.getString("description");
int cacheExpire = propJson.getInt("cacheExpire");
String type = propJson.getString("type");
String value = propJson.getString("value1");
String value2 = propJson.getString("value2");
String length = propJson.getString("length");
int rowLimit = propJson.getInt("rowLimit");
int retryNb = propJson.optInt("retryNb");
int retryPeriod = propJson.optInt("retryPeriod");
String nature = propJson.getString("nature");
String database = propJson.getString("database");
JSONArray countries = propJson.getJSONArray("country");
if (!delete && !property.equals("")) {
for (int j = 0; j < countries.length(); j++) {
String country = countries.getString(j);
testCaseCountryProp.add(testCaseCountryPropertiesFactory.create(test, testCase, country, property, description, type, database, value, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire));
}
}
}
return testCaseCountryProp;
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class UpdateTestCaseProperties1 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 CerberusException
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
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 initialTest = request.getParameter("informationInitialTest");
String initialTestCase = request.getParameter("informationInitialTestCase");
String test = request.getParameter("informationTest");
String testCase = request.getParameter("informationTestCase");
boolean duplicate = false;
/**
* Checking all constrains before calling the services.
*/
if (StringUtil.isNullOrEmpty(test) || StringUtil.isNullOrEmpty(testCase)) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case").replace("%OPERATION%", "Update").replace("%REASON%", "mendatory fields are missing."));
ans.setResultMessage(msg);
} else {
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
ITestCaseCountryPropertiesService tccpService = appContext.getBean(ITestCaseCountryPropertiesService.class);
AnswerItem resp = testCaseService.readByKey(test, testCase);
TestCase tc = (TestCase) resp.getItem();
if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.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%", "Update").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 (!testCaseService.hasPermissionsUpdate(tc, request)) {
// 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%", "Update").replace("%REASON%", "Not enought privilege to update the testcase. You mut belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));
ans.setResultMessage(msg);
} else {
// Test Case exist and we can update it so Global update start here //
/**
* TestcaseCountryProperties Update.
*/
List<TestCaseCountryProperties> tccpFromPage = getTestCaseCountryPropertiesFromParameter(request, appContext, test, testCase);
ans = tccpService.compareListAndUpdateInsertDeleteElements(initialTest, initialTestCase, tccpFromPage);
/**
* Adding Log entry.
*/
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
/**
* Update was successful. Adding Log entry.
*/
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/UpdateTestCaseWithDependencies1", "UPDATE", "Update testcase : ['" + tc.getTest() + "'|'" + tc.getTestCase() + "']", 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.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class UpdateTestCaseProperties1 method getTestCaseCountryPropertiesFromParameter.
private List<TestCaseCountryProperties> getTestCaseCountryPropertiesFromParameter(HttpServletRequest request, ApplicationContext appContext, String test, String testCase) throws JSONException {
List<TestCaseCountryProperties> testCaseCountryProp = new ArrayList();
// String[] testcase_properties_increment = getParameterValuesIfExists(request, "property_increment");
IFactoryTestCaseCountryProperties testCaseCountryPropertiesFactory = appContext.getBean(IFactoryTestCaseCountryProperties.class);
JSONArray properties = new JSONArray(request.getParameter("propArr"));
for (int i = 0; i < properties.length(); i++) {
JSONObject propJson = properties.getJSONObject(i);
boolean delete = propJson.getBoolean("toDelete");
String property = propJson.getString("property");
String description = propJson.getString("description");
String type = propJson.getString("type");
String value = propJson.getString("value1");
String value2 = propJson.getString("value2");
String length = propJson.getString("length");
int rowLimit = propJson.getInt("rowLimit");
int retryNb = propJson.optInt("retryNb");
int retryPeriod = propJson.optInt("retryPeriod");
String nature = propJson.getString("nature");
String database = propJson.getString("database");
JSONArray countries = propJson.getJSONArray("country");
if (!delete && !property.equals("")) {
for (int j = 0; j < countries.length(); j++) {
String country = countries.getString(j);
testCaseCountryProp.add(testCaseCountryPropertiesFactory.create(test, testCase, country, property, description, type, database, value, value2, length, rowLimit, nature, retryNb, retryPeriod, 0));
}
}
}
return testCaseCountryProp;
}
use of org.cerberus.crud.entity.TestCaseCountryProperties in project cerberus-source by cerberustesting.
the class CreateNotDefinedProperty 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 {
JSONObject jsonResponse = new JSONObject();
MessageEvent rs = null;
ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(TestCaseCountryPropertiesService.class);
ITestCaseCountryService testCaseCountryService = appContext.getBean(TestCaseCountryService.class);
IFactoryTestCaseCountryProperties factoryTestCaseCountryProperties = appContext.getBean(FactoryTestCaseCountryProperties.class);
try {
String propertyName = request.getParameter("property");
if (propertyName != null) {
propertyName = propertyName.replace("%", "");
}
String toTest = request.getParameter("totest");
String toTestCase = request.getParameter("totestcase");
String propertyType = request.getParameter("propertyType");
String userLanguage = request.getParameter("userLanguage");
// We retrieve all country of the destination TestCase
List<String> toCountriesAll = testCaseCountryService.findListOfCountryByTestTestCase(toTest, toTestCase);
if (toCountriesAll != null && toCountriesAll.size() > 0) {
// Variable for the properties list of the destination TestCase
List<TestCaseCountryProperties> listOfPropertiesToInsert = new ArrayList<TestCaseCountryProperties>();
// Variable for the countries of a property of the destination TestCase
List<String> toCountriesProp;
IDocumentationService docService = appContext.getBean(DocumentationService.class);
String notDefinedProperty = docService.findLabel("page_testcase", "txt_property_not_defined", "** Property not defined **", userLanguage);
// List of all country of the destination test for the current property
List<String> toCountries = new ArrayList<String>();
toCountries.addAll(toCountriesAll);
// Retrieve the country of the destination TestCase for the property,
// if not empty remove it (property aleady exists for these countries)
toCountriesProp = testCaseCountryPropertiesService.findCountryByPropertyNameAndTestCase(toTest, toTestCase, propertyName);
if (toCountriesProp != null && toCountriesProp.size() > 0) {
toCountries.removeAll(toCountriesProp);
}
for (String country : toCountries) {
listOfPropertiesToInsert.add(factoryTestCaseCountryProperties.create(toTest, toTestCase, country, propertyName, "", propertyType, "---", notDefinedProperty, "", "0", 0, "STATIC", 0, 10000, 0));
}
Answer answer = testCaseCountryPropertiesService.createListTestCaseCountryPropertiesBatch(listOfPropertiesToInsert);
rs = answer.getResultMessage();
// then a new entry should be added by the log service
if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
// Adding Log entry.
ILogEventService logEventService = appContext.getBean(LogEventService.class);
logEventService.createForPrivateCalls("/CreateNotDefinedProperty", "CREATE", "Create NotDefinedProperty:" + " " + propertyName, request);
}
} else {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
rs.setDescription(rs.getDescription().replace("%ITEM%", "Property ").replace("%OPERATION%", "CREATE").replace("%REASON%", "No countries were defined for the test case."));
}
// sets the message returned by the operations
jsonResponse.put("messageType", rs.getMessage().getCodeString());
jsonResponse.put("message", rs.getDescription());
response.setContentType("application/json");
response.getWriter().print(jsonResponse);
response.getWriter().flush();
} catch (JSONException ex) {
LOG.warn(ex);
// returns a default error message with the json format that is able to be parsed by the client-side
response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
}
}
Aggregations