Search in sources :

Example 36 with ThrowableAnticipator

use of org.opennms.test.ThrowableAnticipator in project opennms by OpenNMS.

the class RrdStatisticAttributeVisitorTest method testAfterPropertiesSetNoStartTime.

public void testAfterPropertiesSetNoStartTime() throws Exception {
    RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalStateException("property startTime must be set to a non-null value"));
    attributeVisitor.setFetchStrategy(m_fetchStrategy);
    attributeVisitor.setConsolidationFunction("AVERAGE");
    attributeVisitor.setStartTime(null);
    attributeVisitor.setEndTime(m_endTime);
    attributeVisitor.setStatisticVisitor(m_statisticVisitor);
    try {
        attributeVisitor.afterPropertiesSet();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

Example 37 with ThrowableAnticipator

use of org.opennms.test.ThrowableAnticipator in project opennms by OpenNMS.

the class TopNAttributeStatisticVisitorTest method testVisitWithNull.

public void testVisitWithNull() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("attribute argument must not be null"));
    try {
        visitor.visit(null, 0.0);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

Example 38 with ThrowableAnticipator

use of org.opennms.test.ThrowableAnticipator in project opennms by OpenNMS.

the class ReportDefinitionTest method testBogusReportClass.

@SuppressWarnings("unchecked")
public void testBogusReportClass() throws Exception {
    // Not replaying anything, but need to do it before verifyAll() happens
    m_mocks.replayAll();
    ReportDefinition def = new ReportDefinition();
    Class<? extends AttributeStatisticVisitorWithResults> clazz = (Class<? extends AttributeStatisticVisitorWithResults>) Class.forName("java.lang.String");
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException(ThrowableAnticipator.IGNORE_MESSAGE));
    try {
        def.setReportClass(clazz);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : AttributeStatisticVisitorWithResults(org.opennms.netmgt.model.AttributeStatisticVisitorWithResults) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

Example 39 with ThrowableAnticipator

use of org.opennms.test.ThrowableAnticipator in project opennms by OpenNMS.

the class InstallerDbIT method testCatchIpInterfaceHasNullIpAddrValueOnUpgrade.

@Test
@Ignore("Tests deprecated upgrade functions of InstallerDb")
public void testCatchIpInterfaceHasNullIpAddrValueOnUpgrade() throws Exception {
    getInstallerDb().createSequences();
    getInstallerDb().updatePlPgsql();
    getInstallerDb().addStoredProcedures();
    addTableFromSQL("distpoller");
    addTableFromSQL("node");
    addTableFromSQL("snmpinterface");
    addTableFromSQLWithReplacements("ipinterface", new String[][] { new String[] { "(?i)ipAddr\\s+text\\s+not null,", "ipAddr text," } });
    executeSQL("INSERT INTO node (nodeId, nodeCreateTime) VALUES ( 1, now() )");
    executeSQL("INSERT INTO snmpInterface (nodeId, snmpIfIndex) VALUES ( 1, 1 )");
    executeSQL("INSERT INTO ipInterface (nodeId, ipAddr, ifIndex) VALUES ( 1, null, 1 )");
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new Exception("Error changing table 'ipinterface'.  Nested exception: The 'ipAddr' column in the 'ipInterface' table should never be null, but the entry for this row does have a null 'ipAddr' column.  It needs to be removed or udpated to reflect a valid 'ipAddr' value."));
    try {
        getInstallerDb().createTables();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : SQLException(java.sql.SQLException) IOException(java.io.IOException) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 40 with ThrowableAnticipator

use of org.opennms.test.ThrowableAnticipator in project opennms by OpenNMS.

the class EventExpanderTest method testAfterPropertiesSetWithNoEventConfDao.

@Test
public void testAfterPropertiesSetWithNoEventConfDao() {
    m_mocks.replayAll();
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalStateException("property eventConfDao must be set"));
    EventExpander expander = new EventExpander(new MetricRegistry());
    try {
        expander.afterPropertiesSet();
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : EventExpander(org.opennms.netmgt.eventd.EventExpander) MetricRegistry(com.codahale.metrics.MetricRegistry) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Aggregations

ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)105 Test (org.junit.Test)44 Ignore (org.junit.Ignore)12 ThresholdEvaluatorStateHighLow (org.opennms.netmgt.threshd.ThresholdEvaluatorHighLow.ThresholdEvaluatorStateHighLow)9 Threshold (org.opennms.netmgt.config.threshd.Threshold)8 BindException (org.springframework.validation.BindException)8 Date (java.util.Date)6 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)6 MarshallingResourceFailureException (org.opennms.core.xml.MarshallingResourceFailureException)4 DistributedStatusDetailsCommand (org.opennms.web.svclayer.model.DistributedStatusDetailsCommand)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 InputStreamResource (org.springframework.core.io.InputStreamResource)4 Resource (org.springframework.core.io.Resource)4 Errors (org.springframework.validation.Errors)4 File (java.io.File)3 IOException (java.io.IOException)3 SQLException (java.sql.SQLException)3 JdbcFilterDao (org.opennms.netmgt.filter.JdbcFilterDao)2 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)2 RrdException (org.opennms.netmgt.rrd.RrdException)2