You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "reschke (via GitHub)" <gi...@apache.org> on 2024/02/06 12:31:49 UTC

Re: [PR] JCRVLT-737: test case [jackrabbit-filevault]

reschke commented on code in PR #328:
URL: https://github.com/apache/jackrabbit-filevault/pull/328#discussion_r1479700535


##########
vault-core-it/vault-core-integration-tests/src/main/java/org/apache/jackrabbit/vault/packaging/integration/ReferenceableIdentifiersImportIT.java:
##########
@@ -401,6 +422,138 @@ public void testImportDupPolicyLegacy() throws RepositoryException, IOException,
         assertNull(duplicateNode);
     }
 
+    @Test
+    public void testInstallPackage_CREATE_NEW_ID() throws Exception {
+        test(IdConflictPolicy.CREATE_NEW_ID, null, null, true, true);
+    }
+
+    @Test
+    public void testInstallPackage_FAIL() throws Exception {
+        test(IdConflictPolicy.FAIL, RepositoryException.class, null, false, false);
+    }
+
+    @Test
+    public void testInstallPackage_FORCE_REMOVE_CONFLICTING_ID() throws Exception {
+        test(IdConflictPolicy.FORCE_REMOVE_CONFLICTING_ID, null, null, false, false);
+    }
+
+    @Test
+    public void testInstallPackage_LEGACY() throws Exception {
+        test(IdConflictPolicy.LEGACY, RepositoryException.class, IllegalStateException.class, false, false);
+    }
+
+    private void test(IdConflictPolicy policy, Class<?> expectedException, Class<?> expectedRootCause, boolean expectNewId,
+            boolean expectRenamedNodeKept) throws Exception {
+
+        String TEST_ROOT = "testroot";
+
+        Node testRoot = getNodeOrNull("/" + TEST_ROOT);
+        if (testRoot == null) {
+            testRoot = admin.getRootNode().addNode(TEST_ROOT);
+        }
+
+        String srcName = String.format("%s-%x.txt", policy, System.nanoTime());
+        String srcPath = PathUtil.append(testRoot.getPath(), srcName);
+
+        Node asset = testRoot.addNode(srcName, NodeType.NT_FOLDER);
+        addFileNode(asset, "binary.txt");
+
+        asset.addMixin(NodeType.MIX_REFERENCEABLE);
+        admin.save();
+
+        String id1 = asset.getIdentifier();
+
+        File pkgFile = exportContentPackage(srcPath);
+
+        String dstPath = srcPath + "-renamed";
+        admin.move(srcPath, dstPath);
+        assertNodeMissing(srcPath);
+
+        try {
+            installContentPackage(pkgFile, policy);
+        } catch (Exception ex) {
+            if (expectedException == null) {
+                throw ex;
+            } else {
+                assertTrue("expected: " + expectedException + ", but got: " + ex.getClass(), expectedException.isInstance(ex));
+                if (expectedRootCause != null) {
+                    Throwable rc = ExceptionUtils.getRootCause(ex);
+                    assertTrue("expected: " + expectedRootCause + ", but got: " + rc.getClass(), expectedRootCause.isInstance(rc));
+                }
+                // expected exception -> test done
+                return;
+            }
+        }
+
+        if (expectRenamedNodeKept) {
+            assertNodeExists(dstPath);
+        } else {
+            assertNodeMissing(dstPath);
+        }
+
+        assertNodeExists(srcPath);
+        assertNodeExists(srcPath + "/binary.txt");
+
+        Node asset2 = testRoot.getNode(srcName);
+        String id2 = asset2.getIdentifier();
+        if (expectNewId) {
+            assertNotEquals(id1, id2);
+        } else {
+            assertEquals(id1, id2);
+        }
+    }
+
+    private Node addFileNode(Node parent, String name) throws Exception {

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org