use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class NagiosOutputBuilderTest method testFormatTestSuiteTableException.
@Test
public void testFormatTestSuiteTableException() 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.formatTestSuiteTableStateMessage(testSuiteExample, gearmanProperties.getTemplateSuiteTable());
String lastRun = AbstractOutputBuilder.dateFormat.format(testSuiteExample.getStopDate());
assertEquals(result, "<tr valign=\"top\"><td class=\"serviceCRITICAL\">[CRIT] Sakuli suite \"sakuli-123\"" + " (120.00s) EXCEPTION: 'TEST-ERROR'. (Last suite run: " + lastRun + ")</td></tr>");
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class Icinga2OutputBuilderTest method testBuildErrorInStep.
@Test
public void testBuildErrorInStep() 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).withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.ERRORS).withException(new SakuliException("MY-TEST-ERROR-IN-STEP")).buildExample())).buildExample())).buildExample();
ReflectionTestUtils.setField(testling, "testSuite", testSuite);
Assert.assertEquals(testling.build(), "[CRIT] Sakuli suite \"TEST-SUITE-ID\" (120.00s) EXCEPTION: 'CASE \"TEST-CASE-ID\": STEP \"step_for_unit_test\": MY-TEST-ERROR-IN-STEP'. (Last suite run: 17.08.14 14:02:00)\n" + "[CRIT] case \"TEST-CASE-ID\" EXCEPTION: STEP \"step_for_unit_test\": MY-TEST-ERROR-IN-STEP");
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class BaseActionLoaderTest method testInitNoSahiSession.
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void testInitNoSahiSession() throws Exception {
String testCaseId = "xyz";
when(testSuite.getTestCase(testCaseId)).thenReturn(new TestCase("Test", testCaseId));
when(rhinoScriptRunner.getSession()).thenReturn(null);
when(sakuliProperties.isLoadJavaScriptEngine()).thenReturn(true);
ArgumentCaptor<SakuliException> ac = ArgumentCaptor.forClass(SakuliException.class);
testling.init(testCaseId, ".");
verify(exceptionHandler).handleException(ac.capture());
assertEquals(ac.getValue().getMessage(), "cannot init rhino script runner with sakuli custom delay variable 'sakuli-delay-active'");
verify(session, never()).setVariable(anyString(), anyString());
}
use of org.sakuli.exceptions.SakuliException in project sakuli by ConSol.
the class ExceptionHandlerAspect method processJavaException.
/**
* Throw the handled Exception after {@link SakuliExceptionHandler#processException(Throwable)} to stop the current
* test case execution of an JAVA test.
*/
@After("execution(* org.sakuli.exceptions.SakuliExceptionHandler.processException(..)) ")
public void processJavaException(JoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs();
if (args != null && args.length == 1) {
Object e = args[0];
SakuliExceptionHandler exceptionHandler = BeanLoader.loadBaseActionLoader().getExceptionHandler();
if (e instanceof SakuliException && exceptionHandler.resumeToTestExcecution((SakuliException) e)) {
return;
}
throw (Throwable) e;
}
}
Aggregations