Search in sources :

Example 1 with SakuliExceptionWithScreenshot

use of org.sakuli.exceptions.SakuliExceptionWithScreenshot 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 2 with SakuliExceptionWithScreenshot

use of org.sakuli.exceptions.SakuliExceptionWithScreenshot in project sakuli by ConSol.

the class ScreenshotDivConverterTest method testWithException.

@Test
public void testWithException() throws Exception {
    Path screenshotPath = Paths.get(NagiosOutputBuilder.class.getResource("computer.png").toURI());
    assertTrue(Files.exists(screenshotPath));
    ScreenshotDiv result = testling.convert(new SakuliExceptionWithScreenshot("test", screenshotPath));
    assertNotNull(result);
    assertEquals(result.getId(), ScreenshotDiv.DEFAULT_SAKULI_SCREENSHOT_DIV_ID + result.hashCode());
    assertEquals(result.getBase64screenshot(), base64String);
    assertEquals(result.getFormat(), "png");
    verify(sakuliExceptionHandler, never()).handleException(any(Exception.class));
}
Also used : Path(java.nio.file.Path) SakuliExceptionWithScreenshot(org.sakuli.exceptions.SakuliExceptionWithScreenshot) ScreenshotDiv(org.sakuli.services.forwarder.gearman.model.ScreenshotDiv) NoSuchFileException(java.nio.file.NoSuchFileException) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException) Test(org.testng.annotations.Test)

Example 3 with SakuliExceptionWithScreenshot

use of org.sakuli.exceptions.SakuliExceptionWithScreenshot in project sakuli by ConSol.

the class ScreenshotDivConverterTest method testThrowException.

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void testThrowException() throws Exception {
    Path screenshotPath = Paths.get("computerNOTVALID.png");
    ArgumentCaptor<Throwable> excpCaptor = ArgumentCaptor.forClass(Throwable.class);
    doNothing().when(sakuliExceptionHandler).handleException(excpCaptor.capture());
    ScreenshotDiv result = testling.convert(new SakuliExceptionWithScreenshot("test", screenshotPath));
    assertNull(result);
    verify(sakuliExceptionHandler).handleException(any(SakuliForwarderException.class));
    Throwable excp = excpCaptor.getValue();
    assertTrue(excp instanceof SakuliForwarderException);
    assertEquals(excp.getMessage(), "error during the BASE64 encoding of the screenshot 'computerNOTVALID.png'");
    assertTrue(excp.getSuppressed()[0] instanceof NoSuchFileException);
}
Also used : Path(java.nio.file.Path) SakuliExceptionWithScreenshot(org.sakuli.exceptions.SakuliExceptionWithScreenshot) NoSuchFileException(java.nio.file.NoSuchFileException) SakuliForwarderException(org.sakuli.exceptions.SakuliForwarderException) ScreenshotDiv(org.sakuli.services.forwarder.gearman.model.ScreenshotDiv) Test(org.testng.annotations.Test)

Example 4 with SakuliExceptionWithScreenshot

use of org.sakuli.exceptions.SakuliExceptionWithScreenshot 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)

Example 5 with SakuliExceptionWithScreenshot

use of org.sakuli.exceptions.SakuliExceptionWithScreenshot 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)

Aggregations

Path (java.nio.file.Path)9 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)9 Test (org.testng.annotations.Test)8 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)5 TestCase (org.sakuli.datamodel.TestCase)5 BaseTest (org.sakuli.BaseTest)4 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)3 SakuliForwarderException (org.sakuli.exceptions.SakuliForwarderException)3 GearmanProperties (org.sakuli.services.forwarder.gearman.GearmanProperties)3 NoSuchFileException (java.nio.file.NoSuchFileException)2 ScreenshotDiv (org.sakuli.services.forwarder.gearman.model.ScreenshotDiv)2 SqlLobValue (org.springframework.jdbc.core.support.SqlLobValue)2 IOException (java.io.IOException)1 Date (java.util.Date)1 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)1 TestSuite (org.sakuli.datamodel.TestSuite)1 BASE64Encoder (sun.misc.BASE64Encoder)1