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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations