Search in sources :

Example 1 with AuditDescriptorKey

use of com.synopsys.integration.alert.component.audit.AuditDescriptorKey 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());
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) DefaultRestApiAuditAccessor(com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Test(org.junit.jupiter.api.Test)

Example 2 with AuditDescriptorKey

use of com.synopsys.integration.alert.component.audit.AuditDescriptorKey in project hub-alert by blackducksoftware.

the class AuditEntryActionsTest method testPagedRequest.

@Test
public void testPagedRequest() {
    int totalPages = 2;
    int currentPage = 0;
    int pageSize = 2;
    OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp();
    AlertNotificationModel entity_1 = new AlertNotificationModel(1L, 1L, "provider", "providerConfigName", "notificationType", "{content: \"content is here...\"}", createdAt, createdAt, false);
    entity_1.setId(1L);
    AlertNotificationModel entity_2 = new AlertNotificationModel(2L, 2L, "provider", "providerConfigName", "notificationType", "{content: \"content is here...\"}", createdAt, createdAt, false);
    entity_2.setId(2L);
    List<AlertNotificationModel> pagedEntryList = Arrays.asList(entity_1, entity_2);
    Page<AlertNotificationModel> pageResponse = Mockito.mock(Page.class);
    Mockito.when(pageResponse.getContent()).thenReturn(pagedEntryList);
    Mockito.when(pageResponse.getTotalPages()).thenReturn(totalPages);
    Mockito.when(pageResponse.getNumber()).thenReturn(currentPage);
    Mockito.when(pageResponse.getSize()).thenReturn(pageSize);
    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);
    Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(null);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    NotificationEntity notificationContent = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), "provider", DateUtils.createCurrentDateTimestamp(), "notificationType", "{content: \"content is here...\"}", 1L, 1L).createEntity();
    ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
    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());
    assertEquals(pageResponse.getSize(), restModel.getPageSize());
    for (int index = 0; index < pageSize; index++) {
        AlertNotificationModel entity = pageResponse.getContent().get(index);
        AuditEntryModel entryRestModel = restModel.getContent().get(index);
        assertEquals(String.valueOf(entity.getId()), entryRestModel.getId());
    }
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) PageRequest(org.springframework.data.domain.PageRequest) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) DefaultRestApiAuditAccessor(com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor) 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) MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel) ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) OffsetDateTime(java.time.OffsetDateTime) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 3 with AuditDescriptorKey

use of com.synopsys.integration.alert.component.audit.AuditDescriptorKey in project hub-alert by blackducksoftware.

the class AuditEntryActionsTest method testGetAuditInfoForJobNull.

@Test
public void testGetAuditInfoForJobNull() {
    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());
    DefaultRestApiAuditAccessor auditEntryUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, null);
    AuditEntryActions auditEntryActions = new AuditEntryActions(authorizationManager, auditDescriptorKey, auditEntryUtility, null, null, null, null);
    ActionResponse<AuditJobStatusModel> jobAuditModel = auditEntryActions.getAuditInfoForJob(UUID.randomUUID());
    assertTrue(jobAuditModel.isError());
    assertFalse(jobAuditModel.hasContent());
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) DefaultRestApiAuditAccessor(com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Example 4 with AuditDescriptorKey

use of com.synopsys.integration.alert.component.audit.AuditDescriptorKey in project hub-alert by blackducksoftware.

the class AuditEntryActionsTest method testResendNotificationException.

@Test
public void testResendNotificationException() {
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
    AuditDescriptorKey auditDescriptorKey = new AuditDescriptorKey();
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    NotificationContentRepository notificationRepository = Mockito.mock(NotificationContentRepository.class);
    AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(null);
    MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
    MockNotificationContent mockNotificationEntity = new MockNotificationContent();
    Mockito.when(auditEntryRepository.findById(Mockito.anyLong())).thenReturn(Optional.of(mockAuditEntryEntity.createEmptyEntity()));
    Mockito.when(notificationRepository.findAllById(Mockito.anyList())).thenReturn(Collections.singletonList(mockNotificationEntity.createEntity()));
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationRepository, auditEntryRepository, null);
    DefaultRestApiAuditAccessor auditEntryUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, null, notificationManager, null);
    AuditEntryActions auditEntryActions = new AuditEntryActions(authorizationManager, auditDescriptorKey, auditEntryUtility, notificationManager, jobAccessor, null, null);
    ActionResponse<AuditEntryPageModel> response = auditEntryActions.resendNotification(1L, null);
    assertTrue(response.isError());
    assertFalse(response.hasContent());
}
Also used : MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) DefaultRestApiAuditAccessor(com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) MockAuditEntryEntity(com.synopsys.integration.alert.component.audit.mock.MockAuditEntryEntity) Test(org.junit.jupiter.api.Test)

Example 5 with AuditDescriptorKey

use of com.synopsys.integration.alert.component.audit.AuditDescriptorKey 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());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) AuditDescriptorKey(com.synopsys.integration.alert.component.audit.AuditDescriptorKey) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) AuditEntryPageModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel) ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) PageRequest(org.springframework.data.domain.PageRequest) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) DefaultRestApiAuditAccessor(com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor) 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) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)5 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)5 AuditDescriptorKey (com.synopsys.integration.alert.component.audit.AuditDescriptorKey)5 DefaultRestApiAuditAccessor (com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor)5 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)5 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)5 Test (org.junit.jupiter.api.Test)5 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)4 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)3 AuditEntryPageModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryPageModel)3 AuditNotificationRepository (com.synopsys.integration.alert.database.audit.AuditNotificationRepository)3 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)3 MockNotificationContent (com.synopsys.integration.alert.mock.entity.MockNotificationContent)3 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)2 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)2 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)2 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)2 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)2 DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)2