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());
}
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);
}
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);
}
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);
}
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());
}
Aggregations