NodeStateCopier { public static Builder builder() { return new Builder(); } private  NodeStateCopier(Set<String> includePaths, Set<String> excludePaths, Set<String> fragmentPaths, Set<String> excludeFragments, Set<String> mergePaths); static Builder builder(); static boolean copyNodeStore(@NotNull final NodeStore source, @NotNull final NodeStore target); static boolean copyProperties(NodeState source, NodeBuilder target);  }
@Test public void shouldCreateMissingAncestors() throws CommitFailedException, IOException { final NodeStore source = createPrefilledNodeStore(); final NodeStore target = createNodeStoreWithContent(); builder() .include("/a/b/c") .copy(source, target); expectDifference() .childNodeChanged("/a", "/a/b") .childNodeDeleted("/excluded", "/a/b/excluded") .strict() .verify(source.getRoot(), target.getRoot()); }
@Test public void shouldIncludeMultiplePaths() throws CommitFailedException, IOException { final NodeStore source = createPrefilledNodeStore(); final NodeStore target = createNodeStoreWithContent(); builder() .include("/a/b/c/d", "/a/b/c/e") .copy(source, target); expectDifference() .propertyDeleted("/a/b/c/f/jcr:primaryType") .childNodeChanged("/a", "/a/b", "/a/b/c") .childNodeDeleted("/excluded", "/a/b/excluded", "/a/b/c/f") .strict() .verify(source.getRoot(), target.getRoot()); }
@Test public void shouldSkipNonMatchingIncludes() throws CommitFailedException, IOException { final NodeStore source = createNodeStoreWithContent(); final NodeBuilder builder = source.getRoot().builder(); create(builder, "/a", primaryType); create(builder, "/a/b", primaryType); create(builder, "/a/b/c", primaryType); commit(source, builder); final NodeStore target = createNodeStoreWithContent(); builder() .include("/a", "/z") .copy(source, target); expectDifference() .strict() .verify(source.getRoot(), target.getRoot()); }
@Test public void shouldCopyFromMultipleSources() throws CommitFailedException, IOException { final NodeStore source1 = createNodeStoreWithContent( "/content/foo/en", "/content/foo/de"); final NodeStore source2 = createNodeStoreWithContent( "/content/bar/en", "/content/bar/de", "/content/baz/en"); final NodeStore target = createNodeStoreWithContent(); final NodeState before = target.getRoot(); builder() .include("/content/foo") .copy(source1, target); builder() .include("/content/bar") .exclude("/content/bar/de") .copy(source2, target); final NodeState after = target.getRoot(); expectDifference() .strict() .childNodeAdded( "/content", "/content/foo", "/content/foo/en", "/content/foo/de", "/content/bar", "/content/bar/en" ) .verify(before, after); }
@Test public void shouldRespectMergePaths() throws CommitFailedException, IOException { final NodeStore source = createNodeStoreWithContent("/content/foo/en", "/content/bar/en"); final NodeStore target = createNodeStoreWithContent("/content/foo/de"); builder() .merge("/content") .copy(source, target); final NodeState after = target.getRoot(); expectDifference() .strict() .childNodeAdded("/content/foo/de") .childNodeChanged("/content", "/content/foo") .verify(source.getRoot(), after); }
@Test public void shouldNotDeleteMergedExcludedPaths() throws CommitFailedException, IOException { final NodeStore source = createNodeStoreWithContent("/content/foo/en", "/jcr:system"); final NodeStore target = createNodeStoreWithContent("/jcr:system/jcr:versionStorage"); final NodeState before = target.getRoot(); builder() .merge("/jcr:system") .exclude("/jcr:system") .copy(source, target); final NodeState after = target.getRoot(); expectDifference() .strict() .childNodeAdded("/content", "/content/foo", "/content/foo/en") .verify(before, after); }
@Test public void shouldDeleteExistingNodes() throws CommitFailedException, IOException { final NodeStore source = createNodeStoreWithContent("/content/foo"); final NodeStore target = createNodeStoreWithContent("/content/bar"); final NodeState before = target.getRoot(); builder().copy(source, target); final NodeState after = target.getRoot(); expectDifference() .strict() .childNodeAdded("/content/foo") .childNodeChanged("/content") .childNodeDeleted("/content/bar") .verify(before, after); }
@Test public void shouldDeleteExistingPropertyIfMissingInSource() throws CommitFailedException, IOException { final NodeStore source = createNodeStoreWithContent("/a"); final NodeStore target = createNodeStoreWithContent(); final NodeBuilder builder = target.getRoot().builder(); create(builder, "/a", primaryType); commit(target, builder); final NodeState before = target.getRoot(); builder().copy(source, target); final NodeState after = target.getRoot(); expectDifference() .strict() .propertyDeleted("/a/jcr:primaryType") .childNodeChanged("/a") .verify(before, after); }
@Test public void shouldNotDeleteExistingNodesIfMerged() throws CommitFailedException, IOException { final NodeStore source = createNodeStoreWithContent("/content/foo"); final NodeStore target = createNodeStoreWithContent("/content/bar"); final NodeState before = target.getRoot(); builder() .merge("/content/bar") .copy(source, target); final NodeState after = target.getRoot(); expectDifference() .strict() .childNodeAdded("/content/foo") .childNodeChanged("/content") .verify(before, after); }
@Test public void shouldNotDeleteExistingNodesIfDescendantsOfMerged() throws CommitFailedException, IOException { final NodeStore source = createNodeStoreWithContent("/content/foo"); final NodeStore target = createNodeStoreWithContent("/content/bar"); final NodeState before = target.getRoot(); builder() .merge("/content") .copy(source, target); final NodeState after = target.getRoot(); expectDifference() .strict() .childNodeAdded("/content/foo") .childNodeChanged("/content") .verify(before, after); }
@Test public void shouldIgnoreNonMatchingMergePaths() throws CommitFailedException, IOException { final NodeStore source = createNodeStoreWithContent("/content/foo"); final NodeStore target = createNodeStoreWithContent("/content/bar"); final NodeState before = target.getRoot(); builder() .merge("/con") .copy(source, target); final NodeState after = target.getRoot(); expectDifference() .strict() .childNodeAdded("/content/foo") .childNodeChanged("/content") .childNodeDeleted("/content/bar") .verify(before, after); }