use of org.cerberus.crud.factory.IFactoryTestCaseCountryProperties in project cerberus-source by cerberustesting.
the class UpdateTestCaseWithDependencies method getTestCaseCountryPropertiesFromParameter.
private List<TestCaseCountryProperties> getTestCaseCountryPropertiesFromParameter(HttpServletRequest request, ApplicationContext appContext, String test, String testCase) {
List<TestCaseCountryProperties> testCaseCountryProp = new ArrayList();
String[] testcase_properties_increment = getParameterValuesIfExists(request, "property_increment");
IFactoryTestCaseCountryProperties testCaseCountryPropertiesFactory = appContext.getBean(IFactoryTestCaseCountryProperties.class);
if (testcase_properties_increment != null) {
for (String inc : testcase_properties_increment) {
String[] countries = getParameterValuesIfExists(request, "properties_country_" + inc);
String delete = getParameterIfExists(request, "properties_delete_" + inc);
String property = getParameterIfExists(request, "properties_property_" + inc);
String description = getParameterIfExists(request, "properties_description_" + inc);
String type = getParameterIfExists(request, "properties_type_" + inc);
String value = getParameterIfExists(request, "properties_value1_" + inc);
String value2 = getParameterIfExists(request, "properties_value2_" + inc);
String length = ParameterParserUtil.parseStringParam(getParameterIfExists(request, "properties_length_" + inc), "0");
int rowLimit = getParameterIfExists(request, "properties_rowlimit_" + inc).equals("") ? 0 : Integer.parseInt(getParameterIfExists(request, "properties_rowlimit_" + inc));
int retryNb = getParameterIfExists(request, "properties_retrynb_" + inc).equals("") ? 0 : Integer.parseInt(getParameterIfExists(request, "properties_retrynb_" + inc));
int retryPeriod = getParameterIfExists(request, "properties_retryperiod_" + inc).equals("") ? 0 : Integer.parseInt(getParameterIfExists(request, "properties_retryperiod_" + inc));
String nature = getParameterIfExists(request, "properties_nature_" + inc);
String database = getParameterIfExists(request, "properties_dtb_" + inc);
if (countries != null) {
for (String country : countries) {
if (delete == null && property != null && !property.equals("")) {
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.factory.IFactoryTestCaseCountryProperties 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.factory.IFactoryTestCaseCountryProperties 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.factory.IFactoryTestCaseCountryProperties 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