use of org.sakuli.services.forwarder.gearman.model.ScreenshotDiv in project sakuli by ConSol.
the class CheckMKTemplateOutputBuilderTest method testException.
@Test
public void testException() throws Exception {
doReturn("example_xfce").when(testSuite).getId();
doReturn(TestSuiteState.ERRORS).when(testSuite).getState();
doReturn(300).when(testSuite).getWarningTime();
doReturn(400).when(testSuite).getCriticalTime();
doReturn(44.80f).when(testSuite).getDuration();
doReturn(new DateTime(1970, 1, 1, 10, 36, 0).toDate()).when(testSuite).getStartDate();
doReturn(new DateTime(1970, 1, 1, 10, 36, 44, 800).toDate()).when(testSuite).getStopDate();
when(testSuite.getExceptionMessages(anyBoolean())).thenCallRealMethod();
when(testSuite.getException()).thenCallRealMethod();
SortedSet<TestCase> testCaseAsSortedSet = new TreeSet<>(Arrays.asList(new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 14, 200).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, 36, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 1, 140).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 7, 540).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 1, 470).toDate()).buildExample())).buildExample(), new TestCaseExampleBuilder().withState(TestCaseState.ERRORS).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 36, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 23, 550).toDate()).withId("case2").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.ERRORS).withName("Test_Sahi_landing_page_(case2)").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 1, 50).toDate()).withException(new SakuliException("_highlight(_link(\"xSL Manager\")); TypeError: el is undefined Sahi.prototype._highlight@http://sahi.example.com/_s_/spr/concat.js:1210:9 @http://sahi.example.com/_s_/spr/concat.js line 3607 > eval:1:1 Sahi.prototype.ex@http://sahi.example.com/_s_/spr/concat.js:3607:9 Sahi.prototype.ex@http://sahi.example.com/_s_/spr/sakuli/inject.js:46:12 @http://sahi.example.com/_s_/spr/concat.js:3373:5 <a href='/_s_/dyn/Log_getBrowserScript?href=/root/sakuli/example_test_suites/example_xfce/case2/sakuli_demo.js&n=1210'><b>Click for browser script</b></a>")).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 17, 30).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 21, 390).toDate()).buildExample())).buildExample()));
doReturn(testCaseAsSortedSet).when(testSuite).getTestCasesAsSortedSet();
ScreenshotDiv screenshotDiv = new ScreenshotDiv();
screenshotDiv.setId("sakuli_screenshot243575009");
screenshotDiv.setFormat("jpg");
screenshotDiv.setBase64screenshot("/9j/4AAQSkZJRgABAgAAAQABAAD9k=");
doReturn(screenshotDiv).when(screenshotDivConverter).convert(notNull(Throwable.class));
String output = testling.createOutput();
Assert.assertEquals(output, loadExpectedOutput(TestSuiteState.ERRORS.name()));
}
use of org.sakuli.services.forwarder.gearman.model.ScreenshotDiv 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.services.forwarder.gearman.model.ScreenshotDiv in project sakuli by ConSol.
the class ScreenshotDivConverterTest method testRemoveBase64Data.
@Test
public void testRemoveBase64Data() throws Exception {
ScreenshotDiv testling = new ScreenshotDiv();
testling.setId("test-id");
testling.setFormat("jpg");
testling.setBase64screenshot("00001111");
String result = ScreenshotDivConverter.removeBase64ImageDataString(testling.getPayloadString());
assertEquals(result, "<div id=\"test-id\">" + "<div id=\"openModal_test-id\" class=\"modalDialog\">" + "<a href=\"#close\" title=\"Close\" class=\"close\">Close X</a>" + "<a href=\"#openModal_test-id\"><img class=\"screenshot\" src=\"\" ></a>" + "</div>" + "</div>");
String srcString2 = "blas\nblakdfakdfjie";
assertEquals(srcString2, ScreenshotDivConverter.removeBase64ImageDataString(srcString2));
}
use of org.sakuli.services.forwarder.gearman.model.ScreenshotDiv 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.services.forwarder.gearman.model.ScreenshotDiv in project sakuli by ConSol.
the class AbstractOutputBuilder method generateTestCaseScreenshotsHTML.
/**
* Generates '<div></div>' tag for the screenshots included in the {@link TestCase} and the suppressed {@link TestCaseStep}s.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
protected String generateTestCaseScreenshotsHTML(TestCase testCase) {
StringBuilder sb = new StringBuilder();
ScreenshotDiv caseDiv = screenshotDivConverter.convert(testCase.getException());
if (caseDiv != null) {
sb.append(caseDiv.getPayloadString());
}
for (TestCaseStep step : testCase.getStepsAsSortedSet()) {
ScreenshotDiv stepDiv = screenshotDivConverter.convert(step.getException());
if (stepDiv != null) {
sb.append(stepDiv.getPayloadString());
}
}
return sb.toString();
}
Aggregations