use of com.synopsys.integration.alert.mock.entity.MockNotificationContent 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());
}
use of com.synopsys.integration.alert.mock.entity.MockNotificationContent in project hub-alert by blackducksoftware.
the class AuditEntryHandlerTestIT method resendNotificationTestIT.
@Test
public void resendNotificationTestIT() throws Exception {
String content = ResourceUtil.getResourceAsString(getClass(), "/json/policyOverrideNotification.json", StandardCharsets.UTF_8);
MockNotificationContent mockNotification = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), blackDuckProviderKey.getUniversalKey(), DateUtils.createCurrentDateTimestamp(), "POLICY_OVERRIDE", content, 1L, providerConfigModel.getConfigurationId());
ConfigurationFieldModel providerConfigId = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
providerConfigId.setFieldValue(String.valueOf(providerConfigModel.getConfigurationId()));
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
NotificationEntity savedNotificationEntity = notificationContentRepository.save(mockNotification.createEntity());
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.hasExecutePermission(Mockito.eq(ConfigContextEnum.GLOBAL.name()), Mockito.eq(AuditDescriptor.AUDIT_COMPONENT))).thenReturn(true);
AuditEntryActions auditEntryActions = createAuditActions(authorizationManager);
try {
auditEntryActions.resendNotification(savedNotificationEntity.getId(), null);
auditEntryActions.resendNotification(savedNotificationEntity.getId(), null);
auditEntryActions.resendNotification(savedNotificationEntity.getId(), jobModel.getJobId());
} catch (Exception e) {
logger.error(e.getMessage(), e);
fail("Expected the Audit POST request(s) not to throw an exception");
}
assertResponseStatusException(HttpStatus.GONE, () -> auditEntryActions.resendNotification(-1L, null));
assertResponseStatusException(HttpStatus.GONE, () -> auditEntryActions.resendNotification(savedNotificationEntity.getId(), UUID.randomUUID()));
}
Aggregations