Search in sources :

Example 1 with TestSuiteExampleBuilder

use of org.sakuli.builder.TestSuiteExampleBuilder in project sakuli by ConSol.

the class CacheHandlingResultServiceImplTest method init.

@BeforeMethod
public void init() {
    testSuite = new TestSuiteExampleBuilder().withId("LOG_TEST_SUITE").withState(TestSuiteState.ERRORS).withException(new SakuliException("TEST")).buildExample();
    exceptionHandler = Mockito.mock(SakuliExceptionHandler.class);
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    ReflectionTestUtils.setField(testling, "exceptionHandler", exceptionHandler);
}
Also used : SakuliExceptionHandler(org.sakuli.exceptions.SakuliExceptionHandler) SakuliException(org.sakuli.exceptions.SakuliException) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with TestSuiteExampleBuilder

use of org.sakuli.builder.TestSuiteExampleBuilder in project sakuli by ConSol.

the class NagiosOutputBuilderTest method testGetStatusSummary.

@Test
public void testGetStatusSummary() throws Exception {
    TestSuite testSuite = new TestSuiteExampleBuilder().withState(TestSuiteState.OK).withId("TEST-SUITE-ID").withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withId("TEST-CASE-ID").buildExample())).buildExample();
    String lastRun = AbstractOutputBuilder.dateFormat.format(testSuite.getStopDate());
    String expectedHTML = "[OK] Sakuli suite \"TEST-SUITE-ID\" ok (120.00s). (Last suite run: " + lastRun + ")\\\\n" + String.format(ScreenshotDiv.STYLE_TEMPLATE, testling.getOutputScreenshotDivWidth()) + "<table style=\"border-collapse: collapse;\">" + "<tr valign=\"top\">" + "<td class=\"serviceOK\">[OK] Sakuli suite \"TEST-SUITE-ID\" ok (120.00s). (Last suite run: " + lastRun + ")" + "</td>" + "</tr>" + "<tr valign=\"top\">" + "<td class=\"serviceOK\">[OK] case \"TEST-CASE-ID\" ran in 3.00s - ok</td>" + "</tr>" + "</table>";
    String statusSummary = testling.getStatusSummary(testSuite, gearmanProperties);
    assertEquals(statusSummary, expectedHTML);
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    ReflectionTestUtils.setField(testling, "gearmanProperties", gearmanProperties);
    NagiosOutput output = testling.build();
    String substringStatusSummary = output.getOutputString().substring(0, output.getOutputString().indexOf("|"));
    assertEquals(substringStatusSummary, expectedHTML);
}
Also used : NagiosOutput(org.sakuli.services.forwarder.gearman.model.NagiosOutput) TestSuite(org.sakuli.datamodel.TestSuite) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 3 with TestSuiteExampleBuilder

use of org.sakuli.builder.TestSuiteExampleBuilder in project sakuli by ConSol.

the class AbstractPerformanceDataBuilderTest method testGetPerformanceDataWithPreParsedSteps.

@Test
public void testGetPerformanceDataWithPreParsedSteps() throws Exception {
    Date startDate = new GregorianCalendar(2014, 14, 7, 13, 0).getTime();
    TestSuite testSuiteExample = new TestSuiteExampleBuilder().withId("sakuli-123").withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 120)).withWarningTime(100).withCriticalTime(150).withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withState(TestCaseState.WARNING_IN_STEP).withId("case-warning").withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 20)).withWarningTime(19).withCriticalTime(25).withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withName("step1").withState(TestCaseStepState.WARNING).withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 10)).withWarningTime(9).buildExample(), new TestCaseStepBuilder("step2_not_started").withState(TestCaseStepState.INIT).build())).buildExample())).buildExample();
    testSuiteExample.refreshState();
    assertEquals(AbstractPerformanceDataBuilder.getTestSuitePerformanceData(testSuiteExample), "suite__state=1;;;; " + "suite__warning=100s;;;; " + "suite__critical=150s;;;; " + "suite_sakuli-123=120.00s;100;150;; " + "c_001__state=1;;;; " + "c_001__warning=19s;;;; " + "c_001__critical=25s;;;; " + "c_001_case-warning=20.00s;19;25;; " + "s_001_001_step1=10.00s;9;;; " + "s_001_002_step2_not_started=U;;;;");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 4 with TestSuiteExampleBuilder

use of org.sakuli.builder.TestSuiteExampleBuilder in project sakuli by ConSol.

the class CommonResultServiceImplTest method testSaveAllResults.

@Test(dataProvider = "states")
public void testSaveAllResults(TestSuiteState testSuiteState, TestCaseState testCaseState, String stateOutputRegex) throws Exception {
    TestCaseStepState stepState = TestCaseStepState.WARNING;
    TestSuite testSuite = new TestSuiteExampleBuilder().withId("LOG_TEST_SUITE").withState(testSuiteState).withException(testSuiteState.isError() ? new SakuliCheckedException("TEST") : null).withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withState(stepState).buildExample())).withState(testCaseState).buildExample())).buildExample();
    Path logfile = Paths.get(properties.getLogFile());
    testling.tearDown(Optional.of(testSuite));
    String lastLineOfLogFile = getLastLineOfLogFile(logfile, testSuiteState.isError() ? 42 : 39);
    List<String> regExes = getValidationExpressions(testSuiteState, testCaseState, stepState, stateOutputRegex, "TEST");
    List<String> strings = Arrays.asList(lastLineOfLogFile.split("\n"));
    Iterator<String> regExIterator = regExes.iterator();
    verifyOutputLines(strings, regExIterator);
}
Also used : Path(java.nio.file.Path) TestSuite(org.sakuli.datamodel.TestSuite) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestCaseStepState(org.sakuli.datamodel.state.TestCaseStepState) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) LoggerTest(org.sakuli.LoggerTest)

Example 5 with TestSuiteExampleBuilder

use of org.sakuli.builder.TestSuiteExampleBuilder 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 SakuliCheckedException("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) SakuliCheckedException(org.sakuli.exceptions.SakuliCheckedException) Date(java.util.Date) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test)

Aggregations

TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)29 TestSuite (org.sakuli.datamodel.TestSuite)26 Test (org.testng.annotations.Test)26 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)14 BaseTest (org.sakuli.BaseTest)11 SakuliCheckedException (org.sakuli.exceptions.SakuliCheckedException)7 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)6 SakuliForwarderRuntimeException (org.sakuli.exceptions.SakuliForwarderRuntimeException)6 SakuliRuntimeException (org.sakuli.exceptions.SakuliRuntimeException)6 NagiosCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCheckResult)6 Date (java.util.Date)5 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)5 BeforeMethod (org.testng.annotations.BeforeMethod)3 Path (java.nio.file.Path)2 SakuliException (org.sakuli.exceptions.SakuliException)2 NagiosOutput (org.sakuli.services.forwarder.gearman.model.NagiosOutput)2 Future (java.util.concurrent.Future)1 LoggerTest (org.sakuli.LoggerTest)1 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)1 TestCaseStepState (org.sakuli.datamodel.state.TestCaseStepState)1