Search in sources :

Example 11 with TestCaseStepExampleBuilder

use of org.sakuli.builder.TestCaseStepExampleBuilder in project sakuli by ConSol.

the class NagiosOutputBuilderTest method testFormatTestCaseTableStateMessageWithScreenshotOnylInTestCase.

@Test
public void testFormatTestCaseTableStateMessageWithScreenshotOnylInTestCase() throws Exception {
    Path screenshotPath = Paths.get(NagiosOutputBuilder.class.getResource("computer.png").toURI());
    String htmlTemplate = "<tr valign=\"top\"><td class=\"%s\">%s<\\/td><\\/tr>";
    GearmanProperties properties = MonitoringPropertiesTestHelper.initMock(mock(GearmanProperties.class));
    TestCase testCase = new TestCaseExampleBuilder().withState(TestCaseState.ERRORS).withId("case-error").withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.ERRORS).withException(new SakuliExceptionWithScreenshot("STEP-EXCEPTION-MESSAGE", screenshotPath)).buildExample())).buildExample();
    String regex = String.format(htmlTemplate, "serviceCRITICAL", "\\[CRIT\\] case \"case-error\" EXCEPTION: " + "STEP \"step_for_unit_test\": STEP-EXCEPTION-MESSAGE" + "<div.* src=\"data:image\\/png;base64,.*><\\/div>");
    BaseTest.assertRegExMatch(testling.formatTestCaseTableStateMessage(testCase, properties.lookUpTemplate(testCase.getState())), regex);
}
Also used : Path(java.nio.file.Path) GearmanProperties(org.sakuli.services.forwarder.gearman.GearmanProperties) TestCase(org.sakuli.datamodel.TestCase) SakuliExceptionWithScreenshot(org.sakuli.exceptions.SakuliExceptionWithScreenshot) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 12 with TestCaseStepExampleBuilder

use of org.sakuli.builder.TestCaseStepExampleBuilder 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 13 with TestCaseStepExampleBuilder

use of org.sakuli.builder.TestCaseStepExampleBuilder 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)

Example 14 with TestCaseStepExampleBuilder

use of org.sakuli.builder.TestCaseStepExampleBuilder in project sakuli by ConSol.

the class CheckMKTemplateOutputBuilderTest method testCritInSuite.

@Test
public void testCritInSuite() throws Exception {
    doReturn("example_xfce").when(testSuite).getId();
    doReturn(TestSuiteState.CRITICAL_IN_SUITE).when(testSuite).getState();
    doReturn(30).when(testSuite).getWarningTime();
    doReturn(40).when(testSuite).getCriticalTime();
    doReturn(44.81f).when(testSuite).getDuration();
    doReturn(new DateTime(1970, 1, 1, 10, 33, 0).toDate()).when(testSuite).getStartDate();
    doReturn(new DateTime(1970, 1, 1, 10, 33, 44, 810).toDate()).when(testSuite).getStopDate();
    SortedSet<TestCase> testCaseAsSortedSet = new TreeSet<>(Arrays.asList(new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 33, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 33, 13, 910).toDate()).withId("case1").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Test_Sahi_landing_page").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 33, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 33, 1, 160).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 33, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 33, 7, 250).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 33, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 33, 1, 450).toDate()).buildExample())).buildExample(), new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 33, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 33, 23, 550).toDate()).withId("case2").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Test_Sahi_landing_page_(case2)").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 33, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 33, 1, 50).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 33, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 33, 17, 30).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 33, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 33, 21, 390).toDate()).buildExample())).buildExample()));
    doReturn(testCaseAsSortedSet).when(testSuite).getTestCasesAsSortedSet();
    String output = testling.createOutput();
    Assert.assertEquals(output, loadExpectedOutput(TestSuiteState.CRITICAL_IN_SUITE.name()));
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TreeSet(java.util.TreeSet) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) DateTime(org.joda.time.DateTime) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 15 with TestCaseStepExampleBuilder

use of org.sakuli.builder.TestCaseStepExampleBuilder in project sakuli by ConSol.

the class CheckMKTemplateOutputBuilderTest method testCritInCase.

@Test
public void testCritInCase() throws Exception {
    doReturn("example_xfce").when(testSuite).getId();
    doReturn(TestSuiteState.CRITICAL_IN_CASE).when(testSuite).getState();
    doReturn(300).when(testSuite).getWarningTime();
    doReturn(400).when(testSuite).getCriticalTime();
    doReturn(46.96f).when(testSuite).getDuration();
    doReturn(new DateTime(1970, 1, 1, 10, 35, 0).toDate()).when(testSuite).getStartDate();
    doReturn(new DateTime(1970, 1, 1, 10, 35, 46, 960).toDate()).when(testSuite).getStopDate();
    SortedSet<TestCase> testCaseAsSortedSet = new TreeSet<>(Arrays.asList(new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 35, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 35, 14, 130).toDate()).withId("case1").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Test_Sahi_landing_page").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 35, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 35, 1, 280).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 35, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 35, 7, 310).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 35, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 35, 1, 470).toDate()).buildExample())).buildExample(), new TestCaseExampleBuilder().withState(TestCaseState.CRITICAL).withWarningTime(2).withCriticalTime(3).withStartDate(new DateTime(1970, 1, 1, 10, 35, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 35, 33, 700).toDate()).withId("case2").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Test_Sahi_landing_page_(case2)").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 35, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 35, 1, 80).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 35, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 35, 7, 120).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 35, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 35, 1, 440).toDate()).buildExample())).buildExample()));
    doReturn(testCaseAsSortedSet).when(testSuite).getTestCasesAsSortedSet();
    String output = testling.createOutput();
    Assert.assertEquals(output, loadExpectedOutput(TestSuiteState.CRITICAL_IN_CASE.name()));
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TreeSet(java.util.TreeSet) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) DateTime(org.joda.time.DateTime) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Aggregations

TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)19 Test (org.testng.annotations.Test)19 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)17 BaseTest (org.sakuli.BaseTest)15 TestCase (org.sakuli.datamodel.TestCase)11 DateTime (org.joda.time.DateTime)9 TreeSet (java.util.TreeSet)7 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)6 TestSuite (org.sakuli.datamodel.TestSuite)6 Path (java.nio.file.Path)4 SakuliException (org.sakuli.exceptions.SakuliException)4 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)3 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)3 GearmanProperties (org.sakuli.services.forwarder.gearman.GearmanProperties)3 Date (java.util.Date)2 Future (java.util.concurrent.Future)1 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)1 LoggerTest (org.sakuli.LoggerTest)1 TestCaseStepState (org.sakuli.datamodel.state.TestCaseStepState)1 SakuliActionException (org.sakuli.exceptions.SakuliActionException)1