use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryControllerTestIT method testResendNotification.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testResendNotification() throws Exception {
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel job = jobAccessor.createJob(jobRequestModel);
NotificationEntity notificationEntity = mockNotificationContent.createEntity();
notificationEntity = notificationRepository.save(notificationEntity);
mockAuditEntryEntity.setCommonConfigId(job.getJobId());
AuditEntryEntity auditEntity = mockAuditEntryEntity.createEntity();
auditEntity = auditEntryRepository.save(auditEntity);
auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
String resendUrl = auditUrl + "/resend/" + notificationEntity.getId() + "/";
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryControllerTestIT method testResendJobConfig.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testResendJobConfig() throws Exception {
List<ConfigurationFieldModel> slackFields = new ArrayList<>(MockConfigurationModelFactory.createSlackDistributionFields());
ConfigurationFieldModel providerConfigName = providerConfigModel.getField(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME).orElse(null);
slackFields.add(providerConfigName);
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
NotificationEntity notificationEntity = mockNotificationContent.createEntity();
notificationEntity = notificationRepository.save(notificationEntity);
mockAuditEntryEntity.setCommonConfigId(jobModel.getJobId());
AuditEntryEntity auditEntity = mockAuditEntryEntity.createEntity();
auditEntity = auditEntryRepository.save(auditEntity);
auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
String resendUrl = auditUrl + "/resend/" + notificationEntity.getId() + "/job/" + auditEntity.getCommonConfigId();
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity 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.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryHandlerTestIT method getGetAuditInfoForJobIT.
@Test
public void getGetAuditInfoForJobIT() {
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel job = jobAccessor.createJob(jobRequestModel);
AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(job.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasReadPermission(Mockito.eq(ConfigContextEnum.GLOBAL), Mockito.eq(auditDescriptorKey))).thenReturn(true);
AuditEntryActions auditEntryController = createAuditActions(authorizationManager);
AuditJobStatusModel jobStatusModel = auditEntryController.getAuditInfoForJob(savedAuditEntryEntity.getCommonConfigId()).getContent().orElse(null);
assertNotNull(jobStatusModel);
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class MockAuditEntryEntity method createEntity.
@Override
public AuditEntryEntity createEntity() {
AuditEntryEntity entity = new AuditEntryEntity(commonConfigId, timeCreated, timeLastSent, status.toString(), errorMessage, errorStackTrace);
entity.setId(id);
entity.setErrorMessage(errorMessage);
entity.setErrorStackTrace(errorStackTrace);
entity.setTimeLastSent(timeLastSent);
return entity;
}
Aggregations