use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.
the class TestCaseStepHelper method readCachedStepDefinitions.
public static List<TestCaseStep> readCachedStepDefinitions(Path tcFile) throws IOException {
List<TestCaseStep> result = new ArrayList<>();
if (tcFile != null) {
Path stepsCacheFile = tcFile.getParent().resolve(STEPS_CACHE_FILE);
if (Files.exists(stepsCacheFile)) {
try {
List<String> lines = FileUtils.readLines(stepsCacheFile.toFile(), Charset.forName("UTF-8"));
DateTime creationDate = new DateTime();
for (String line : lines) {
if (StringUtils.isNotEmpty(line)) {
TestCaseStep step = new TestCaseStepBuilder(line).withCreationDate(creationDate).build();
result.add(step);
LOGGER.debug("add cached step definition: " + step);
//increase creation date to ensure correct sorting
creationDate = creationDate.plusMillis(1);
}
}
} catch (IOException e) {
throw new IOException(String.format("Can't read in cached step definitions in file '%s'", stepsCacheFile), e);
}
}
}
return result;
}
use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.
the class TestCaseStepExampleBuilder method buildExample.
@Override
public TestCaseStep buildExample() {
TestCaseStep step = new TestCaseStepBuilder(name).build();
step.setStartDate(startDate);
step.setStopDate(stopDate);
step.setWarningTime(warningTime);
step.setName(name);
step.setState(state);
step.addException(exception);
step.setCreationDate(creationDate);
return step;
}
use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.
the class TestSuiteTest method testGetExceptionMessageWithErrorInStep.
@Test
public void testGetExceptionMessageWithErrorInStep() {
TestSuite testSuite = new TestSuite();
String message = "suite-exception";
testSuite.addException(new SakuliException(message));
assertEquals(testSuite.getExceptionMessages(false), message);
assertEquals(testSuite.getExceptionMessages(true), message);
TestCase tc1 = new TestCase("case1", "case1");
String messageCase = "case-exception";
tc1.addException(new SakuliException(messageCase));
testSuite.addTestCase(tc1.getId(), tc1);
TestCaseStep step1 = new TestCaseStepBuilder("step1").build();
String messageStep = "step-exception";
step1.addException(new SakuliException(messageStep));
tc1.addStep(step1);
assertEquals(testSuite.getExceptionMessages(false), message + "\n" + "CASE \"" + tc1.getId() + "\": " + messageCase + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
assertEquals(testSuite.getExceptionMessages(true), message + " -- CASE \"" + tc1.getId() + "\": " + messageCase + " - STEP \"" + step1.getId() + "\": " + messageStep);
tc1.exception = null;
assertEquals(testSuite.getExceptionMessages(false), message + "\n" + "CASE \"" + tc1.getId() + "\": " + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
assertEquals(testSuite.getExceptionMessages(true), message + " -- CASE \"" + tc1.getId() + "\": " + "STEP \"" + step1.getId() + "\": " + messageStep);
testSuite.exception = null;
assertEquals(testSuite.getExceptionMessages(false), "CASE \"" + tc1.getId() + "\": " + "\n\tSTEP \"" + step1.getId() + "\": " + messageStep);
assertEquals(testSuite.getExceptionMessages(true), "CASE \"" + tc1.getId() + "\": " + "STEP \"" + step1.getId() + "\": " + messageStep);
}
use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.
the class TestCaseStepHelperTest method testWriteCachedStepsError.
@Test
public void testWriteCachedStepsError() throws Throwable {
Path tcFile = getResource("stephelper/tc.js");
TestSuite testSuite = mock(TestSuite.class);
TestCase tc = mock(TestCase.class);
when(tc.getTcFile()).thenReturn(tcFile);
when(tc.getSteps()).thenReturn(Arrays.asList(new TestCaseStepBuilder("step_warning").withState(TestCaseStepState.WARNING).build(), new TestCaseStepBuilder("step_ok").withState(TestCaseStepState.OK).build(), new TestCaseStepBuilder("step_not_started_1").build(), new TestCaseStepBuilder("step_not_started_2").build()));
when(testSuite.getTestCases()).thenReturn(Collections.singletonMap("1", tc));
TestCaseStepHelper.writeCachedStepDefinitions(testSuite);
Path cacheFile = getResource(CACHEFILE_NAME);
assertTrue(Files.exists(cacheFile));
assertEquals(FileUtils.readFileToString(cacheFile.toFile(), Charset.forName("UTF-8")), "step_warning\nstep_ok\nstep_not_started_1\nstep_not_started_2\n");
}
Aggregations