@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(); }
@Test public void test_execute_when_messageProvider_message_is_null_not_in_recovery() throws SchedulerException { final FlowEvent mockFlowEvent = mockery.mock(FlowEvent.class); final MessageProvider mockMessageProvider = mockery.mock(MessageProvider.class); final String identifier = "testId"; // expectations mockery.checking( new Expectations() { { exactly(1).of(mockMessageProvider).invoke(jobExecutionContext); will(returnValue(null)); // schedule the job exactly(0) .of(mockManagedEventIdentifierService) .getEventIdentifier(jobExecutionContext); will(returnValue(identifier)); exactly(0).of(flowEventFactory).newEvent(identifier, jobExecutionContext); will(returnValue(mockFlowEvent)); exactly(0).of(eventListener).invoke(mockFlowEvent); exactly(1).of(mockManagedResourceRecoveryManager).isRecovering(); will(returnValue(false)); exactly(1).of(consumerConfiguration).isEager(); will(returnValue(false)); } }); ScheduledConsumer scheduledConsumer = new StubbedScheduledConsumer(scheduler); scheduledConsumer.setConfiguration(consumerConfiguration); scheduledConsumer.setEventFactory(flowEventFactory); scheduledConsumer.setEventListener(eventListener); scheduledConsumer.setManagedEventIdentifierService(mockManagedEventIdentifierService); scheduledConsumer.setManagedResourceRecoveryManager(mockManagedResourceRecoveryManager); scheduledConsumer.setMessageProvider(mockMessageProvider); // test scheduledConsumer.execute(jobExecutionContext); // assert mockery.assertIsSatisfied(); }