use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class JavaMailAckReaderIT method workingWithMultiPartMessages.
/**
* tests the ability to create acknowledgments from an email for a multi-part text. This test
* creates a message from scratch rather than reading from an inbox. This message creation
* may not actually represent what comes from a mail server.
*/
@Test
public void workingWithMultiPartMessages() throws JavaMailerException, MessagingException {
List<Message> msgs = new ArrayList<Message>();
Properties props = new Properties();
Message msg = new MimeMessage(Session.getDefaultInstance(props));
Address[] addrs = new Address[1];
addrs[0] = new InternetAddress("david@opennms.org");
msg.addFrom(addrs);
msg.addRecipient(RecipientType.TO, new InternetAddress("david@opennms.org"));
msg.setSubject("Re: Notice #1234 JavaMailReaderImplTest Test Message");
Multipart mpContent = new MimeMultipart();
BodyPart textBp = new MimeBodyPart();
BodyPart htmlBp = new MimeBodyPart();
textBp.setText("ack");
htmlBp.setContent("<html>\n" + " <head>\n" + " <title>\n" + " Acknowledge\n" + " </title>\n" + " </head>\n" + " <body>\n" + " <h1>\n" + " ack\n" + " </h1>\n" + " </body>\n" + "</html>", "text/html");
mpContent.addBodyPart(textBp);
mpContent.addBodyPart(htmlBp);
msg.setContent(mpContent);
msgs.add(msg);
List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
Assert.assertEquals(1, acks.size());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
Assert.assertEquals("david@opennms.org", acks.get(0).getAckUser());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
Assert.assertEquals(new Integer(1234), acks.get(0).getRefId());
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class AckdIT method testAcknowledgeAlarm.
/**
* This tests the acknowledgment of an alarm and any related notifications.
*/
@Test
public void testAcknowledgeAlarm() {
VerificationObject vo = createAckStructure();
Assert.assertTrue(vo.m_nodeId > 0);
Assert.assertTrue(vo.m_alarmId > 0);
Assert.assertTrue(vo.m_eventID > 0);
Assert.assertTrue(vo.m_userNotifId > 0);
OnmsAlarm alarm = m_alarmDao.get(vo.m_alarmId);
OnmsAcknowledgment ack = new OnmsAcknowledgment(m_alarmDao.get(vo.m_alarmId));
m_ackDao.save(ack);
m_ackDao.flush();
m_ackDao.processAck(ack);
alarm = m_alarmDao.get(ack.getRefId());
Assert.assertNotNull(alarm.getAlarmAckUser());
Assert.assertEquals("admin", alarm.getAlarmAckUser());
OnmsNotification notif = m_notificationDao.get(vo.m_notifId);
Assert.assertNotNull(notif);
Assert.assertEquals("admin", notif.getAnsweredBy());
Assert.assertTrue(alarm.getAlarmAckTime().before(notif.getRespondTime()));
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class AckdIT method testAcknowledgeNotification.
/**
* This tests acknowledging a notification and a related alarm. If events are being deduplicated
* they should all have the same alarm ID.
* @throws InterruptedException
*/
@Test
public void testAcknowledgeNotification() throws InterruptedException {
VerificationObject vo = createAckStructure();
Assert.assertTrue(vo.m_nodeId > 0);
Assert.assertTrue(vo.m_alarmId > 0);
Assert.assertTrue(vo.m_eventID > 0);
Assert.assertTrue(vo.m_userNotifId > 0);
OnmsAcknowledgment ack = new OnmsAcknowledgment(m_notificationDao.get(vo.m_notifId));
m_ackDao.save(ack);
m_ackDao.flush();
Thread.sleep(1);
m_ackDao.processAck(ack);
OnmsNotification notif = m_notificationDao.get(ack.getRefId());
Assert.assertNotNull(notif.getAnsweredBy());
Assert.assertEquals("admin", notif.getAnsweredBy());
OnmsAlarm alarm = m_alarmDao.get(vo.m_alarmId);
Assert.assertNotNull(alarm);
Assert.assertEquals("admin", alarm.getAlarmAckUser());
long ackTime = ack.getAckTime().getTime();
long respondTime = notif.getRespondTime().getTime();
//the DAOs now set the acknowledgment time for each Acknowledgable and should
//be later (by a few millis in this test) than the time the acknowledgment was created
//this will give us an idea about the processing time of an acknowledgment
Assert.assertTrue(ackTime < respondTime);
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class DefaultAckServiceIT method processAck.
@Test
public void processAck() {
OnmsNode dbNode = m_nodeDao.get(m_populator.getNode1().getId());
OnmsEvent event = getEvent(dbNode);
OnmsNotification notif = getNotification(event);
// OnmsUserNotification un = getUserNotification(notif);
Assert.assertTrue(m_notifDao.countAll() > 0);
List<OnmsNotification> notifs = m_notifDao.findAll();
Assert.assertTrue((notifs.contains(notif)));
OnmsAcknowledgment ack = new OnmsAcknowledgment();
ack.setRefId(notif.getNotifyId());
ack.setAckType(AckType.NOTIFICATION);
m_ackDao.processAck(ack);
List<Acknowledgeable> ackables = m_ackDao.findAcknowledgables(ack);
Assert.assertEquals(1, ackables.size());
Acknowledgeable ackable = ackables.get(0);
Assert.assertEquals("admin", ackable.getAckUser());
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class JavaMailAckReaderIT method workingWithSimpleTextMessages.
/**
* tests the ability to create acknowledgments from an email for plain text. This test
* creates a message from scratch rather than reading from an inbox.
*/
@Test
public void workingWithSimpleTextMessages() {
Properties props = new Properties();
Message msg = new MimeMessage(Session.getDefaultInstance(props));
try {
Address[] addrs = new Address[1];
addrs[0] = new InternetAddress("david@opennms.org");
msg.addFrom(addrs);
msg.addRecipient(javax.mail.internet.MimeMessage.RecipientType.TO, addrs[0]);
msg.setSubject("Re: Notice #1234 JavaMailReaderImplTest Test Message");
msg.setText("ACK");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
List<Message> msgs = new ArrayList<Message>(1);
msgs.add(msg);
List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
Assert.assertEquals(1, acks.size());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
Assert.assertEquals("david@opennms.org", acks.get(0).getAckUser());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
Assert.assertEquals(new Integer(1234), acks.get(0).getRefId());
}
Aggregations