Search in sources :

Example 6 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class DaoTestCaseImplTest method testGetScreenshotAsSqlLobValueTestCase.

@Test
public void testGetScreenshotAsSqlLobValueTestCase() throws Exception {
    Path screenshotPath = Paths.get(this.getClass().getResource("computer.png").toURI());
    TestCase testCase = new TestCaseExampleBuilder().withException(null).withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withException(new SakuliExceptionWithScreenshot("test-exception", screenshotPath)).buildExample())).buildExample();
    SqlLobValue result = testling.getScreenshotAsSqlLobValue(testCase);
    assertNotNull(result);
}
Also used : Path(java.nio.file.Path) SqlLobValue(org.springframework.jdbc.core.support.SqlLobValue) 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)

Example 7 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class AbstractOutputBuilderTest method testGetTextPlaceHolderTestCase.

@Test
public void testGetTextPlaceHolderTestCase() throws Exception {
    TestCase testCase = new TestCaseExampleBuilder().withState(TestCaseState.OK).withTestCaseFile(Paths.get("folder/_tc.js")).buildExample();
    final PlaceholderMap textPlaceholder = testling.getTextPlaceholder(testCase);
    assertEquals(textPlaceholder.get(STATE), "OK");
    assertEquals(textPlaceholder.get(STATE_SHORT), "[OK]");
    assertEquals(textPlaceholder.get(STATE_DESC), "ok");
    assertEquals(textPlaceholder.get(NAME), testCase.getName());
    assertEquals(textPlaceholder.get(ID), testCase.getId());
    assertEquals(textPlaceholder.get(DURATION), "3.00");
    assertEquals(textPlaceholder.get(STOP_DATE), AbstractOutputBuilder.dateFormat.format(testCase.getStopDate()));
    assertEquals(textPlaceholder.get(START_DATE), AbstractOutputBuilder.dateFormat.format(testCase.getStartDate()));
    assertEquals(textPlaceholder.get(WARN_THRESHOLD), "4");
    assertEquals(textPlaceholder.get(CRITICAL_THRESHOLD), "5");
    assertEquals(textPlaceholder.get(ERROR_MESSAGE), "");
    assertEquals(textPlaceholder.get(CASE_FILE), String.format("folder%s_tc.js", File.separator));
    assertEquals(textPlaceholder.get(CASE_LAST_URL), "http://www.last-url.com");
    assertEquals(textPlaceholder.get(CASE_START_URL), "http://www.start-url.com");
    assertEquals(textPlaceholder.get(STEP_INFORMATION), "");
    assertEquals(textPlaceholder.get(TD_CSS_CLASS), "serviceOK");
    //assert empty fields
    assertEquals(textPlaceholder.get(SUITE_SUMMARY), "");
    assertEquals(textPlaceholder.get(SUITE_FOLDER), "");
    assertEquals(textPlaceholder.get(HOST), "");
    assertEquals(textPlaceholder.get(BROWSER_INFO), "");
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) Test(org.testng.annotations.Test)

Example 8 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class CheckMKTemplateOutputBuilderTest method testOK.

@Test
public void testOK() throws Exception {
    doReturn("example_xfce").when(testSuite).getId();
    doReturn(TestSuiteState.OK).when(testSuite).getState();
    doReturn(300).when(testSuite).getWarningTime();
    doReturn(400).when(testSuite).getCriticalTime();
    doReturn(44.99f).when(testSuite).getDuration();
    doReturn(new DateTime(1970, 1, 1, 10, 30, 0).toDate()).when(testSuite).getStartDate();
    doReturn(new DateTime(1970, 1, 1, 10, 30, 44, 99).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, 30, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 14, 20).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, 30, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 1, 160).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 30, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 7, 290).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 30, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 1, 500).toDate()).buildExample())).buildExample(), new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 30, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 23, 580).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, 30, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 1, 30).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 30, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 7, 80).toDate()).buildExample(), new TestCaseStepExampleBuilder().withName("Editor_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 30, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 1, 390).toDate()).buildExample())).buildExample()));
    doReturn(testCaseAsSortedSet).when(testSuite).getTestCasesAsSortedSet();
    String output = testling.createOutput();
    Assert.assertEquals(output, loadExpectedOutput(TestCaseState.OK.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 9 with TestCase

use of org.sakuli.datamodel.TestCase 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 10 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class NagiosOutputBuilderTest method testFormatTestCaseTableStateMessageWithScreenshotTestCase.

@Test
public void testFormatTestCaseTableStateMessageWithScreenshotTestCase() 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").withException(new SakuliExceptionWithScreenshot("EXCEPTION-MESSAGE", screenshotPath)).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: EXCEPTION-MESSAGE" + " - STEP \"step_for_unit_test\": STEP-EXCEPTION-MESSAGE" + "<div.* src=\"data:image\\/png;base64,.*><\\/div>" + "<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)

Aggregations

TestCase (org.sakuli.datamodel.TestCase)49 Test (org.testng.annotations.Test)33 BaseTest (org.sakuli.BaseTest)20 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)14 Path (java.nio.file.Path)13 TestSuite (org.sakuli.datamodel.TestSuite)13 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)11 DateTime (org.joda.time.DateTime)8 TestCaseStep (org.sakuli.datamodel.TestCaseStep)8 TreeSet (java.util.TreeSet)7 IOException (java.io.IOException)5 Date (java.util.Date)5 SakuliException (org.sakuli.exceptions.SakuliException)5 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)5 GearmanProperties (org.sakuli.services.forwarder.gearman.GearmanProperties)4 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)3 DaoTestCase (org.sakuli.services.forwarder.database.dao.DaoTestCase)2 DaoTestCaseStep (org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)2 SqlLobValue (org.springframework.jdbc.core.support.SqlLobValue)2 File (java.io.File)1