/** * Generate schema. * * @throws Exception the exception */ @Test public void generateSchema() throws Exception { File schemaFile = fileAnticipator.expecting("tca-datacollection-config.xsd"); context.generateSchema(new TestOutputResolver(schemaFile)); if (fileAnticipator.isInitialized()) { fileAnticipator.deleteExpected(); } }
@After public void tearDown() { if (m_fileAnticipator.isInitialized()) { m_fileAnticipator.deleteExpected(); } m_fileAnticipator.tearDown(); }
@Test public void testGetResourceByNodeSourceAndIndexGetLabelStringAttribute() throws IOException { try { System.setProperty("org.opennms.rrd.storeByForeignSource", "true"); GenericIndexResourceType rt = new GenericIndexResourceType( m_resourceStorageDao, "foo", "Foo Resource", "${stringAttribute}", m_storageStrategy); File rrd = touch("snmp", "fs", "source1", "123", "foo", "1", RRD_FILE_NAME); m_fileAnticipator.tempFile( rrd.getParentFile(), RrdResourceAttributeUtils.STRINGS_PROPERTIES_FILE_NAME, "stringAttribute=hello!!!!"); m_mocks.replayAll(); OnmsResource resource = rt.getChildByName(getNodeResource("source1", "123"), "1"); m_mocks.verifyAll(); assertNotNull("resource", resource); assertEquals("resource label", "hello!!!!", resource.getLabel()); } finally { System.setProperty("org.opennms.rrd.storeByForeignSource", "false"); } }
@Before public void setUp() throws IOException { m_fileAnticipator = new FileAnticipator(); m_resourceStorageDao = new FilesystemResourceStorageDao(); m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir()); m_resourceStorageDao.setRrdStrategy(new NullRrdStrategy()); }
@After public void tearDown() throws Exception { /* if (m_fileAnticipator.isInitialized()) { m_fileAnticipator.deleteExpected(); } */ m_fileAnticipator.tearDown(); }
public File createRrdFile() throws Exception { String rrdFileBase = "foo"; m_fileAnticipator.initialize(); // This is so the RrdUtils.getExtension() call in the strategy works // Properties properties = new Properties(); // properties.setProperty("org.opennms.rrd.fileExtension", rrdExtension); // RrdConfig.getInstance().setProperties(properties); List<RrdDataSource> dataSources = new ArrayList<RrdDataSource>(); dataSources.add(new RrdDataSource("bar", "GAUGE", 3000, "U", "U")); List<String> rraList = new ArrayList<String>(); rraList.add("RRA:AVERAGE:0.5:1:2016"); File tempDir = m_fileAnticipator.getTempDir(); // Create an '/rrd/snmp/1' directory in the temp directory so that the // RRDs created by the test will have a realistic path File rrdDir = m_fileAnticipator.tempDir( m_fileAnticipator.tempDir(m_fileAnticipator.tempDir(tempDir, "rrd"), "snmp"), "1"); RrdDefinition def = m_strategy.createDefinition( "hello!", rrdDir.getAbsolutePath(), rrdFileBase, 300, dataSources, rraList); m_strategy.createFile(def, null); return m_fileAnticipator.expecting(rrdDir, rrdFileBase + RRD_EXTENSION); }
private File touch(String first, String... more) { Path parent = m_fileAnticipator.getTempDir().toPath(); Path path = parent.resolve(Paths.get(first, more)); File file = path.toFile(); file.getParentFile().mkdirs(); try { file.createNewFile(); } catch (IOException e) { throw Throwables.propagate(e); } assertTrue(file.canRead()); return file; }