Search in sources :

Example 66 with AlertException

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());
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ProcessingAuditAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProcessingAuditAccessor) Optional(java.util.Optional) Set(java.util.Set) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobDetailsAccessor) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) DistributionEvent(com.synopsys.integration.alert.processor.api.distribute.DistributionEvent) DistributionEvent(com.synopsys.integration.alert.processor.api.distribute.DistributionEvent) ProcessingAuditAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProcessingAuditAccessor) UUID(java.util.UUID) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 67 with AlertException

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
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 68 with AlertException

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);
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) Test(org.junit.jupiter.api.Test) List(java.util.List) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) ChannelMessageFormatter(com.synopsys.integration.alert.api.channel.convert.ChannelMessageFormatter) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) AbstractChannelMessageConverter(com.synopsys.integration.alert.api.channel.convert.AbstractChannelMessageConverter) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) Test(org.junit.jupiter.api.Test)

Example 69 with AlertException

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);
    }
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) Credential(com.google.api.client.auth.oauth2.Credential) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) AzureHttpRequestCreator(com.synopsys.integration.azure.boards.common.http.AzureHttpRequestCreator) IOException(java.io.IOException) AzureHttpService(com.synopsys.integration.azure.boards.common.http.AzureHttpService) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) AzureAuthorizationCodeFlow(com.synopsys.integration.azure.boards.common.oauth.AzureAuthorizationCodeFlow)

Example 70 with AlertException

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;
}
Also used : ComponentItem(com.synopsys.integration.alert.channel.email.attachment.compatibility.ComponentItem) ProviderMessageContent(com.synopsys.integration.alert.channel.email.attachment.compatibility.ProviderMessageContent) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) MessageContentGroup(com.synopsys.integration.alert.channel.email.attachment.compatibility.MessageContentGroup) LinkedList(java.util.LinkedList) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)

Aggregations

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)101 Test (org.junit.jupiter.api.Test)35 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)22 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 List (java.util.List)18 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)16 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 Optional (java.util.Optional)13 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)11 HashMap (java.util.HashMap)11 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ArrayList (java.util.ArrayList)9 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 UUID (java.util.UUID)8 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)7