use of com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender in project hub-alert by blackducksoftware.
the class IssueTrackerFieldModelTestActionTest method testConfigSendMessagesReturnsNoIssues.
@Test
public void testConfigSendMessagesReturnsNoIssues() throws AlertException {
IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(messageSender.sendMessages(Mockito.any())).thenReturn(List.of());
IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory);
MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
assertTrue(messageResult.hasErrors(), EXPECTED_ERRORS);
}
use of com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender in project hub-alert by blackducksoftware.
the class IssueTrackerFieldModelTestActionTest method testConfigNoResolveTransition.
@Test
public void testConfigNoResolveTransition() throws AlertException {
IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(messageSender.sendMessages(Mockito.any())).thenReturn(List.of(TEST_ISSUE_RESPONSE_MODEL));
IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory);
MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
assertFalse(messageResult.hasErrors(), EXPECTED_NO_ERRORS);
assertFalse(messageResult.hasWarnings(), EXPECTED_NO_WARNINGS);
}
use of com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender in project hub-alert by blackducksoftware.
the class IssueTrackerFieldModelTestActionTest method testConfigReopenFailure.
@Test
public void testConfigReopenFailure() throws AlertException {
IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(messageSender.sendMessages(Mockito.any())).thenAnswer(invocation -> {
IssueTrackerModelHolder<String> argument = invocation.getArgument(0);
List<IssueTransitionModel<String>> transitionModels = argument.getIssueTransitionModels();
if (!transitionModels.isEmpty()) {
if (transitionModels.stream().anyMatch(model -> IssueOperation.RESOLVE.equals(model.getIssueOperation()))) {
return List.of(TEST_ISSUE_RESPONSE_MODEL);
} else {
return List.of();
}
}
return List.of(TEST_ISSUE_RESPONSE_MODEL);
});
IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory, true, true);
MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
assertTrue(messageResult.hasErrors(), EXPECTED_ERRORS);
}
use of com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender in project hub-alert by blackducksoftware.
the class IssueTrackerFieldModelTestActionTest method testConfigSendMessagesThrowsException.
@Test
public void testConfigSendMessagesThrowsException() throws AlertException {
String testExceptionMessage = "test exception message";
IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(messageSender.sendMessages(Mockito.any())).thenThrow(new AlertException(testExceptionMessage));
IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory);
MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
assertTrue(messageResult.getStatusMessage().contains(testExceptionMessage), "Expected the message result to contain the expected exception message");
}
use of com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender in project hub-alert by blackducksoftware.
the class IssueTrackerChannelTest method distributeMessagesTest.
@Test
public void distributeMessagesTest() throws AlertException {
IssueTrackerModelExtractor<String> modelExtractor = new IssueTrackerModelExtractor<>(createFormatter(), null);
IssueTrackerMessageSender<String> messageSender = createMessageSender();
IssueTrackerProcessor<String> processor = new IssueTrackerProcessor<>(modelExtractor, messageSender);
IssueTrackerProcessorFactory<DistributionJobDetailsModel, String> processorFactory = x -> processor;
IssueTrackerResponsePostProcessor postProcessor = new IssueTrackerResponsePostProcessor() {
@Override
public <T extends Serializable> void postProcess(IssueTrackerResponse<T> response) {
}
};
IssueTrackerChannel<DistributionJobDetailsModel, String> issueTrackerChannel = new IssueTrackerChannel<>(processorFactory, postProcessor) {
};
MessageResult testResult = issueTrackerChannel.distributeMessages(null, ProviderMessageHolder.empty(), null);
IssueTrackerResponse<?> processorResponse = processor.processMessages(ProviderMessageHolder.empty(), "jobName");
assertEquals(processorResponse.getStatusMessage(), testResult.getStatusMessage());
}
Aggregations