use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.
the class TestHelperConfigurationTest method testMessageWithErrors.
@Test
public void testMessageWithErrors() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.success()), () -> ConfigurationTestResult.failure("Failure"));
ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.
the class ChannelDescriptorTest method getterTest.
@Test
public void getterTest() {
String name = "channel";
ChannelKey channelKey = new ChannelKey(name, name) {
};
ChannelDescriptor channelDescriptor = new ChannelDescriptor(channelKey, Set.of(ConfigContextEnum.DISTRIBUTION)) {
@Override
public Optional<GlobalConfigurationFieldModelValidator> getGlobalValidator() {
return Optional.empty();
}
@Override
public Optional<DistributionConfigurationValidator> getDistributionValidator() {
return Optional.empty();
}
};
assertEquals(name, channelDescriptor.getDescriptorKey().getUniversalKey());
}
use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.
the class DistributionEventHandlerTest method handleEventSuccessTest.
@Test
public void handleEventSuccessTest() {
ProcessingAuditAccessor auditAccessor = Mockito.mock(ProcessingAuditAccessor.class);
Mockito.doNothing().when(auditAccessor).setAuditEntrySuccess(Mockito.any(), Mockito.anySet());
DistributionJobDetailsModel details = new DistributionJobDetailsModel(null, null) {
};
JobDetailsAccessor<DistributionJobDetailsModel> jobDetailsAccessor = x -> Optional.of(details);
DistributionChannel<DistributionJobDetailsModel> channel = (x, y, z) -> null;
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)).setAuditEntrySuccess(Mockito.eq(testJobId), Mockito.eq(testNotificationIds));
}
use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.
the class ProviderMessageDistributor method distribute.
public void distribute(ProcessedNotificationDetails processedNotificationDetails, ProcessedProviderMessageHolder processedMessageHolder) {
String channelName = processedNotificationDetails.getChannelName();
ChannelKey destinationKey = ChannelKeys.getChannelKey(channelName);
if (null == destinationKey) {
logger.warn("Unable to send {}. No {} with the name {} exists", EVENT_CLASS_NAME, DESTINATION_WRAPPER_CLASS_NAME, channelName);
return;
}
for (ProcessedProviderMessageHolder singleMessageHolder : processedMessageHolder.expand()) {
distributeIndividually(processedNotificationDetails.getJobId(), processedNotificationDetails.getJobName(), destinationKey, singleMessageHolder);
}
}
use of com.synopsys.integration.alert.descriptor.api.model.ChannelKey in project hub-alert by blackducksoftware.
the class ConfigurationCrudHelperTest method testGetOneEmpty.
@Test
public void testGetOneEmpty() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, 255);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ActionResponse response = configurationHelper.getOne(() -> createEmptyOptional());
assertEquals(HttpStatus.NOT_FOUND, response.getHttpStatus());
}
Aggregations