Search in sources :

Example 11 with TestCase

use of org.sakuli.datamodel.TestCase 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 12 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method testSaveExceptionsInCase.

@Test
public void testSaveExceptionsInCase() throws Exception {
    TestSuite ts = new TestSuite();
    when(loader.getTestSuite()).thenReturn(ts);
    TestCase tc = new TestCase(null, null);
    when(loader.getCurrentTestCase()).thenReturn(tc);
    testling.saveException(new SakuliException("test"));
    assertNull(ts.getException());
    assertEquals(tc.getException().getMessage(), "test");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 13 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method testContainsExceptionsSuite.

@Test
public void testContainsExceptionsSuite() throws Exception {
    TestSuite ts = new TestSuite();
    ts.addException(new SakuliException("bla"));
    TestCase tc = new TestCase(null, null);
    ts.addTestCase(tc);
    TestCaseStep step = new TestCaseStep();
    tc.addStep(step);
    assertTrue(SakuliExceptionHandler.containsException(ts));
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 14 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class BaseActionLoaderTest method testInitNoSahiDelay.

@Test
public void testInitNoSahiDelay() throws Exception {
    String testCaseId = "xyz";
    when(testSuite.getTestCase(testCaseId)).thenReturn(new TestCase("Test", testCaseId));
    when(sahiProxyProperties.isRequestDelayActive()).thenReturn(false);
    when(sakuliProperties.isLoadJavaScriptEngine()).thenReturn(true);
    testling.init(testCaseId, ".");
    verify(exceptionHandler, never()).handleException(any(Exception.class));
    verify(session).setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_ACTIVE_VAR, "false");
}
Also used : TestCase(org.sakuli.datamodel.TestCase) IOException(java.io.IOException) SakuliException(org.sakuli.exceptions.SakuliException) Test(org.testng.annotations.Test)

Example 15 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class BaseActionLoaderTest method testGetCurrenTestCase.

@Test
public void testGetCurrenTestCase() throws Exception {
    assertNull(testling.getCurrentTestCaseStep());
    TestCase tc = new TestCase("test", "nocase");
    ReflectionTestUtils.setField(testling, "currentTestCase", tc);
    assertNotNull(testling.getCurrentTestCase());
    assertNull(testling.getCurrentTestCaseStep());
    DateTime creationDate = new DateTime();
    tc.addStep(new TestCaseStepBuilder("step_ok").withState(TestCaseStepState.OK).withCreationDate(creationDate).build());
    tc.addStep(new TestCaseStepBuilder("step_warning").withState(TestCaseStepState.WARNING).withCreationDate(creationDate.plusMillis(1)).build());
    assertNull(testling.getCurrentTestCaseStep());
    tc.addStep(new TestCaseStepBuilder("step_init_1").withState(TestCaseStepState.INIT).withCreationDate(creationDate.plusMillis(10)).build());
    assertNotNull(testling.getCurrentTestCaseStep());
    assertEquals(testling.getCurrentTestCaseStep().getName(), "step_init_1");
    tc.addStep(new TestCaseStepBuilder("step_init_2").withState(TestCaseStepState.INIT).withCreationDate(creationDate.plusMillis(11)).build());
    assertNotNull(testling.getCurrentTestCaseStep());
    assertEquals(testling.getCurrentTestCaseStep().getName(), "step_init_1");
    //add step before other init state's
    tc.addStep(new TestCaseStepBuilder("step_error").withState(TestCaseStepState.ERRORS).withCreationDate(creationDate.plusMillis(2)).build());
    assertNotNull(testling.getCurrentTestCaseStep());
    assertEquals(testling.getCurrentTestCaseStep().getName(), "step_error");
}
Also used : TestCase(org.sakuli.datamodel.TestCase) DateTime(org.joda.time.DateTime) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) Test(org.testng.annotations.Test)

Aggregations

TestCase (org.sakuli.datamodel.TestCase)49 Test (org.testng.annotations.Test)33 BaseTest (org.sakuli.BaseTest)20 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)14 Path (java.nio.file.Path)13 TestSuite (org.sakuli.datamodel.TestSuite)13 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)11 DateTime (org.joda.time.DateTime)8 TestCaseStep (org.sakuli.datamodel.TestCaseStep)8 TreeSet (java.util.TreeSet)7 IOException (java.io.IOException)5 Date (java.util.Date)5 SakuliException (org.sakuli.exceptions.SakuliException)5 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)5 GearmanProperties (org.sakuli.services.forwarder.gearman.GearmanProperties)4 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)3 DaoTestCase (org.sakuli.services.forwarder.database.dao.DaoTestCase)2 DaoTestCaseStep (org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)2 SqlLobValue (org.springframework.jdbc.core.support.SqlLobValue)2 File (java.io.File)1