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"));
}
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");
}
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));
}
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");
}
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");
}
Aggregations