Search in sources :

Example 6 with TestCaseStepBuilder

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;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) TestCaseStep(org.sakuli.datamodel.TestCaseStep) IOException(java.io.IOException) DateTime(org.joda.time.DateTime) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder)

Example 7 with TestCaseStepBuilder

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;
}
Also used : TestCaseStep(org.sakuli.datamodel.TestCaseStep) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder)

Example 8 with TestCaseStepBuilder

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);
}
Also used : SakuliException(org.sakuli.exceptions.SakuliException) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) Test(org.testng.annotations.Test)

Example 9 with TestCaseStepBuilder

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");
}
Also used : Path(java.nio.file.Path) TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Aggregations

TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)9 Test (org.testng.annotations.Test)7 DateTime (org.joda.time.DateTime)4 BaseTest (org.sakuli.BaseTest)4 Path (java.nio.file.Path)3 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)3 TestCase (org.sakuli.datamodel.TestCase)3 TestCaseStep (org.sakuli.datamodel.TestCaseStep)2 TestSuite (org.sakuli.datamodel.TestSuite)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)1 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)1 SakuliException (org.sakuli.exceptions.SakuliException)1