Search in sources :

Example 61 with TestCase

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

the class TestCaseDAO method readByKey.

@Override
public AnswerItem readByKey(String test, String testCase) {
    AnswerItem ans = new AnswerItem();
    TestCase result = null;
    final String query = "SELECT * FROM `testcase` tec LEFT OUTER JOIN application app ON app.application=tec.application WHERE tec.`test` = ? AND tec.`testcase` = ?";
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, test);
        preStat.setString(2, testCase);
        try (ResultSet resultSet = preStat.executeQuery()) {
            if (resultSet.first()) {
                result = loadFromResultSet(resultSet);
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                ans.setItem(result);
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    }
    // sets the message
    ans.setResultMessage(msg);
    return ans;
}
Also used : TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 62 with TestCase

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

the class TestCaseExecutionQueueService method convertToTestCaseExecution.

@Override
public TestCaseExecution convertToTestCaseExecution(TestCaseExecutionQueue testCaseExecutionInQueue) {
    String test = testCaseExecutionInQueue.getTest();
    String testCase = testCaseExecutionInQueue.getTestCase();
    String environment = testCaseExecutionInQueue.getEnvironment();
    String country = testCaseExecutionInQueue.getCountry();
    String browser = testCaseExecutionInQueue.getBrowser();
    String robotDecli = testCaseExecutionInQueue.getRobot();
    if (StringUtil.isNullOrEmpty(robotDecli)) {
        if (!StringUtil.isNullOrEmpty(browser)) {
            robotDecli = browser;
        } else {
            robotDecli = "";
        }
    }
    String version = testCaseExecutionInQueue.getBrowserVersion();
    String platform = testCaseExecutionInQueue.getPlatform();
    long start = testCaseExecutionInQueue.getRequestDate() != null ? testCaseExecutionInQueue.getRequestDate().getTime() : 0;
    long end = 0;
    String controlStatus = TestCaseExecution.CONTROLSTATUS_QU;
    String controlMessage = "Queued with State : " + testCaseExecutionInQueue.getState().name() + " - " + testCaseExecutionInQueue.getComment();
    Application applicationObj = testCaseExecutionInQueue.getApplicationObj();
    String application = testCaseExecutionInQueue.getApplicationObj() != null ? testCaseExecutionInQueue.getApplicationObj().getApplication() : "";
    String ip = testCaseExecutionInQueue.getRobotIP();
    String port = testCaseExecutionInQueue.getRobotPort();
    String tag = testCaseExecutionInQueue.getTag();
    int verbose = testCaseExecutionInQueue.getVerbose();
    int screenshot = testCaseExecutionInQueue.getScreenshot();
    int pageSource = testCaseExecutionInQueue.getPageSource();
    int seleniumLog = testCaseExecutionInQueue.getSeleniumLog();
    int retry = testCaseExecutionInQueue.getRetries();
    boolean synchroneous = true;
    String timeout = testCaseExecutionInQueue.getTimeout();
    String outputFormat = "";
    TestCase tCase = testCaseExecutionInQueue.getTestCaseObj();
    boolean manualURL = (testCaseExecutionInQueue.getManualURL() >= 1);
    String manualExecution = testCaseExecutionInQueue.getManualExecution();
    String myHost = testCaseExecutionInQueue.getManualHost();
    String myContextRoot = testCaseExecutionInQueue.getManualContextRoot();
    String myLoginRelativeURL = testCaseExecutionInQueue.getManualLoginRelativeURL();
    String myEnvData = testCaseExecutionInQueue.getManualEnvData();
    String seleniumIP = testCaseExecutionInQueue.getRobotIP();
    String seleniumPort = testCaseExecutionInQueue.getRobotPort();
    String description = "";
    if ((testCaseExecutionInQueue.getTestCaseObj() != null) && (testCaseExecutionInQueue.getTestCaseObj().getDescription() != null)) {
        description = testCaseExecutionInQueue.getTestCaseObj().getDescription();
    }
    TestCaseExecution result = factoryTestCaseExecution.create(0, test, testCase, description, null, null, environment, country, browser, version, platform, browser, start, end, controlStatus, controlMessage, application, applicationObj, ip, "", port, tag, verbose, screenshot, pageSource, seleniumLog, synchroneous, timeout, outputFormat, "", "", tCase, null, null, manualURL, myHost, myContextRoot, myLoginRelativeURL, myEnvData, seleniumIP, seleniumPort, null, null, null, retry, "", null, "", "", "", "", "", manualExecution, "", 0, "", robotDecli);
    result.setQueueID(testCaseExecutionInQueue.getId());
    result.setQueueState(testCaseExecutionInQueue.getState().name());
    result.setId(testCaseExecutionInQueue.getExeId());
    return result;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCase(org.cerberus.crud.entity.TestCase) Application(org.cerberus.crud.entity.Application)

Example 63 with TestCase

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

the class TestCaseService method readByKeyWithDependency.

@Override
public AnswerItem readByKeyWithDependency(String test, String testCase) {
    AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));
    AnswerItem ai = testCaseDao.readByKey(test, testCase);
    if (ai.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && ai.getItem() != null) {
        TestCase tc = (TestCase) ai.getItem();
        AnswerList al = testCaseStepService.readByTestTestCaseWithDependency(tc.getTest(), tc.getTestCase());
        if (al.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && al.getDataList() != null) {
            tc.setTestCaseStep(al.getDataList());
        }
        answer.setResultMessage(al.getResultMessage());
        answer.setItem(tc);
    }
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 64 with TestCase

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

the class TestCaseService method findTestWithTestCaseActiveAutomatedBySystem.

@Override
public List<String> findTestWithTestCaseActiveAutomatedBySystem(String system) {
    TestCase tCase = factoryTCase.create(null, null, null, null, null, null, null, null, null, null, null, null, null, null, -1, null, null, null, null, null, "Y", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
    List<String> result = new ArrayList();
    List<TestCase> testCases = findTestCaseByAllCriteria(tCase, null, system);
    for (TestCase testCase : testCases) {
        if (!testCase.getGroup().equals("PRIVATE")) {
            result.add(testCase.getTest());
        }
    }
    Set<String> uniqueResult = new HashSet<String>(result);
    result = new ArrayList();
    result.addAll(uniqueResult);
    Collections.sort(result);
    return result;
}
Also used : TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 65 with TestCase

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

the class TestCaseService method findUseTestCaseList.

@Override
public List<TestCase> findUseTestCaseList(String test, String testCase) throws CerberusException {
    List<TestCase> result = new ArrayList();
    List<TestCaseStep> tcsList = testCaseStepService.getListOfSteps(test, testCase);
    for (TestCaseStep tcs : tcsList) {
        if (("Y").equals(tcs.getUseStep())) {
            result.add(this.findTestCaseByKey(tcs.getUseStepTest(), tcs.getUseStepTestCase()));
        }
    }
    return result;
}
Also used : TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) ArrayList(java.util.ArrayList) TestCaseStep(org.cerberus.crud.entity.TestCaseStep)

Aggregations

TestCase (org.cerberus.crud.entity.TestCase)68 ITestCaseService (org.cerberus.crud.service.ITestCaseService)30 ArrayList (java.util.ArrayList)29 IFactoryTestCase (org.cerberus.crud.factory.IFactoryTestCase)29 JSONObject (org.json.JSONObject)26 AnswerItem (org.cerberus.util.answer.AnswerItem)24 ApplicationContext (org.springframework.context.ApplicationContext)24 MessageEvent (org.cerberus.engine.entity.MessageEvent)23 SQLException (java.sql.SQLException)17 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)17 JSONArray (org.json.JSONArray)17 PolicyFactory (org.owasp.html.PolicyFactory)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 CerberusException (org.cerberus.exception.CerberusException)16 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)15 ILogEventService (org.cerberus.crud.service.ILogEventService)15 AnswerList (org.cerberus.util.answer.AnswerList)15 List (java.util.List)13