WebsterPrivilegesTarget implements WebsterTarget, ArchiveAware { @Override public void setArchive(final Archive archive, final File writeBackDir) { this.archive = archive; this.writeBackDir = writeBackDir; } WebsterPrivilegesTarget(final File targetFile); @Override void setArchive(final Archive archive, final File writeBackDir); @Override void perform(final Session session);  }
@Test public void testConstruct() throws Exception { final File targetFile = new File(testOutDir, "testConstruct.xml"); final File writeBack = new File(testOutDir, "testConstruct_writeback"); if (targetFile.exists()) { targetFile.delete(); } if (writeBack.exists()) { FileUtils.deleteDirectory(writeBack); } OakMachine.Builder builder = TestUtil.fromPlan(obj().get()); WebsterPrivilegesTarget target = new WebsterPrivilegesTarget(targetFile); target.setArchive(new FileArchive(new File("src/test/resources/filevault/onePrivRef")), writeBack); builder.build().initAndInspect(target::perform); assertFileContains(targetFile, "<privileges/>"); }
@Test public void testWithExisting() throws Exception { final File targetFile = new File(testOutDir, "testWithExisting.xml"); final File writeBack = new File(testOutDir, "testWithExisting_writeback"); if (targetFile.exists()) { targetFile.delete(); } if (writeBack.exists()) { FileUtils.deleteDirectory(writeBack); } OakMachine.Builder builder = TestUtil.fromPlan(obj() .key("jcrNamespaces", arr(JcrNs.create("foo", "http: .key("jcrPrivileges", arr("foo:canBar")) .get()); WebsterPrivilegesTarget target = new WebsterPrivilegesTarget(targetFile); target.setArchive(new FileArchive(new File("src/test/resources/filevault/onePrivRef")), writeBack); builder.build().initAndInspect(target::perform); assertFileNotContains(targetFile, "<privileges/>"); assertFileContains(targetFile, "name=\"foo:canBar\""); OakMachine.Builder builderWithAbstract = TestUtil.fromPlan(obj() .key("jcrNamespaces", arr(JcrNs.create("foo", "http: .key("jcrPrivileges", key("foo:canBar", key("abstract", true))) .get()); WebsterPrivilegesTarget targetWithAbstract = new WebsterPrivilegesTarget(targetFile); targetWithAbstract.setArchive(new FileArchive(new File("src/test/resources/filevault/onePrivRef")), writeBack); builderWithAbstract.build().initAndInspect(targetWithAbstract::perform); assertFileNotContains(targetFile, "<privileges/>"); assertFileContains(targetFile, "name=\"foo:canBar\""); assertFileContains(targetFile, "abstract=\"true\""); }