use of org.opennms.reporting.core.DeliveryOptions in project opennms by OpenNMS.
the class DefaultSchedulerServiceIT method testScheduleBadCronExpression.
@Test
public void testScheduleBadCronExpression() {
expect(m_reportWrapperService.validate(m_criteria, REPORT_ID)).andReturn(true);
replay(m_reportWrapperService);
MockRequestContext context = new MockRequestContext();
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setInstanceId("testScheduleBadCronExpressionTrigger");
assertEquals("error", m_schedulerService.addCronTrigger(REPORT_ID, m_criteria, deliveryOptions, "bad expression", context));
verify(m_reportWrapperService);
}
use of org.opennms.reporting.core.DeliveryOptions in project opennms by OpenNMS.
the class DefaultSchedulerServiceIT method testScheduleAndRun.
@Test
public void testScheduleAndRun() throws SchedulerException, InterruptedException {
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setInstanceId("testScheduleAndRunTrigger");
expect(m_reportWrapperService.validate(m_criteria, REPORT_ID)).andReturn(true);
m_reportWrapperService.run(m_criteria, ReportMode.SCHEDULED, deliveryOptions, REPORT_ID);
replay(m_reportWrapperService);
MockRequestContext context = new MockRequestContext();
assertEquals("success", m_schedulerService.addCronTrigger(REPORT_ID, m_criteria, deliveryOptions, CRON_EXPRESSION, context));
// give the trigger a chance to fire (one minute)
Thread.sleep(61000);
m_schedulerService.removeTrigger("testScheduleAndRunTrigger");
verify(m_reportWrapperService);
m_schedulerService.removeTrigger("testScheduleAndRunTrigger");
assertEquals(0, m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(TRIGGER_GROUP)).size());
}
use of org.opennms.reporting.core.DeliveryOptions in project opennms by OpenNMS.
the class DefaultReportWrapperService method getDeliveryOptions.
/** {@inheritDoc} */
@Override
public DeliveryOptions getDeliveryOptions(final String reportId, final String userId) {
final DeliveryOptions options = new DeliveryOptions();
options.setFormat(ReportFormat.HTML);
options.setPersist(true);
options.setSendMail(false);
Logging.withPrefix(LOG4J_CATEGORY, new Runnable() {
@Override
public void run() {
UserManager userFactory = UserFactory.getInstance();
try {
final String emailAddress = userFactory.getEmail(userId);
if (emailAddress != null && !emailAddress.isEmpty()) {
options.setMailTo(emailAddress);
}
} catch (final Exception e) {
LOG.error("An error occurred while attempting to determine and set the destination email address for user {}", userId, e);
}
options.setInstanceId(reportId + " " + userId);
}
});
return options;
}
use of org.opennms.reporting.core.DeliveryOptions in project opennms by OpenNMS.
the class DefaultSchedulerServiceIT method testScheduleAndRemove.
@Test
public void testScheduleAndRemove() throws SchedulerException {
expect(m_reportWrapperService.validate(m_criteria, REPORT_ID)).andReturn(true);
replay(m_reportWrapperService);
MockRequestContext context = new MockRequestContext();
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setInstanceId("testScheduleAndRemoveTrigger");
assertEquals("success", m_schedulerService.addCronTrigger(REPORT_ID, m_criteria, deliveryOptions, CRON_EXPRESSION, context));
verify(m_reportWrapperService);
Set<TriggerKey> triggers = m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(TRIGGER_GROUP));
assertEquals(1, triggers.size());
assertEquals("testScheduleAndRemoveTrigger", triggers.iterator().next().getName());
m_schedulerService.removeTrigger("testScheduleAndRemoveTrigger");
assertEquals(0, m_scheduler.getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(TRIGGER_GROUP)).size());
}
use of org.opennms.reporting.core.DeliveryOptions in project opennms by OpenNMS.
the class DefaultSchedulerServiceIT method testExecuteFailure.
@Test
public void testExecuteFailure() throws InterruptedException {
expect(m_reportWrapperService.validate(m_criteria, REPORT_ID)).andReturn(false);
replay(m_reportWrapperService);
MockRequestContext context = new MockRequestContext();
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setInstanceId("testExecuteFailureTrigger");
assertEquals("error", m_schedulerService.execute(REPORT_ID, m_criteria, deliveryOptions, context));
// give the trigger a chance to fire
Thread.sleep(1000);
verify(m_reportWrapperService);
}
Aggregations