WebsterPlan { public void perform() throws Exception { if (this.globalSegmentStore == null) { this.performWithGlobalMemory(); } else { this.performWithGlobalSegment(); } } WebsterPlan(final @NotNull FixtureProvider fixtureProvider,
                final @NotNull List<WebsterTarget> targets,
                final @Nullable File globalSegmentStore,
                final @Nullable File archiveRoot); void perform();  }
@Test(expected = IllegalStateException.class) public void testBuilder_perform_emptyThrows() throws Exception { WebsterPlan.Builder builder = new WebsterPlan.Builder(); builder.build().perform(); }
@Test public void testBuilder_perform_withMemoryFixture() throws Exception { WebsterPlan.Builder builder = new WebsterPlan.Builder(); builder.withFixtureProvider(() -> JcrFactory.getNodeStoreFixture(true, "memory")); builder.build().perform(); }
@Test public void testBuilder_perform_withGlobalMemory() throws Exception { WebsterPlan.Builder builder = new WebsterPlan.Builder(); builder.withGlobalMemoryStore(); final JcrNs fooNs = JcrNs.create("foo", "http: final List<JcrNs> jcrNs = Collections.singletonList(fooNs); final NamespaceMapping mapping = JsonCnd.toNamespaceMapping(jcrNs); builder.withFixtureProvider(() -> { final NodeStoreFixture fixture = JcrFactory.getNodeStoreFixture(true, "memory"); new OakMachine.Builder().withNodeStoreSupplier(fixture::getStore).withInitStage( new InitStage.Builder() .withNs(jcrNs) .withQNodeTypes(JsonCnd.getQTypesFromJson(obj().key("foo:mixin", obj().key("@", arr("mixin"))).get(), mapping)) .withForcedRoot("/foo", "nt:folder", "foo:mixin") .build()).build().scanPackage(); return fixture; }); final File targetFile = new File(testOutDir, "testBuilder_perform_withGlobalMemory.json"); if (targetFile.exists()) { targetFile.delete(); } builder.withTarget(JsonTargetFactory.CHECKLIST.createTarget(targetFile, obj().key("selectPaths", arr().val("/foo")).get())); builder.build().perform(); }
@Test(expected = IllegalStateException.class) public void testBuilder_perform_withGlobalMemory_throws() throws Exception { WebsterPlan.Builder builder = new WebsterPlan.Builder(); builder.withGlobalMemoryStore(); final JcrNs fooNs = JcrNs.create("foo", "http: final List<JcrNs> jcrNs = Collections.singletonList(fooNs); builder.withFixtureProvider(() -> { final NodeStoreFixture fixture = mock(NodeStoreFixture.class); doThrow(IllegalStateException.class).when(fixture).getStore(); return fixture; }); final File targetFile = new File(testOutDir, "testBuilder_perform_withGlobalMemory_throws.json"); if (targetFile.exists()) { targetFile.delete(); } builder.withTarget(JsonTargetFactory.CHECKLIST.createTarget(targetFile, obj().key("selectPaths", arr().val("/foo")).get())); builder.build().perform(); }
@Test public void testBuilder_perform_withGlobalSegment() throws Exception { final File globalStore = new File(testOutDir, "testBuilder_perform_withGlobalSegment/segmentstore"); if (globalStore.exists()) { FileUtils.deleteDirectory(globalStore); } WebsterPlan.Builder builder = new WebsterPlan.Builder(); builder.withGlobalSegmentStore(globalStore); final JcrNs fooNs = JcrNs.create("foo", "http: final List<JcrNs> jcrNs = Collections.singletonList(fooNs); final NamespaceMapping mapping = JsonCnd.toNamespaceMapping(jcrNs); builder.withFixtureProvider(() -> { final NodeStoreFixture fixture = JcrFactory.getNodeStoreFixture(true, "memory"); new OakMachine.Builder().withNodeStoreSupplier(fixture::getStore).withInitStage( new InitStage.Builder() .withNs(jcrNs) .withQNodeTypes(JsonCnd.getQTypesFromJson(obj().key("foo:mixin", obj().key("@", arr("mixin"))).get(), mapping)) .withForcedRoot("/foo", "nt:folder", "foo:mixin") .build()).build().scanPackage(); return fixture; }); final File targetFile = new File(testOutDir, "testBuilder_perform_withGlobalSegment.json"); if (targetFile.exists()) { targetFile.delete(); } builder.withTarget(JsonTargetFactory.CHECKLIST.createTarget(targetFile, obj().key("selectPaths", arr().val("/foo")).get())); builder.build().perform(); }
@Test(expected = IllegalStateException.class) public void testBuilder_perform_withGlobalSegment_throws() throws Exception { final File globalStore = new File(testOutDir, "testBuilder_perform_withGlobalSegment_throws/segmentstore"); if (globalStore.exists()) { FileUtils.deleteDirectory(globalStore); } WebsterPlan.Builder builder = new WebsterPlan.Builder(); builder.withGlobalSegmentStore(globalStore); final JcrNs fooNs = JcrNs.create("foo", "http: final List<JcrNs> jcrNs = Collections.singletonList(fooNs); final NamespaceMapping mapping = JsonCnd.toNamespaceMapping(jcrNs); builder.withFixtureProvider(() -> { final NodeStoreFixture fixture = mock(NodeStoreFixture.class); doThrow(IllegalStateException.class).when(fixture).getStore(); return fixture; }); final File targetFile = new File(testOutDir, "testBuilder_perform_withGlobalSegment_throws.json"); if (targetFile.exists()) { targetFile.delete(); } builder.withTarget(JsonTargetFactory.CHECKLIST.createTarget(targetFile, obj().key("selectPaths", arr().val("/foo")).get())); builder.build().perform(); }
@Test public void testBuilder_withArchiveRoot() throws Exception { final File testBase = new File(testOutDir, "testBuilder_withArchiveRoot"); final File archiveSrc = new File("src/test/resources/filevault/noReferences"); final File archiveRoot = new File(testBase, "noReferences"); FileUtils.deleteDirectory(archiveRoot); FileUtils.copyDirectory(archiveSrc, archiveRoot); final JcrNs fooNs = JcrNs.create("foo", "http: final List<JcrNs> jcrNs = Collections.singletonList(fooNs); final NamespaceMapping mapping = JsonCnd.toNamespaceMapping(jcrNs); WebsterPlan.Builder builder = new WebsterPlan.Builder(); builder.withFixtureProvider(() -> { final NodeStoreFixture fixture = JcrFactory.getNodeStoreFixture(true, "memory"); new OakMachine.Builder().withNodeStoreSupplier(fixture::getStore).withInitStage( new InitStage.Builder() .withNs(jcrNs) .withQNodeTypes(JsonCnd.getQTypesFromJson(obj().key("foo:mixin", obj().key("@", arr("mixin"))).get(), mapping)) .withForcedRoot("/foo", "nt:folder", "foo:mixin") .build()).build().scanPackage(); return fixture; }); final CompletableFuture<File> slot = new CompletableFuture<>(); final ArchiveAwareTarget target = mock(ArchiveAwareTarget.class); doAnswer(call -> slot.complete(call.getArgument(1, File.class))) .when(target).setArchive(any(Archive.class), any(File.class)); builder.withArchiveRoot(archiveRoot); builder.withTarget(target); builder.build().perform(); assertSame("should be same as archiveRoot", archiveRoot, slot.getNow(null)); }