use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.
the class DistributionConfigActions method saveConfig.
@Override
public D saveConfig(final R restModel) throws AlertException {
if (restModel != null) {
try {
D createdEntity = getObjectTransformer().configRestModelToDatabaseEntity(restModel, getDatabaseEntityClass());
CommonDistributionConfigEntity commonEntity = getObjectTransformer().configRestModelToDatabaseEntity(restModel, CommonDistributionConfigEntity.class);
if (createdEntity != null && commonEntity != null) {
createdEntity = getRepository().save(createdEntity);
commonEntity.setDistributionConfigId(createdEntity.getId());
commonEntity = commonDistributionRepository.save(commonEntity);
configuredProjectsActions.saveConfiguredProjects(commonEntity, restModel);
notificationTypesActions.saveNotificationTypes(commonEntity, restModel);
cleanUpStaleChannelConfigurations();
return createdEntity;
}
} catch (final Exception e) {
throw new AlertException(e.getMessage(), e);
}
}
return null;
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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());
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.
the class DistributionChannelTest method receiveMessageTest.
@Test
public void receiveMessageTest() {
final GlobalProperties globalProperties = new TestGlobalProperties();
final Gson gson = new Gson();
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final GlobalEmailRepositoryWrapper globalEmailRepositoryWrapper = Mockito.mock(GlobalEmailRepositoryWrapper.class);
final EmailGroupDistributionRepositoryWrapper emailGroupRepositoryWrapper = Mockito.mock(EmailGroupDistributionRepositoryWrapper.class);
final CommonDistributionRepositoryWrapper commonRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
final EmailGroupChannel channel = new EmailGroupChannel(globalProperties, gson, auditEntryRepository, globalEmailRepositoryWrapper, emailGroupRepositoryWrapper, commonRepositoryWrapper);
final Long commonId = 1L;
final EmailGroupEvent event = new EmailGroupEvent(createProjectData("Distribution Channel Test"), commonId);
final String jsonRepresentation = gson.toJson(event);
final CommonDistributionConfigEntity commonEntity = new CommonDistributionConfigEntity(commonId, SupportedChannels.EMAIL_GROUP, "Email Config", DigestTypeEnum.REAL_TIME, false);
Mockito.when(commonRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(commonEntity);
final EmailGroupDistributionConfigEntity specificEntity = new EmailGroupDistributionConfigEntity("admins", "", "TEST SUBJECT LINE");
Mockito.when(emailGroupRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(specificEntity);
channel.receiveMessage(jsonRepresentation);
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.
the class CommonDistributionConfigActions method saveConfig.
@Override
public CommonDistributionConfigEntity saveConfig(final CommonDistributionConfigRestModel restModel) throws AlertException {
if (restModel != null) {
try {
CommonDistributionConfigEntity createdEntity = getObjectTransformer().configRestModelToDatabaseEntity(restModel, getDatabaseEntityClass());
if (createdEntity != null) {
createdEntity = getCommonDistributionRepository().save(createdEntity);
getConfiguredProjectsActions().saveConfiguredProjects(createdEntity, restModel);
getNotificationTypesActions().saveNotificationTypes(createdEntity, restModel);
return createdEntity;
}
} catch (final Exception e) {
throw new AlertException(e.getMessage(), e);
}
}
return null;
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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());
}
Aggregations