use of com.synopsys.integration.alert.common.ContentConverter in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method convertToAuditEntryModelFromNotificationTest.
@Test
public void convertToAuditEntryModelFromNotificationTest() throws Exception {
Long id = 1L;
Long providerConfigId = 2L;
String provider = "provider-test";
String providerConfigName = "providerConfigName-test";
String notificationType = "notificationType-test";
String content = "content-test";
OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
OffsetDateTime timeCreated = timeLastSent.minusSeconds(10);
Long auditEntryId = 3L;
String channelName = "test-channel.common.name-value";
String eventType = "test-channel.common.channel.name-value";
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
AlertNotificationModel alertNotificationModel = new AlertNotificationModel(id, providerConfigId, provider, providerConfigName, notificationType, content, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryId, alertNotificationModel.getId());
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(UUID.randomUUID(), timeCreated, timeLastSent, AuditEntryStatus.SUCCESS.name(), null, null);
Mockito.when(auditNotificationRepository.findByNotificationId(Mockito.any())).thenReturn(List.of(auditNotificationRelation));
Mockito.when(auditEntryRepository.findAllById(Mockito.any())).thenReturn(List.of(auditEntryEntity));
DistributionJobModel distributionJob = DistributionJobModel.builder().jobId(UUID.randomUUID()).enabled(true).blackDuckGlobalConfigId(2L).channelDescriptorName("test-channel.common.channel.name-value").name("test-channel.common.name-value").distributionFrequency(FrequencyType.REAL_TIME).filterByProject(false).notificationTypes(List.of(NotificationType.LICENSE_LIMIT.name())).processingType(ProcessingType.DEFAULT).createdAt(DateUtils.createCurrentDateTimestamp()).build();
Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(Optional.of(distributionJob));
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, configurationModelConfigurationAccessor, null, contentConverter);
AuditEntryModel testAuditEntryModel = auditUtility.convertToAuditEntryModelFromNotification(alertNotificationModel);
assertEquals(id, Long.valueOf(testAuditEntryModel.getId()));
assertNotNull(testAuditEntryModel.getNotification());
assertFalse(testAuditEntryModel.getJobs().isEmpty());
assertEquals(1, testAuditEntryModel.getJobs().size());
JobAuditModel testJob = testAuditEntryModel.getJobs().get(0);
assertEquals(channelName, testJob.getName());
assertEquals(eventType, testJob.getEventType());
assertEquals(AuditEntryStatus.SUCCESS.getDisplayName(), testAuditEntryModel.getOverallStatus());
assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testAuditEntryModel.getLastSent());
}
use of com.synopsys.integration.alert.common.ContentConverter in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method findFirstByJobIdNullTest.
@Test
public void findFirstByJobIdNullTest() {
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
ContentConverter contentConverter = Mockito.mock(ContentConverter.class);
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(null, null, null, null, null, null);
Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, contentConverter);
UUID testUUID = UUID.randomUUID();
AuditJobStatusModel auditJobStatusModel = auditUtility.findFirstByJobId(testUUID).get();
String timeAuditCreated = auditJobStatusModel.getTimeAuditCreated();
String timeLastSent = auditJobStatusModel.getTimeLastSent();
String status = auditJobStatusModel.getStatus();
assertTrue(auditUtility.findFirstByJobId(testUUID).isPresent());
assertNull(timeAuditCreated);
assertNull(timeLastSent);
assertNull(status);
}
use of com.synopsys.integration.alert.common.ContentConverter in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method findFirstByJobIdEmptyTest.
@Test
public void findFirstByJobIdEmptyTest() {
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
ContentConverter contentConverter = Mockito.mock(ContentConverter.class);
Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.empty());
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, contentConverter);
assertFalse(auditUtility.findFirstByJobId(UUID.randomUUID()).isPresent());
}
use of com.synopsys.integration.alert.common.ContentConverter 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.common.ContentConverter in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testPagedRequestEmptyList.
@Test
public void testPagedRequestEmptyList() {
int totalPages = 1;
int currentPage = 1;
int pageSize = 1;
Page<AlertNotificationModel> pageResponse = Mockito.mock(Page.class);
Mockito.when(pageResponse.getContent()).thenReturn(Collections.emptyList());
Mockito.when(pageResponse.getTotalPages()).thenReturn(totalPages);
Mockito.when(pageResponse.getNumber()).thenReturn(currentPage);
Mockito.when(pageResponse.getSize()).thenReturn(0);
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);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
NotificationEntity notificationContent = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), "provider", DateUtils.createCurrentDateTimestamp(), "notificationType", "{content: \"content is here...\"}", 1L, 1L).createEntity();
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());
// Assert 0 because there aren't any entries in the pageResponse content
assertEquals(0, restModel.getPageSize());
assertTrue(restModel.getContent().isEmpty());
}
Aggregations