Search in sources :

Example 1 with AuditJobStatusModel

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

the class JobAuditModelTest method testModel.

@Test
public void testModel() {
    String id = "1";
    String configId = "22";
    String name = "name";
    String eventType = "eventType";
    String timeAuditCreated = new Date(400).toString();
    String timeLastSent = new Date(500).toString();
    String status = AuditEntryStatus.SUCCESS.name();
    String errorMessage = "errorMessage";
    String errorStackTrace = "errorStackTrace";
    AuditJobStatusModel auditJobStatusModel = new AuditJobStatusModel(UUID.randomUUID(), timeAuditCreated, timeLastSent, status);
    JobAuditModel restModel = new JobAuditModel(id, configId, name, eventType, auditJobStatusModel, errorMessage, errorStackTrace);
    assertEquals(errorMessage, restModel.getErrorMessage());
    assertEquals(errorStackTrace, restModel.getErrorStackTrace());
    assertEquals(eventType, restModel.getEventType());
    assertEquals(name, restModel.getName());
    assertEquals(status, restModel.getAuditJobStatusModel().getStatus());
    assertEquals(timeAuditCreated, restModel.getAuditJobStatusModel().getTimeAuditCreated());
    assertEquals(timeLastSent, restModel.getAuditJobStatusModel().getTimeLastSent());
    assertEquals(configId, restModel.getConfigId());
    assertEquals(id, restModel.getId());
}
Also used : AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 2 with AuditJobStatusModel

use of com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel 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 3 with AuditJobStatusModel

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

the class DefaultRestApiAuditAccessorTest method findFirstByJobIdNotNullTest.

@Test
public void findFirstByJobIdNotNullTest() {
    OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime timeCreated = timeLastSent.minusMinutes(10L);
    AuditEntryStatus status = AuditEntryStatus.PENDING;
    UUID testUUID = UUID.randomUUID();
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(testUUID, timeCreated, timeLastSent, status.name(), null, null);
    Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, null);
    AuditJobStatusModel auditJobStatusModel = auditUtility.findFirstByJobId(testUUID).get();
    String testTimeAuditCreated = auditJobStatusModel.getTimeAuditCreated();
    String testTimeLastSent = auditJobStatusModel.getTimeLastSent();
    String testStatus = auditJobStatusModel.getStatus();
    assertTrue(auditUtility.findFirstByJobId(testUUID).isPresent());
    assertEquals(DateUtils.formatDate(timeCreated, DateUtils.AUDIT_DATE_FORMAT), testTimeAuditCreated);
    assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testTimeLastSent);
    assertEquals(status.getDisplayName(), testStatus);
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) OffsetDateTime(java.time.OffsetDateTime) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with AuditJobStatusModel

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

the class DefaultRestApiAuditAccessorTest method findFirstByJobIdNullTest.

@Test
public void findFirstByJobIdNullTest() {
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    ContentConverter contentConverter = Mockito.mock(ContentConverter.class);
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(null, null, null, null, null, null);
    Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, contentConverter);
    UUID testUUID = UUID.randomUUID();
    AuditJobStatusModel auditJobStatusModel = auditUtility.findFirstByJobId(testUUID).get();
    String timeAuditCreated = auditJobStatusModel.getTimeAuditCreated();
    String timeLastSent = auditJobStatusModel.getTimeLastSent();
    String status = auditJobStatusModel.getStatus();
    assertTrue(auditUtility.findFirstByJobId(testUUID).isPresent());
    assertNull(timeAuditCreated);
    assertNull(timeLastSent);
    assertNull(status);
}
Also used : ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 5 with AuditJobStatusModel

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

Aggregations

AuditJobStatusModel (com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel)7 Test (org.junit.jupiter.api.Test)5 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)4 UUID (java.util.UUID)4 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)3 AuditEntryStatus (com.synopsys.integration.alert.common.enumeration.AuditEntryStatus)2 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 JobAuditModel (com.synopsys.integration.alert.common.rest.model.JobAuditModel)2 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)2 OffsetDateTime (java.time.OffsetDateTime)2 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)1 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)1 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)1 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)1 AuditJobStatusesModel (com.synopsys.integration.alert.common.rest.model.AuditJobStatusesModel)1 NotificationConfig (com.synopsys.integration.alert.common.rest.model.NotificationConfig)1 AuditDescriptorKey (com.synopsys.integration.alert.component.audit.AuditDescriptorKey)1 DefaultRestApiAuditAccessor (com.synopsys.integration.alert.database.api.DefaultRestApiAuditAccessor)1 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)1