Search in sources :

Example 6 with TestCaseStep

use of org.cerberus.crud.entity.TestCaseStep in project cerberus-source by cerberustesting.

the class TestCaseStepDAO method getStepLibraryBySystem.

@Override
public List<TestCaseStep> getStepLibraryBySystem(String system) throws CerberusException {
    List<TestCaseStep> list = null;
    StringBuilder query = new StringBuilder();
    query.append("SELECT tcs.test, tcs.testcase, tcs.step, tcs.sort, tcs.description, tc.description as tcdesc FROM testcasestep tcs ");
    query.append("join testcase tc on tc.test=tcs.test and tc.testcase=tcs.testcase ");
    query.append("join application app  on tc.application=app.application ");
    query.append("where tcs.inlibrary = 'Y' and app.system = ?  ");
    query.append("order by tcs.test, tcs.testcase, tcs.sort");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, system);
            ResultSet resultSet = preStat.executeQuery();
            list = new ArrayList<TestCaseStep>();
            try {
                while (resultSet.next()) {
                    String t = resultSet.getString("test");
                    String tc = resultSet.getString("testcase");
                    String tcdesc = resultSet.getString("tcdesc");
                    int s = resultSet.getInt("step");
                    int sort = resultSet.getInt("sort");
                    String description = resultSet.getString("description");
                    TestCaseStep tcs = factoryTestCaseStep.create(t, tc, s, sort, null, null, null, null, description, null, null, null, 0, null);
                    TestCase tcObj = factoryTestCase.create(t, tc, tcdesc);
                    tcs.setTestCaseObj(tcObj);
                    list.add(tcs);
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn("Exception Closing the connection : " + e.toString());
        }
    }
    return list;
}
Also used : TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) PreparedStatement(java.sql.PreparedStatement)

Example 7 with TestCaseStep

use of org.cerberus.crud.entity.TestCaseStep in project cerberus-source by cerberustesting.

the class TestCaseStepDAO method getTestCaseStepUsingTestCaseInParamter.

@Override
public List<TestCaseStep> getTestCaseStepUsingTestCaseInParamter(String test, String testCase) throws CerberusException {
    List<TestCaseStep> list = null;
    final String query = "SELECT * FROM testcasestep WHERE usestep='Y' AND usesteptest = ? AND usesteptestcase = ?";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testCase);
            ResultSet resultSet = preStat.executeQuery();
            list = new ArrayList<TestCaseStep>();
            try {
                while (resultSet.next()) {
                    list.add(loadFromResultSet(resultSet));
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn("Exception Closing the connection : " + e.toString());
        }
    }
    return list;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) PreparedStatement(java.sql.PreparedStatement)

Example 8 with TestCaseStep

use of org.cerberus.crud.entity.TestCaseStep 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);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CerberusException(org.cerberus.exception.CerberusException) PolicyFactory(org.owasp.html.PolicyFactory) JSONObject(org.json.JSONObject) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) TestCaseStep(org.cerberus.crud.entity.TestCaseStep)

Example 9 with TestCaseStep

use of org.cerberus.crud.entity.TestCaseStep in project cerberus-source by cerberustesting.

the class LoadTestCaseService method loadTestCaseStep.

@Override
public List<TestCaseStep> loadTestCaseStep(TestCase testCase) {
    List<TestCaseStep> result = new ArrayList<TestCaseStep>();
    for (TestCaseStep testCaseStep : this.testCaseStepService.getListOfSteps(testCase.getTest(), testCase.getTestCase())) {
        LOG.debug("set list of step :" + testCaseStep.getStep());
        /**
         * If use Step, load action and control of used step
         */
        if (!testCaseStep.getUseStep().equals("Y")) {
            List<TestCaseStepAction> tcsa = this.loadTestCaseStepAction(testCaseStep, null);
            if (tcsa != null) {
                testCaseStep.setTestCaseStepAction(tcsa);
            }
        } else {
            // Step is used from another testcase.
            List<TestCaseStepAction> tcsa = this.loadTestCaseStepAction(testCaseStep, factoryTCS.create(testCaseStep.getUseStepTest(), testCaseStep.getUseStepTestCase(), testCaseStep.getUseStepStep(), testCaseStep.getSort(), null, null, null, null, null, null, null, null, 0, null));
            if (tcsa != null) {
                testCaseStep.setTestCaseStepAction(tcsa);
            }
            // Copy the usedStep property to main step. Loop and conditionoper are taken from used step.
            testCaseStep = testCaseStepService.modifyTestCaseStepDataFromUsedStep(testCaseStep);
        }
        LOG.debug("adding testCaseStep");
        result.add(testCaseStep);
    }
    LOG.debug("return List<TestCaseStep>");
    return result;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) ArrayList(java.util.ArrayList) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep)

Example 10 with TestCaseStep

use of org.cerberus.crud.entity.TestCaseStep in project cerberus-source by cerberustesting.

the class FactoryTestCaseStep method create.

@Override
public TestCaseStep create(String test, String testCase, int step, int sort, String loop, String conditionOper, String conditionVal1, String conditionVal2, String description, String useStep, String useStepTest, String useStepTestCase, Integer useStepStep, String inLibrary) {
    TestCaseStep testCaseStep = new TestCaseStep();
    testCaseStep.setDescription(description);
    testCaseStep.setStep(step);
    testCaseStep.setSort(sort);
    testCaseStep.setLoop(loop);
    testCaseStep.setConditionOper(conditionOper);
    testCaseStep.setConditionVal1(conditionVal1);
    testCaseStep.setConditionVal2(conditionVal2);
    testCaseStep.setTest(test);
    testCaseStep.setTestCase(testCase);
    testCaseStep.setUseStep(useStep);
    testCaseStep.setUseStepTest(useStepTest);
    testCaseStep.setUseStepTestCase(useStepTestCase);
    testCaseStep.setUseStepStep(useStepStep);
    testCaseStep.setInLibrary(inLibrary);
    return testCaseStep;
}
Also used : IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep)

Aggregations

TestCaseStep (org.cerberus.crud.entity.TestCaseStep)41 ArrayList (java.util.ArrayList)20 IFactoryTestCaseStep (org.cerberus.crud.factory.IFactoryTestCaseStep)19 ITestCaseStepService (org.cerberus.crud.service.ITestCaseStepService)16 TestCase (org.cerberus.crud.entity.TestCase)15 TestCaseStepAction (org.cerberus.crud.entity.TestCaseStepAction)13 JSONObject (org.json.JSONObject)13 ApplicationContext (org.springframework.context.ApplicationContext)12 SQLException (java.sql.SQLException)11 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)11 TestCaseStepActionControl (org.cerberus.crud.entity.TestCaseStepActionControl)11 Connection (java.sql.Connection)10 PreparedStatement (java.sql.PreparedStatement)10 ResultSet (java.sql.ResultSet)10 ITestCaseService (org.cerberus.crud.service.ITestCaseService)10 JSONArray (org.json.JSONArray)10 PolicyFactory (org.owasp.html.PolicyFactory)10 ITestCaseStepActionService (org.cerberus.crud.service.ITestCaseStepActionService)9 MessageEvent (org.cerberus.engine.entity.MessageEvent)9 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)8