Search in sources :

Example 1 with StatisticsReportCommand

use of org.opennms.web.svclayer.model.StatisticsReportCommand in project opennms by OpenNMS.

the class DefaultStatisticsReportServiceTest method testNullCommandObjectId.

@Test
public void testNullCommandObjectId() {
    StatisticsReportCommand command = new StatisticsReportCommand();
    BindException errors = new BindException(command, "");
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("id property on command object cannot be null"));
    m_mocks.replayAll();
    try {
        m_service.getReport(command, errors);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : BindException(org.springframework.validation.BindException) StatisticsReportCommand(org.opennms.web.svclayer.model.StatisticsReportCommand) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) Test(org.junit.Test)

Example 2 with StatisticsReportCommand

use of org.opennms.web.svclayer.model.StatisticsReportCommand in project opennms by OpenNMS.

the class DefaultStatisticsReportServiceTest method testDatumWithNonExistentResource.

@Test
public void testDatumWithNonExistentResource() {
    StatisticsReport report = new StatisticsReport();
    report.setId(1);
    StatisticsReportData datum = new StatisticsReportData();
    ResourceReference resourceRef = new ResourceReference();
    resourceRef.setId(1);
    resourceRef.setResourceId("node[1].interfaceSnmp[en0]");
    datum.setId(1);
    datum.setResource(resourceRef);
    datum.setReport(report);
    datum.setValue(0.1d);
    report.addData(datum);
    StatisticsReportCommand command = new StatisticsReportCommand();
    command.setId(report.getId());
    BindException errors = new BindException(command, "");
    expect(m_statisticsReportDao.load(report.getId())).andReturn(report);
    m_statisticsReportDao.initialize(report);
    m_statisticsReportDao.initialize(report.getData());
    expect(m_resourceDao.getResourceById(ResourceId.fromString(resourceRef.getResourceId()))).andReturn(null);
    m_mocks.replayAll();
    StatisticsReportModel model = m_service.getReport(command, errors);
    assertNotNull("model should not be null", model);
    assertNotNull("model.getData() should not be null", model.getData());
    SortedSet<Datum> data = model.getData();
    assertEquals("data size", 1, data.size());
    Datum d = data.first();
    assertNotNull("first datum should not be null", d);
    assertNull("first datum resource should be null", d.getResource());
}
Also used : Datum(org.opennms.web.svclayer.model.StatisticsReportModel.Datum) StatisticsReport(org.opennms.netmgt.model.StatisticsReport) StatisticsReportData(org.opennms.netmgt.model.StatisticsReportData) BindException(org.springframework.validation.BindException) ResourceReference(org.opennms.netmgt.model.ResourceReference) StatisticsReportCommand(org.opennms.web.svclayer.model.StatisticsReportCommand) StatisticsReportModel(org.opennms.web.svclayer.model.StatisticsReportModel) Test(org.junit.Test)

Example 3 with StatisticsReportCommand

use of org.opennms.web.svclayer.model.StatisticsReportCommand in project opennms by OpenNMS.

the class StatisticsReportCommandValidator method validate.

/** {@inheritDoc} */
@Override
public void validate(Object obj, Errors errors) {
    StatisticsReportCommand cmd = (StatisticsReportCommand) obj;
    if (cmd.getId() == null) {
        errors.rejectValue("id", "statisticsReportId.notSpecified", new Object[] { "id" }, "Value required.");
    } else {
        try {
            int id = cmd.getId();
            m_statisticsReportDao.load(id);
        } catch (DataAccessException e) {
            errors.rejectValue("id", "statisticsReportId.notFound", new Object[] { "id", cmd.getId() }, "Valid statistics report ID required.");
        }
    }
}
Also used : StatisticsReportCommand(org.opennms.web.svclayer.model.StatisticsReportCommand) DataAccessException(org.springframework.dao.DataAccessException)

Aggregations

StatisticsReportCommand (org.opennms.web.svclayer.model.StatisticsReportCommand)3 Test (org.junit.Test)2 BindException (org.springframework.validation.BindException)2 ResourceReference (org.opennms.netmgt.model.ResourceReference)1 StatisticsReport (org.opennms.netmgt.model.StatisticsReport)1 StatisticsReportData (org.opennms.netmgt.model.StatisticsReportData)1 ThrowableAnticipator (org.opennms.test.ThrowableAnticipator)1 StatisticsReportModel (org.opennms.web.svclayer.model.StatisticsReportModel)1 Datum (org.opennms.web.svclayer.model.StatisticsReportModel.Datum)1 DataAccessException (org.springframework.dao.DataAccessException)1