use of com.synopsys.integration.alert.mock.entity.MockNotificationContent in project hub-alert by blackducksoftware.
the class NotificationContentRepositoryIT method createEntity.
private NotificationEntity createEntity(String dateString, String content) throws ParseException {
OffsetDateTime providerCreationTime = DateUtils.parseDateFromJsonString(dateString);
final String provider = "provider_blackduck";
final String notificationType = "type_1";
NotificationEntity entity = new MockNotificationContent(providerCreationTime, provider, providerCreationTime, notificationType, content, null, providerConfigModel.getConfigurationId()).createEntity();
NotificationEntity savedEntity = notificationContentRepository.save(entity);
return savedEntity;
}
use of com.synopsys.integration.alert.mock.entity.MockNotificationContent in project hub-alert by blackducksoftware.
the class AuditEntryHandlerTestIT method getTestIT.
@Test
public void getTestIT() {
NotificationEntity savedNotificationEntity = notificationContentRepository.save(mockNotification.createEntity());
notificationContentRepository.save(new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), "provider", DateUtils.createCurrentDateTimestamp(), "notificationType", "{}", 234L, providerConfigModel.getConfigurationId()).createEntity());
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(jobModel.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
AuditEntryActions auditEntryActions = createAuditActions(authorizationManager);
AuditEntryPageModel auditEntries = auditEntryActions.get(null, null, null, null, null, true).getContent().orElse(null);
assertEquals(1, auditEntries.getContent().size());
AuditEntryModel auditEntryResponse = auditEntryActions.get(savedNotificationEntity.getId()).getContent().orElse(null);
assertNotNull(auditEntryResponse);
AuditEntryModel auditEntry = auditEntries.getContent().get(0);
assertEquals(savedNotificationEntity.getId().toString(), auditEntry.getId());
assertFalse(auditEntry.getJobs().isEmpty());
assertEquals(1, auditEntry.getJobs().size());
NotificationConfig notification = auditEntry.getNotification();
String createdAtStringValue = DateUtils.formatDate(savedNotificationEntity.getCreatedAt(), DateUtils.AUDIT_DATE_FORMAT);
assertEquals(createdAtStringValue, notification.getCreatedAt());
assertEquals(savedNotificationEntity.getNotificationType(), notification.getNotificationType());
assertNotNull(notification.getContent());
auditEntries = auditEntryActions.get(null, null, null, null, null, false).getContent().orElse(null);
assertEquals(2, auditEntries.getContent().size());
}
use of com.synopsys.integration.alert.mock.entity.MockNotificationContent in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTestIT method createAlertNotificationModel.
private AlertNotificationModel createAlertNotificationModel(boolean processed) {
String bomEditContent = "{" + "\"type\":\"" + NotificationType.BOM_EDIT.name() + "\"," + "\"content\": {" + "\"projectVersion\": \"" + properties.getBlackDuckURL() + "/api/projects\"," + "\"bomComponent\": \"" + properties.getBlackDuckURL() + "\"," + "\"componentName\": \"test\"," + "\"componentVersionName\": \"test\"" + "}" + "}";
MockNotificationContent notificationMocker = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), blackDuckProviderKey.getUniversalKey(), DateUtils.createCurrentDateTimestamp(), NotificationType.BOM_EDIT.name(), bomEditContent, null, blackDuckGlobalConfigId);
NotificationEntity entity = notificationMocker.createEntity();
return new AlertNotificationModel(null, entity.getProviderConfigId(), entity.getProvider(), "providerConfigName", entity.getNotificationType(), entity.getContent(), entity.getCreatedAt(), entity.getProviderCreationTime(), processed);
}
use of com.synopsys.integration.alert.mock.entity.MockNotificationContent 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());
}
}
use of com.synopsys.integration.alert.mock.entity.MockNotificationContent in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testResendNotificationException.
@Test
public void testResendNotificationException() {
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
AuditDescriptorKey auditDescriptorKey = new AuditDescriptorKey();
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
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);
MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
MockNotificationContent mockNotificationEntity = new MockNotificationContent();
Mockito.when(auditEntryRepository.findById(Mockito.anyLong())).thenReturn(Optional.of(mockAuditEntryEntity.createEmptyEntity()));
Mockito.when(notificationRepository.findAllById(Mockito.anyList())).thenReturn(Collections.singletonList(mockNotificationEntity.createEntity()));
DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationRepository, auditEntryRepository, null);
DefaultRestApiAuditAccessor auditEntryUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, null, notificationManager, null);
AuditEntryActions auditEntryActions = new AuditEntryActions(authorizationManager, auditDescriptorKey, auditEntryUtility, notificationManager, jobAccessor, null, null);
ActionResponse<AuditEntryPageModel> response = auditEntryActions.resendNotification(1L, null);
assertTrue(response.isError());
assertFalse(response.hasContent());
}
Aggregations