@Override public void createSoapLibrary(SoapLibrary soapLibrary) throws CerberusException { boolean throwExcep = false; StringBuilder query = new StringBuilder(); query.append( "INSERT INTO soaplibrary (`Type`, `Name`, `Envelope`, `Description`, `ServicePath`, `ParsingAnswer`, `Method`) "); query.append("VALUES (?,?,?,?,?,?,?);"); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setString(1, soapLibrary.getType()); preStat.setString(2, soapLibrary.getName()); preStat.setString(3, soapLibrary.getEnvelope()); preStat.setString(4, soapLibrary.getDescription()); preStat.setString(5, soapLibrary.getServicePath()); preStat.setString(6, soapLibrary.getParsingAnswer()); preStat.setString(7, soapLibrary.getMethod()); preStat.executeUpdate(); throwExcep = false; } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(SoapLibraryDAO.class.getName(), Level.WARN, e.toString()); } } if (throwExcep) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE)); } }
@Override public List<SoapLibrary> findAllSoapLibrary() { List<SoapLibrary> list = null; final String query = "SELECT * FROM SoapLibrary"; Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query); try { ResultSet resultSet = preStat.executeQuery(); list = new ArrayList<SoapLibrary>(); try { while (resultSet.next()) { list.add(this.loadFromResultSet(resultSet)); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(SoapLibraryDAO.class.getName(), Level.WARN, e.toString()); } } return list; }
@Override public void updateSoapLibrary(String name, String columnName, String value) throws CerberusException { boolean throwExcep = false; StringBuilder query = new StringBuilder(); query.append("update soaplibrary set `"); query.append(columnName); query.append("`=? where `name`=? "); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { preStat.setString(1, value); preStat.setString(2, name); preStat.executeUpdate(); throwExcep = false; } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(SoapLibraryDAO.class.getName(), Level.WARN, e.toString()); } } if (throwExcep) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE)); } }
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { this.processRequest(request, response); } catch (CerberusException ex) { MyLogger.log(CreateSoapLibrary.class.getName(), Level.FATAL, ex.toString()); } }
@Override protected void doGet( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); ITestCaseService testService = appContext.getBean(ITestCaseService.class); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); String test = policy.sanitize(httpServletRequest.getParameter("test")); JSONArray array = new JSONArray(); JSONObject jsonObject = new JSONObject(); for (TCase testcase : testService.findTestCaseByTest(test)) { array.put(testcase.getTestCase()); } try { jsonObject.put("testcasesList", array); httpServletResponse.setContentType("application/json"); httpServletResponse.getWriter().print(jsonObject.toString()); } catch (JSONException exception) { MyLogger.log(GetTestCaseList.class.getName(), Level.WARN, exception.toString()); } }
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); DatabaseSpring database = appContext.getBean(DatabaseSpring.class); ITestCaseCountryPropertiesService propertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class); IFactoryTestCaseCountryProperties propertiesFactory = appContext.getBean(IFactoryTestCaseCountryProperties.class); Connection connection = database.connect(); try { Statement stmt4 = connection.createStatement(); try { /* * PROPERTIES */ /* * Get Test, TestCase and Country to update */ String test_testcase_no_format_prop = this.getStringParameter("testcase_hidden", request); this.getStringParameter("Test", request); this.getStringParameter("TestCase", request); String country_list_no_format = this.getStringParameter("CountryList", request); /* * Properties Insert/Update */ String[] testcase_properties_delete = request.getParameterValues("properties_delete"); // this.getStringTable("old_property_hidden", request); // String[] testcase_properties_countr_list = this.getStringTable( // "old_property_hidden", request); String[] testcase_properties_countr_list = request.getParameterValues("old_property_hidden"); if (testcase_properties_countr_list == null) { testcase_properties_countr_list = new String[0]; } String[] testcase_properties_propertyrow = request.getParameterValues("property_hidden"); String[] testcase_properties_property = this.getStringTable("properties_property", request); String[] testcase_properties_description = this.getStringTable("properties_description", request); String[] testcase_properties_country = this.getStringTable("properties_country", request); String[] testcase_properties_type = this.getStringTable("properties_type", request); String[] testcase_properties_value = this.getStringTable("properties_value", request); String[] testcase_properties_value2 = this.getStringTable("properties_value2", request); // String[] testcase_properties_value = // request.getParameterValues("properties_type"); String[] testcase_properties_length = this.getStringTable("properties_length", request); String[] testcase_properties_rowlimit = this.getStringTable("properties_rowlimit", request); String[] testcase_properties_retrynb = this.getStringTable("properties_retrynb", request); String[] testcase_properties_retryperiod = this.getStringTable("properties_retryperiod", request); String[] testcase_properties_nature = this.getStringTable("properties_nature", request); String[] testcase_properties_database = this.getStringTable("properties_dtb", request); /* * 0 : Test 1 : TestCase */ String[] test_testcase_format_prop = new String[] {"", ""}; test_testcase_format_prop = test_testcase_no_format_prop.split(" - "); String[] country_list = country_list_no_format.split(" - "); /* * Properties */ List<String[]> testcase_properties_propertycountry = new ArrayList<String[]>(); testcase_properties_propertycountry.add(testcase_properties_country); List<String[]> testcase_properties_info = new ArrayList<String[]>(); testcase_properties_info.add(testcase_properties_propertyrow); testcase_properties_info.add(testcase_properties_property); testcase_properties_info.add(testcase_properties_type); testcase_properties_info.add(testcase_properties_value); testcase_properties_info.add(testcase_properties_value2); testcase_properties_info.add(testcase_properties_length); testcase_properties_info.add(testcase_properties_rowlimit); testcase_properties_info.add(testcase_properties_retrynb); testcase_properties_info.add(testcase_properties_retryperiod); testcase_properties_info.add(testcase_properties_nature); testcase_properties_info.add(testcase_properties_database); List<String[]> countr_list = new ArrayList<String[]>(); countr_list.add(testcase_properties_countr_list); // To Delete the country unselected Collection<String> listOne = new ArrayList<String>(); Collection<String> listTwo = new ArrayList<String>(); Collection<String> similar = new ArrayList<String>(); Collection<String> different = new ArrayList<String>(); listOne.addAll(Arrays.asList(testcase_properties_countr_list)); listTwo.addAll(Arrays.asList(testcase_properties_country)); similar.addAll(listOne); similar.retainAll(listTwo); different.addAll(listOne); different.removeAll(similar); List<String> differentlist = new ArrayList<String>(different); // ResultSet rs_Properties = stmt4.executeQuery( "SELECT * " + " FROM testcasecountryproperties " + " WHERE Test = '" + test_testcase_format_prop[0] + "'" + " AND TestCase = '" + test_testcase_format_prop[1] + "'"); try { // the country property already exists???? if (rs_Properties.first()) { for (int i = 0; i < testcase_properties_property.length; i++) { for (int j = 0; j < differentlist.size(); j++) { String[] tc_country = new String[] {"", ""}; tc_country = differentlist.get(j).split(" - "); if (testcase_properties_propertyrow[i].equals(tc_country[0])) { // if the number of the line is the same for the // country and the property: Statement stmt3 = connection.createStatement(); try { stmt3.execute( "DELETE FROM testcasecountryproperties " + " WHERE Test = '" + test_testcase_format_prop[0] + "' " + " AND TestCase = '" + test_testcase_format_prop[1] + "' " + " AND Country = '" + tc_country[1] + "' " + " AND Property = '" + testcase_properties_property[i] + "'"); } finally { stmt3.close(); } // Is the country exist in the database?? } // end of the if loop } // end of the loop for differnet list } // end of the property loop >>>>>The country unselected have // been removed // Delete the property which have been renamed for (int i = 0; i < testcase_properties_property.length; i++) { for (int p = 0; p < testcase_properties_countr_list.length; p++) { String[] tc_prop = new String[] {"", "", ""}; tc_prop = testcase_properties_countr_list[p].split(" - "); if (testcase_properties_propertyrow[i].equals(tc_prop[0]) && !testcase_properties_property[i].equals(tc_prop[2])) { Statement stmt3 = connection.createStatement(); try { stmt3.execute( "DELETE FROM testcasecountryproperties " + " WHERE Test = '" + test_testcase_format_prop[0] + "' " + " AND TestCase = '" + test_testcase_format_prop[1] + "' " + " AND Country = '" + tc_prop[1] + "' " + " AND Property = '" + tc_prop[2] + "'"); } finally { stmt3.close(); } } } } // for each line, insert the property when not exist and update // when exist. for (int i = 0; i < testcase_properties_property.length; i++) { // for each country flagged in the page for (int j = 0; j < testcase_properties_country.length; j++) { // separate the number of the line to the country: // example: 1 - AT String[] testcase_country = new String[] {"", ""}; testcase_country = testcase_properties_country[j].split(" - "); // if the number of the line is the same for the country // and the property: if (testcase_properties_propertyrow[i].equals(testcase_country[0])) { Statement stmt3 = connection.createStatement(); try { ResultSet rs_numberOfTestCasesCountryProperties = stmt3.executeQuery( "SELECT Test, TestCase, Country, Property " + " FROM testcasecountryproperties " + " WHERE Test = '" + test_testcase_format_prop[0] + "'" + " AND TestCase = '" + test_testcase_format_prop[1] + "'" + " AND Country = '" + testcase_country[1] + "'" + " AND Property = '" + testcase_properties_property[i] + "'"); try { // Is the country exist in the database?? // the country property already exists, make an // update if (rs_numberOfTestCasesCountryProperties.first()) { String test = test_testcase_format_prop[0]; String testcase = test_testcase_format_prop[1]; String country = testcase_country[1]; String property = testcase_properties_property[i]; String description = testcase_properties_description[i]; String nature = testcase_properties_nature[i]; int rowlimit = Integer.parseInt(testcase_properties_rowlimit[i]); int length = Integer.parseInt(testcase_properties_length[i]); int retryNb = Integer.parseInt(testcase_properties_retrynb[i]); int retryPeriod = Integer.parseInt(testcase_properties_retryperiod[i]); String value1 = testcase_properties_value[i]; String value2 = testcase_properties_value2[i]; String type = testcase_properties_type[i]; String dtb = testcase_properties_database[i]; TestCaseCountryProperties tccp = propertiesFactory.create( test, testcase, country, property, description, type, dtb, value1, value2, length, rowlimit, nature, retryNb, retryPeriod); propertiesService.updateTestCaseCountryProperties(tccp); } else // the country property does'nt extist, make an // insert : { /* * Insert new rows */ String test = test_testcase_format_prop[0]; String testcase = test_testcase_format_prop[1]; String country = testcase_country[1]; String property = testcase_properties_property[i]; String description = testcase_properties_description[i]; String nature = testcase_properties_nature[i]; int rowlimit = Integer.parseInt(testcase_properties_rowlimit[i]); int length = Integer.parseInt(testcase_properties_length[i]); int retryNb = Integer.parseInt(testcase_properties_retrynb[i]); int retryPeriod = Integer.parseInt(testcase_properties_retryperiod[i]); String value1 = testcase_properties_value[i]; String value2 = testcase_properties_value2[i]; String type = testcase_properties_type[i]; String dtb = testcase_properties_database[i]; TestCaseCountryProperties tccp = propertiesFactory.create( test, testcase, country, property, description, type, dtb, value1, value2, length, rowlimit, nature, retryNb, retryPeriod); propertiesService.insertTestCaseCountryProperties(tccp); } // end of the else loop } finally { rs_numberOfTestCasesCountryProperties.close(); } } finally { stmt3.close(); } } // end of the if loop } // Close the loop for country } // Close the loop for (property) } // end of the if loop (property already exists?? else // The property is a first one { for (int i = 0; i < testcase_properties_property.length; i++) { // for each country flagged in the page for (int j = 0; j < testcase_properties_country.length; j++) { // separate the number of the line to the country: // example: 1 - AT String[] testcase_country = new String[] {"", ""}; testcase_country = testcase_properties_country[j].split(" - "); // if the number of the line is the same for the country // and the property: if (testcase_properties_propertyrow[i].equals(testcase_country[0])) { String test = test_testcase_format_prop[0]; String testcase = test_testcase_format_prop[1]; String country = testcase_country[1]; String property = testcase_properties_property[i]; String description = testcase_properties_description[i]; String nature = testcase_properties_nature[i]; int rowlimit = Integer.parseInt(testcase_properties_rowlimit[i]); int length = Integer.parseInt(testcase_properties_length[i]); int retryNb = Integer.parseInt(testcase_properties_retrynb[i]); int retryPeriod = Integer.parseInt(testcase_properties_retryperiod[i]); String value1 = testcase_properties_value[i]; String value2 = testcase_properties_value2[i]; String type = testcase_properties_type[i]; String dtb = testcase_properties_database[i]; TestCaseCountryProperties tccp = propertiesFactory.create( test, testcase, country, property, description, type, dtb, value1, value2, length, rowlimit, nature, retryNb, retryPeriod); propertiesService.insertTestCaseCountryProperties(tccp); } // Close the condition on the row number } // Close the loop for (country) } // Close the else condition } } finally { rs_Properties.close(); } /* * Delete Properties */ if (testcase_properties_delete != null) { // If some properties // check for delete Statement stmt3 = connection.createStatement(); try { for (String element : testcase_properties_delete) { String property_and_country[] = element.split(" - "); for (int i = 1; i < property_and_country.length; i++) { stmt3.execute( "DELETE FROM testcasecountryproperties " + " WHERE Test = '" + test_testcase_format_prop[0] + "' " + " AND TestCase = '" + test_testcase_format_prop[1] + "' " + " AND Country = '" + property_and_country[i] + "' " + " AND Property = '" + property_and_country[0] + "'"); } } } finally { stmt3.close(); } } String sqlupd = "UPDATE testcase " + "SET LastModifier = '" + request.getUserPrincipal().getName() + "' WHERE Test = '" + test_testcase_format_prop[0] + "' AND TestCase = '" + test_testcase_format_prop[1] + "' "; stmt4.execute(sqlupd); /* * END OF PROPERTIES */ /* * Get Test, TestCase and Country to update */ String test_testcase_no_format = this.getStringParameter("testcase_hidden", request); this.getStringParameter("Test", request); this.getStringParameter("TestCase", request); /* * Get TestCase Step Informations */ /* * Step Number & Description */ String step_delete[] = request.getParameterValues("testcasestep_delete"); String step_id[] = this.getStringTable("testcasestep_hidden", request); String step_desc[] = this.getStringTable("step_description", request, true); String step_number_toadd[] = this.getStringTable("step_number_add", request); String step_desc_toadd[] = this.getStringTable("step_description_add", request, true); /* * Step actions */ String step_action_delete[] = request.getParameterValues("actions_delete"); String step_number_hide[] = this.getStringTable("stepnumber_hidden", request); String step_sequence[] = this.getStringTable("actions_sequence", request); String step_action[] = this.getStringTable("actions_action", request); String step_conditionOper[] = this.getStringTable("actions_conditionOper", request); String step_conditionVal1[] = this.getStringTable("actions_conditionVal1", request); String step_conditionVal2[] = this.getStringTable("actions_conditionVal2", request); String step_value1[] = this.getStringTable("actions_value1", request); String step_value2[] = this.getStringTable("actions_value2", request); String step_description[] = this.getStringTable("actions_description", request, true); /* * Get TestCase Step Controls Informations */ String controls_delete[] = request.getParameterValues("controls_delete"); String controls_step[] = this.getStringTable("controls_step", request); String controls_sequence[] = this.getStringTable("controls_sequence", request); String controls_controlsequence[] = this.getStringTable("controls_controlsequence", request); String controls_conditionoper[] = this.getStringTable("controls_conditionoper", request, true); String controls_conditionval1[] = this.getStringTable("controls_conditionval1", request, true); String controls_conditionval2[] = this.getStringTable("controls_conditionval2", request, true); String controls_control[] = this.getStringTable("controls_control", request); String controls_value1[] = this.getStringTable("controls_value1", request); String controls_value2[] = this.getStringTable("controls_value2", request); String controls_description[] = this.getStringTable("controls_description", request, true); String controls_fatal[] = this.getStringTable("controls_fatal", request); /* * Properties Insert/Update */ String[] test_testcase_format = test_testcase_no_format.split(" - "); /* * Properties */ /* * Actions */ List<String[]> testcase_actions_info = new ArrayList<String[]>(); testcase_actions_info.add(step_number_hide); testcase_actions_info.add(step_sequence); testcase_actions_info.add(step_conditionOper); testcase_actions_info.add(step_conditionVal1); testcase_actions_info.add(step_conditionVal2); testcase_actions_info.add(step_action); testcase_actions_info.add(step_value1); testcase_actions_info.add(step_value2); testcase_actions_info.add(step_description); /* * Controls */ List<String[]> testcase_controls_info = new ArrayList<String[]>(); testcase_controls_info.add(controls_step); testcase_controls_info.add(controls_sequence); testcase_controls_info.add(controls_controlsequence); testcase_controls_info.add(controls_description); testcase_controls_info.add(controls_conditionoper); testcase_controls_info.add(controls_conditionval1); testcase_controls_info.add(controls_conditionval2); testcase_controls_info.add(controls_control); testcase_controls_info.add(controls_value1); testcase_controls_info.add(controls_value2); testcase_controls_info.add(controls_fatal); /* * Test Case Step Description */ /* * Update Test Case Step */ int numberOfSteps = 0; Integer steps = 0; ResultSet rs_step = stmt4.executeQuery( "SELECT COUNT(*) " + " FROM testcasestep " + " WHERE Test = '" + test_testcase_format[0] + "'" + " AND TestCase = '" + test_testcase_format[1] + "'"); try { if (rs_step.next()) { numberOfSteps = rs_step.getInt(1); } if (request.getParameter("step_number_add") != null) { steps = Integer.parseInt(request.getParameter("step_number_add")); } if (steps == null || steps == 0) { steps = step_id.length; } } finally { rs_step.close(); } for (int i = 0; i < steps; i++) { int i2 = i + 1; String step_batch[] = request.getParameterValues("batch-" + i2); if (i < numberOfSteps) { stmt4.executeUpdate( "UPDATE testcasestep " + " SET Description = '" + step_desc[i] + "' " + " WHERE Test = '" + test_testcase_format[0] + "'" + " AND TestCase = '" + test_testcase_format[1] + "' " + " AND Step = " + step_id[i] + ""); stmt4.executeUpdate( "DELETE FROM testcasestepbatch WHERE " + " test = '" + test_testcase_format[0] + "' " + " AND TestCase = '" + test_testcase_format[1] + "' AND STEP = '" + step_id[i] + "' "); if (step_batch != null) { for (int j = 0; j < step_batch.length; j++) { try { stmt4.executeUpdate( "INSERT INTO testcasestepbatch (`Test`, `TestCase`, `Step`, `Batch`) VALUES ( " + "'" + test_testcase_format[0] + "', " + "'" + test_testcase_format[1] + "', " + "'" + step_id[i] + "', " + "'" + step_batch[j] + "' )"); } catch (Exception e) { MyLogger.log( UpdateTestCaseDetail.class.getName(), Level.FATAL, "Error on insert into TestCaseStepBatch: " + e.toString()); } } } } } /* * Insert Test Case Step */ for (int i = 0; i < step_number_toadd.length; i++) { if (this.formIsFill(step_number_toadd[i]) && this.formIsFill(step_desc_toadd[i])) { String sql = ("INSERT INTO testcasestep (`Test`,`Testcase`,`Step`,`Description`) " + " VALUES('" + test_testcase_format[0] + "', " + "'" + test_testcase_format[1] + "', " + step_number_toadd[i] + ", " + "'" + step_desc_toadd[i] + "')"); stmt4.execute(sql); } stmt4.executeUpdate( "DELETE FROM testcasestepbatch WHERE " + " test = '" + test_testcase_format[0] + "' " + " AND TestCase = '" + test_testcase_format[1] + "' AND STEP = '" + request.getParameter("step_number_add") + "' "); String step_batch[] = request.getParameterValues("batch-" + step_number_toadd[i]); if (step_batch != null) { for (int j = 0; j < step_batch.length; j++) { try { String sql = "INSERT INTO testcasestepbatch (`Test`, `TestCase`, `Step`, `Batch`) VALUES ( " + "'" + test_testcase_format[0] + "', " + "'" + test_testcase_format[1] + "', " + "'" + step_number_toadd[i] + "', " + "'" + step_batch[j] + "' )"; stmt4.executeUpdate(sql); } catch (Exception e) { MyLogger.log( UpdateTestCaseDetail.class.getName(), Level.FATAL, "Error on insert into TestCaseStepBatch: " + e.toString()); } } } } /* * Test Case Step Actions */ for (int i = 0; i < step_number_hide.length; i++) { /* * Select to know if need to update or insert */ if (this.formIsFill(step_sequence[i]) && (step_sequence[i].length() > 0)) { String sql = ("SELECT * " + " FROM testcasestepaction" + " WHERE Test = '" + test_testcase_format[0] + "'" + " AND TestCase = '" + test_testcase_format[1] + "' " + " AND Step = " + step_number_hide[i] + " " + " AND Sequence = " + step_sequence[i]); ResultSet rs_stepaction = stmt4.executeQuery(sql); try { IFactoryTestCaseStepAction actionFactory = appContext.getBean(IFactoryTestCaseStepAction.class); ITestCaseStepActionService actionService = appContext.getBean(ITestCaseStepActionService.class); TestCaseStepAction tcsa = actionFactory.create( test_testcase_format[0], test_testcase_format[1], Integer.parseInt(step_number_hide[i]), Integer.parseInt(step_sequence[i]), Integer.parseInt(step_sequence[i]), step_conditionOper[i], step_conditionVal1[i], step_conditionVal2[i], step_action[i], step_value1[i], step_value2[i], "", step_description[i], ""); if (rs_stepaction.next()) { actionService.updateTestCaseStepAction(tcsa); } else if (this.formIsFullFill(testcase_actions_info, i)) { actionService.insertTestCaseStepAction(tcsa); } } finally { rs_stepaction.close(); } } } /* * TestCase Step Controls */ /* * Get Number of actual testcase controls */ for (int i = 0; i < controls_controlsequence.length; i++) { /* * Select to know if need to update or insert */ if (this.formIsFill(controls_sequence[i]) && (controls_sequence[i].length() > 0)) { String sql = ("SELECT * " + " FROM testcasestepactioncontrol" + " WHERE Test = '" + test_testcase_format[0] + "'" + " AND TestCase = '" + test_testcase_format[1] + "' " + " AND Step = " + controls_step[i] + " " + " AND Sequence = " + controls_sequence[i] + " " + " AND controlSequence = " + controls_controlsequence[i]); ResultSet rs_stepactioncontrol = stmt4.executeQuery(sql); try { IFactoryTestCaseStepActionControl controlFactory = appContext.getBean(IFactoryTestCaseStepActionControl.class); ITestCaseStepActionControlService controlService = appContext.getBean(ITestCaseStepActionControlService.class); TestCaseStepActionControl control = controlFactory.create( test_testcase_format[0], test_testcase_format[1], Integer.parseInt(controls_step[i]), Integer.parseInt(controls_sequence[i]), Integer.parseInt(controls_controlsequence[i]), 0, controls_conditionoper[i], controls_conditionval1[i], controls_conditionval2[i], controls_control[i], (controls_value1[i]), controls_value2[i], controls_fatal[i], controls_description[i], ""); if (rs_stepactioncontrol.next()) { controlService.updateTestCaseStepActionControl(control); } else { // if (this.formIsFullFill(testcase_controls_info, i)) { controlService.insertTestCaseStepActionControl(control); // } } } finally { rs_stepactioncontrol.close(); } } } /* * DELETE */ if (step_delete != null) { for (String step_to_delete : step_delete) { stmt4.execute( "DELETE FROM testcasestep " + " WHERE Test = '" + test_testcase_format[0] + "' " + " AND TestCase = '" + test_testcase_format[1] + "' " + " AND Step = " + step_to_delete + ""); } } /* * Delete Actions */ if (step_action_delete != null) { // If some actions to delete for (String action_to_delete : step_action_delete) { // Delete // with // key String[] step_action_split = action_to_delete.split("-"); stmt4.execute( "DELETE FROM testcasestepaction " + " WHERE Test = '" + test_testcase_format[0] + "' " + " AND TestCase = '" + test_testcase_format[1] + "' " + " AND Step = " + step_action_split[0] + " " + " AND Sequence = " + step_action_split[1] + ""); } } /* * Delete Controls */ if (controls_delete != null) { // If controls to delete for (String keys_to_delete : controls_delete) { String[] key_delete = keys_to_delete.split("-"); // Get // Step, // Sequence // and // Control stmt4.execute( "DELETE FROM testcasestepactioncontrol " + " WHERE Test = '" + test_testcase_format[0] + "' " + " AND TestCase = '" + test_testcase_format[1] + "' " + " AND Step = " + key_delete[0] + " " + " AND Sequence = " + key_delete[1] + " " + " AND ControlSequence = " + key_delete[2] + ""); } } stmt4.execute( "UPDATE testcase " + "SET LastModifier = '" + request.getUserPrincipal().getName() + "' " + "WHERE Test = '" + test_testcase_format[0] + "' " + " AND TestCase = '" + test_testcase_format[1] + "' "); /** Adding Log entry. */ ILogEventService logEventService = appContext.getBean(LogEventService.class); logEventService.createPrivateCalls( "/UpdateTestCaseDetail", "UPDATE", "Update testcase detail : ['" + test_testcase_format_prop[0] + "'|'" + test_testcase_format_prop[1] + "']", request); /* * Redirect */ response.sendRedirect( "TestCase.jsp?Load=Load&Test=" + test_testcase_format[0] + "&TestCase=" + test_testcase_format[1]); return; } finally { stmt4.close(); } } catch (SQLException ex) { MyLogger.log(UpdateTestCaseDetail.class.getName(), Level.FATAL, "" + ex); // out.println ( UpdateTestCase.class.getName ( ) + ex ) ; } catch (NullPointerException ex) { MyLogger.log(UpdateTestCaseDetail.class.getName(), Level.FATAL, "" + ex); } catch (ArrayIndexOutOfBoundsException ex) { MyLogger.log(UpdateTestCaseDetail.class.getName(), Level.FATAL, "" + ex); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(UpdateTestCaseDetail.class.getName(), Level.WARN, e.toString()); } } response.sendRedirect( "TestCase.jsp?Load=Load&Test=" + request.getParameter("Test") + "&TestCase=" + request.getParameter("TestCase")); out.close(); }
@Override public SoapLibrary findSoapLibraryByKey(String name) throws CerberusException { boolean throwEx = false; SoapLibrary result = null; final String query = "SELECT * FROM soaplibrary WHERE NAME = ?"; Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query); try { preStat.setString(1, name); ResultSet resultSet = preStat.executeQuery(); try { if (resultSet.first()) { String type = resultSet.getString("Type"); String envelope = resultSet.getString("Envelope"); String description = resultSet.getString("Description"); String servicePath = resultSet.getString("servicePath"); String parsingAnswer = resultSet.getString("parsingAnswer"); String method = resultSet.getString("method"); result = this.factorySoapLib.create( type, name, envelope, description, servicePath, parsingAnswer, method); } else { throwEx = true; } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(SoapLibraryDAO.class.getName(), Level.WARN, e.toString()); } } if (throwEx) { throw new CerberusException(new MessageGeneral(MessageGeneralEnum.SQLLIB_NOT_FOUND)); } return result; }
@Override public Integer getNumberOfSoapLibraryPerCrtiteria(String searchTerm, String inds) { Integer result = 0; StringBuilder query = new StringBuilder(); StringBuilder gSearch = new StringBuilder(); String searchSQL = ""; query.append("SELECT count(*) FROM soaplibrary"); gSearch.append(" where (`name` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `type` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `envelope` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `description` like '%"); gSearch.append(searchTerm); gSearch.append("%')"); if (!searchTerm.equals("") && !inds.equals("")) { searchSQL = gSearch.toString() + " and " + inds; } else if (!inds.equals("")) { searchSQL = " where " + inds; } else if (!searchTerm.equals("")) { searchSQL = gSearch.toString(); } query.append(searchSQL); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { ResultSet resultSet = preStat.executeQuery(); try { if (resultSet.first()) { result = resultSet.getInt(1); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(SoapLibraryDAO.class.getName(), Level.ERROR, e.toString()); } } return result; }
@Override public List<SoapLibrary> findSoapLibraryListByCriteria( int start, int amount, String column, String dir, String searchTerm, String individualSearch) { List<SoapLibrary> soapLibraryList = new ArrayList<SoapLibrary>(); StringBuilder gSearch = new StringBuilder(); StringBuilder searchSQL = new StringBuilder(); StringBuilder query = new StringBuilder(); query.append("SELECT * FROM soaplibrary "); gSearch.append(" where (`type` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `name` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `envelope` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `description` like '%"); gSearch.append(searchTerm); gSearch.append("%')"); if (!searchTerm.equals("") && !individualSearch.equals("")) { searchSQL.append(gSearch.toString()); searchSQL.append(" and "); searchSQL.append(individualSearch); } else if (!individualSearch.equals("")) { searchSQL.append(" where `"); searchSQL.append(individualSearch); searchSQL.append("`"); } else if (!searchTerm.equals("")) { searchSQL.append(gSearch.toString()); } query.append(searchSQL); query.append("order by `"); query.append(column); query.append("` "); query.append(dir); query.append(" limit "); query.append(start); query.append(" , "); query.append(amount); SoapLibrary soapLibrary; Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { ResultSet resultSet = preStat.executeQuery(); try { while (resultSet.next()) { soapLibraryList.add(this.loadFromResultSet(resultSet)); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { MyLogger.log( SoapLibraryDAO.class.getName(), Level.ERROR, "Unable to execute query : " + exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { MyLogger.log(SoapLibraryDAO.class.getName(), Level.ERROR, e.toString()); } } return soapLibraryList; }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); ITestCaseService testService = appContext.getBean(ITestCaseService.class); IInvariantService invariantService = appContext.getBean(IInvariantService.class); ICampaignService campaignService = appContext.getBean(ICampaignService.class); ITestBatteryService testBatteryService = appContext.getBean(ITestBatteryService.class); IBuildRevisionInvariantService buildRevisionInvariantService = appContext.getBean(IBuildRevisionInvariantService.class); String system = req.getParameter("system"); JSONArray jsonResponse = new JSONArray(); String[] columns = { "test", "project", "ticket", "bugID", "origine", "creator", "application", "priority", "status", "group", "activePROD", "activeUAT", "activeQA", "tcActive" }; try { JSONObject data; for (String s : columns) { data = new JSONObject(); data.put("data", new JSONArray(testService.findUniqueDataOfColumn(s))); data.put("name", s); jsonResponse.put(data); } JSONArray build = new JSONArray(); for (BuildRevisionInvariant bri : buildRevisionInvariantService.convert( buildRevisionInvariantService.readBySystemLevel(system, 1))) { build.put(bri.getVersionName()); } data = new JSONObject(); data.put("data", build); data.put("name", "fromBuild"); jsonResponse.put(data); data = new JSONObject(); data.put("data", build); data.put("name", "toBuild"); jsonResponse.put(data); data = new JSONObject(); data.put("data", build); data.put("name", "targetBuild"); jsonResponse.put(data); JSONArray revision = new JSONArray(); for (BuildRevisionInvariant bri : buildRevisionInvariantService.convert( buildRevisionInvariantService.readBySystemLevel(system, 2))) { revision.put(bri.getVersionName()); } data = new JSONObject(); data.put("data", revision); data.put("name", "fromRev"); jsonResponse.put(data); data = new JSONObject(); data.put("data", revision); data.put("name", "toRev"); jsonResponse.put(data); data = new JSONObject(); data.put("data", revision); data.put("name", "targetRev"); jsonResponse.put(data); JSONArray env = new JSONArray(); AnswerList answer = invariantService.readByIdname( "ENVIRONMENT"); // TODO: handle if the response does not turn ok for (Invariant i : (List<Invariant>) answer.getDataList()) { env.put(i.getValue()); } data = new JSONObject(); data.put("data", env); data.put("name", "executionEnv"); jsonResponse.put(data); JSONArray country = new JSONArray(); answer = invariantService.readByIdname("COUNTRY"); // TODO: handle if the response does not turn ok for (Invariant i : (List<Invariant>) answer.getDataList()) { country.put(i.getValue()); } data = new JSONObject(); data.put("data", country); data.put("name", "executionCountry"); jsonResponse.put(data); JSONArray campaign = new JSONArray(); for (Campaign c : campaignService.findAll()) { campaign.put(c.getCampaign()); } data = new JSONObject(); data.put("data", campaign); data.put("name", "campaign"); jsonResponse.put(data); JSONArray battery = new JSONArray(); for (TestBattery c : testBatteryService.findAll()) { battery.put(c.getTestbattery()); } data = new JSONObject(); data.put("data", battery); data.put("name", "testBattery"); jsonResponse.put(data); resp.setContentType("application/json"); resp.getWriter().print(jsonResponse.toString()); } catch (JSONException e) { MyLogger.log(GetDataForTestCaseSearch.class.getName(), Level.FATAL, "" + e); resp.setContentType("text/html"); resp.getWriter().print(e.getMessage()); } catch (CerberusException e) { MyLogger.log(GetDataForTestCaseSearch.class.getName(), Level.FATAL, "" + e); resp.setContentType("text/html"); resp.getWriter().print(e.getMessage()); } }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); testBatteryService = appContext.getBean(ITestBatteryService.class); factoryTestBatteryContent = appContext.getBean(IFactoryTestBatteryContent.class); PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); String jsonResponse = "-1"; String testbattery = policy.sanitize(request.getParameter("TestBattery")); String testBatteryName; String[] testcasesselected = request.getParameterValues("testcaseselected"); if (testcasesselected == null) { response.setStatus(404); jsonResponse = "Please select at least one testcase !"; } else { try { testBatteryName = testBatteryService.findTestBatteryByKey(Integer.parseInt(testbattery)).getTestbattery(); } catch (CerberusException ex) { MyLogger.log(AddTestBatteryContent.class.getName(), Level.DEBUG, ex.getMessage()); testBatteryName = null; } if (testBatteryName != null) { String test; String testcase; // response.setContentType("text/html"); for (String testcaseselect : testcasesselected) { test = policy.sanitize( URLDecoder.decode( testcaseselect.split("Test=")[1].split("&TestCase=")[0], "UTF-8")); testcase = policy.sanitize(URLDecoder.decode(testcaseselect.split("&TestCase=")[1], "UTF-8")); try { testBatteryService.createTestBatteryContent( factoryTestBatteryContent.create(null, test, testcase, testBatteryName)); List<TestBatteryContent> batteryContent = testBatteryService.findTestBatteryContentsByCriteria( null, testBatteryName, test, testcase); if (batteryContent != null && batteryContent.size() == 1) { String newTestBatteryContentId = String.valueOf( testBatteryService .findTestBatteryContentsByCriteria(null, testBatteryName, test, testcase) .get(0) .getTestbatterycontentID()); jsonResponse = newTestBatteryContentId; } } catch (CerberusException ex) { MyLogger.log(AddTestBatteryContent.class.getName(), Level.DEBUG, ex.getMessage()); jsonResponse = "-1"; } } } } response.getWriter().append(jsonResponse).close(); }