Search in sources :

Example 96 with ThrowableAnticipator

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

the class JRobinRrdStrategyTest method testSampleSetFloatingPointValueWithExtraJunk.

/**
     * This test fails because of
     * <a href="http://bugzilla.opennms.org/show_bug.cgi?id=2272">bug #2272</a>
     * in org.jrobin.core.Sample.
     */
@Test
@Ignore("fails due to bug 2272")
public void testSampleSetFloatingPointValueWithExtraJunk() throws Exception {
    File rrdFile = createRrdFile();
    RrdDb openedFile = m_strategy.openFile(rrdFile.getAbsolutePath());
    Sample sample = openedFile.createSample();
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new Exception("Some exception that complains about bogus data"));
    try {
        sample.set("N:1.234 extra junk");
    } catch (Throwable t) {
        ta.throwableReceived(t);
    } finally {
        m_strategy.closeFile(openedFile);
    }
    ta.verifyAnticipated();
}
Also used : Sample(org.jrobin.core.Sample) RrdDb(org.jrobin.core.RrdDb) File(java.io.File) RrdException(org.opennms.netmgt.rrd.RrdException) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 97 with ThrowableAnticipator

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

the class JRobinRrdStrategyTest method testCommandWithoutDrawing.

@Test
public void testCommandWithoutDrawing() throws Exception {
    long end = System.currentTimeMillis();
    long start = end - (24 * 60 * 60 * 1000);
    String command = "--start=" + start + " --end=" + end;
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new RrdException(ThrowableAnticipator.IGNORE_MESSAGE));
    try {
        m_strategy.createGraph(command, new File(""));
    } catch (Throwable t) {
        ta.throwableReceived(t);
        // We don't care about the exact message, just a few details
        String problemText = "no graph was produced";
        assertTrue("cause message should contain '" + problemText + "'", t.getMessage().contains(problemText));
        String suggestionText = "Does the command have any drawing commands";
        assertTrue("cause message should contain '" + suggestionText + "'", t.getMessage().contains(suggestionText));
    }
    ta.verifyAnticipated();
}
Also used : RrdException(org.opennms.netmgt.rrd.RrdException) File(java.io.File) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Example 98 with ThrowableAnticipator

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

the class GenericIndexResourceTypeTest method testNullResourceType.

@Test
public void testNullResourceType() {
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("resourceType argument must not be null"));
    try {
        new GenericIndexResourceType(null, null, null);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Example 99 with ThrowableAnticipator

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

the class DefaultDistributedStatusServiceTest method testCreateFacilityStatusTableNoStartDate.

public void testCreateFacilityStatusTableNoStartDate() {
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("argument start cannot be null"));
    m_easyMockUtils.replayAll();
    try {
        m_service.createFacilityStatusTable(null, new Date());
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
    m_easyMockUtils.verifyAll();
}
Also used : Date(java.util.Date) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

Example 100 with ThrowableAnticipator

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

the class DefaultDistributedStatusServiceTest method testFindLocationSpecificStatusNullApplication.

public void testFindLocationSpecificStatusNullApplication() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation(m_locationDefinition1.getLocationName());
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("application cannot be null"));
    try {
        m_service.findLocationSpecificStatus(command, errors);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : Errors(org.springframework.validation.Errors) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) BindException(org.springframework.validation.BindException) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

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