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);
}
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;
}
Aggregations