jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1512568 [30/39] - in /jackrabbit/commons/filevault/trunk: ./ parent/ vault-cli/ vault-cli/src/ vault-cli/src/main/ vault-cli/src/main/appassembler/ vault-cli/src/main/assembly/ vault-cli/src/main/java/ vault-cli/src/main/java/org/ vault-cl...
Date Sat, 10 Aug 2013 05:53:54 GMT
Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ImportTests.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ImportTests.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ImportTests.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/ImportTests.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.IOException;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
+import org.apache.jackrabbit.vault.fs.io.Importer;
+import org.apache.jackrabbit.vault.fs.io.JcrArchive;
+import org.apache.jackrabbit.vault.fs.io.ZipArchive;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * <code>ImportTests</code>...
+ */
+public class ImportTests extends IntegrationTestBase {
+
+    /**
+     * default logger
+     */
+    private static final Logger log = LoggerFactory.getLogger(ImportTests.class);
+
+    public static final String TEST_ROOT = "/testroot";
+
+    public static final String ARCHIVE_ROOT = "/archiveroot";
+
+    @Before
+    public void init() {
+        clean(TEST_ROOT);
+        clean(ARCHIVE_ROOT);
+    }
+
+    @Test
+    public void testImport() throws IOException, RepositoryException, ConfigurationException {
+        ZipArchive archive = new ZipArchive(getTempFile("testpackages/tmp.zip"));
+        archive.open(true);
+        Node rootNode = admin.getRootNode();
+        ImportOptions opts = getDefaultOptions();
+        Importer importer = new Importer(opts);
+        importer.run(archive, rootNode);
+
+        assertNodeExists("/tmp/foo/bar/tobi");
+    }
+
+    @Test
+    public void testFilteredImport() throws IOException, RepositoryException, ConfigurationException {
+        ZipArchive archive = new ZipArchive(getTempFile("testpackages/filtered_package.zip"));
+        archive.open(true);
+        Node rootNode = admin.getRootNode();
+        ImportOptions opts = getDefaultOptions();
+
+        Importer importer = new Importer(opts);
+        importer.run(archive, rootNode);
+
+        assertNodeExists("/tmp");
+        assertNodeExists("/tmp/foo");
+        assertNodeExists("/tmp/foo/bar");
+        assertNodeExists("/tmp/foo/bar/tobi");
+        assertNodeMissing("/tmp/foo/bar/tom");
+    }
+
+    @Test
+    public void testUnFilteredImport() throws IOException, RepositoryException, ConfigurationException {
+        ZipArchive archive = new ZipArchive(getTempFile("testpackages/unfiltered_package.zip"));
+        archive.open(true);
+        Node rootNode = admin.getRootNode();
+        ImportOptions opts = getDefaultOptions();
+
+        Importer importer = new Importer(opts);
+        importer.run(archive, rootNode);
+
+        assertNodeExists("/tmp");
+        assertNodeExists("/tmp/foo");
+        assertNodeExists("/tmp/foo/bar");
+        assertNodeExists("/tmp/foo/bar/tobi");
+        assertNodeExists("/tmp/foo/bar/tom");
+    }
+
+    @Test
+    public void testRelativeImport() throws IOException, RepositoryException, ConfigurationException {
+        ZipArchive archive = new ZipArchive(getTempFile("testpackages/tmp.zip"));
+
+        admin.getRootNode().addNode(TEST_ROOT.substring(1, TEST_ROOT.length()));
+        admin.save();
+
+        archive.open(true);
+        Node rootNode = admin.getNode(TEST_ROOT);
+        ImportOptions opts = getDefaultOptions();
+        // manually creating filterPaths with correct coverage
+        WorkspaceFilter filter = archive.getMetaInf().getFilter();
+        for (PathFilterSet pathFilterSet : filter.getFilterSets()) {
+            pathFilterSet.setRoot(TEST_ROOT + pathFilterSet.getRoot());
+        }
+        opts.setFilter(filter);
+        Importer importer = new Importer(opts);
+        importer.run(archive, rootNode);
+
+        assertNodeExists(TEST_ROOT + "/tmp/foo/bar/tobi");
+    }
+
+    /**
+     * Imports an empty package with a filter "/testnode" relative to "/testnode". Since this is a relative import,
+     * the "/testnode" would map to "/testnode/testnode". So the import should not remove "/testnode".
+     */
+    @Test
+    public void testRelativeEmptyImport() throws IOException, RepositoryException, ConfigurationException {
+        ZipArchive archive = new ZipArchive(getTempFile("testpackages/empty_testnode.zip"));
+
+        admin.getRootNode().addNode(TEST_ROOT.substring(1, TEST_ROOT.length()));
+        admin.save();
+
+        archive.open(true);
+        Node rootNode = admin.getNode(TEST_ROOT);
+        ImportOptions opts = getDefaultOptions();
+        Importer importer = new Importer(opts);
+        importer.run(archive, rootNode);
+
+        assertNodeExists(TEST_ROOT);
+    }
+
+    /**
+     * Creates an jcr archive at /archiveroot mapped to /testroot and imports it.
+     */
+    @Test
+    public void testJcrArchiveImport() throws IOException, RepositoryException, ConfigurationException {
+        // create Jcr Archive
+        Node archiveNode = admin.getRootNode().addNode(ARCHIVE_ROOT.substring(1, ARCHIVE_ROOT.length()));
+        admin.save();
+        createNodes(archiveNode, 2, 4);
+        admin.save();
+        assertNodeExists(ARCHIVE_ROOT + "/n3/n3/n3");
+        JcrArchive archive = new JcrArchive(archiveNode, TEST_ROOT);
+
+        Node testRoot = admin.getRootNode().addNode(TEST_ROOT.substring(1, TEST_ROOT.length()));
+        testRoot.addNode("dummy", "nt:folder");
+        admin.save();
+
+        archive.open(true);
+        Node rootNode = admin.getNode(TEST_ROOT);
+        ImportOptions opts = getDefaultOptions();
+        //opts.setListener(new DefaultProgressListener());
+        Importer importer = new Importer(opts);
+        importer.run(archive, rootNode);
+        admin.save();
+
+        assertNodeExists(TEST_ROOT + "/n3/n3/n3");
+        assertNodeMissing(TEST_ROOT + "dummy");
+    }
+
+    @Test
+    public void testConcurrentModificationHandling() throws IOException, RepositoryException, PackageException, ConfigurationException {
+        ZipArchive archive = new ZipArchive(getTempFile("testpackages/tags.zip"));
+        archive.open(true);
+        Node rootNode = admin.getRootNode();
+        ImportOptions opts = getDefaultOptions();
+        opts.setAutoSaveThreshold(7);
+        Importer importer = new Importer(opts);
+        importer.setDebugFailAfterSave(2);
+        importer.run(archive, rootNode);
+        admin.save();
+
+        // count nodes
+        assertNodeExists("/etc/tags");
+        Node tags = admin.getNode("/etc/tags");
+        int numNodes = countNodes(tags);
+        assertEquals("Number of tags installed", 487, numNodes);
+
+    }
+
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/IntegrationTestBase.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener;
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
+import org.apache.jackrabbit.vault.packaging.JcrPackageManager;
+import org.apache.jackrabbit.vault.packaging.impl.JcrPackageManagerImpl;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * <code>IntegrationTestBase</code>...
+ */
+public class IntegrationTestBase  {
+
+    /**
+     * default logger
+     */
+    private static final Logger log = LoggerFactory.getLogger(IntegrationTestBase.class);
+
+    private static final String REPO_HOME = "target/repository";
+
+    protected static RepositoryImpl repository;
+
+    protected Session admin;
+
+    protected JcrPackageManager packMgr;
+
+    @BeforeClass
+    public static void initRepository() throws RepositoryException {
+        InputStream in = IntegrationTestBase.class.getResourceAsStream("repository.xml");
+        RepositoryConfig cfg = RepositoryConfig.create(in, REPO_HOME);
+        repository = RepositoryImpl.create(cfg);
+    }
+
+    @AfterClass
+    public static void shutdownRepository() {
+        if (repository != null) {
+            repository.shutdown();
+            repository = null;
+        }
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        admin = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
+
+        // ensure not packages or tmp
+        clean("/etc");
+        clean("/tmp");
+        clean("/testroot");
+
+        packMgr = new JcrPackageManagerImpl(admin);
+    }
+
+    public void clean(String path) {
+        try {
+            admin.getNode(path).remove();
+            admin.save();
+        } catch (RepositoryException e) {
+            // ignore
+        }
+    }
+    @After
+    public void tearDown() throws Exception {
+        packMgr = null;
+        if (admin != null) {
+            admin.logout();
+            admin = null;
+        }
+    }
+
+    public InputStream getStream(String name) {
+        InputStream in;
+        if (name.startsWith("/")) {
+           in = getClass().getClassLoader().getResourceAsStream(name);
+        } else {
+            in = getClass().getResourceAsStream(name);
+        }
+        return in;
+    }
+
+    public File getTempFile(String name) throws IOException {
+        InputStream in = getStream(name);
+
+        File tmpFile = File.createTempFile("vaultpack", ".zip");
+        FileOutputStream out = FileUtils.openOutputStream(tmpFile);
+        IOUtils.copy(in, out);
+        in.close();
+        out.close();
+        return tmpFile;
+    }
+
+
+    public ImportOptions getDefaultOptions() {
+        ImportOptions opts = new ImportOptions();
+        opts.setListener(new ProgressTrackerListener() {
+            public void onMessage(Mode mode, String action, String path) {
+                log.info("{} {}", action, path);
+            }
+
+            public void onError(Mode mode, String path, Exception e) {
+                log.info("E {} {}", path, e.toString());
+            }
+        });
+        return opts;
+    }
+
+    public void assertNodeExists(String path) throws RepositoryException {
+        assertTrue(path + " should exist", admin.nodeExists(path));
+    }
+
+    public void assertNodeMissing(String path) throws RepositoryException {
+        assertFalse(path + " should not exist", admin.nodeExists(path));
+    }
+
+    public void assertProperty(String path, String value) throws RepositoryException {
+        assertEquals(path + " should contain " + value, value, admin.getProperty(path).getString());
+    }
+
+    public void createNodes(Node parent, int maxDepth, int nodesPerFolder) throws RepositoryException {
+        for (int i=0; i<nodesPerFolder; i++) {
+            Node n = parent.addNode("n" + i, "nt:folder");
+            if (maxDepth > 0) {
+                createNodes(n, maxDepth - 1, nodesPerFolder);
+            }
+        }
+    }
+
+    public int countNodes(Node parent) throws RepositoryException {
+        int total = 1;
+        NodeIterator iter = parent.getNodes();
+        while (iter.hasNext()) {
+            total += countNodes(iter.nextNode());
+        }
+        return total;
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestACLAndMerge.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestACLAndMerge.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestACLAndMerge.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestACLAndMerge.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.security.AccessControlEntry;
+import javax.jcr.security.AccessControlPolicy;
+import javax.jcr.security.Privilege;
+
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * AC Handling and import mode tests
+ */
+public class TestACLAndMerge extends IntegrationTestBase {
+
+    @Override
+    public void tearDown() throws Exception {
+        // remove test node
+        if (admin.nodeExists("/testroot")) {
+            admin.getNode("/testroot").remove();
+            admin.save();
+        }
+        super.tearDown();
+    }
+
+    /**
+     * Installs 2 packages both with AC Handling OVERWRITE and Import Mode MERGE and tests if AC Handling wins over
+     * import mode.
+     */
+    @Test
+    public void testACAndMerge() throws RepositoryException, IOException, PackageException {
+        assertNodeMissing("/testroot");
+
+        JcrPackage pack = packMgr.upload(getStream("testpackages/mode_ac_test_a.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // test if nodes and ACLs of first package exist
+        assertNodeExists("/testroot/node_a");
+        assertPermission("/testroot/secured", false, new String[]{"jcr:all"}, "everyone", null);
+
+        pack = packMgr.upload(getStream("testpackages/mode_ac_test_b.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // test if nodes and ACLs of 2nd package exist
+        assertNodeExists("/testroot/node_a");
+        assertNodeExists("/testroot/node_b");
+        assertPermission("/testroot/secured", false, new String[]{"jcr:all"}, "everyone", null);
+        assertPermission("/testroot/secured", true, new String[]{"jcr:read"}, "everyone", "*/foo/*");
+
+    }
+
+    /**
+     * Installs 2 packages with the same ACL. the later packages has AC Handling MERGE and should overwrite the
+     * existing ACL.
+     */
+    @Test
+    public void testACMerge() throws RepositoryException, IOException, PackageException {
+        assertNodeMissing("/testroot");
+
+        JcrPackage pack = packMgr.upload(getStream("testpackages/mode_ac_test_a.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // test if nodes and ACLs of first package exist
+        assertNodeExists("/testroot/node_a");
+        assertPermission("/testroot/secured", false, new String[]{"jcr:all"}, "everyone", null);
+
+        pack = packMgr.upload(getStream("testpackages/mode_ac_test_b_merge.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // test if nodes and ACLs of 2nd package exist
+        assertNodeExists("/testroot/node_a");
+        assertNodeExists("/testroot/node_b");
+        assertPermission("/testroot/secured", false, new String[]{"jcr:all"}, "everyone", null);
+        assertPermission("/testroot/secured", true, new String[]{"jcr:read"}, "everyone", "*/foo/*");
+
+    }
+
+    /**
+     * Installs 2 packages with the same ACL. the later packages has AC Handling MERGE_PRESERVER and should
+     * retain the existing ACL.
+     */
+    @Test
+    public void testACMergePreserve() throws RepositoryException, IOException, PackageException {
+        assertNodeMissing("/testroot");
+
+        JcrPackage pack = packMgr.upload(getStream("testpackages/mode_ac_test_a.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // test if nodes and ACLs of first package exist
+        assertNodeExists("/testroot/node_a");
+        assertPermission("/testroot/secured", false, new String[]{"jcr:all"}, "everyone", null);
+
+        pack = packMgr.upload(getStream("testpackages/mode_ac_test_b_preserve.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // test if nodes and ACLs of 2nd package exist
+        assertNodeExists("/testroot/node_a");
+        assertNodeExists("/testroot/node_b");
+        assertPermission("/testroot/secured", false, new String[]{"jcr:all"}, "everyone", null);
+        assertPermissionMissing("/testroot/secured", true, new String[]{"jcr:read"}, "everyone", "*/foo/*");
+
+    }
+
+    protected void assertPermissionMissing(String path, boolean allow, String[] privs, String name, String globRest)
+            throws RepositoryException {
+        if (hasPermission(path, allow, privs, name, globRest)) {
+            fail("Expected permission should not exist on path " + path);
+        }
+    }
+
+    protected void assertPermission(String path, boolean allow, String[] privs, String name, String globRest)
+            throws RepositoryException {
+        if (!hasPermission(path, allow, privs, name, globRest)) {
+            fail("Expected permission missing on path " + path);
+        }
+    }
+
+    protected boolean hasPermission(String path, boolean allow, String[] privs, String name, String globRest)
+            throws RepositoryException {
+        AccessControlPolicy[] ap = admin.getAccessControlManager().getPolicies(path);
+        boolean found = false;
+        for (AccessControlPolicy p: ap) {
+            if (p instanceof JackrabbitAccessControlList) {
+                JackrabbitAccessControlList acl = (JackrabbitAccessControlList) p;
+                for (AccessControlEntry ac: acl.getAccessControlEntries()) {
+                    if (ac instanceof JackrabbitAccessControlEntry) {
+                        JackrabbitAccessControlEntry ace = (JackrabbitAccessControlEntry) ac;
+                        if (ace.isAllow() != allow) {
+                            continue;
+                        }
+                        if (!ace.getPrincipal().getName().equals(name)) {
+                            continue;
+                        }
+                        Set<String> expectedPrivs = new HashSet<String>(Arrays.asList(privs));
+                        for (Privilege priv: ace.getPrivileges()) {
+                            if (!expectedPrivs.remove(priv.getName())) {
+                                expectedPrivs.add("dummy");
+                                break;
+                            }
+                        }
+                        if (!expectedPrivs.isEmpty()) {
+                            continue;
+                        }
+                        if (globRest != null && !globRest.equals(ace.getRestriction("rep:glob").getString())) {
+                            continue;
+                        }
+                        found = true;
+                        break;
+                    }
+                }
+            }
+        }
+        return found;
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCustomPrivileges.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCustomPrivileges.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCustomPrivileges.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCustomPrivileges.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.api.JackrabbitWorkspace;
+import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * Test cases for packages with custom privileges
+ */
+public class TestCustomPrivileges extends IntegrationTestBase {
+
+    /**
+     * Installs a package that contains a custom privilege and then checks if it was installed.
+     */
+    @Test
+    public void installWithPrivs() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/privileges.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // check if privilege was installed
+        PrivilegeManager mgr = ((JackrabbitWorkspace) admin.getWorkspace()).getPrivilegeManager();
+        try {
+            mgr.getPrivilege("testns:testpriv");
+        } catch (RepositoryException e) {
+            fail("testns:testpriv privilege not registered.");
+        }
+    }
+
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEmptyPackage.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEmptyPackage.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEmptyPackage.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEmptyPackage.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * <code>TestEmptyPackage</code>...
+ */
+public class TestEmptyPackage extends IntegrationTestBase {
+
+    /**
+     * Installs a package that contains /tmp/foo/bar/tobi and then installs one
+     * that is empty but contains a filter for '/tmp'. expect /tmp to be removed.
+     */
+    @Test
+    public void installEmptyLevel1() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+
+        // now install the empty package
+        pack = packMgr.upload(getStream("testpackages/empty_tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeMissing("/tmp");
+    }
+
+    /**
+     * Installs a package that contains /tmp/foo/bar/tobi and then installs one
+     * that is empty but contains a filter for '/tmp/foo'. expect /tmp/foo to be removed.
+     */
+    @Test
+    public void installEmptyLevel2() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+
+        // now install the empty package
+        pack = packMgr.upload(getStream("testpackages/empty_tmp_foo.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp");
+        assertNodeMissing("/tmp/foo");
+    }
+
+    /**
+     * Installs a package that contains /tmp/foo/bar/tobi and then installs one
+     * that is empty but contains a filter for '/tmp/foo/bar'. expect /tmp/foo/bar to be removed.
+     */
+    @Test
+    public void installEmptyLevel3() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+
+        // now install the empty package
+        pack = packMgr.upload(getStream("testpackages/empty_tmp_foo_bar.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo");
+        assertNodeMissing("/tmp/foo/bar");
+    }
+
+    /**
+     * Installs a package that contains /tmp/test/content/foo/foo.jsp and then creates a new node
+     * /tmp/test/content/bar/bar.jsp. Tests if after reinstall the new node was deleted.
+     */
+    @Test
+    public void installEmptyFolder() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_test_folders.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/test/content/foo/foo.jsp");
+
+        // create new node
+        Node content = admin.getNode("/tmp/test/content");
+        Node bar = content.addNode("bar", NodeType.NT_FOLDER);
+        InputStream is = new ByteArrayInputStream("hello, world.".getBytes());
+        JcrUtils.putFile(bar, "bar.jsp", "text/plain", is);
+        admin.save();
+
+        // now re-install package
+        pack.install(getDefaultOptions());
+
+        assertNodeMissing("/tmp/test/content/bar");
+        assertNodeMissing("/tmp/test/content/bar/bar.jsp");
+    }
+
+    /**
+     * Installs a package that contains /tmp and then uninstalls it.
+     */
+    @Test
+    public void installUninstallLevel1() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+
+        pack.uninstall(getDefaultOptions());
+        assertNodeMissing("/tmp");
+    }
+
+    /**
+     * Installs a package that contains /tmp/foo and then uninstalls it.
+     * expect the intermediate node /tmp remains.
+     */
+    @Test
+    public void installUninstallLevel2() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_foo.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+
+        pack.uninstall(getDefaultOptions());
+        assertNodeExists("/tmp");
+        assertNodeMissing("/tmp/foo");
+    }
+
+    /**
+     * Installs a package that contains /tmp/foo/bar and then unnstalls it.
+     * expect the intermediate node /tmp/foo remains.
+     */
+    @Test
+    public void installUninstallLevel3() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_foo_bar.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+
+        pack.uninstall(getDefaultOptions());
+        assertNodeExists("/tmp/foo");
+        assertNodeMissing("/tmp/foo/bar");
+    }
+
+
+    /**
+     * Installs a package that contains /tmp, then and empty one, then unnstalls it.
+     * expect the original /tmp/foo/bar/tobi remaining.
+     */
+    @Test
+    public void installUninstallSubsequent() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+
+        // now install the empty package
+        JcrPackage pack2 = packMgr.upload(getStream("testpackages/empty_tmp_foo_bar.zip"), false);
+        assertNotNull(pack2);
+        pack2.install(getDefaultOptions());
+
+        assertNodeExists("/tmp/foo");
+        assertNodeMissing("/tmp/foo/bar");
+
+        pack2.uninstall(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+    }
+
+    /**
+     * Installs a package that contains /tmp/foo/bar/test.txt and then uninstalls it.
+     */
+    @Test
+    public void installUninstallFile() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_foo_bar_test.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/test.txt");
+
+        pack.uninstall(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar");
+        assertNodeMissing("/tmp/foo/bar/test.txt");
+    }
+
+
+    /**
+     * Installs a package that contains /tmp/foo/bar/test.txt but no filter for it.
+     */
+    @Test
+    public void installInstallNoFilter() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_foo_bar_test_nofilter.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/test.txt");
+
+        pack.uninstall(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/test.txt");
+    }
+
+
+    /**
+     * Installs a package that contains no filter and no .content.xml files.
+     */
+    @Test
+    public void installInstallMinimal() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_foo_bar_test_minimal.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/test.txt");
+
+        pack.uninstall(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/test.txt");
+    }
+
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestGroupMergePackage.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestGroupMergePackage.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestGroupMergePackage.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestGroupMergePackage.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * <code>TestEmptyPackage</code>...
+ */
+public class TestGroupMergePackage extends IntegrationTestBase {
+
+    @Override
+    public void tearDown() throws Exception {
+        // remove test authorizables
+        UserManager mgr = ((JackrabbitSession) admin).getUserManager();
+        removeAuthorizable(mgr, "test-group");
+        removeAuthorizable(mgr, "test-user-a");
+        removeAuthorizable(mgr, "test-user-b");
+        removeAuthorizable(mgr, "test-user-c");
+
+        super.tearDown();
+    }
+
+    private void removeAuthorizable(UserManager mgr, String name) throws RepositoryException {
+        Authorizable a = mgr.getAuthorizable(name);
+        if (a != null) {
+            a.remove();
+        }
+    }
+
+    /**
+     * Installs a package that contains a "test-group" and a "test-user-a" as member of the group.
+     */
+    @Test
+    public void installGroupA() throws RepositoryException, IOException, PackageException {
+        UserManager mgr = ((JackrabbitSession) admin).getUserManager();
+        assertNull("test-group must not exist", mgr.getAuthorizable("test-group"));
+        assertNull("test-user-a must not exist", mgr.getAuthorizable("test-user-a"));
+
+        JcrPackage pack = packMgr.upload(getStream("testpackages/group_with_a.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // check if group exists
+        Group grp = (Group) mgr.getAuthorizable("test-group");
+        assertNotNull("test-group must exist", grp);
+        User userA = (User) mgr.getAuthorizable("test-user-a");
+        assertNotNull("test-user-a must exist", userA);
+        assertTrue("test-user-a is member of test-group", grp.isMember(userA));
+    }
+
+    /**
+     * Installs 2 packages with "test-group" that contain test-user-a and test-user-b,test-user-c respectively.
+     * since the import mode is merge, the memberships should be merged.
+     */
+    @Test
+    public void installGroupABC() throws RepositoryException, IOException, PackageException {
+        // ensure that test users don't exist yet (proper setup)
+        UserManager mgr = ((JackrabbitSession) admin).getUserManager();
+        assertNull("test-group must not exist", mgr.getAuthorizable("test-group"));
+        assertNull("test-user-a must not exist", mgr.getAuthorizable("test-user-a"));
+        assertNull("test-user-b must not exist", mgr.getAuthorizable("test-user-b"));
+        assertNull("test-user-c must not exist", mgr.getAuthorizable("test-user-c"));
+
+        JcrPackage pack = packMgr.upload(getStream("testpackages/group_with_a.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        pack = packMgr.upload(getStream("testpackages/group_with_bc.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        // check if group exists
+        Group grp = (Group) mgr.getAuthorizable("test-group");
+        assertNotNull("test-group must exist", grp);
+        User userA = (User) mgr.getAuthorizable("test-user-a");
+        User userB = (User) mgr.getAuthorizable("test-user-b");
+        User userC = (User) mgr.getAuthorizable("test-user-c");
+        assertNotNull("test-user-a must exist", userA);
+        assertNotNull("test-user-b must exist", userB);
+        assertNotNull("test-user-c must exist", userC);
+
+        assertTrue("test-user-a is member of test-group", grp.isMember(userA));
+        assertTrue("test-user-b is member of test-group", grp.isMember(userB));
+        assertTrue("test-user-c is member of test-group", grp.isMember(userC));
+    }
+
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestMappedExport.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestMappedExport.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestMappedExport.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestMappedExport.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
+import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
+import org.apache.jackrabbit.vault.packaging.ExportOptions;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.apache.jackrabbit.vault.packaging.VaultPackage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * <code>TestEmptyPackage</code>...
+ */
+public class TestMappedExport extends IntegrationTestBase {
+
+    @Test
+    public void exportMapped() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_foo_bar_test.zip"), false);
+        assertNotNull(pack);
+        pack.extract(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/test.txt");
+
+        ExportOptions opts = new ExportOptions();
+        DefaultMetaInf inf = new DefaultMetaInf();
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        filter.add(new PathFilterSet("/tmp/foo/bar"));
+        inf.setFilter(filter);
+        Properties props = new Properties();
+        props.setProperty(VaultPackage.NAME_GROUP, "adobe/test");
+        props.setProperty(VaultPackage.NAME_NAME, "test-package");
+        inf.setProperties(props);
+
+        opts.setMetaInf(inf);
+        opts.setMountPath("/tmp/foo");
+        opts.setRootPath("/content/geometrixx");
+        File tmpFile = File.createTempFile("vaulttest", "zip");
+        VaultPackage pkg = packMgr.assemble(admin, opts, tmpFile);
+
+        // check if entries are present
+        WorkspaceFilter newFilter = pkg.getMetaInf().getFilter();
+        assertTrue(newFilter.contains("/content/geometrixx/bar/test.txt"));
+        assertNotNull(pkg.getArchive().getEntry("jcr_root/content/geometrixx/bar/test.txt"));
+        pkg.close();
+        tmpFile.delete();
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.vault.packaging.InstallContext;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.apache.tika.io.IOUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * <code>TestPackageInstall</code>...
+ */
+public class TestPackageInstall extends IntegrationTestBase {
+
+    /**
+     * Installs a package that contains and checks if everything is correct.
+     */
+    @Test
+    public void testUpload() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+        assertNodeExists("/etc/packages/my_packages/tmp.zip");
+
+        // upload already unrwapps it, so check if definition is ok
+        assertNodeExists("/etc/packages/my_packages/tmp.zip/jcr:content/vlt:definition");
+
+        // todo: check definition props
+
+    }
+
+    /**
+     * Installs a package that contains /tmp/fullcoverage/a/aa using a vlt:FullCoverage mixin.
+     * check if the package manager installs that node type although not present in the package.
+     */
+    @Test
+    public void testFullCoverageNT() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/fullcoverage.zip"), false);
+        assertNotNull(pack);
+
+        // just extract - no snapshots
+        pack.extract(getDefaultOptions());
+        assertNodeExists("/tmp/fullcoverage/a/aa");
+
+        admin.getWorkspace().getNodeTypeManager().getNodeType("vlt:FullCoverage");
+    }
+
+    /**
+     * Installs a package that contains a folder below a jcr:resource which is augmented by a
+     * mixin that should allow a sub folder.
+     */
+    @Test
+    public void testDeepMixin() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/deepmixintest.zip"), false);
+        assertNotNull(pack);
+
+        // just extract - no snapshots
+        pack.extract(getDefaultOptions());
+        assertNodeExists("/etc/designs/agadobe/images/backgroundImage.png/jcr:content/dam:thumbnails/dam:thumbnail_48.png");
+    }
+
+    /**
+     * Installs a package that contains a folder a filter to a jcr:content[nt:unstructured] node.
+     * See bug #42562
+     */
+    @Test
+    public void testJcrContent() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_testpage_jcr_content.zip"), false);
+        assertNotNull(pack);
+
+        // just extract - no snapshots
+        pack.extract(getDefaultOptions());
+        assertNodeExists("/tmp/testpage/jcr:content/foo");
+    }
+
+    /**
+     * Installs a package that just adds a property to the root node.
+     */
+    @Test
+    public void testRootImport() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/testrootimport.zip"), false);
+        assertNotNull(pack);
+
+        // just extract - no snapshots
+        pack.extract(getDefaultOptions());
+        assertProperty("/testproperty", "hello");
+    }
+
+    /**
+     * Installs a package with an install hook
+     */
+    @Test
+    public void testHook() throws RepositoryException, IOException, PackageException {
+        // Disabled for now, since the bundled package contains a hook that still contain classes
+        // compiled the com.day.jcr.vault.*
+
+//        JcrPackage pack = packMgr.upload(getStream("testpackages/test_hook.zip"), false);
+//        assertNotNull(pack);
+//        pack.install(getDefaultOptions());
+//        assertProperty("/testroot/TestHook", InstallContext.Phase.INSTALLED.toString());
+    }
+
+    /**
+     * Installs a package with an invalid hook
+     */
+    @Test
+    public void testInvalidHook() throws RepositoryException, IOException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/invalid_hook.zip"), false);
+        assertNotNull(pack);
+
+        try {
+            pack.install(getDefaultOptions());
+            fail("Package install should fail.");
+        } catch (PackageException e) {
+            // ok
+        }
+    }
+
+    /**
+     * Installs a package with an external hook
+     */
+    @Test
+    public void testExternalHook() throws RepositoryException, IOException, PackageException {
+        // Disabled for now, since the bundled package contains a hook that still contain classes
+        // compiled the com.day.jcr.vault.*
+
+
+//        if (!admin.nodeExists("/testroot")) {
+//            admin.getRootNode().addNode("testroot", "nt:unstructured");
+//            admin.save();
+//        }
+//
+//        JcrPackage pack = packMgr.upload(getStream("testpackages/external_hook.zip"), false);
+//        assertNotNull(pack);
+//
+//        pack.install(getDefaultOptions());
+//
+//        assertProperty("/testroot/TestHook1", InstallContext.Phase.END.toString());
+//        assertProperty("/testroot/TestHook2", InstallContext.Phase.END.toString());
+    }
+
+    /**
+     * Installs a package with no properties
+     */
+    @Test
+    public void testNoProperties() throws RepositoryException, IOException, PackageException {
+        File tmpFile = File.createTempFile("vlttest", "zip");
+        IOUtils.copy(getStream("testpackages/tmp_no_properties.zip"), FileUtils.openOutputStream(tmpFile));
+        JcrPackage pack = packMgr.upload(tmpFile, true, true, "testpackage", false);
+        assertNotNull(pack);
+
+        pack.install(getDefaultOptions());
+    }
+
+    @Test
+    public void testDeepContentImport() throws IOException, RepositoryException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp_test_deep.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        assertNodeExists("/tmp/test/content/foo/jcr:content/a/b/foo.jsp/jcr:content");
+        assertNodeExists("/tmp/test/content/foo/jcr:content/a/c/resource");
+        assertNodeExists("/tmp/test/content/foo/jcr:content/a/d");
+        assertNodeExists("/tmp/test/content/foo/jcr:content/a/folder/file.txt/jcr:content");
+    }
+
+
+
+    // todo: upload with version
+    // todo: install / uninstall
+    // todo: sub packages
+    // todo: rename
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestResolve.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestResolve.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestResolve.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestResolve.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.packaging.Dependency;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.apache.jackrabbit.vault.packaging.PackageId;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * <code>TestPackageInstall</code>...
+ */
+public class TestResolve extends IntegrationTestBase {
+
+    /**
+     * Installs some packages and tests the resolve method
+     */
+    @Test
+    public void testResolve() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/package_1.0.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        pack = packMgr.upload(getStream("testpackages/package_2.0.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        pack = packMgr.upload(getStream("testpackages/empty_tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        PackageId id = packMgr.resolve(Dependency.fromString("my_packages:package:[1.0,2.0]"), true);
+        assertEquals(PackageId.fromString("my_packages:package:2.0"), id);
+
+        id = packMgr.resolve(Dependency.fromString("my_packages:package:[1.0,2.0)"), true);
+        assertEquals(PackageId.fromString("my_packages:package:1.0"), id);
+    }
+
+    /**
+     * uploads and installs some packages and tests the resolve method
+     */
+    @Test
+    public void testResolvePartial() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/package_1.0.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        pack = packMgr.upload(getStream("testpackages/package_2.0.zip"), false);
+        assertNotNull(pack);
+        // do NOT install
+        //pack.install(getDefaultOptions());
+
+        pack = packMgr.upload(getStream("testpackages/empty_tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        PackageId id = packMgr.resolve(Dependency.fromString("my_packages:package:[1.0,2.0]"), true);
+        assertEquals(PackageId.fromString("my_packages:package:1.0"), id);
+
+        id = packMgr.resolve(Dependency.fromString("my_packages:package:[1.0,2.0]"), false);
+        assertEquals(PackageId.fromString("my_packages:package:2.0"), id);
+
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSpecialDoubleProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSpecialDoubleProperties.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSpecialDoubleProperties.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSpecialDoubleProperties.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Properties;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
+import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.io.Archive;
+import org.apache.jackrabbit.vault.packaging.ExportOptions;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.apache.jackrabbit.vault.packaging.VaultPackage;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * <code>TestEmptyPackage</code>...
+ */
+public class TestSpecialDoubleProperties extends IntegrationTestBase {
+
+    @Test
+    public void exportDoubles() throws RepositoryException, IOException, PackageException {
+        Node tmp = admin.getRootNode().addNode("tmp", "nt:unstructured");
+        Node content = tmp.addNode("jcr:content", "nt:unstructured");
+        content.setProperty("double_nan", Double.NaN);
+        content.setProperty("double_pos_inf", Double.POSITIVE_INFINITY);
+        content.setProperty("double_neg_inf", Double.NEGATIVE_INFINITY);
+        admin.save();
+
+        ExportOptions opts = new ExportOptions();
+        DefaultMetaInf inf = new DefaultMetaInf();
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        PathFilterSet set1 = new PathFilterSet("/tmp");
+        filter.add(set1);
+        inf.setFilter(filter);
+        Properties props = new Properties();
+        props.setProperty(VaultPackage.NAME_GROUP, "adobe/test");
+        props.setProperty(VaultPackage.NAME_NAME, "test-package");
+        inf.setProperties(props);
+
+        opts.setMetaInf(inf);
+        File tmpFile = File.createTempFile("vaulttest", ".zip");
+        VaultPackage pkg = packMgr.assemble(admin, opts, tmpFile);
+
+        Archive.Entry e = pkg.getArchive().getEntry("jcr_root/tmp/.content.xml");
+        InputSource is = pkg.getArchive().getInputSource(e);
+        Reader r = new InputStreamReader(is.getByteStream(), "utf-8");
+        String contentXml = IOUtils.toString(r);
+
+        assertEquals("Serialized content",
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                        "<jcr:root xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" xmlns:nt=\"http://www.jcp.org/jcr/nt/1.0\"\n" +
+                        "    jcr:primaryType=\"nt:unstructured\">\n" +
+                        "    <jcr:content\n" +
+                        "        jcr:primaryType=\"nt:unstructured\"\n" +
+                        "        double_nan=\"{Double}NaN\"\n" +
+                        "        double_neg_inf=\"{Double}-Infinity\"\n" +
+                        "        double_pos_inf=\"{Double}Infinity\"/>\n" +
+                        "</jcr:root>\n",
+                contentXml);
+        pkg.close();
+        tmpFile.delete();
+    }
+
+    @Test
+    public void importDoubles() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/double_properties.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        Node tmp = admin.getNode("/tmp/jcr:content");
+        assertEquals(Double.NaN, tmp.getProperty("double_nan").getDouble(), 0.0);
+        assertEquals(Double.POSITIVE_INFINITY, tmp.getProperty("double_pos_inf").getDouble(), 0.0);
+        assertEquals(Double.NEGATIVE_INFINITY, tmp.getProperty("double_neg_inf").getDouble(), 0.0);
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.packaging.integration;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Tests that covers sub packages. the package "my_packages:subtest" contains 2 sub packages
+ * "my_packages:sub_a" and "my_packages:sub_b" which each contain 1 node /tmp/a and /tmp/b respectively.
+ */
+public class TestSubPackages extends IntegrationTestBase {
+
+    /**
+     * Installs a package that contains sub packages non recursive
+     */
+    @Test
+    public void testNonRecursive() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/subtest.zip"), false);
+        assertNotNull(pack);
+
+        // install
+        ImportOptions opts = getDefaultOptions();
+        opts.setNonRecursive(true);
+        pack.install(opts);
+
+        // check for sub packages
+        assertNodeExists("/etc/packages/my_packages/sub_a.zip");
+        assertNodeExists("/etc/packages/my_packages/sub_b.zip");
+
+        assertNodeMissing("/tmp/a");
+        assertNodeMissing("/tmp/b");
+    }
+
+    /**
+     * Installs a package that contains sub packages recursive
+     */
+    @Test
+    public void testRecursive() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/subtest.zip"), false);
+        assertNotNull(pack);
+
+        // install
+        ImportOptions opts = getDefaultOptions();
+        opts.setNonRecursive(false);
+        pack.install(opts);
+
+        // check for sub packages
+        assertNodeExists("/etc/packages/my_packages/sub_a.zip");
+        assertNodeExists("/etc/packages/my_packages/sub_b.zip");
+
+        assertNodeExists("/tmp/a");
+        assertNodeExists("/tmp/b");
+    }
+
+
+    /**
+     * Uninstalls a package that contains sub packages non recursive
+     */
+    @Test
+    public void testUninstallNonRecursive() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/subtest.zip"), false);
+        assertNotNull(pack);
+
+        // install
+        ImportOptions opts = getDefaultOptions();
+        opts.setNonRecursive(false);
+        pack.install(opts);
+
+        assertNodeExists("/tmp/a");
+        assertNodeExists("/tmp/b");
+
+        // uninstall
+        opts.setNonRecursive(true);
+        pack.uninstall(opts);
+
+        assertNodeMissing("/etc/packages/my_packages/sub_a.zip");
+        assertNodeMissing("/etc/packages/my_packages/sub_b.zip");
+        assertNodeExists("/tmp/a");
+        assertNodeExists("/tmp/b");
+
+    }
+
+    /**
+     * Uninstalls a package that contains sub packages recursive
+     */
+    @Test
+    public void testUninstallRecursive() throws RepositoryException, IOException, PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/subtest.zip"), false);
+        assertNotNull(pack);
+
+        // install
+        ImportOptions opts = getDefaultOptions();
+        opts.setNonRecursive(false);
+        pack.install(opts);
+
+        assertNodeExists("/tmp/a");
+        assertNodeExists("/tmp/b");
+
+        // uninstall
+        opts.setNonRecursive(false);
+        pack.uninstall(opts);
+
+        assertNodeMissing("/etc/packages/my_packages/sub_a.zip");
+        assertNodeMissing("/etc/packages/my_packages/sub_b.zip");
+        assertNodeMissing("/tmp/a");
+        assertNodeMissing("/tmp/b");
+
+    }
+
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/DocViewPropertyTest.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.util;
+
+import javax.jcr.PropertyType;
+
+import org.apache.jackrabbit.util.Text;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>DocViewPropertyTest</code>...
+ */
+public class DocViewPropertyTest extends TestCase {
+
+    public void testParseUndefined() {
+        DocViewProperty p = DocViewProperty.parse("foo", "hello");
+        assertEquals(p, false, PropertyType.UNDEFINED, "hello");
+    }
+
+    public void testParseLong() {
+        DocViewProperty p = DocViewProperty.parse("foo", "{Long}1234");
+        assertEquals(p, false, PropertyType.LONG, "1234");
+    }
+
+    public void testParseEmpty() {
+        DocViewProperty p = DocViewProperty.parse("foo", "{Binary}");
+        assertEquals(p, false, PropertyType.BINARY, "");
+    }
+
+    public void testParseSpecial() {
+        DocViewProperty p = DocViewProperty.parse("foo", "\\{hello, world}");
+        assertEquals(p, false, PropertyType.UNDEFINED, "{hello, world}");
+        p = DocViewProperty.parse("foo", "{String}\\[hello");
+        assertEquals(p, false, PropertyType.STRING, "[hello");
+    }
+
+    public void testParseStringTyped() {
+        DocViewProperty p = DocViewProperty.parse("foo", "{String}hello");
+        assertEquals(p, false, PropertyType.STRING, "hello");
+    }
+
+    public void testParseStringUnicode() {
+        DocViewProperty p = DocViewProperty.parse("foo", "{String}he\\u000fllo");
+        assertEquals(p, false, PropertyType.STRING, "he\u000fllo");
+    }
+
+    public void testParseMVString() {
+        DocViewProperty p = DocViewProperty.parse("foo", "[hello,world]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "hello", "world");
+        p = DocViewProperty.parse("foo", "[hello\\,world]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "hello,world");
+    }
+
+    public void testParseEmptyMVStrings() {
+        DocViewProperty p = DocViewProperty.parse("foo", "[,a,b,c]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "", "a", "b", "c");
+        p = DocViewProperty.parse("foo", "[a,b,c,]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "a", "b", "c", "");
+        p = DocViewProperty.parse("foo", "[,,,]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "", "", "", "");
+    }
+
+    public void testParseMVSpecial() {
+        DocViewProperty p = DocViewProperty.parse("foo", "[\\[hello,world]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "[hello", "world");
+        p = DocViewProperty.parse("foo", "[[hello],[world]]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "[hello]", "[world]");
+        p = DocViewProperty.parse("foo", "[he\\[llo,world]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "he[llo", "world");
+        p = DocViewProperty.parse("foo", "[hello\\[,world]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "hello[", "world");
+        p = DocViewProperty.parse("foo", "[hello,\\[world]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "hello", "[world");
+        p = DocViewProperty.parse("foo", "[hello,world\\[]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "hello", "world[");
+        p = DocViewProperty.parse("foo", "[hello,world");
+        assertEquals(p, true, PropertyType.UNDEFINED, "hello", "world");
+        p = DocViewProperty.parse("foo", "[bla{a\\,b},foo{a\\,b},bar{a\\,b}]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "bla{a,b}", "foo{a,b}", "bar{a,b}");
+        p = DocViewProperty.parse("foo", "[/content/[a-z]{2\\,3}/[a-z]{2\\,3}(/.*)]");
+        assertEquals(p, true, PropertyType.UNDEFINED, "/content/[a-z]{2,3}/[a-z]{2,3}(/.*)");
+    }
+
+    public void testParseMVLong() {
+        DocViewProperty p = DocViewProperty.parse("foo", "{Long}[1,2]");
+        assertEquals(p, true, PropertyType.LONG, "1", "2");
+    }
+
+    public void testParseMVLongEmpty() {
+        DocViewProperty p = DocViewProperty.parse("foo", "{Long}[]");
+        assertEquals(p, true, PropertyType.LONG);
+    }
+
+    public void testParseMVStringEmpty() {
+        DocViewProperty p = DocViewProperty.parse("foo", "[]");
+        assertEquals(p, true, PropertyType.UNDEFINED);
+    }
+
+    public void testEscape() {
+        assertEscaped("hello", "hello", false);
+        assertEscaped("hello, world", "hello, world", false);
+        assertEscaped("hello, world", "hello\\, world", true);
+        assertEscaped("[hello]", "\\[hello]", false);
+        assertEscaped("[hello]", "[hello]", true);
+        assertEscaped("{hello}", "\\{hello}", false);
+        assertEscaped("{hello}", "{hello}", true);
+        assertEscaped("hello\u000fworld", "hello\\u000fworld", false);
+        assertEscaped("hello\u000fworld", "hello\\u000fworld", true);
+        assertEscaped("hello\\world", "hello\\\\world", false);
+        assertEscaped("hello\\world", "hello\\\\world", true);
+    }
+
+    private void assertEscaped(String original, String expected, boolean multi) {
+        StringBuffer buf = new StringBuffer();
+        DocViewProperty.escape(buf, original, multi);
+        assertEquals(expected, buf.toString());
+    }
+
+    private void assertEquals(DocViewProperty p, boolean m, int type, String ... values) {
+        assertEquals("Multiple", m, p.isMulti);
+        assertEquals("Type", type, p.type);
+        assertEquals("Array Length", values.length, p.values.length);
+        assertEquals("Values", Text.implode(values, ","), Text.implode(p.values, ","));
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/LineInputTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/LineInputTest.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/LineInputTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/LineInputTest.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+import org.apache.commons.io.IOUtils;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>LineOutputTest</code>...
+ *
+ */
+public class LineInputTest extends TestCase {
+
+    public void testInput0() throws Exception {
+        byte[] in = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0};
+        byte[] u = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0};
+        byte[] w = new byte[]{0,0,0,0x0d,0x0a,0,0,0,0x0d,0x0a,0,0,0};
+        doTest(in, u, w);
+    }
+
+    public void testInput1() throws Exception {
+        byte[] in = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0x0a};
+        byte[] u = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0x0a};
+        byte[] w = new byte[]{0,0,0,0x0d,0x0a,0,0,0,0x0d,0x0a,0,0,0x0d,0x0a};
+        doTest(in, u, w);
+    }
+
+    public void testInput2() throws Exception {
+        byte[] in = new byte[]{0,0,0,0x0a,0x0d,0,0,0,0x0a,0x0d,0,0,0x0a,0x0d};
+        byte[] u = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0x0a};
+        byte[] w = new byte[]{0,0,0,0x0d,0x0a,0,0,0,0x0d,0x0a,0,0,0x0d,0x0a};
+        doTest(in, u, w);
+    }
+
+    public void testInput3() throws Exception {
+        byte[] in = new byte[]{0,0,0,0x0a,0x0a,0,0,0,0x0d,0x0d,0,0,0x0a,0x0d};
+        byte[] u = new byte[]{0,0,0,0x0a,0x0a,0,0,0,0x0a,0x0a,0,0,0x0a};
+        byte[] w = new byte[]{0,0,0,0x0d,0x0a,0x0d,0x0a,0,0,0,0x0d,0x0a,0x0d,0x0a,0,0,0x0d,0x0a};
+        doTest(in, u, w);
+    }
+
+    public void testInput4() throws Exception {
+        byte[] in = "bla */\r\n\r\n/** bla */\r\n".getBytes();
+        byte[] u = "bla */\n\n/** bla */\n".getBytes();
+        byte[] w = "bla */\r\n\r\n/** bla */\r\n".getBytes();
+        doTest(in, u, w);
+    }
+
+    public void testInput5() throws Exception {
+        byte[] in = "bla */\n\n\n/** bla */\n".getBytes();
+        byte[] u = "bla */\n\n\n/** bla */\n".getBytes();
+        byte[] w = "bla */\r\n\r\n\r\n/** bla */\r\n".getBytes();
+        doTest(in, u, w);
+    }
+
+    public void testInput6() throws Exception {
+        byte[] in = "bla */\r\n\r\n\r\n\r\n/** bla */\r\n".getBytes();
+        byte[] u = "bla */\n\n\n\n/** bla */\n".getBytes();
+        byte[] w = "bla */\r\n\r\n\r\n\r\n/** bla */\r\n".getBytes();
+        doTest(in, u, w);
+    }
+
+    public void testLarge1() throws Exception {
+        byte[] in = new byte[3*8192];
+        Arrays.fill(in, (byte) 20);
+        in[8192] = 0xa;
+        byte[] u = new byte[3*8192];
+        Arrays.fill(u, (byte) 20);
+        u[8192] = 0xa;
+        byte[] w = new byte[3*8192 + 1];
+        Arrays.fill(w, (byte) 20);
+        w[8192] = 0xd;
+        w[8193] = 0xa;
+        doTest(in, u, w);
+    }
+
+    public void testLarge2() throws Exception {
+        byte[] in = new byte[3*8192];
+        Arrays.fill(in, (byte) 20);
+        in[8191] = 0xa;
+        byte[] u = new byte[3*8192];
+        Arrays.fill(u, (byte) 20);
+        u[8191] = 0xa;
+        byte[] w = new byte[3*8192 + 1];
+        Arrays.fill(w, (byte) 20);
+        w[8191] = 0xd;
+        w[8192] = 0xa;
+        doTest(in, u, w);
+    }
+
+    public void testLarge3() throws Exception {
+        byte[] in = new byte[3*8192];
+        Arrays.fill(in, (byte) 20);
+        in[8193] = 0xa;
+        byte[] u = new byte[3*8192];
+        Arrays.fill(u, (byte) 20);
+        u[8193] = 0xa;
+        byte[] w = new byte[3*8192 + 1];
+        Arrays.fill(w, (byte) 20);
+        w[8193] = 0xd;
+        w[8194] = 0xa;
+        doTest(in, u, w);
+    }
+
+    private void doTest(byte[] in, byte[] expectUnix, byte[] expectWindows) throws Exception {
+        check(in, expectUnix, LineInputStream.LS_UNIX);
+        check(in, expectWindows, LineInputStream.LS_WINDOWS);
+    }
+
+    private void check(byte[] in, byte[] expect, byte[] ls) throws Exception {
+        ByteArrayInputStream src = new ByteArrayInputStream(in);
+        ByteArrayOutputStream bo = new ByteArrayOutputStream();
+
+        LineInputStream lis = new LineInputStream(src, ls);
+        IOUtils.copy(lis, bo);
+        lis.close();
+
+        byte[] result = bo.toByteArray();
+
+        StringBuffer hexIn = new StringBuffer();
+        for (byte b: expect) {
+            hexIn.append(String.format("%x, ", b));
+        }
+        StringBuffer hexOut = new StringBuffer();
+        for (byte b: result) {
+            hexOut.append(String.format("%x, ", b));
+        }
+        assertEquals(hexIn.toString(), hexOut.toString());
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/LineOutputTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/LineOutputTest.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/LineOutputTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/util/LineOutputTest.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.util;
+
+import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+/**
+ * <code>LineOutputTest</code>...
+ *
+ */
+public class LineOutputTest extends TestCase {
+
+    public void testInput0() throws Exception {
+        byte[] in = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0};
+        byte[] u = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0};
+        byte[] w = new byte[]{0,0,0,0x0d,0x0a,0,0,0,0x0d,0x0a,0,0,0};
+        doTest(in, u, w);
+    }
+
+    public void testInput1() throws Exception {
+        byte[] in = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0x0a};
+        byte[] u = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0x0a};
+        byte[] w = new byte[]{0,0,0,0x0d,0x0a,0,0,0,0x0d,0x0a,0,0,0x0d,0x0a};
+        doTest(in, u, w);
+    }
+
+    public void testInput2() throws Exception {
+        byte[] in = new byte[]{0,0,0,0x0a,0x0d,0,0,0,0x0a,0x0d,0,0,0x0a,0x0d};
+        byte[] u = new byte[]{0,0,0,0x0a,0,0,0,0x0a,0,0,0x0a};
+        byte[] w = new byte[]{0,0,0,0x0d,0x0a,0,0,0,0x0d,0x0a,0,0,0x0d,0x0a};
+        doTest(in, u, w);
+    }
+
+    public void testInput3() throws Exception {
+        byte[] in = new byte[]{0,0,0,0x0a,0x0a,0,0,0,0x0d,0x0d,0,0,0x0a,0x0d};
+        byte[] u = new byte[]{0,0,0,0x0a,0x0a,0,0,0,0x0a,0x0a,0,0,0x0a};
+        byte[] w = new byte[]{0,0,0,0x0d,0x0a,0x0d,0x0a,0,0,0,0x0d,0x0a,0x0d,0x0a,0,0,0x0d,0x0a};
+        doTest(in, u, w);
+    }
+
+    public void testInput4() throws Exception {
+        byte[] in = "bla */\r\n\r\n/** bla */\r\n".getBytes();
+        byte[] u = "bla */\n\n/** bla */\n".getBytes();
+        byte[] w = "bla */\r\n\r\n/** bla */\r\n".getBytes();
+        doTest(in, u, w);
+    }
+
+    public void testInput5() throws Exception {
+        byte[] in = "bla */\n\n\n/** bla */\n".getBytes();
+        byte[] u = "bla */\n\n\n/** bla */\n".getBytes();
+        byte[] w = "bla */\r\n\r\n\r\n/** bla */\r\n".getBytes();
+        doTest(in, u, w);
+    }
+
+    public void testInput6() throws Exception {
+        byte[] in = "bla */\r\n\r\n\r\n\r\n/** bla */\r\n".getBytes();
+        byte[] u = "bla */\n\n\n\n/** bla */\n".getBytes();
+        byte[] w = "bla */\r\n\r\n\r\n\r\n/** bla */\r\n".getBytes();
+        doTest(in, u, w);
+    }
+
+    public void testLarge1() throws Exception {
+        byte[] in = new byte[3*8192];
+        Arrays.fill(in, (byte) 20);
+        in[8192] = 0xa;
+        byte[] u = new byte[3*8192];
+        Arrays.fill(u, (byte) 20);
+        u[8192] = 0xa;
+        byte[] w = new byte[3*8192 + 1];
+        Arrays.fill(w, (byte) 20);
+        w[8192] = 0xd;
+        w[8193] = 0xa;
+        doTest(in, u, w);
+    }
+
+    private void doTest(byte[] in, byte[] expectUnix, byte[] expectWindows) throws Exception {
+        check(in, expectUnix, LineInputStream.LS_UNIX);
+        check(in, expectWindows, LineInputStream.LS_WINDOWS);
+    }
+
+    private void check(byte[] in, byte[] expect, byte[] ls) throws Exception {
+        ByteArrayOutputStream bo = new ByteArrayOutputStream();
+        LineOutputStream lo = new LineOutputStream(bo,ls);
+        lo.write(in);
+        lo.close();
+        byte[] result = bo.toByteArray();
+
+        StringBuffer hexIn = new StringBuffer();
+        for (byte b: expect) {
+            hexIn.append(String.format("%x, ", b));
+        }
+        StringBuffer hexOut = new StringBuffer();
+        for (byte b: result) {
+            hexOut.append(String.format("%x, ", b));
+        }
+        assertEquals(hexIn.toString(), hexOut.toString());
+    }
+}
\ No newline at end of file



Mime
View raw message