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");
}
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");
}
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);
}
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));
}
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);
}
}
Aggregations