use of com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate in project hub-alert by blackducksoftware.
the class ChannelTemplateManagerTest method testNotAbstractChannelEvent.
@Test
public void testNotAbstractChannelEvent() {
final ChannelTemplateManager channelTemplateManager = new ChannelTemplateManager(new Gson(), null, null, null) {
@Override
public boolean hasTemplate(final String destination) {
return true;
}
@Override
public AbstractJmsTemplate getTemplate(final String destination) {
final AbstractJmsTemplate abstractJmsTemplate = Mockito.mock(AbstractJmsTemplate.class);
Mockito.doNothing().when(abstractJmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
return abstractJmsTemplate;
}
};
final DBStoreEvent dbStoreEvent = new DBStoreEvent(null);
final boolean isTrue = channelTemplateManager.sendEvent(dbStoreEvent);
assertTrue(isTrue);
}
use of com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate in project hub-alert by blackducksoftware.
the class ChannelTemplateManager method sendEvent.
public boolean sendEvent(final AbstractEvent event) {
final String destination = event.getTopic();
if (hasTemplate(destination)) {
if (event instanceof AbstractChannelEvent) {
final AbstractChannelEvent channelEvent = (AbstractChannelEvent) event;
AuditEntryEntity auditEntryEntity = null;
if (channelEvent.getAuditEntryId() == null) {
auditEntryEntity = new AuditEntryEntity(channelEvent.getCommonDistributionConfigId(), new Date(System.currentTimeMillis()), null, null, null, null);
} else {
auditEntryEntity = auditEntryRepository.findOne(channelEvent.getAuditEntryId());
}
auditEntryEntity.setStatus(StatusEnum.PENDING);
final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity);
channelEvent.setAuditEntryId(savedAuditEntryEntity.getId());
for (final Long notificationId : channelEvent.getProjectData().getNotificationIds()) {
final AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId);
auditNotificationRepository.save(auditNotificationRelation);
}
final String jsonMessage = gson.toJson(channelEvent);
final AbstractJmsTemplate template = getTemplate(destination);
template.convertAndSend(destination, jsonMessage);
} else {
final String jsonMessage = gson.toJson(event);
final AbstractJmsTemplate template = getTemplate(destination);
template.convertAndSend(destination, jsonMessage);
}
return true;
} else {
return false;
}
}
use of com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate in project hub-alert by blackducksoftware.
the class ChannelTemplateManagerTest method testSendEvents.
@Test
public void testSendEvents() {
final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
final AuditEntryRepositoryWrapper auditEntryRepositoryWrapper = Mockito.mock(AuditEntryRepositoryWrapper.class);
Mockito.when(auditEntryRepositoryWrapper.save(Mockito.any(AuditEntryEntity.class))).thenReturn(mockAuditEntryEntity.createEntity());
final ChannelTemplateManager channelTemplateManager = new ChannelTemplateManager(new Gson(), auditEntryRepositoryWrapper, null, null) {
@Override
public boolean hasTemplate(final String destination) {
return true;
}
@Override
public AbstractJmsTemplate getTemplate(final String destination) {
testCount++;
final AbstractJmsTemplate abstractJmsTemplate = Mockito.mock(AbstractJmsTemplate.class);
Mockito.doNothing().when(abstractJmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
return abstractJmsTemplate;
}
};
testCount = 0;
final ProjectData projectData = new ProjectData(DigestTypeEnum.DAILY, "test", "version", Arrays.asList(), null);
final HipChatEvent slackEvent = new HipChatEvent(projectData, 1L);
channelTemplateManager.sendEvents(Arrays.asList(slackEvent));
assertEquals(1, testCount);
}
Aggregations