/** * Test successful consumer stop. * * @throws SchedulerException */ @Test public void test_successful_stop() throws SchedulerException { final JobKey jobKey = new JobKey("flowName", "moduleName"); // expectations mockery.checking( new Expectations() { { exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); // unschedule the job exactly(1).of(scheduler).checkExists(jobKey); will(returnValue(Boolean.TRUE)); exactly(1).of(scheduler).deleteJob(jobKey); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.setJobDetail(mockJobDetail); scheduledConsumer.stop(); mockery.assertIsSatisfied(); }
/** * Test successful consumer start. * * @throws SchedulerException */ @Test public void test_successful_start() throws SchedulerException { final JobKey jobKey = new JobKey("flowName", "moduleName"); // expectations mockery.checking( new Expectations() { { // get flow and module name from the job exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); // access configuration for details exactly(1).of(consumerConfiguration).getCronExpression(); will(returnValue("* * * * ? ?")); // schedule the job exactly(1).of(scheduler).scheduleJob(mockJobDetail, trigger); will(returnValue(new Date())); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.setJobDetail(mockJobDetail); scheduledConsumer.start(); mockery.assertIsSatisfied(); }
@Test public void test_execute_when_messageProvider_message_is_null_when_in_recovery_and_reinstate_business_schedule() throws SchedulerException { final MessageProvider mockMessageProvider = mockery.mock(MessageProvider.class); final JobKey jobKey = new JobKey(""); // expectations mockery.checking( new Expectations() { { exactly(1).of(mockMessageProvider).invoke(jobExecutionContext); will(returnValue(null)); exactly(1).of(consumerConfiguration).isEager(); will(returnValue(false)); exactly(2).of(mockManagedResourceRecoveryManager).isRecovering(); will(returnValue(true)); // cancel recovery exactly(1).of(mockManagedResourceRecoveryManager).cancel(); // nope, consumer is not running exactly(1).of(scheduler).isShutdown(); will(returnValue(false)); exactly(1).of(scheduler).isInStandbyMode(); will(returnValue(false)); exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); exactly(1).of(scheduler).checkExists(jobKey); will(returnValue(false)); // start consumer exactly(1).of(mockJobDetail).getKey(); will(returnValue(jobKey)); exactly(1).of(consumerConfiguration).getCronExpression(); will(returnValue("*")); exactly(1).of(scheduler).scheduleJob(mockJobDetail, trigger); will(returnValue(new Date())); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setEventFactory(flowEventFactory); scheduledConsumer.setEventListener(eventListener); scheduledConsumer.setManagedEventIdentifierService(mockManagedEventIdentifierService); scheduledConsumer.setManagedResourceRecoveryManager(mockManagedResourceRecoveryManager); scheduledConsumer.setMessageProvider(mockMessageProvider); scheduledConsumer.setJobDetail(mockJobDetail); scheduledConsumer.setConfiguration(consumerConfiguration); // test scheduledConsumer.execute(jobExecutionContext); // assert mockery.assertIsSatisfied(); }
@Test public void test_execute_when_messageProvider_message_is_not_null_and_consumer_is_eager_existing_eagerTrigger() throws SchedulerException { final FlowEvent mockFlowEvent = mockery.mock(FlowEvent.class); final String identifier = "testId"; final JobKey jobKey = new JobKey("flowName", "moduleName"); final JobDetail jobDetail = mockery.mock(JobDetail.class); // expectations mockery.checking( new Expectations() { { exactly(1).of(mockManagedResourceRecoveryManager).isRecovering(); will(returnValue(false)); // schedule the job exactly(1) .of(mockManagedEventIdentifierService) .getEventIdentifier(jobExecutionContext); will(returnValue(identifier)); exactly(1).of(flowEventFactory).newEvent(identifier, jobExecutionContext); will(returnValue(mockFlowEvent)); exactly(1).of(eventListener).invoke(mockFlowEvent); exactly(1).of(consumerConfiguration).isEager(); will(returnValue(true)); exactly(1).of(jobDetail).getKey(); will(returnValue(jobKey)); exactly(1).of(scheduler).checkExists(with(any(TriggerKey.class))); will(returnValue(true)); exactly(1) .of(scheduler) .rescheduleJob(with(any(TriggerKey.class)), with(any(Trigger.class))); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.setEventFactory(flowEventFactory); scheduledConsumer.setEventListener(eventListener); scheduledConsumer.setManagedEventIdentifierService(mockManagedEventIdentifierService); scheduledConsumer.setManagedResourceRecoveryManager(mockManagedResourceRecoveryManager); scheduledConsumer.setJobDetail(jobDetail); // test scheduledConsumer.execute(jobExecutionContext); // assert mockery.assertIsSatisfied(); }