Search in sources :

Example 1 with PropertiesGraphDao

use of org.opennms.netmgt.dao.support.PropertiesGraphDao in project opennms by OpenNMS.

the class JsmiMibParserTest method testGenerateGraphTemplates.

/**
     * Test generate graph templates.
     *
     * @throws Exception the exception
     */
@Test
public void testGenerateGraphTemplates() throws Exception {
    if (parser.parseMib(new File(MIB_DIR, "Clavister-MIB.mib"))) {
        List<PrefabGraph> graphs = parser.getPrefabGraphs();
        StringWriter writer = new StringWriter();
        PrefabGraphDumper dumper = new PrefabGraphDumper();
        dumper.dump(graphs, writer);
        System.out.println(writer.getBuffer().toString());
        // FIXME we should implement a more comprehensive check here.
        Assert.assertEquals(102533, writer.getBuffer().toString().length());
        PropertiesGraphDao dao = new PropertiesGraphDao();
        StringBuffer sb = new StringBuffer();
        sb.append("command.prefix=/usr/bin/rrdtool\n");
        sb.append("output.mime=image/png\n");
        sb.append(writer.getBuffer().toString());
        dao.loadProperties("performance", new ByteArrayInputStream(sb.toString().getBytes()));
        Assert.assertEquals(graphs.size(), dao.getAllPrefabGraphs().size());
        for (PrefabGraph g : graphs) {
            try {
                PrefabGraph graph = dao.getPrefabGraph(g.getName());
                Assert.assertEquals(g.getTitle(), graph.getTitle());
            } catch (ObjectRetrievalFailureException e) {
                Assert.fail(e.getMessage());
            }
        }
    } else {
        Assert.fail("The Clavister-MIB.mib file couldn't be parsed successfully.");
    }
}
Also used : PrefabGraphDumper(org.opennms.features.mibcompiler.services.PrefabGraphDumper) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) PropertiesGraphDao(org.opennms.netmgt.dao.support.PropertiesGraphDao) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) File(java.io.File) Test(org.junit.Test)

Example 2 with PropertiesGraphDao

use of org.opennms.netmgt.dao.support.PropertiesGraphDao in project opennms by OpenNMS.

the class GraphResultsControllerTest method setUp.

/**
	 * Sets the up.
	 *
	 * @throws Exception the exception
	 */
@Before
public void setUp() throws Exception {
    m_service = EasyMock.createMock(GraphResultsService.class);
    PropertiesGraphDao graphDao = new PropertiesGraphDao();
    graphDao.loadProperties("performance", new FileSystemResource(new File("src/test/resources/etc/snmp-graph.properties")));
    List<PrefabGraph> prefabs = graphDao.getAllPrefabGraphs();
    Assert.assertNotNull(prefabs);
    Assert.assertFalse(prefabs.isEmpty());
    EasyMock.expect(m_service.getAllPrefabGraphs(ResourceId.get("node", "1").resolve("nodeSnmp", ""))).andReturn(prefabs.toArray(new PrefabGraph[prefabs.size()])).anyTimes();
    m_controller = new GraphResultsController();
    m_controller.setGraphResultsService(m_service);
    EasyMock.replay(m_service);
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) GraphResultsService(org.opennms.web.svclayer.api.GraphResultsService) PropertiesGraphDao(org.opennms.netmgt.dao.support.PropertiesGraphDao) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Before(org.junit.Before)

Aggregations

File (java.io.File)2 PropertiesGraphDao (org.opennms.netmgt.dao.support.PropertiesGraphDao)2 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringWriter (java.io.StringWriter)1 Before (org.junit.Before)1 Test (org.junit.Test)1 PrefabGraphDumper (org.opennms.features.mibcompiler.services.PrefabGraphDumper)1 GraphResultsService (org.opennms.web.svclayer.api.GraphResultsService)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)1