FilePlugin implements ActionPluginListener { @Override public void process(ActionMessage msg) throws Exception { if (msg == null || msg.getAction() == null || msg.getAction().getEvent() == null) { log.warnMessageReceivedWithoutPayload("file"); } String path = msg.getAction().getProperties() != null ? msg.getAction().getProperties().get("path") : null; path = path == null ? defaultProperties.get("path") : path; path = path == null ? System.getProperty("user.home") : path; Event event = msg.getAction() != null ? msg.getAction().getEvent() : null; String fileName = event.getId() + "-timestamp-" + System.currentTimeMillis() + ".txt"; BufferedWriter writer = null; try { File pathFile = new File(path); if (!pathFile.exists()) { pathFile.mkdirs(); } File alertFile = new File(pathFile, fileName); if (!alertFile.exists()) { alertFile.createNewFile(); } writer = new BufferedWriter(new FileWriter(alertFile)); String jsonEvent = objectMapper.writeValueAsString(event); writer.write(jsonEvent); log.infoActionReceived("file", msg.toString()); Action successAction = msg.getAction(); successAction.setResult(MESSAGE_PROCESSED); sendResult(successAction); } catch (Exception e) { log.errorCannotProcessMessage("file", e.getMessage()); Action failedAction = msg.getAction(); failedAction.setResult(MESSAGE_FAILED); sendResult(failedAction); } finally { if (writer != null) { writer.close(); } } } FilePlugin(); @Override Set<String> getProperties(); @Override Map<String, String> getDefaultProperties(); @Override void process(ActionMessage msg);  }
@Test public void thresholdTest() throws Exception { filePlugin.process(openThresholdMsg); filePlugin.process(ackThresholdMsg); filePlugin.process(resolvedThresholdMsg); }
@Test public void availabilityTest() throws Exception { filePlugin.process(openAvailMsg); filePlugin.process(ackAvailMsg); filePlugin.process(resolvedAvailMsg); }
@Test public void mixedTest() throws Exception { filePlugin.process(openTwoCondMsg); filePlugin.process(ackTwoCondMsg); filePlugin.process(resolvedTwoCondMsg); }