HerdJmsDestinationResolver implements DestinationResolver { @Override public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) throws JMSException { String sqsQueueName; switch (destinationName) { case SQS_DESTINATION_HERD_INCOMING: sqsQueueName = getSqsQueueName(ConfigurationValue.HERD_NOTIFICATION_SQS_INCOMING_QUEUE_NAME); break; case SQS_DESTINATION_STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE: sqsQueueName = getSqsQueueName(ConfigurationValue.STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE_NAME); break; case SQS_DESTINATION_SAMPLE_DATA_QUEUE: sqsQueueName = getSqsQueueName(ConfigurationValue.SAMPLE_DATA_SQS_QUEUE_NAME); break; case SQS_DESTINATION_SEARCH_INDEX_UPDATE_QUEUE: sqsQueueName = getSqsQueueName(ConfigurationValue.SEARCH_INDEX_UPDATE_SQS_QUEUE_NAME); break; default: LOGGER.warn("Failed to resolve the destination name: \"%s\".", destinationName); sqsQueueName = ""; break; } Destination destination; try { destination = session.createQueue(sqsQueueName); } catch (Exception ex) { throw new IllegalStateException(String.format("Failed to resolve the SQS queue: \"%s\".", sqsQueueName), ex); } return destination; }  @Override Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain); static final String SQS_DESTINATION_HERD_INCOMING; static final String SQS_DESTINATION_STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE; static final String SQS_DESTINATION_SAMPLE_DATA_QUEUE; static final String SQS_DESTINATION_SEARCH_INDEX_UPDATE_QUEUE; }
@Test public void testResolveDestinationNameNoExists() throws Exception { try { herdJmsDestinationResolver.resolveDestinationName(null, "queue_not_exists", false); fail("Should throw an IllegalStateException."); } catch (IllegalStateException ex) { assertEquals(String.format("Failed to resolve the SQS queue: \"%s\".", ""), ex.getMessage()); } }
@Test public void testResolveDestinationNameNoQueueExists() throws Exception { try { herdJmsDestinationResolver.resolveDestinationName(null, HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING, false); fail("Should throw an IllegalStateException."); } catch (IllegalStateException ex) { assertTrue("\"Failed to resolve the SQS queue:\" error message doesn't match", ex.getMessage().startsWith("Failed to resolve the SQS queue:")); } }
@Test public void testResolveDestinationNameNoConfig() throws Exception { removeReloadablePropertySourceFromEnvironment(); try { herdJmsDestinationResolver.resolveDestinationName(null, HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING, false); fail("Should throw an IllegalStateException."); } catch (IllegalStateException ex) { assertEquals(String.format("SQS queue name not found. Ensure the \"%s\" configuration entry is configured.", ConfigurationValue.HERD_NOTIFICATION_SQS_INCOMING_QUEUE_NAME.getKey()), ex.getMessage()); } finally { restorePropertySourceInEnvironment(); } }
@Test public void testResolveDestinationHerdIncoming() throws Exception { Session session = mock(Session.class); Queue queue = mock(Queue.class); when(session.createQueue(any())).thenReturn(queue); Destination destination = herdJmsDestinationResolver.resolveDestinationName(session, HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING, false); assertThat("Destination is null.", destination, not(nullValue())); verify(session, times(1)).createQueue(any()); }
@Test public void testResolveDestinationStoragePolicy() throws Exception { Session session = mock(Session.class); Queue queue = mock(Queue.class); when(session.createQueue(any())).thenReturn(queue); Destination destination = herdJmsDestinationResolver.resolveDestinationName(session, HerdJmsDestinationResolver.SQS_DESTINATION_STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE, false); assertThat("Destination is null.", destination, not(nullValue())); verify(session, times(1)).createQueue(any()); }
@Test public void testResolveDestinationSampleData() throws Exception { Session session = mock(Session.class); Queue queue = mock(Queue.class); when(session.createQueue(any())).thenReturn(queue); Destination destination = herdJmsDestinationResolver.resolveDestinationName(session, HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, false); assertThat("Destination is null.", destination, not(nullValue())); verify(session, times(1)).createQueue(any()); }
@Test public void testResolveDestinationSearchIndexUpdate() throws Exception { Session session = mock(Session.class); Queue queue = mock(Queue.class); when(session.createQueue(any())).thenReturn(queue); Destination destination = herdJmsDestinationResolver.resolveDestinationName(session, HerdJmsDestinationResolver.SQS_DESTINATION_SEARCH_INDEX_UPDATE_QUEUE, false); assertThat("Destination is null.", destination, not(nullValue())); verify(session, times(1)).createQueue(any()); }