Search in sources :

Example 6 with OnmsAcknowledgment

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());
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) InternetAddress(javax.mail.internet.InternetAddress) MimeMultipart(javax.mail.internet.MimeMultipart) Multipart(javax.mail.Multipart) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) Message(javax.mail.Message) SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage) MimeMessage(javax.mail.internet.MimeMessage) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) ArrayList(java.util.ArrayList) Properties(java.util.Properties) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) MimeBodyPart(javax.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 7 with OnmsAcknowledgment

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()));
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

Example 8 with OnmsAcknowledgment

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);
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

Example 9 with OnmsAcknowledgment

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsNode(org.opennms.netmgt.model.OnmsNode) Acknowledgeable(org.opennms.netmgt.model.Acknowledgeable) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

Example 10 with OnmsAcknowledgment

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());
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) Message(javax.mail.Message) SendmailMessage(org.opennms.netmgt.config.javamail.SendmailMessage) MimeMessage(javax.mail.internet.MimeMessage) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) Properties(java.util.Properties) MimeMessage(javax.mail.internet.MimeMessage) AddressException(javax.mail.internet.AddressException) Test(org.junit.Test)

Aggregations

OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)25 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)14 Test (org.junit.Test)11 Transactional (org.springframework.transaction.annotation.Transactional)10 Date (java.util.Date)6 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)6 Message (javax.mail.Message)4 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 ArrayList (java.util.ArrayList)3 InternetAddress (javax.mail.internet.InternetAddress)3 MimeMessage (javax.mail.internet.MimeMessage)3 Consumes (javax.ws.rs.Consumes)3 SendmailMessage (org.opennms.netmgt.config.javamail.SendmailMessage)3 Properties (java.util.Properties)2 Address (javax.mail.Address)2 MessagingException (javax.mail.MessagingException)2 PUT (javax.ws.rs.PUT)2 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)2 OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)2