Search in sources :

Example 11 with TestCaseStep

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

the class TestCaseStepHelperTest method testParseSteps.

@Test
public void testParseSteps() throws Throwable {
    Path tcFile = getResource("stephelper/tc.js");
    FileUtils.writeStringToFile(tcFile.getParent().resolve(TestCaseStepHelper.STEPS_CACHE_FILE).toFile(), "z_step_1\nother_step_2\nstep_3?special\n", Charset.forName("UTF-8"));
    List<TestCaseStep> steps = TestCaseStepHelper.readCachedStepDefinitions(tcFile);
    //do this to ensure correct sorting
    List<TestCaseStep> result = Arrays.asList(steps.get(2), steps.get(0), steps.get(1));
    Collections.sort(result);
    assertNotNull(getResource(CACHEFILE_NAME));
    assertEquals(result.size(), 3);
    Iterator<TestCaseStep> it = result.iterator();
    assertInitStep(it.next(), "z_step_1");
    assertInitStep(it.next(), "other_step_2");
    assertInitStep(it.next(), "step_3?special");
}
Also used : Path(java.nio.file.Path) TestCaseStep(org.sakuli.datamodel.TestCaseStep) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 12 with TestCaseStep

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

the class SakuliExceptionHandlerTest method testSaveExceptionsInStep.

@Test
public void testSaveExceptionsInStep() throws Exception {
    TestSuite ts = new TestSuite();
    when(loader.getTestSuite()).thenReturn(ts);
    TestCase tc = new TestCase(null, null);
    when(loader.getCurrentTestCase()).thenReturn(tc);
    TestCaseStep step = new TestCaseStep();
    when(loader.getCurrentTestCaseStep()).thenReturn(step);
    testling.saveException(new SakuliException("test"));
    assertNull(ts.getException());
    assertNull(tc.getException());
    assertEquals(step.getException().getMessage(), "test");
}
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 13 with TestCaseStep

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

the class SakuliExceptionHandlerTest method testGetAllExceptions.

@Test
public void testGetAllExceptions() throws Exception {
    TestSuite ts = new TestSuite();
    ts.addException(new SakuliException("bla"));
    TestCase tc = new TestCase(null, null);
    tc.addException(new SakuliException("bla2"));
    ts.addTestCase(tc);
    TestCaseStep step = new TestCaseStep();
    step.addException(new SakuliException("bla3"));
    tc.addStep(step);
    List<Throwable> allExceptions = SakuliExceptionHandler.getAllExceptions(ts);
    assertEquals(allExceptions.size(), 3);
}
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 14 with TestCaseStep

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

the class SakuliExceptionHandlerTest method testContainsExceptionsCase.

@Test
public void testContainsExceptionsCase() throws Exception {
    TestSuite ts = new TestSuite();
    TestCase tc = new TestCase(null, null);
    tc.addException(new SakuliException("bla2"));
    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 15 with TestCaseStep

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

the class DaoTestCaseStepImpl method saveTestCaseSteps.

@Override
public void saveTestCaseSteps(SortedSet<TestCaseStep> steps, int primaryKeyOfTestCase) {
    for (TestCaseStep step : steps) {
        LOGGER.info("============== save STEP \"" + step.getName() + "\" ==============");
        MapSqlParameterSource stepParameters = new MapSqlParameterSource();
        stepParameters.addValue("sakuli_cases_id", primaryKeyOfTestCase);
        stepParameters.addValue("result", step.getState().getErrorCode());
        stepParameters.addValue("result_desc", step.getState());
        stepParameters.addValue("name", step.getName());
        stepParameters.addValue("start", step.getStartDateAsUnixTimestamp());
        stepParameters.addValue("stop", step.getStopDateAsUnixTimestamp());
        int warningTime = step.getWarningTime();
        stepParameters.addValue("warning", (warningTime != 0) ? warningTime : null);
        stepParameters.addValue("duration", step.getDuration());
        LOGGER.debug("write the following values to 'sakuli_steps': " + stepParameters.getValues() + "\n now execute ....");
        //generate the sql-statement
        SimpleJdbcInsert insertStepResults = new SimpleJdbcInsert(getDataSource()).withTableName("sakuli_steps").usingGeneratedKeyColumns("id");
        //execute the sql-statement and save the primary key
        int dbPrimaryKey = insertStepResults.executeAndReturnKey(stepParameters).intValue();
        LOGGER.info("test case step '" + step.getName() + "' has been written to 'sakuli_steps' with  primaryKey=" + dbPrimaryKey);
        step.setDbPrimaryKey(dbPrimaryKey);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SimpleJdbcInsert(org.springframework.jdbc.core.simple.SimpleJdbcInsert) TestCaseStep(org.sakuli.datamodel.TestCaseStep) DaoTestCaseStep(org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)

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