Search in sources :

Example 26 with TestSuite

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

the class RegionImplTest method testResolveTakeScreenshotFolderFallback.

@Test
public void testResolveTakeScreenshotFolderFallback() throws Exception {
    TestCase tc = mock(TestCase.class);
    Path examplePath = Paths.get(BaseTest.TEST_FOLDER_PATH + File.separator + "NO_tc.js");
    when(tc.getTcFile()).thenReturn(examplePath);
    when(loader.getCurrentTestCase()).thenReturn(tc);
    TestSuite ts = mock(TestSuite.class);
    when(ts.getTestSuiteFolder()).thenReturn(Paths.get(BaseTest.TEST_FOLDER_PATH));
    when(loader.getTestSuite()).thenReturn(ts);
    Path result = RegionImpl.resolveTakeScreenshotFolder("test", loader);
    assertEquals(result.toString(), Paths.get(BaseTest.TEST_FOLDER_PATH) + File.separator + "test");
    verify(loader).getTestSuite();
    verify(loader).getCurrentTestCase();
}
Also used : Path(java.nio.file.Path) TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 27 with TestSuite

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

the class TestSuiteExampleBuilder method buildExample.

public TestSuite buildExample() {
    TestSuite testSuite = new TestSuite();
    testSuite.setName("Unit Test Sample Test Suite");
    testSuite.setId(id);
    testSuite.setStartDate(startDate);
    testSuite.setStopDate(stopDate);
    testSuite.setWarningTime(warningTime);
    testSuite.setCriticalTime(criticalTime);
    testSuite.setState(state);
    testSuite.setHost(host);
    testSuite.setBrowserInfo("Firefox Test Browser");
    testSuite.addException(exception);
    testSuite.setTestSuiteFolder(folder);
    testSuite.setBrowserInfo(browserInfo);
    for (TestCase testCase : testCases) {
        testSuite.addTestCase(testCase.getId(), testCase);
    }
    return testSuite;
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase)

Example 28 with TestSuite

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

the class NagiosOutputBuilderTest method testFormatTestSuiteTableExceptionWithScreenshot.

@Test
public void testFormatTestSuiteTableExceptionWithScreenshot() throws Exception {
    Path screenshotPath = Paths.get(NagiosOutputBuilder.class.getResource("computer.png").toURI());
    Date startDate = new Date();
    TestSuite testSuiteExample = new TestSuiteExampleBuilder().withId("sakuli-123").withState(TestSuiteState.ERRORS).withStartDate(startDate).withException(new SakuliExceptionWithScreenshot("TEST-ERROR", screenshotPath)).withStopDate(DateUtils.addSeconds(startDate, 120)).buildExample();
    String result = testling.formatTestSuiteTableStateMessage(testSuiteExample, gearmanProperties.getTemplateSuiteTable());
    String lastRun = AbstractOutputBuilder.dateFormat.format(testSuiteExample.getStopDate());
    final String separator = "<div";
    assertEquals(result.substring(0, result.indexOf(separator)), "<tr valign=\"top\"><td class=\"serviceCRITICAL\">[CRIT] Sakuli suite \"sakuli-123\"" + " (120.00s) EXCEPTION: 'TEST-ERROR'. (Last suite run: " + lastRun + ")");
    String screenshotHash = result.substring(result.indexOf(ScreenshotDiv.DEFAULT_SAKULI_SCREENSHOT_DIV_ID) + ScreenshotDiv.DEFAULT_SAKULI_SCREENSHOT_DIV_ID.length());
    screenshotHash = screenshotHash.substring(0, screenshotHash.indexOf("\">"));
    String start_1 = "<div id=\"sakuli_screenshot" + screenshotHash + "\">" + "<div id=\"openModal_sakuli_screenshot" + screenshotHash + "\" class=\"modalDialog\">" + "<a href=\"#close\" title=\"Close\" class=\"close\">Close X</a>" + "<a href=\"#openModal_sakuli_screenshot" + screenshotHash + "\"><img class=\"screenshot\" src=\"";
    String start = start_1 + "data:image/png;base64,";
    String end = "</a></div></div></td></tr>";
    String substring = result.substring(result.indexOf(separator));
    assertEquals(substring.substring(0, start.length()), start);
    assertEquals(substring.substring(substring.length() - end.length()), end);
    //now check the remove function
    String resultWithOutBase64Data = ScreenshotDivConverter.removeBase64ImageDataString(substring);
    assertEquals(resultWithOutBase64Data, start_1 + "\" >" + end);
}
Also used : Path(java.nio.file.Path) TestSuite(org.sakuli.datamodel.TestSuite) SakuliExceptionWithScreenshot(org.sakuli.exceptions.SakuliExceptionWithScreenshot) Date(java.util.Date) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 29 with TestSuite

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

the class NagiosOutputBuilderTest method testFormatTestSuiteTableException.

@Test
public void testFormatTestSuiteTableException() throws Exception {
    Date startDate = new Date();
    TestSuite testSuiteExample = new TestSuiteExampleBuilder().withId("sakuli-123").withState(TestSuiteState.ERRORS).withStartDate(startDate).withException(new SakuliException("TEST-ERROR")).withStopDate(DateUtils.addSeconds(startDate, 120)).buildExample();
    String result = testling.formatTestSuiteTableStateMessage(testSuiteExample, gearmanProperties.getTemplateSuiteTable());
    String lastRun = AbstractOutputBuilder.dateFormat.format(testSuiteExample.getStopDate());
    assertEquals(result, "<tr valign=\"top\"><td class=\"serviceCRITICAL\">[CRIT] Sakuli suite \"sakuli-123\"" + " (120.00s) EXCEPTION: 'TEST-ERROR'. (Last suite run: " + lastRun + ")</td></tr>");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) SakuliException(org.sakuli.exceptions.SakuliException) Date(java.util.Date) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 30 with TestSuite

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

the class Icinga2OutputBuilderTest method testBuildOk.

@Test
public void testBuildOk() throws Exception {
    TestSuite testSuite = new TestSuiteExampleBuilder().withState(TestSuiteState.OK).withId("TEST-SUITE-ID").withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withId("TEST-CASE-ID").buildExample())).buildExample();
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    Assert.assertEquals(testling.build(), "[OK] Sakuli suite \"TEST-SUITE-ID\" ok (120.00s). (Last suite run: 17.08.14 14:02:00)\n" + "[OK] case \"TEST-CASE-ID\" ran in 3.00s - ok");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test)

Aggregations

TestSuite (org.sakuli.datamodel.TestSuite)41 Test (org.testng.annotations.Test)34 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)21 BaseTest (org.sakuli.BaseTest)15 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)15 TestCase (org.sakuli.datamodel.TestCase)13 SakuliException (org.sakuli.exceptions.SakuliException)7 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)6 TestCaseStep (org.sakuli.datamodel.TestCaseStep)6 Path (java.nio.file.Path)5 Date (java.util.Date)5 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)2 SakuliInitException (org.sakuli.exceptions.SakuliInitException)2 FileNotFoundException (java.io.FileNotFoundException)1 Entry (java.util.Map.Entry)1 Future (java.util.concurrent.Future)1 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)1 DateTime (org.joda.time.DateTime)1 Matchers.anyString (org.mockito.Matchers.anyString)1 LoggerTest (org.sakuli.LoggerTest)1