Search in sources :

Example 11 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.

the class StaticJobAccessorTest method createAzureBoardsJobTest.

@Test
void createAzureBoardsJobTest() {
    UUID jobId = UUID.randomUUID();
    AzureBoardsJobDetailsModel azureBoardsJobDetailsModel = new AzureBoardsJobDetailsModel(jobId, false, null, null, null, null);
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.AZURE_BOARDS.getUniversalKey(), azureBoardsJobDetailsModel);
    AzureBoardsJobDetailsEntity azureBoardsJobDetailsEntity = new AzureBoardsJobDetailsEntity(null, false, null, null, null, null);
    DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
    distributionJobEntity.setAzureBoardsJobDetails(azureBoardsJobDetailsEntity);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
    Mockito.when(azureBoardsJobDetailsAccessor.saveAzureBoardsJobDetails(Mockito.any(), Mockito.any())).thenReturn(azureBoardsJobDetailsEntity);
    Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
    DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
    assertEquals(jobId, createdJob.getJobId());
    assertEquals(jobName, createdJob.getName());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) AzureBoardsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.AzureBoardsJobDetailsModel) AzureBoardsJobDetailsEntity(com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 12 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.

the class StaticJobAccessorTest method createJobTest.

@Test
void createJobTest() {
    UUID jobId = UUID.randomUUID();
    SlackJobDetailsModel slackJobDetailsModel = new SlackJobDetailsModel(jobId, null, null, null);
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.SLACK.getUniversalKey(), slackJobDetailsModel);
    SlackJobDetailsEntity slackJobDetailsEntity = new SlackJobDetailsEntity();
    DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
    distributionJobEntity.setSlackJobDetails(slackJobDetailsEntity);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
    Mockito.when(slackJobDetailsAccessor.saveSlackJobDetails(Mockito.any(), Mockito.any())).thenReturn(slackJobDetailsEntity);
    Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
    DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
    assertEquals(jobId, createdJob.getJobId());
    assertEquals(jobName, createdJob.getName());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) SlackJobDetailsEntity(com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 13 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel 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 14 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel 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 15 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel 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)

Aggregations

DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)34 Test (org.junit.jupiter.api.Test)25 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)18 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)16 UUID (java.util.UUID)10 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)7 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)7 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)6 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)6 ArrayList (java.util.ArrayList)6 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)4 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)4 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)3 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)3 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)3 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)3