Search in sources :

Example 1 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.

the class AuditEntryControllerTestIT method testPostConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testPostConfig() throws Exception {
    CommonDistributionConfigEntity commonEntity = mockCommonDistributionEntity.createEntity();
    final MockNotificationEntity mockNotifications = new MockNotificationEntity();
    NotificationEntity notificationEntity = mockNotifications.createEntity();
    notificationEntity = notificationRepository.save(notificationEntity);
    commonEntity = commonDistributionRepository.save(commonEntity);
    mockAuditEntity.setCommonConfigId(commonEntity.getId());
    AuditEntryEntity auditEntity = mockAuditEntity.createEntity();
    auditEntity = auditEntryRepository.save(auditEntity);
    auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
    final String resendUrl = auditUrl + "/" + String.valueOf(auditEntity.getId()) + "/" + "/resend";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 2 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.

the class AuditEntryControllerTestIT method testGetConfigWithId.

@Test
@WithMockUser(roles = "ADMIN")
public void testGetConfigWithId() throws Exception {
    AuditEntryEntity entity = mockAuditEntity.createEntity();
    entity = auditEntryRepository.save(entity);
    final String getUrl = auditUrl + "/" + String.valueOf(entity.getId());
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(getUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 3 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.

the class DistributionChannelTest method setAuditEntryFailureTest.

@Test
public void setAuditEntryFailureTest() {
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final EmailGroupChannel channel = new EmailGroupChannel(null, null, auditEntryRepository, null, null, null);
    final AuditEntryEntity entity = new AuditEntryEntity(1L, new Date(System.currentTimeMillis() - 1000), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, null, null);
    entity.setId(1L);
    Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(entity);
    Mockito.when(auditEntryRepository.save(entity)).thenReturn(entity);
    channel.setAuditEntryFailure(null, null, null);
    channel.setAuditEntryFailure(entity.getId(), "error", new Exception());
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) EmailGroupChannel(com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupChannel) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) Date(java.util.Date) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Test(org.junit.Test)

Example 4 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.

the class CommonDistributionConfigActions method addAuditEntryInfoToRestModel.

private void addAuditEntryInfoToRestModel(final CommonDistributionConfigRestModel restModel) {
    String lastRan = "Unknown";
    String status = "Unknown";
    final Long id = getObjectTransformer().stringToLong(restModel.getId());
    final AuditEntryEntity lastRanEntry = auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(id);
    if (lastRanEntry != null) {
        lastRan = getObjectTransformer().objectToString(lastRanEntry.getTimeLastSent());
        status = lastRanEntry.getStatus().getDisplayName();
    }
    restModel.setLastRan(lastRan);
    restModel.setStatus(status);
}
Also used : AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)

Example 5 with AuditEntryEntity

use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity in project hub-alert by blackducksoftware.

the class AuditEntryHandlerTestIT method resendNotificationTestIt.

@Test
public void resendNotificationTestIt() {
    final MockNotificationEntity mockNotification = new MockNotificationEntity();
    final MockCommonDistributionEntity mockDistributionConfig = new MockCommonDistributionEntity();
    final NotificationEntity savedNotificationEntity = notificationRepository.save(mockNotification.createEntity());
    final CommonDistributionConfigEntity savedConfigEntity = commonDistributionRepository.save(mockDistributionConfig.createEntity());
    final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null));
    final AuditEntryEntity badAuditEntryEntity_1 = auditEntryRepository.save(new AuditEntryEntity(-1L, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    final AuditEntryEntity badAuditEntryEntity_2 = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    final AuditEntryEntity badAuditEntryEntityBoth = auditEntryRepository.save(new AuditEntryEntity(-1L, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    final ResponseEntity<String> invalidIdResponse = auditEntryHandler.resendNotification(-1L);
    assertEquals(HttpStatus.BAD_REQUEST, invalidIdResponse.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponse_1 = auditEntryHandler.resendNotification(badAuditEntryEntity_1.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponse_1.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponse_2 = auditEntryHandler.resendNotification(badAuditEntryEntity_2.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponse_2.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponseBoth = auditEntryHandler.resendNotification(badAuditEntryEntityBoth.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponseBoth.getStatusCode());
    final ResponseEntity<String> validResponse = auditEntryHandler.resendNotification(savedAuditEntryEntity.getId());
    assertEquals(HttpStatus.OK, validResponse.getStatusCode());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.sql.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Aggregations

AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)14 Test (org.junit.Test)7 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)6 Date (java.util.Date)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)5 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)5 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)4 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)4 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)3 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)3 MockNotificationEntity (com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity)3 ComponentRestModel (com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel)3 NotificationRestModel (com.blackducksoftware.integration.hub.alert.web.model.NotificationRestModel)3 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)3 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 MockAuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity)2 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)2 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)2 ChannelEventFactory (com.blackducksoftware.integration.hub.alert.channel.manager.ChannelEventFactory)2