use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class DistributionEventHandlerTest method handleEventExceptionTest.
@Test
public void handleEventExceptionTest() {
ProcessingAuditAccessor auditAccessor = Mockito.mock(ProcessingAuditAccessor.class);
Mockito.doNothing().when(auditAccessor).setAuditEntryFailure(Mockito.any(), Mockito.anySet(), Mockito.anyString(), Mockito.any());
DistributionJobDetailsModel details = new DistributionJobDetailsModel(null, null) {
};
JobDetailsAccessor<DistributionJobDetailsModel> jobDetailsAccessor = x -> Optional.of(details);
AlertException testException = new AlertException("Test exception");
DistributionChannel<DistributionJobDetailsModel> channel = (x, y, z) -> {
throw testException;
};
DistributionEventHandler<DistributionJobDetailsModel> eventHandler = new DistributionEventHandler<>(channel, jobDetailsAccessor, auditAccessor);
UUID testJobId = UUID.randomUUID();
Set<Long> testNotificationIds = Set.of(1L, 3L, 5L);
DistributionEvent testEvent = new DistributionEvent(channelKey, testJobId, "jobName", testNotificationIds, null);
eventHandler.handle(testEvent);
Mockito.verify(auditAccessor, Mockito.times(1)).setAuditEntryFailure(Mockito.eq(testJobId), Mockito.eq(testNotificationIds), Mockito.anyString(), Mockito.any());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method sendMessageAlertExceptionTest.
@Test
public void sendMessageAlertExceptionTest() throws IntegrationException {
Response response = createMockResponse(HttpStatus.BAD_REQUEST);
IntHttpClient intHttpClient = createMockHttpClientWithResponse(response);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
try {
restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
fail("Expected an exception to be thrown");
} catch (AlertException e) {
// Pass
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class MessageBoardChannelTest method distributeMessagesTest.
@Test
public void distributeMessagesTest() throws AlertException {
MessageResult expectedResult = new MessageResult("Test result");
DistributionJobDetailsModel testDetails = new DistributionJobDetailsModel(null, null) {
};
AbstractChannelMessageConverter<DistributionJobDetailsModel, Object> converter = createConverter();
ChannelMessageSender<DistributionJobDetailsModel, Object, MessageResult> sender = (x, y) -> expectedResult;
MessageBoardChannel<DistributionJobDetailsModel, Object> messageBoardChannel = new MessageBoardChannel<>(converter, sender) {
};
MessageResult testResult = messageBoardChannel.distributeMessages(testDetails, ProviderMessageHolder.empty(), "jobName");
assertEquals(expectedResult, testResult);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class AzureBoardsProperties method createAzureHttpService.
public AzureHttpService createAzureHttpService(ProxyInfo proxy, Gson gson, String authorizationCode) throws AlertException {
HttpTransport httpTransport = createHttpTransport(proxy);
try {
AuthorizationCodeFlow oAuthFlow = createOAuthFlow(httpTransport);
Credential oAuthCredential = requestTokens(oAuthFlow, authorizationCode).orElseThrow(() -> new AlertException(String.format("Cannot request Azure OAuth credential associated with '%s'", oauthUserId)));
AzureHttpRequestCreator httpRequestCreator = AzureHttpRequestCreatorFactory.withCredential(httpTransport, oAuthCredential, gson);
return new AzureHttpService(gson, httpRequestCreator);
} catch (IOException e) {
throw new AlertException("Cannot request OAuth credentials", e);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ProjectMessageToMessageContentGroupConversionUtils method toMessageContentGroup.
public static MessageContentGroup toMessageContentGroup(ProjectMessage projectMessage) {
ProviderMessageContent.Builder providerMessageContentBuilder = new ProviderMessageContent.Builder();
LinkableItem provider = projectMessage.getProvider();
providerMessageContentBuilder.applyProvider(provider.getLabel(), -1L, provider.getValue(), provider.getUrl().orElse(null));
LinkableItem project = projectMessage.getProject();
providerMessageContentBuilder.applyTopic(project.getLabel(), project.getValue(), project.getUrl().orElse(null));
Optional<LinkableItem> optionalProjectVersion = projectMessage.getProjectVersion();
if (optionalProjectVersion.isPresent()) {
LinkableItem projectVersion = optionalProjectVersion.get();
providerMessageContentBuilder.applySubTopic(projectVersion.getLabel(), projectVersion.getValue(), projectVersion.getUrl().orElse(null));
}
projectMessage.getOperation().map(ProjectMessageToMessageContentGroupConversionUtils::convertToItemOperation).ifPresent(providerMessageContentBuilder::applyAction);
MessageContentGroup messageContentGroup = new MessageContentGroup();
List<ComponentItem> componentItems = new LinkedList<>();
for (BomComponentDetails bomComponent : projectMessage.getBomComponents()) {
List<ComponentItem> bomComponentItems = convertToComponentItems(bomComponent);
componentItems.addAll(bomComponentItems);
}
providerMessageContentBuilder.applyAllComponentItems(componentItems);
try {
ProviderMessageContent providerMessageContent = providerMessageContentBuilder.build();
messageContentGroup.add(providerMessageContent);
} catch (AlertException e) {
// Ignore for feature parity
}
return messageContentGroup;
}
Aggregations