Search in sources :

Example 1 with TestCaseStep

use of org.sakuli.datamodel.TestCaseStep in project sakuli by ConSol.

the class DatabaseResultServiceImplTest method testSaveResultsInDatabaseWithTestcases.

@Test
public void testSaveResultsInDatabaseWithTestcases() throws Exception {
    Integer tcPrimaryKey = 22;
    TestCase tc1 = mock(TestCase.class);
    TestCaseStep tcs1 = mock(TestCaseStep.class);
    when(tc1.getDbPrimaryKey()).thenReturn(tcPrimaryKey);
    SortedSet<TestCaseStep> tcStepList = new TreeSet<>(Collections.singleton(tcs1));
    when(tc1.getStepsAsSortedSet()).thenReturn(tcStepList);
    TestCase tc2 = mock(TestCase.class);
    when(tc2.getSteps()).thenReturn(new ArrayList<>());
    Map<String, TestCase> testCaseMap = new HashMap<>();
    testCaseMap.put("1", tc1);
    testCaseMap.put("2", tc2);
    testSuite = new TestSuite();
    testSuite.setTestCases(testCaseMap);
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    testling.saveAllResults();
    verify(daoTestSuite).saveTestSuiteResult();
    verify(daoTestSuite).saveTestSuiteToSahiJobs();
    verify(daoTestCase).saveTestCaseResult(tc1);
    verify(daoTestCase).saveTestCaseResult(tc2);
    verify(daoTestCase, times(2)).saveTestCaseResult(any(TestCase.class));
    verify(daoTestCaseStep).saveTestCaseSteps(tcStepList, tcPrimaryKey);
    verify(daoTestCaseStep).saveTestCaseSteps(any(SortedSet.class), anyInt());
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) DaoTestSuite(org.sakuli.services.forwarder.database.dao.DaoTestSuite) DaoTestCase(org.sakuli.services.forwarder.database.dao.DaoTestCase) TestCase(org.sakuli.datamodel.TestCase) DaoTestCaseStep(org.sakuli.services.forwarder.database.dao.DaoTestCaseStep) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test)

Example 2 with TestCaseStep

use of org.sakuli.datamodel.TestCaseStep in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method testContainsExceptionsSuite.

@Test
public void testContainsExceptionsSuite() throws Exception {
    TestSuite ts = new TestSuite();
    ts.addException(new SakuliException("bla"));
    TestCase tc = new TestCase(null, null);
    ts.addTestCase(tc);
    TestCaseStep step = new TestCaseStep();
    tc.addStep(step);
    assertTrue(SakuliExceptionHandler.containsException(ts));
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 3 with TestCaseStep

use of org.sakuli.datamodel.TestCaseStep in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method testContainsExceptionsStep.

@Test
public void testContainsExceptionsStep() throws Exception {
    TestSuite ts = new TestSuite();
    TestCase tc = new TestCase(null, null);
    ts.addTestCase(tc);
    TestCaseStep step = new TestCaseStep();
    step.addException(new SakuliException("bla3"));
    tc.addStep(step);
    assertTrue(SakuliExceptionHandler.containsException(ts));
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 4 with TestCaseStep

use of org.sakuli.datamodel.TestCaseStep in project sakuli by ConSol.

the class TestCaseAction method findStep.

protected TestCaseStep findStep(String stepName) {
    TestCaseStep newStep = new TestCaseStep();
    newStep.setId(stepName);
    for (TestCaseStep step : loader.getCurrentTestCase().getSteps()) {
        if (StringUtils.equals(step.getId(), newStep.getId())) {
            return step;
        }
    }
    return newStep;
}
Also used : TestCaseStep(org.sakuli.datamodel.TestCaseStep)

Example 5 with TestCaseStep

use of org.sakuli.datamodel.TestCaseStep in project sakuli by ConSol.

the class DatabaseResultServiceImpl method saveAllResults.

@Override
public void saveAllResults() {
    LOGGER.info("======= SAVE RESULTS TO DATABASE ======");
    ;
    try {
        daoTestSuite.saveTestSuiteResult();
        daoTestSuite.saveTestSuiteToSahiJobs();
        if (!CollectionUtils.isEmpty(testSuite.getTestCases())) {
            for (TestCase tc : testSuite.getTestCasesAsSortedSet()) {
                //write testcase and steps to DB
                daoTestCase.saveTestCaseResult(tc);
                LOGGER.info("... try to save all STEPS for test case '" + tc.getId() + "'!");
                SortedSet<TestCaseStep> steps = tc.getStepsAsSortedSet();
                if (!steps.isEmpty()) {
                    daoTestCaseStep.saveTestCaseSteps(steps, tc.getDbPrimaryKey());
                    LOGGER.info("all STEPS for '" + tc.getId() + "' saved!");
                } else {
                    LOGGER.info("no STEPS for '\" + tc.getId() +\"'found => no STEPS saved in DB!");
                }
            }
        }
        LOGGER.info("======= FINISHED: SAVE RESULTS TO DATABASE ======");
    } catch (Throwable e) {
        exceptionHandler.handleException(new SakuliForwarderException(e, String.format("error by saving the results to the database [%s]", testSuite.toString())), true);
    }
}
Also used : DaoTestCase(org.sakuli.services.forwarder.database.dao.DaoTestCase) TestCase(org.sakuli.datamodel.TestCase) DaoTestCaseStep(org.sakuli.services.forwarder.database.dao.DaoTestCaseStep) TestCaseStep(org.sakuli.datamodel.TestCaseStep) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException)

Aggregations

TestCaseStep (org.sakuli.datamodel.TestCaseStep)21 Test (org.testng.annotations.Test)10 BaseTest (org.sakuli.BaseTest)8 TestCase (org.sakuli.datamodel.TestCase)8 TestSuite (org.sakuli.datamodel.TestSuite)6 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 DaoTestCaseStep (org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)3 IOException (java.io.IOException)2 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)2 DaoTestCase (org.sakuli.services.forwarder.database.dao.DaoTestCase)2 InputStream (java.io.InputStream)1 DateTime (org.joda.time.DateTime)1 LogToResult (org.sakuli.actions.logging.LogToResult)1 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)1 DaoTestSuite (org.sakuli.services.forwarder.database.dao.DaoTestSuite)1 ScreenshotDiv (org.sakuli.services.forwarder.gearman.model.ScreenshotDiv)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 SimpleJdbcInsert (org.springframework.jdbc.core.simple.SimpleJdbcInsert)1