PriamConfigurationPersister extends Task { @Override public void execute() throws Exception { ensurePaths(); Path tempPath = null; try { File output = File.createTempFile( structuredPath.getFileName().toString(), ".tmp", mergedConfigDirectory.toFile()); tempPath = output.toPath(); Files.setPosixFilePermissions(tempPath, PosixFilePermissions.fromString("rw-------")); Map<String, Object> structuredConfiguration = config.getStructuredConfiguration("all"); ObjectMapper mapper = new ObjectMapper(); ObjectWriter structuredPathTmpWriter = mapper.writer(new MinimalPrettyPrinter()); structuredPathTmpWriter.writeValue(output, structuredConfiguration); if (!output.renameTo(structuredPath.toFile())) logger.error("Failed to persist structured Priam configuration"); } finally { if (tempPath != null) Files.deleteIfExists(tempPath); } } @Inject  PriamConfigurationPersister(IConfiguration config); @Override void execute(); @Override String getName(); static TaskTimer getTimer(IConfiguration config); static final String NAME; }
@Test @SuppressWarnings("unchecked") public void execute() throws Exception { Path structuredJson = Paths.get(folder.getRoot().getPath(), "structured.json"); persister.execute(); assertTrue(structuredJson.toFile().exists()); ObjectMapper objectMapper = new ObjectMapper(); Map<String, Object> myMap = objectMapper.readValue(Files.readAllBytes(structuredJson), HashMap.class); assertEquals(myMap.get("backupLocation"), fakeConfiguration.getBackupLocation()); }