Search in sources :

Example 1 with ConfigurationHelper

use of org.finra.herd.core.helper.ConfigurationHelper in project herd by FINRAOS.

the class SampleDataJmsMessageListenerTest method testControlListener.

@Test
public void testControlListener() {
    configurationHelper = Mockito.mock(ConfigurationHelper.class);
    ReflectionTestUtils.setField(sampleDataJmsMessageListener, "configurationHelper", configurationHelper);
    MessageListenerContainer mockMessageListenerContainer = Mockito.mock(MessageListenerContainer.class);
    // The listener is not enabled
    when(configurationHelper.getProperty(ConfigurationValue.SAMPLE_DATA_JMS_LISTENER_ENABLED)).thenReturn("false");
    JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
    when(registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE)).thenReturn(mockMessageListenerContainer);
    // the listener is not running, nothing happened
    when(mockMessageListenerContainer.isRunning()).thenReturn(false);
    sampleDataJmsMessageListener.controlSampleDataJmsMessageListener();
    verify(mockMessageListenerContainer, Mockito.times(0)).stop();
    verify(mockMessageListenerContainer, Mockito.times(0)).start();
    // the listener is running, but it is not enable, should stop
    when(mockMessageListenerContainer.isRunning()).thenReturn(true);
    sampleDataJmsMessageListener.controlSampleDataJmsMessageListener();
    verify(mockMessageListenerContainer).stop();
    // The listener is enabled
    when(configurationHelper.getProperty(ConfigurationValue.SAMPLE_DATA_JMS_LISTENER_ENABLED)).thenReturn("true");
    // the listener is running, should not call the start method
    when(mockMessageListenerContainer.isRunning()).thenReturn(true);
    sampleDataJmsMessageListener.controlSampleDataJmsMessageListener();
    verify(mockMessageListenerContainer, Mockito.times(0)).start();
    // the listener is not running, but it is enabled, should start
    when(mockMessageListenerContainer.isRunning()).thenReturn(false);
    sampleDataJmsMessageListener.controlSampleDataJmsMessageListener();
    verify(mockMessageListenerContainer).start();
}
Also used : JmsListenerEndpointRegistry(org.springframework.jms.config.JmsListenerEndpointRegistry) ConfigurationHelper(org.finra.herd.core.helper.ConfigurationHelper) MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 2 with ConfigurationHelper

use of org.finra.herd.core.helper.ConfigurationHelper in project herd by FINRAOS.

the class HerdJmsMessageListenerTest method testControlListener.

@Test
public void testControlListener() {
    configurationHelper = Mockito.mock(ConfigurationHelper.class);
    ReflectionTestUtils.setField(herdJmsMessageListener, "configurationHelper", configurationHelper);
    MessageListenerContainer mockMessageListenerContainer = Mockito.mock(MessageListenerContainer.class);
    // The listener is not enabled
    when(configurationHelper.getProperty(ConfigurationValue.JMS_LISTENER_ENABLED)).thenReturn("false");
    JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
    when(registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING)).thenReturn(mockMessageListenerContainer);
    // the listener is not running, nothing happened
    when(mockMessageListenerContainer.isRunning()).thenReturn(false);
    herdJmsMessageListener.controlHerdJmsMessageListener();
    verify(mockMessageListenerContainer, Mockito.times(0)).stop();
    verify(mockMessageListenerContainer, Mockito.times(0)).start();
    // the listener is running, but it is not enable, should stop
    when(mockMessageListenerContainer.isRunning()).thenReturn(true);
    herdJmsMessageListener.controlHerdJmsMessageListener();
    verify(mockMessageListenerContainer).stop();
    // The listener is enabled
    when(configurationHelper.getProperty(ConfigurationValue.JMS_LISTENER_ENABLED)).thenReturn("true");
    // the listener is running, should not call the start method
    when(mockMessageListenerContainer.isRunning()).thenReturn(true);
    herdJmsMessageListener.controlHerdJmsMessageListener();
    verify(mockMessageListenerContainer, Mockito.times(0)).start();
    // the listener is not running, but it is enabled, should start
    when(mockMessageListenerContainer.isRunning()).thenReturn(false);
    herdJmsMessageListener.controlHerdJmsMessageListener();
    verify(mockMessageListenerContainer).start();
}
Also used : JmsListenerEndpointRegistry(org.springframework.jms.config.JmsListenerEndpointRegistry) ConfigurationHelper(org.finra.herd.core.helper.ConfigurationHelper) MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 3 with ConfigurationHelper

use of org.finra.herd.core.helper.ConfigurationHelper in project herd by FINRAOS.

the class StoragePolicyProcessorJmsMessageListenerTest method testControlListener.

@Test
public void testControlListener() {
    configurationHelper = Mockito.mock(ConfigurationHelper.class);
    ReflectionTestUtils.setField(storagePolicyProcessorJmsMessageListener, "configurationHelper", configurationHelper);
    MessageListenerContainer mockMessageListenerContainer = Mockito.mock(MessageListenerContainer.class);
    // The listener is not enabled
    when(configurationHelper.getProperty(ConfigurationValue.STORAGE_POLICY_PROCESSOR_JMS_LISTENER_ENABLED)).thenReturn("false");
    JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext().getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);
    when(registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE)).thenReturn(mockMessageListenerContainer);
    // the listener is not running, nothing happened
    when(mockMessageListenerContainer.isRunning()).thenReturn(false);
    storagePolicyProcessorJmsMessageListener.controlStoragePolicyProcessorJmsMessageListener();
    verify(mockMessageListenerContainer, Mockito.times(0)).stop();
    verify(mockMessageListenerContainer, Mockito.times(0)).start();
    // the listener is running, but it is not enable, should stop
    when(mockMessageListenerContainer.isRunning()).thenReturn(true);
    storagePolicyProcessorJmsMessageListener.controlStoragePolicyProcessorJmsMessageListener();
    verify(mockMessageListenerContainer).stop();
    // The listener is enabled
    when(configurationHelper.getProperty(ConfigurationValue.STORAGE_POLICY_PROCESSOR_JMS_LISTENER_ENABLED)).thenReturn("true");
    // the listener is running, should not call the start method
    when(mockMessageListenerContainer.isRunning()).thenReturn(true);
    storagePolicyProcessorJmsMessageListener.controlStoragePolicyProcessorJmsMessageListener();
    verify(mockMessageListenerContainer, Mockito.times(0)).start();
    // the listener is not running, but it is enabled, should start
    when(mockMessageListenerContainer.isRunning()).thenReturn(false);
    storagePolicyProcessorJmsMessageListener.controlStoragePolicyProcessorJmsMessageListener();
    verify(mockMessageListenerContainer).start();
}
Also used : JmsListenerEndpointRegistry(org.springframework.jms.config.JmsListenerEndpointRegistry) ConfigurationHelper(org.finra.herd.core.helper.ConfigurationHelper) MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

ConfigurationHelper (org.finra.herd.core.helper.ConfigurationHelper)3 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)3 Test (org.junit.Test)3 JmsListenerEndpointRegistry (org.springframework.jms.config.JmsListenerEndpointRegistry)3 MessageListenerContainer (org.springframework.jms.listener.MessageListenerContainer)3