Search in sources :

Example 11 with AuditEntryEntity

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());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) MockAuditEntryEntity(com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 12 with AuditEntryEntity

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());
}
Also used : ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ArrayList(java.util.ArrayList) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) MockAuditEntryEntity(com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with AuditEntryEntity

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());
}
Also used : MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) NotificationConfig(com.synopsys.integration.alert.common.rest.model.NotificationConfig) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest)

Example 14 with AuditEntryEntity

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);
}
Also used : AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest)

Example 15 with AuditEntryEntity

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;
}
Also used : AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity)

Aggregations

AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)26 Test (org.junit.jupiter.api.Test)18 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)12 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)10 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)9 UUID (java.util.UUID)9 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)8 OffsetDateTime (java.time.OffsetDateTime)8 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)7 AuditJobStatusModel (com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 MockAuditEntryEntity (com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity)4 ArrayList (java.util.ArrayList)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)4 Transactional (org.springframework.transaction.annotation.Transactional)4 AuditEntryStatus (com.synopsys.integration.alert.common.enumeration.AuditEntryStatus)3 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)3 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)3