⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testpublishissues.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * Now both users try to edit the sibling of "test.txt" in their folder.<p>
     * 
     * TODO: How are concurrent file modifications avoided on the sibling?
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishScenarioB() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing publish scenario B");

        // set up the test case first
        String folderA = "/foldera/";
        String folderB = "/folderb/";
        String resourceA = folderA + "test.txt";
        String resourceB = folderB + "test.txt";

        // create the resource and the sibling
        cms.createResource(folderA, CmsResourceTypeFolder.getStaticTypeId());
        cms.createResource(folderB, CmsResourceTypeFolder.getStaticTypeId());
        cms.createResource(resourceA, CmsResourceTypePlain.getStaticTypeId());
        cms.createSibling(resourceA, resourceB, Collections.EMPTY_LIST);
        CmsFile cmsFile = cms.readFile(resourceA);
        cmsFile.setContents("Hello, this is a test!".getBytes());
        cms.writeFile(cmsFile);

        // now publish the project
        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();

        // check if the setup was created as planned
        cmsFile = cms.readFile(resourceA);
        assertEquals(2, cmsFile.getSiblingCount());
        assertState(cms, resourceA, CmsResource.STATE_UNCHANGED);
        cmsFile = cms.readFile(resourceB);
        assertEquals(2, cmsFile.getSiblingCount());
        assertState(cms, resourceB, CmsResource.STATE_UNCHANGED);

        // we use the default "Offline" project as "projectA"
        //        CmsProject projectA = cms.readProject("Offline");        

        // create "projectB" as Admin user       
        cms.createProject(
            "projectB",
            "Test project 2 for scenario B",
            OpenCms.getDefaultUsers().getGroupUsers(),
            OpenCms.getDefaultUsers().getGroupUsers());

        CmsProject projectB = cms.readProject("projectB");
        cms.getRequestContext().setCurrentProject(projectB);
        cms.copyResourceToProject("/");

        // check if the project was created as planned
        List resources = cms.readProjectResources(projectB);
        assertEquals(1, resources.size());
        assertEquals("/sites/default/", (String)resources.get(0));

        // TODO: The wanted behaviour in this case must be defined!        
    }

    /**
     * Tests publish scenario "C".<p>
     * 
     * This scenario is described as follows:
     * Direct publishing of folders containing subfolders skips all changed subfolders e.g. direct publish of /folder1/ 
     * publishes /folder1/ and /folder1/index.html/, but not /folder1/subfolder11/.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishScenarioC() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing publish scenario C");

        long touchTime = System.currentTimeMillis();

        cms.lockResource("/folder1/");
        cms.setDateLastModified("/folder1/", touchTime, false);
        cms.setDateLastModified("/folder1/index.html", touchTime, false);
        cms.setDateLastModified("/folder1/subfolder11/", touchTime, false);
        cms.setDateLastModified("/folder1/subfolder11/index.html", touchTime, false);

        cms.unlockResource("/folder1/");
        OpenCms.getPublishManager().publishResource(cms, "/folder1/");
        OpenCms.getPublishManager().waitWhileRunning();

        assertState(cms, "/folder1/", CmsResource.STATE_UNCHANGED);
        assertState(cms, "/folder1/index.html", CmsResource.STATE_UNCHANGED);
        assertState(cms, "/folder1/subfolder11/", CmsResource.STATE_UNCHANGED);
        assertState(cms, "/folder1/subfolder11/index.html", CmsResource.STATE_UNCHANGED);

        cms.createResource("/folder_a/", CmsResourceTypeFolder.getStaticTypeId());
        cms.createResource("/folder_a/file_a.txt", CmsResourceTypePlain.getStaticTypeId());
        cms.createResource("/folder_a/folder_b/", CmsResourceTypeFolder.getStaticTypeId());
        cms.createResource("/folder_a/folder_b/file_b.txt", CmsResourceTypePlain.getStaticTypeId());

        cms.unlockResource("/folder_a/");
        OpenCms.getPublishManager().publishResource(cms, "/folder_a/");
        OpenCms.getPublishManager().waitWhileRunning();

        assertState(cms, "/folder_a/", CmsResource.STATE_UNCHANGED);
        assertState(cms, "/folder_a/file_a.txt", CmsResource.STATE_UNCHANGED);
        assertState(cms, "/folder_a/folder_b/", CmsResource.STATE_UNCHANGED);
        assertState(cms, "/folder_a/folder_b/file_b.txt", CmsResource.STATE_UNCHANGED);

    }

    /**
     * Tests publish scenario "D".<p>
     * 
     * This scenario is described as follows:
     * 
     * Direct publishing of folders containing subfolders skips all (sibling)
     * resources in subfolders. 
     * 
     * e.g. direct publish of /folder2/folder1/ 
     * publishes /folder2/folder1/ and /folder2/folder1/index.html/, 
     * but not /folder2/folder1/subfolder11/index.html.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishScenarioD() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing publish scenario D");

        cms.lockResource("/folder1/");
        // copy the whole folder creating siblings of all resources
        cms.copyResource("/folder1/", "/folder2/folder1", CmsResource.COPY_AS_SIBLING);
        cms.unlockResource("/folder1/");

        // direct publish the new folder
        cms.unlockResource("/folder2/folder1/");
        OpenCms.getPublishManager().publishResource(cms, "/folder2/folder1/");
        OpenCms.getPublishManager().waitWhileRunning();

        // check the state of all resources
        Iterator itResources = cms.readResources("/folder2/folder1/", CmsResourceFilter.ALL, true).iterator();
        while (itResources.hasNext()) {
            CmsResource res = (CmsResource)itResources.next();
            assertEquals(res.getState(), CmsResource.STATE_UNCHANGED);
        }
    }

    /**
     * Tests publish scenario "E".<p>
     * 
     * This scenario is described as follows:
     * 
     * Deletion of folders containing shared locked siblings, 
     * after copying a folder creating siblings into a new folder and publishing. <p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishScenarioE() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing publish scenario E");

        // change to the offline project 
        CmsProject project = cms.readProject("Offline");
        cms.getRequestContext().setCurrentProject(project);

        // create folder
        cms.createResource("/test", CmsResourceTypeFolder.getStaticTypeId());

        // create siblings
        cms.copyResource("/folder1/subfolder12/subsubfolder121", "/test/subtest", CmsResource.COPY_AS_SIBLING);

        // publish
        cms.unlockResource("/test");
        OpenCms.getPublishManager().publishResource(cms, "/test");
        OpenCms.getPublishManager().waitWhileRunning();

        // lock sibling 
        cms.lockResource("/folder1/subfolder12/subsubfolder121/image1.gif");
        CmsUser user = cms.getRequestContext().currentUser();
        
        // login as user test2
        cms.addUserToGroup("test2", "Projectmanagers");
        cms.loginUser("test2", "test2");
        cms.getRequestContext().setCurrentProject(project);

        // check lock
        assertLock(cms, "/test/subtest/image1.gif", CmsLockType.SHARED_EXCLUSIVE, user);

        // delete the folder
        cms.lockResource("/test/subtest");
        cms.deleteResource("/test/subtest", CmsResource.DELETE_PRESERVE_SIBLINGS);
        cms.unlockResource("/test/subtest");

        // publish
        OpenCms.getPublishManager().publishResource(cms, "/test");
        OpenCms.getPublishManager().waitWhileRunning();
    }

    /**
     * Tests publish scenario "F".<p>
     * 
     * This scenario is described as follows:
     * 
     * We have 2 siblings: sibA.txt and sibB.txt
     * We set a shared property and we publish
     * just one sibling let's say sibA.txt.
     * 
     * After publishing both siblings should be unchanged
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishScenarioF() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing publish scenario F");

        String sibA = "sibA.txt";
        String sibB = "sibB.txt";
        
        cms.createResource(sibA, CmsResourceTypePlain.getStaticTypeId());
        cms.createSibling(sibA, sibB, null);

        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();

        CmsProperty prop = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, null, "shared");
        cms.lockResource(sibA);
        cms.writePropertyObject(sibA, prop);
        
        assertState(cms, sibA, CmsResource.STATE_CHANGED);
        assertState(cms, sibB, CmsResource.STATE_CHANGED);
        
        cms.unlockResource(sibA);
        OpenCms.getPublishManager().publishResource(cms, sibA, false, new CmsShellReport(cms.getRequestContext().getLocale()));
        OpenCms.getPublishManager().waitWhileRunning();
        
        assertState(cms, sibA, CmsResource.STATE_UNCHANGED);
        assertState(cms, sibB, CmsResource.STATE_UNCHANGED);
    }

    /**
     * Tests publish scenario "G".<p>
     * 
     * This scenario is described as follows:
     * 
     * We have 2 siblings: sib1.txt and sib2.txt
     * We do a content modification and we publish
     * just one sibling let's say sib1.txt.
     * 
     * After publishing both siblings should be unchanged
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishScenarioG() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing publish scenario G");

        String sib1 = "sib1.txt";
        String sib2 = "sib2.txt";
        
        cms.createResource(sib1, CmsResourceTypePlain.getStaticTypeId());
        cms.createSibling(sib1, sib2, null);

        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();

        CmsFile file = cms.readFile(sib1);
        file.setContents("abc".getBytes());
        cms.lockResource(sib1);
        cms.writeFile(file);
        
        assertState(cms, sib1, CmsResource.STATE_CHANGED);
        assertState(cms, sib2, CmsResource.STATE_CHANGED);
        
        cms.unlockResource(sib1);
        OpenCms.getPublishManager().publishResource(cms, sib1, false, new CmsShellReport(cms.getRequestContext().getLocale()));
        OpenCms.getPublishManager().waitWhileRunning();
        
        assertState(cms, sib1, CmsResource.STATE_UNCHANGED);
        assertState(cms, sib2, CmsResource.STATE_UNCHANGED);
    }

    /**
     * Tests publish scenario "H".<p>
     * 
     * This scenario is described as follows:
     * 
     * We have 2 unchanged siblings: sibX.txt and sibY.txt
     * Now we set a different individual property on each sibling 
     * and we publish just one sibling let's say sibX.txt.
     * 
     * After publishing only sibX.txt should be unchanged
     * and sibY.txt should still be changed
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishScenarioH() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing publish scenario H");

        String sibX = "sibX.txt";
        String sibY = "sibY.txt";
        
        cms.createResource(sibX, CmsResourceTypePlain.getStaticTypeId());
        cms.createSibling(sibX, sibY, null);

        cms.unlockProject(cms.getRequestContext().currentProject().getUuid());
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();

        CmsProperty propX = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "individual X", null);
        cms.lockResource(sibX);
        cms.writePropertyObject(sibX, propX);
        
        assertState(cms, sibX, CmsResource.STATE_CHANGED);
        assertState(cms, sibY, CmsResource.STATE_UNCHANGED);
        
        CmsProperty propY = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "individual Y", null);
        cms.lockResource(sibY);
        cms.writePropertyObject(sibY, propY);
        
        assertState(cms, sibX, CmsResource.STATE_CHANGED);
        assertState(cms, sibY, CmsResource.STATE_CHANGED);
        
        cms.unlockResource(sibX);
        OpenCms.getPublishManager().publishResource(cms, sibX, false, new CmsShellReport(cms.getRequestContext().getLocale()));
        OpenCms.getPublishManager().waitWhileRunning();
        
        assertState(cms, sibX, CmsResource.STATE_UNCHANGED);
        assertState(cms, sibY, CmsResource.STATE_CHANGED);

        OpenCms.getPublishManager().publishResource(cms, sibY, false, new CmsShellReport(cms.getRequestContext().getLocale()));
        OpenCms.getPublishManager().waitWhileRunning();

        assertState(cms, sibX, CmsResource.STATE_UNCHANGED);
        assertState(cms, sibY, CmsResource.STATE_UNCHANGED);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -