@Test public void testCopyExtraRule() throws NoSuchMethodException, IOException, InvocationTargetException, IllegalAccessException, URISyntaxException { Method method = AnsibleExtraSensor.class.getDeclaredMethod("copyExtraRule", Path.class, Path.class); method.setAccessible(true); Path tempDir = Files.createTempDirectory(EXTRA_RULES_TEMP_DIR); assertFalse((Boolean)method.invoke(sensor, Paths.get("src/test/resources/extra-rules/extra-rule1.foo"), tempDir)); Path file = Paths.get(getClass().getResource("/extra-rules/extra-rule1.cmd").toURI()); assertTrue((Boolean)method.invoke(sensor, file, tempDir)); assertTrue(tempDir.resolve(file.toFile().getName()).toFile().exists()); assertEquals(Files.readAllLines(file), Files.readAllLines(tempDir.resolve(file.toFile().getName()))); }
private boolean copyExtraRule(Path ruleFile, Path directory) { LOGGER.debug("Copying rule script {} to {}", ruleFile.toString(), directory.toString()); try (OutputStream resStreamOut = new FileOutputStream(directory.resolve(ruleFile.getFileName().toString()).toString())) { resStreamOut.write(Files.readAllBytes(ruleFile)); } catch (IOException e) { LOGGER.error("Cannot extract rule " + ruleFile.toString() + " to " + directory.toString(), e); return false; } return true; }
AnsibleExtraSensor extends AbstractAnsibleSensor { private boolean copyExtraRule(Path ruleFile, Path directory) { LOGGER.debug("Copying rule script {} to {}", ruleFile.toString(), directory.toString()); try (OutputStream resStreamOut = new FileOutputStream(directory.resolve(ruleFile.getFileName().toString()).toString())) { resStreamOut.write(Files.readAllBytes(ruleFile)); } catch (IOException e) { LOGGER.error("Cannot extract rule " + ruleFile.toString() + " to " + directory.toString(), e); return false; } return true; } }
AnsibleExtraSensor extends AbstractAnsibleSensor { private boolean copyExtraRule(Path ruleFile, Path directory) { LOGGER.debug("Copying rule script {} to {}", ruleFile.toString(), directory.toString()); try (OutputStream resStreamOut = new FileOutputStream(directory.resolve(ruleFile.getFileName().toString()).toString())) { resStreamOut.write(Files.readAllBytes(ruleFile)); } catch (IOException e) { LOGGER.error("Cannot extract rule " + ruleFile.toString() + " to " + directory.toString(), e); return false; } return true; } AnsibleExtraSensor(FileSystem fileSystem); }
AnsibleExtraSensor extends AbstractAnsibleSensor { private boolean copyExtraRule(Path ruleFile, Path directory) { LOGGER.debug("Copying rule script {} to {}", ruleFile.toString(), directory.toString()); try (OutputStream resStreamOut = new FileOutputStream(directory.resolve(ruleFile.getFileName().toString()).toString())) { resStreamOut.write(Files.readAllBytes(ruleFile)); } catch (IOException e) { LOGGER.error("Cannot extract rule " + ruleFile.toString() + " to " + directory.toString(), e); return false; } return true; } AnsibleExtraSensor(FileSystem fileSystem); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); }
AnsibleExtraSensor extends AbstractAnsibleSensor { private boolean copyExtraRule(Path ruleFile, Path directory) { LOGGER.debug("Copying rule script {} to {}", ruleFile.toString(), directory.toString()); try (OutputStream resStreamOut = new FileOutputStream(directory.resolve(ruleFile.getFileName().toString()).toString())) { resStreamOut.write(Files.readAllBytes(ruleFile)); } catch (IOException e) { LOGGER.error("Cannot extract rule " + ruleFile.toString() + " to " + directory.toString(), e); return false; } return true; } AnsibleExtraSensor(FileSystem fileSystem); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); static final String EXTRA_RULES_TEMP_DIR; static final String EXTRA_RULES_DIR; }