Search in sources :

Example 1 with DeliveryOptions

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);
}
Also used : MockRequestContext(org.springframework.webflow.test.MockRequestContext) DeliveryOptions(org.opennms.reporting.core.DeliveryOptions) Test(org.junit.Test)

Example 2 with DeliveryOptions

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());
}
Also used : MockRequestContext(org.springframework.webflow.test.MockRequestContext) DeliveryOptions(org.opennms.reporting.core.DeliveryOptions) Test(org.junit.Test)

Example 3 with DeliveryOptions

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;
}
Also used : UserManager(org.opennms.netmgt.config.UserManager) DeliveryOptions(org.opennms.reporting.core.DeliveryOptions) ReportException(org.opennms.api.reporting.ReportException) JavaMailerException(org.opennms.javamail.JavaMailerException)

Example 4 with DeliveryOptions

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());
}
Also used : TriggerKey(org.quartz.TriggerKey) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DeliveryOptions(org.opennms.reporting.core.DeliveryOptions) Test(org.junit.Test)

Example 5 with DeliveryOptions

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);
}
Also used : MockRequestContext(org.springframework.webflow.test.MockRequestContext) DeliveryOptions(org.opennms.reporting.core.DeliveryOptions) Test(org.junit.Test)

Aggregations

DeliveryOptions (org.opennms.reporting.core.DeliveryOptions)9 Test (org.junit.Test)8 MockRequestContext (org.springframework.webflow.test.MockRequestContext)8 TriggerKey (org.quartz.TriggerKey)2 ReportException (org.opennms.api.reporting.ReportException)1 JavaMailerException (org.opennms.javamail.JavaMailerException)1 UserManager (org.opennms.netmgt.config.UserManager)1