Search in sources :

Example 1 with TestCaseStepBuilder

use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.

the class AbstractPerformanceDataBuilderTest method testGetPerformanceDataWithPreParsedSteps.

@Test
public void testGetPerformanceDataWithPreParsedSteps() throws Exception {
    Date startDate = new GregorianCalendar(2014, 14, 7, 13, 0).getTime();
    TestSuite testSuiteExample = new TestSuiteExampleBuilder().withId("sakuli-123").withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 120)).withWarningTime(100).withCriticalTime(150).withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withState(TestCaseState.WARNING_IN_STEP).withId("case-warning").withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 20)).withWarningTime(19).withCriticalTime(25).withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withName("step1").withState(TestCaseStepState.WARNING).withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 10)).withWarningTime(9).buildExample(), new TestCaseStepBuilder("step2_not_started").withState(TestCaseStepState.INIT).build())).buildExample())).buildExample();
    testSuiteExample.refreshState();
    assertEquals(AbstractPerformanceDataBuilder.getTestSuitePerformanceData(testSuiteExample), "suite__state=1;;;; " + "suite__warning=100s;;;; " + "suite__critical=150s;;;; " + "suite_sakuli-123=120.00s;100;150;; " + "c_001__state=1;;;; " + "c_001__warning=19s;;;; " + "c_001__critical=25s;;;; " + "c_001_case-warning=20.00s;19;25;; " + "s_001_001_step1=10.00s;9;;; " + "s_001_002_step2_not_started=U;;;;");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 2 with TestCaseStepBuilder

use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.

the class CacheHandlingResultServiceImplTest method testWriteCachedStepDefinitions.

@Test
public void testWriteCachedStepDefinitions() throws Exception {
    final String cacheFilePath = "valid/validTestCase/" + TestCaseStepHelper.STEPS_CACHE_FILE;
    if (this.getClass().getResource(cacheFilePath) != null) {
        Files.deleteIfExists(getResource(cacheFilePath, true));
    }
    Path tcFile = getResource("valid/validTestCase/_tc.js", true);
    testSuite.setState(TestSuiteState.ERRORS);
    TestCase tc = new TestCase("test", "test");
    tc.setTcFile(tcFile);
    tc.setSteps(Arrays.asList(new TestCaseStepBuilder("step_ok").withState(TestCaseStepState.OK).build(), new TestCaseStepBuilder("step_not_started").build(), new TestCaseStepBuilder("step_warning").withState(TestCaseStepState.WARNING).build()));
    testSuite.setTestCases(Collections.singletonMap("1", tc));
    //on error no cache file should be written
    testling.saveAllResults();
    assertNull(getResource(cacheFilePath, false));
    //on != error cache file should be written
    testSuite.setState(TestSuiteState.CRITICAL_IN_SUITE);
    testling.saveAllResults();
    Path cacheFile = getResource(cacheFilePath, true);
    assertTrue(Files.exists(cacheFile));
    assertEquals(FileUtils.readFileToString(cacheFile.toFile(), Charset.forName("UTF-8")), "step_ok\nstep_warning\n");
}
Also used : Path(java.nio.file.Path) TestCase(org.sakuli.datamodel.TestCase) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) Test(org.testng.annotations.Test)

Example 3 with TestCaseStepBuilder

use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.

the class BaseActionLoaderTest method testGetCurrenTestCase.

@Test
public void testGetCurrenTestCase() throws Exception {
    assertNull(testling.getCurrentTestCaseStep());
    TestCase tc = new TestCase("test", "nocase");
    ReflectionTestUtils.setField(testling, "currentTestCase", tc);
    assertNotNull(testling.getCurrentTestCase());
    assertNull(testling.getCurrentTestCaseStep());
    DateTime creationDate = new DateTime();
    tc.addStep(new TestCaseStepBuilder("step_ok").withState(TestCaseStepState.OK).withCreationDate(creationDate).build());
    tc.addStep(new TestCaseStepBuilder("step_warning").withState(TestCaseStepState.WARNING).withCreationDate(creationDate.plusMillis(1)).build());
    assertNull(testling.getCurrentTestCaseStep());
    tc.addStep(new TestCaseStepBuilder("step_init_1").withState(TestCaseStepState.INIT).withCreationDate(creationDate.plusMillis(10)).build());
    assertNotNull(testling.getCurrentTestCaseStep());
    assertEquals(testling.getCurrentTestCaseStep().getName(), "step_init_1");
    tc.addStep(new TestCaseStepBuilder("step_init_2").withState(TestCaseStepState.INIT).withCreationDate(creationDate.plusMillis(11)).build());
    assertNotNull(testling.getCurrentTestCaseStep());
    assertEquals(testling.getCurrentTestCaseStep().getName(), "step_init_1");
    //add step before other init state's
    tc.addStep(new TestCaseStepBuilder("step_error").withState(TestCaseStepState.ERRORS).withCreationDate(creationDate.plusMillis(2)).build());
    assertNotNull(testling.getCurrentTestCaseStep());
    assertEquals(testling.getCurrentTestCaseStep().getName(), "step_error");
}
Also used : TestCase(org.sakuli.datamodel.TestCase) DateTime(org.joda.time.DateTime) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) Test(org.testng.annotations.Test)

Example 4 with TestCaseStepBuilder

use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.

the class AbstractTestDataEntityTest method testCompareToMixedSteps.

@Test
public void testCompareToMixedSteps() throws Exception {
    TestCaseStep third = new TestCaseStepBuilder("third").withCreationDate(new DateTime()).build();
    TestCaseStep fourth = new TestCaseStepBuilder("fourth").withCreationDate(//ensure that the creation time is not equal
    new DateTime().plusMillis(1)).build();
    List<TestCaseStep> values = Arrays.asList(new TestCaseStepExampleBuilder().withStartDate(new DateTime().plusMinutes(5).toDate()).withName("second").buildExample(), third, fourth, new TestCaseStepExampleBuilder().withName("first").buildExample());
    //first should be the step with startdate, after that the init steps will follow after the creation date
    TreeSet<TestCaseStep> sorted = new TreeSet<>(values);
    print(sorted);
    assertEquals(sorted.size(), 4);
    Iterator<TestCaseStep> it = sorted.iterator();
    assertEquals(it.next().getName(), "first");
    assertEquals(it.next().getName(), "second");
    assertEquals(it.next().getName(), "third");
    assertEquals(it.next().getName(), "fourth");
}
Also used : TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) DateTime(org.joda.time.DateTime) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 5 with TestCaseStepBuilder

use of org.sakuli.datamodel.builder.TestCaseStepBuilder in project sakuli by ConSol.

the class AbstractTestDataEntityTest method testCompareTo.

@Test
public void testCompareTo() throws Exception {
    TestCaseStep second = new TestCaseStepBuilder("second").withCreationDate(new DateTime()).build();
    TestCaseStep third = new TestCaseStepBuilder("third").withCreationDate(//ensure that the creation time is not equal
    new DateTime().plusMillis(1)).build();
    List<TestCaseStep> values = Arrays.asList(second, third, new TestCaseStepExampleBuilder().withName("first").buildExample());
    //first should be the step with startdate, after that the init steps will follow after the creation date
    TreeSet<TestCaseStep> sorted = new TreeSet<>(values);
    print(sorted);
    assertEquals(sorted.size(), 3);
    assertEquals(sorted.first().getName(), "first");
    assertEquals(sorted.last().getName(), "third");
}
Also used : TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) DateTime(org.joda.time.DateTime) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) 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