use of com.synopsys.integration.alert.common.persistence.model.AuditEntryModel 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.persistence.model.AuditEntryModel in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method getPageOfAuditEntriesTest.
@Test
public void getPageOfAuditEntriesTest() {
Integer pageNumber = 0;
int pageSize = 2;
String searchTerm = null;
String sortField = "lastSent";
String sortOrder = "ASC";
Boolean onlyShowSentNotifications = Boolean.TRUE;
String overallStatus = "overallStatusString";
String lastSent = DateUtils.createCurrentDateString(DateUtils.AUDIT_DATE_FORMAT);
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
DefaultNotificationAccessor notificationManager = Mockito.mock(DefaultNotificationAccessor.class);
AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
PageRequest pageRequest = PageRequest.of(0, 10);
Mockito.when(auditEntryRepository.findMatchingAudit(Mockito.anyLong(), Mockito.any(UUID.class))).thenReturn(Optional.empty());
Mockito.when(notificationManager.getPageRequestForNotifications(pageNumber, pageSize, sortField, sortOrder)).thenReturn(pageRequest);
// At least two AlertNotificationModel are required for the comparator
AlertNotificationModel alertNotificationModel = new AlertNotificationModel(1L, 1L, "provider-test", "providerConfigName-test", "notificationType-test", "{content: \"content is here...\"}", DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
AlertNotificationModel alertNotificationModel2 = new AlertNotificationModel(2L, 2L, "provider-test2", "providerConfigName-test2", "notificationType-test2", "{content: \"content is here2..\"}", DateUtils.createCurrentDateTimestamp().minusSeconds(15), DateUtils.createCurrentDateTimestamp().minusSeconds(10), false);
Pageable auditPageable = Mockito.mock(Pageable.class);
Mockito.when(auditPageable.getOffset()).thenReturn(pageNumber.longValue());
Mockito.when(auditPageable.getPageSize()).thenReturn(pageSize);
Page<AlertNotificationModel> auditPage = new PageImpl<>(List.of(alertNotificationModel, alertNotificationModel2), auditPageable, 1);
Mockito.when(notificationManager.findAll(pageRequest, onlyShowSentNotifications)).thenReturn(auditPage);
NotificationConfig notificationConfig = new NotificationConfig("3", "createdAtString", "providerString", 2L, "providerConfigNameString", "providerCreationTimeString", "notificationTypeString", "content-test");
AuditEntryModel auditEntryModel = new AuditEntryModel("2", notificationConfig, List.of(), overallStatus, lastSent);
Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter = (AlertNotificationModel notificationModel) -> auditEntryModel;
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, null, null, notificationManager, null);
AuditEntryPageModel alertPagedModel = auditUtility.getPageOfAuditEntries(pageNumber, pageSize, searchTerm, sortField, sortOrder, onlyShowSentNotifications, notificationToAuditEntryConverter);
assertEquals(1, alertPagedModel.getTotalPages());
assertEquals(pageNumber.intValue(), alertPagedModel.getCurrentPage());
assertEquals(pageSize, alertPagedModel.getPageSize());
assertEquals(2, alertPagedModel.getContent().size());
assertEquals(lastSent, alertPagedModel.getContent().get(0).getLastSent());
assertEquals(lastSent, alertPagedModel.getContent().get(1).getLastSent());
AuditEntryModel auditContentTest = alertPagedModel.getContent().stream().findFirst().orElse(null);
assertEquals(auditEntryModel.getId(), auditContentTest.getId());
assertEquals(notificationConfig, auditContentTest.getNotification());
assertEquals(0, auditContentTest.getJobs().size());
assertEquals(overallStatus, auditContentTest.getOverallStatus());
assertEquals(lastSent, auditContentTest.getLastSent());
}
use of com.synopsys.integration.alert.common.persistence.model.AuditEntryModel in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testGetNull.
@Test
public void testGetNull() {
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);
Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any())).thenReturn(Optional.empty());
DefaultNotificationAccessor notificationAccessor = Mockito.mock(DefaultNotificationAccessor.class);
Mockito.when(notificationAccessor.findById(Mockito.anyLong())).thenReturn(Optional.empty());
DefaultRestApiAuditAccessor auditEntryUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, notificationAccessor, null);
AuditEntryActions auditEntryActions = new AuditEntryActions(authorizationManager, auditDescriptorKey, auditEntryUtility, notificationAccessor, null, null, null);
ActionResponse<AuditEntryModel> auditEntryModel = auditEntryActions.get(1L);
assertTrue(auditEntryModel.isError());
assertFalse(auditEntryModel.hasContent());
}
use of com.synopsys.integration.alert.common.persistence.model.AuditEntryModel 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.common.persistence.model.AuditEntryModel in project hub-alert by blackducksoftware.
the class AuditEntryRestModelTest method testRestModel.
@Test
public void testRestModel() {
String id = "1";
String timeLastSent = new Date(500).toString();
String overallStatus = AuditEntryStatus.SUCCESS.name();
NotificationConfig notification = new NotificationConfig();
List<JobAuditModel> jobAuditModels = Collections.singletonList(new JobAuditModel());
AuditEntryModel restModel = new AuditEntryModel(id, notification, jobAuditModels, overallStatus, timeLastSent);
assertEquals(notification, restModel.getNotification());
assertEquals(jobAuditModels, restModel.getJobs());
assertEquals(overallStatus, restModel.getOverallStatus());
assertEquals(timeLastSent, restModel.getLastSent());
assertEquals(id, restModel.getId());
}
Aggregations