use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method updatePasswordEmailGlobalConfigTest.
@Test
void updatePasswordEmailGlobalConfigTest() throws AlertConfigurationException {
AuthorizationManager authorizationManager = createEmailAuthorizationManager();
EmailGlobalCrudActions emailGlobalCrudActions = createEmailCrudActions(authorizationManager);
GlobalConfigurationModelToConcreteConversionService globalConfigurationModelToConcreteConversionService = createConversionService(emailGlobalCrudActions);
ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, globalConfigurationModelToConcreteConversionService);
FieldModel fieldModel = createEmailFieldModel();
fieldModel = configActions.create(fieldModel).getContent().orElseThrow(() -> new AlertConfigurationException("Couldn't create configuration"));
String updatedHost = "updated." + TEST_SMTP_HOST;
String updatedPassword = "updatedPassword";
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedHost), false));
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedPassword), false));
configActions.update(Long.valueOf(fieldModel.getId()), fieldModel);
Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
assertTrue(staticEmailConfig.isPresent());
EmailGlobalConfigModel staticModel = staticEmailConfig.get();
assertEquals(Boolean.TRUE, staticModel.getSmtpAuth().orElse(null));
assertEquals(TEST_AUTH_USER, staticModel.getSmtpUsername().orElse(null));
assertEquals(updatedPassword, staticModel.getSmtpPassword().orElse(null));
assertEquals(updatedHost, staticModel.getSmtpHost().orElse(null));
assertEquals(Integer.valueOf(TEST_SMTP_PORT), staticModel.getSmtpPort().orElse(null));
assertEquals(TEST_FROM, staticModel.getSmtpFrom().orElse(null));
String propertyValue = staticModel.getAdditionalJavaMailProperties().map(map -> map.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey())).orElse(null);
assertEquals("true", propertyValue);
}
use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method saveAllNotificationsTest.
@Test
void saveAllNotificationsTest() {
OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp();
OffsetDateTime providerCreationTime = createdAt.minusSeconds(10);
AlertNotificationModel alertNotificationModel = new AlertNotificationModel(null, providerConfigId, provider, providerConfigName, notificationType, content, createdAt, providerCreationTime, false);
NotificationEntity notificationEntity = new NotificationEntity(id, createdAt, provider, providerConfigId, providerCreationTime, notificationType, content, false);
ConfigurationModel configurationModel = createConfigurationModel();
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.saveAll(Mockito.any())).thenReturn(List.of(notificationEntity));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
List<AlertNotificationModel> alertNotificationModelList = notificationManager.saveAllNotifications(List.of(alertNotificationModel));
assertEquals(1, alertNotificationModelList.size());
AlertNotificationModel testAlertNotificationModel = alertNotificationModelList.get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
}
use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method findByCreatedAtBetweenTest.
@Test
void findByCreatedAtBetweenTest() {
NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
ConfigurationModel configurationModel = createConfigurationModel();
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.findByCreatedAtBetween(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(new PageImpl<>(List.of(notificationEntity)));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
List<AlertNotificationModel> alertNotificationModelList = notificationManager.findByCreatedAtBetween(DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE).getModels();
assertEquals(1, alertNotificationModelList.size());
AlertNotificationModel alertNotificationModel = alertNotificationModelList.get(0);
testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModel);
}
use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class DefaultNotificationAccessorTest method setNotificationsProcessedByIdTest.
@Test
void setNotificationsProcessedByIdTest() {
NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
ConfigurationModel configurationModel = createConfigurationModel();
Set<Long> notificationIds = Set.of(1L);
NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(notificationContentRepository.findAllById(Mockito.any())).thenReturn(List.of(notificationEntity));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
notificationManager.setNotificationsProcessedById(notificationIds);
Mockito.verify(notificationContentRepository).setProcessedByIds(Mockito.any());
}
use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testPagedRequest.
@Test
public void testPagedRequest() {
int totalPages = 2;
int currentPage = 0;
int pageSize = 2;
OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp();
AlertNotificationModel entity_1 = new AlertNotificationModel(1L, 1L, "provider", "providerConfigName", "notificationType", "{content: \"content is here...\"}", createdAt, createdAt, false);
entity_1.setId(1L);
AlertNotificationModel entity_2 = new AlertNotificationModel(2L, 2L, "provider", "providerConfigName", "notificationType", "{content: \"content is here...\"}", createdAt, createdAt, false);
entity_2.setId(2L);
List<AlertNotificationModel> pagedEntryList = Arrays.asList(entity_1, entity_2);
Page<AlertNotificationModel> pageResponse = Mockito.mock(Page.class);
Mockito.when(pageResponse.getContent()).thenReturn(pagedEntryList);
Mockito.when(pageResponse.getTotalPages()).thenReturn(totalPages);
Mockito.when(pageResponse.getNumber()).thenReturn(currentPage);
Mockito.when(pageResponse.getSize()).thenReturn(pageSize);
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
AuditDescriptorKey auditDescriptorKey = new AuditDescriptorKey();
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
DefaultNotificationAccessor notificationManager = Mockito.mock(DefaultNotificationAccessor.class);
Mockito.when(notificationManager.findAll(Mockito.any(PageRequest.class), Mockito.anyBoolean())).thenReturn(pageResponse);
PageRequest pageRequest = PageRequest.of(currentPage, pageSize, Sort.unsorted());
Mockito.when(notificationManager.getPageRequestForNotifications(Mockito.anyInt(), Mockito.anyInt(), Mockito.any(), Mockito.any())).thenReturn(pageRequest);
NotificationContentRepository notificationRepository = Mockito.mock(NotificationContentRepository.class);
AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(null);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
NotificationEntity notificationContent = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), "provider", DateUtils.createCurrentDateTimestamp(), "notificationType", "{content: \"content is here...\"}", 1L, 1L).createEntity();
ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
DistributionJobModel distributionJob = DistributionJobModel.builder().jobId(UUID.randomUUID()).enabled(true).blackDuckGlobalConfigId(2L).channelDescriptorName("distributionType").name("name").createdAt(OffsetDateTime.now()).distributionFrequency(FrequencyType.REAL_TIME).filterByProject(false).notificationTypes(List.of("type")).processingType(ProcessingType.DEFAULT).build();
Mockito.doReturn(Optional.of(distributionJob)).when(jobAccessor).getJobById(Mockito.any());
Mockito.when(notificationRepository.findAllById(Mockito.anyList())).thenReturn(Collections.singletonList(notificationContent));
DefaultRestApiAuditAccessor auditEntryUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, configurationModelConfigurationAccessor, notificationManager, contentConverter);
AuditEntryActions auditEntryActions = new AuditEntryActions(authorizationManager, auditDescriptorKey, auditEntryUtility, notificationManager, jobAccessor, null, null);
ActionResponse<AuditEntryPageModel> response = auditEntryActions.get(currentPage, pageSize, null, null, null, true);
assertTrue(response.hasContent());
AuditEntryPageModel restModel = response.getContent().orElse(null);
assertEquals(pageResponse.getTotalPages(), restModel.getTotalPages());
assertEquals(pageResponse.getNumber(), restModel.getCurrentPage());
assertEquals(pageResponse.getSize(), restModel.getPageSize());
for (int index = 0; index < pageSize; index++) {
AlertNotificationModel entity = pageResponse.getContent().get(index);
AuditEntryModel entryRestModel = restModel.getContent().get(index);
assertEquals(String.valueOf(entity.getId()), entryRestModel.getId());
}
}
Aggregations