use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class AbstractOutputBuilderTest method testFormatTestSuiteStateMessageException.
@Test
public void testFormatTestSuiteStateMessageException() 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.formatTestSuiteSummaryStateMessage(testSuiteExample, properties.getTemplateSuiteSummary());
String lastRun = AbstractOutputBuilder.dateFormat.format(testSuiteExample.getStopDate());
assertEquals(result, "[CRIT] Sakuli suite \"sakuli-123\" (120.00s) EXCEPTION: 'TEST-ERROR'. (Last suite run: " + lastRun + ")");
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class NagiosOutputBuilderTest method testFormatTestCaseTableStateMessage.
@Test
public void testFormatTestCaseTableStateMessage() throws Exception {
String htmlTemplate = "<tr valign=\"top\"><td class=\"%s\">%s</td></tr>";
GearmanProperties properties = MonitoringPropertiesTestHelper.initMock(mock(GearmanProperties.class));
TestCase testCase = new TestCaseExampleBuilder().withState(TestCaseState.OK).withId("case-ok").buildExample();
assertEquals(testling.formatTestCaseTableStateMessage(testCase, properties.lookUpTemplate(testCase.getState())), String.format(htmlTemplate, "serviceOK", "[OK] case \"case-ok\" ran in 3.00s - ok"));
Date startDate = new Date();
testCase = new TestCaseExampleBuilder().withId("case-warning").withState(TestCaseState.WARNING).withStartDate(startDate).withStopDate(DateUtils.addMilliseconds(startDate, 5500)).withWarningTime(5).buildExample();
assertEquals(testling.formatTestCaseTableStateMessage(testCase, properties.lookUpTemplate(testCase.getState())), String.format(htmlTemplate, "serviceWARNING", "[WARN] case \"case-warning\" over runtime (5.50s/warn at 5s)"));
testCase = new TestCaseExampleBuilder().withState(TestCaseState.WARNING_IN_STEP).withId("case-warning").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withName("step-name").withState(TestCaseStepState.WARNING).withStartDate(startDate).withStopDate(DateUtils.addMilliseconds(startDate, 3154)).withWarningTime(3).buildExample(), new TestCaseStepExampleBuilder().withName("step-name2").withState(TestCaseStepState.WARNING).withStartDate(DateUtils.addMilliseconds(startDate, 4000)).withStopDate(DateUtils.addMilliseconds(startDate, 4154)).withWarningTime(1).buildExample())).buildExample();
assertEquals(testling.formatTestCaseTableStateMessage(testCase, properties.lookUpTemplate(testCase.getState())), String.format(htmlTemplate, "serviceWARNING", "[WARN] case \"case-warning\" (3.00s) ok, step \"step-name\" over runtime (3.15s/warn at 3s), " + "step \"step-name2\" over runtime (0.15s/warn at 1s)"));
testCase = new TestCaseExampleBuilder().withState(TestCaseState.CRITICAL).withId("case-critical").withStartDate(startDate).withStopDate(DateUtils.addMilliseconds(startDate, 8888)).withCriticalTime(7).buildExample();
assertEquals(testling.formatTestCaseTableStateMessage(testCase, properties.lookUpTemplate(testCase.getState())), String.format(htmlTemplate, "serviceCRITICAL", "[CRIT] case \"case-critical\" over runtime (8.89s/crit at 7s)"));
testCase = new TestCaseExampleBuilder().withState(TestCaseState.ERRORS).withId("case-error").withException(new SakuliException("EXCEPTION-MESSAGE")).buildExample();
assertEquals(testling.formatTestCaseTableStateMessage(testCase, properties.lookUpTemplate(testCase.getState())), String.format(htmlTemplate, "serviceCRITICAL", "[CRIT] case \"case-error\" EXCEPTION: EXCEPTION-MESSAGE"));
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class Icinga2OutputBuilderTest method testBuildErrorInCase.
@Test
public void testBuildErrorInCase() throws Exception {
TestSuite testSuite = new TestSuiteExampleBuilder().withState(TestSuiteState.ERRORS).withId("TEST-SUITE-ID").withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withId("TEST-CASE-ID").withState(TestCaseState.ERRORS).withException(new SakuliException("MY-TEST-ERROR-CASE")).buildExample())).buildExample();
ReflectionTestUtils.setField(testling, "testSuite", testSuite);
Assert.assertEquals(testling.build(), "[CRIT] Sakuli suite \"TEST-SUITE-ID\" (120.00s) EXCEPTION: 'CASE \"TEST-CASE-ID\": MY-TEST-ERROR-CASE'. (Last suite run: 17.08.14 14:02:00)\n" + "[CRIT] case \"TEST-CASE-ID\" EXCEPTION: MY-TEST-ERROR-CASE");
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class ImageLib method addImagesFromFolder.
/**
* Helper methode to load all png images from folders as {@link ImageLibObject}
*
* @param paths multiple path to image folders
*/
public void addImagesFromFolder(Path... paths) throws IOException {
for (Path path : paths) {
logger.info("load all pics from \"" + path.toString() + "\" in picLib");
DirectoryStream<Path> directory = Files.newDirectoryStream(path);
for (Path file : directory) {
if (!Files.isDirectory(file)) {
try {
ImageLibObject imageLibObject = new ImageLibObject(file);
if (imageLibObject.getId() != null) {
put(imageLibObject.getId(), imageLibObject);
}
} catch (SakuliException e) {
logger.error(e.getMessage());
}
}
}
}
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class Application method killAppName.
private Application killAppName(String name) throws SakuliException {
try {
String cmd = String.format(Settings.isWindows() ? "Taskkill /IM \"%s\" /F" : "pkill \"%s\"", name);
CommandExecutorHelper.execute(cmd, 0);
} catch (Exception e) {
throw new SakuliException(e, String.format("could not kill application with name '%s'.", name));
}
return this;
}
Aggregations