Search in sources :

Example 6 with SakuliException

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 + ")");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) SakuliException(org.sakuli.exceptions.SakuliException) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test)

Example 7 with SakuliException

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"));
}
Also used : GearmanProperties(org.sakuli.services.forwarder.gearman.GearmanProperties) TestCase(org.sakuli.datamodel.TestCase) SakuliException(org.sakuli.exceptions.SakuliException) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) Date(java.util.Date) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 8 with SakuliException

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");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) SakuliException(org.sakuli.exceptions.SakuliException) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test)

Example 9 with SakuliException

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());
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) SakuliException(org.sakuli.exceptions.SakuliException)

Example 10 with SakuliException

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;
}
Also used : SakuliException(org.sakuli.exceptions.SakuliException) SakuliException(org.sakuli.exceptions.SakuliException)

Aggregations

SakuliException (org.sakuli.exceptions.SakuliException)19 Test (org.testng.annotations.Test)12 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)8 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)7 TestSuite (org.sakuli.datamodel.TestSuite)7 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)4 Date (java.util.Date)3 BaseTest (org.sakuli.BaseTest)3 TestCase (org.sakuli.datamodel.TestCase)3 Path (java.nio.file.Path)2 SakuliExceptionHandler (org.sakuli.exceptions.SakuliExceptionHandler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ConnectException (java.net.ConnectException)1 TreeSet (java.util.TreeSet)1 Report (net.sf.sahi.ant.Report)1 TestRunner (net.sf.sahi.test.TestRunner)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)1 After (org.aspectj.lang.annotation.After)1 DateTime (org.joda.time.DateTime)1