Search in sources :

Example 1 with MessagingConfigurationException

use of org.jboss.pnc.messaging.spi.MessagingConfigurationException in project pnc by project-ncl.

the class MessageSenderProviderTest method shouldNotGetMessageSenderWithInvalidId.

@Test
public void shouldNotGetMessageSenderWithInvalidId() {
    // given
    Instance<MessageSender> messageSenders = getMessageSenders();
    SystemConfig systemConfig = Mockito.mock(SystemConfig.class);
    Mockito.when(systemConfig.getMessageSenderId()).thenReturn("invalidId");
    Exception exception = null;
    // when
    try {
        new MessageSenderProvider(messageSenders, systemConfig);
    } catch (MessagingConfigurationException e) {
        exception = e;
    }
    // expect
    Assert.assertTrue(exception instanceof MessagingConfigurationException);
}
Also used : SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) MessageSender(org.jboss.pnc.messaging.spi.MessageSender) MessagingConfigurationException(org.jboss.pnc.messaging.spi.MessagingConfigurationException) MessagingConfigurationException(org.jboss.pnc.messaging.spi.MessagingConfigurationException) Test(org.junit.Test)

Example 2 with MessagingConfigurationException

use of org.jboss.pnc.messaging.spi.MessagingConfigurationException in project pnc by project-ncl.

the class MessageSenderProvider method selectMessageSender.

private Optional<MessageSender> selectMessageSender() throws MessagingConfigurationException {
    Optional<MessageSender> selectedMessageSender;
    if (messageSenders.isUnsatisfied()) {
        logger.warn("Messaging to MQ is disabled. There is no message sender available to inject.");
        selectedMessageSender = Optional.empty();
    } else if (messageSenders.isAmbiguous()) {
        logAvailableInstances(logger, messageSenders);
        MessageSender matchingMessageSender = null;
        String messageSenderName = config.getMessageSenderId();
        if (!StringUtils.isEmpty(messageSenderName)) {
            matchingMessageSender = selectMessageSenderByClassName(messageSenders, messageSenderName);
        }
        if (matchingMessageSender == null) {
            matchingMessageSender = selectMessageSenderByClassName(messageSenders, DEFAULT_MESSAGE_SENDER);
        }
        if (matchingMessageSender != null) {
            logger.info("Using {} MQ message sender.", matchingMessageSender.getMessageSenderId());
            selectedMessageSender = Optional.of(matchingMessageSender);
        } else {
            throw new MessagingConfigurationException("Non of the available MessageSenders is matching configured name or the default.");
        }
    } else {
        logger.info("Using {} MQ message sender.", messageSenders.get().getClass().getName());
        selectedMessageSender = Optional.of(messageSenders.get());
    }
    selectedMessageSender.ifPresent(MessageSender::init);
    return selectedMessageSender;
}
Also used : MessageSender(org.jboss.pnc.messaging.spi.MessageSender) MessagingConfigurationException(org.jboss.pnc.messaging.spi.MessagingConfigurationException)

Aggregations

MessageSender (org.jboss.pnc.messaging.spi.MessageSender)2 MessagingConfigurationException (org.jboss.pnc.messaging.spi.MessagingConfigurationException)2 SystemConfig (org.jboss.pnc.common.json.moduleconfig.SystemConfig)1 Test (org.junit.Test)1