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

📄 testpublishing.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
       // publish a deleted resource with siblings, 
       // delete the siblings also, but publish only the resource itself
       
       // delete the resources 
       cms.lockResource(resource2);
       cms.deleteResource(resource2, CmsResource.DELETE_REMOVE_SIBLINGS);
       cms.unlockResource(resource2);
       
       // this test makes only sense when siblings are published
       cms.publishResource(resource2, false, new CmsShellReport(cms.getRequestContext().getLocale()));

       // the online file must be deleted
       cms.getRequestContext().setCurrentProject(onlineProject);
       try {
           cms.readResource(resource2);
           fail ("Resource " + resource2 + " was not deleted online");
       } catch (CmsVfsResourceNotFoundException e) {
           // ok
      } catch (CmsException e) {
           fail("Resource " + resource2 + " error:" +e);
       }    
       // the other siblings must still be there
      try {
          cms.readResource(resource3);
      } catch (CmsException e) {
              fail("Resource " + resource3 + " error:" +e);
      }
      try {
          cms.readResource(resource4);
      } catch (CmsException e) {
            fail("Resource " + resource4 + " error:" +e);
      }
      
      cms.getRequestContext().setCurrentProject(offlineProject);
      // in the offline project, the siblings must be still marked as deleted
      assertState(cms, resource3, CmsResource.STATE_DELETED);
      assertState(cms, resource4, CmsResource.STATE_DELETED);
      
      // publish a deleted resource with siblings, delete the siblings
      //
      cms.publishResource(resource3, true, new CmsShellReport(cms.getRequestContext().getLocale()));
      
      // the online files must be deleted
      cms.getRequestContext().setCurrentProject(onlineProject);
      try {
          cms.readResource(resource3);
          fail ("Resource " + resource3 + " was not deleted online");
      } catch (CmsVfsResourceNotFoundException e) {
          // ok
      } catch (CmsException e) {
          fail("Resource " + resource3 + " error:" +e);
      } 
      try {
          cms.readResource(resource4);
          fail ("Resource " + resource4 + " was not deleted online");
      } catch (CmsVfsResourceNotFoundException e) {
          // ok
      } catch (CmsException e) {
          fail("Resource " + resource4 + " error:" +e);
      } 
      
      cms.getRequestContext().setCurrentProject(offlineProject);

    }

    /**
     * Test publishing changed files.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishLockedFiles() throws Throwable {
        
        CmsObject cms = getCmsObject();     
        echo("Testing publish locked files");
        
        String source = "/folder2/subfolder21/image1.gif";
        String resource1 = "/folder2/image1_new.gif";
        String resource2 = "/folder2/image1_sibling1.gif";
        
        CmsProject onlineProject  = cms.readProject("Online");
        
        CmsProperty prop0;
        CmsProperty prop1;
        CmsProperty prop2;
  
        // make changes to the resources 
        // do not need to make any changes to resource3 and resource4 as they are
        // siblings of resource2!
 
        cms.lockResource(source);
        cms.lockResource(resource1);
        cms.lockResource(resource2);
        
        cms.writePropertyObject(source, new CmsProperty("Title", source + " modified", null));
        cms.writePropertyObject(resource1, new CmsProperty("Title", resource1 + " modified", null));
        cms.writePropertyObject(resource2, new CmsProperty("Title", resource2 + " modified", null));

        storeResources(cms, source);
        storeResources(cms, resource1);
        storeResources(cms, resource2);
       
        // publish a modified resource without siblings
        cms.publishProject();

        // ensure that all changed resources are still changed in the offline project
        assertState(cms, source, CmsResource.STATE_CHANGED);
        assertState(cms, resource1, CmsResource.STATE_CHANGED);
        assertState(cms, resource2, CmsResource.STATE_CHANGED);
                
        // ensure that all changed resources are NOT published
        cms.getRequestContext().setCurrentProject(onlineProject);
        prop0 = cms.readPropertyObject(source, "Title", false);
        prop1 = cms.readPropertyObject(resource1, "Title", false);
        prop2 = cms.readPropertyObject(resource2, "Title", false);
        
        if (prop0.getValue().equals((source + " modified"))) {
            fail("Property published for " + source);
        }
        if (prop1.getValue().equals((resource1 + " modified"))) {
            fail("Property published for " + resource1);
        }        
        if (prop2.getValue().equals((resource2 + " modified"))) {
            fail("Property published for " + resource2);
        }
    }  
    
    
    
    
    /**
     * Test publishing new files.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishNewFiles() throws Throwable {
        
        CmsObject cms = getCmsObject();     
        echo("Testing publish new files");
        
        String source = "/folder2/subfolder21/image1.gif";
        String destination1 = "/folder2/image1_new.gif";
        String destination2 = "/folder2/image1_sibling1.gif";
        String destination3 = "/folder2/image1_sibling2.gif";
        String destination4 = "/folder2/image1_sibling3.gif";
        
        CmsProject onlineProject  = cms.readProject("Online");
        CmsProject offlineProject  = cms.readProject("Offline");

        // make four copies of a file to be published later
        cms.copyResource(source, destination1, CmsResource.COPY_AS_NEW);
        cms.copyResource(source, destination2, CmsResource.COPY_AS_SIBLING);
        cms.copyResource(source, destination3, CmsResource.COPY_AS_SIBLING);
        cms.copyResource(source, destination4, CmsResource.COPY_AS_SIBLING);
        
        storeResources(cms, destination1);
        storeResources(cms, destination2);
        storeResources(cms, destination3);
        storeResources(cms, destination4);
        
        // unlock all new resources
        // do not neet do unlock destination3 as it is a sibling of destination2     
        cms.unlockResource(destination1);
        cms.unlockResource(destination2);    
        
        // publish a new resource
        //
        cms.publishResource(destination1);

        // the file must be now available in the online project
        cms.getRequestContext().setCurrentProject(onlineProject);
        try {
            cms.readResource(destination1);
        } catch (CmsException e) {
            fail("Resource " + destination1 + " not found in online project:" +e);
        }    
        assertFilter(cms, destination1, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);  
        
        // check if the file in the offline project is unchancged now
        cms.getRequestContext().setCurrentProject(offlineProject);
        assertState(cms, destination1, CmsResource.STATE_UNCHANGED);     
 
        // publish a sibling without publishing other siblings
        //
        cms.publishResource(destination2);
        
        // the file must be now available in the online project
        cms.getRequestContext().setCurrentProject(onlineProject);
        try {
            cms.readResource(destination2);
        } catch (CmsException e) {
            fail("Resource " + destination2 + " not found in online project:" +e);
        }
        // the other siblings must not be available in the online project yet
        try {
            cms.readResource(destination3);
            fail("Resource " + destination3+ " should not available online yet");
        } catch (CmsVfsResourceNotFoundException e) {
            // ok
        } catch (CmsException e) {
            fail("Resource " + destination3 + " error:" +e);
        }
        try {
            cms.readResource(destination4);
            fail("Resource " + destination4+ " should not available online yet");
        } catch (CmsVfsResourceNotFoundException e) {
            // ok
        } catch (CmsException e) {
            fail("Resource " + destination4 + " error:" +e);
        }
        
        assertFilter(cms, destination2, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);          
        
        // check if the file in the offline project is unchancged now
        cms.getRequestContext().setCurrentProject(offlineProject);
        assertState(cms, destination2, CmsResource.STATE_UNCHANGED);
        // the other siblings in the offline project must still be shown as new
        assertState(cms, destination3, CmsResource.STATE_NEW);
        assertState(cms, destination4, CmsResource.STATE_NEW);
        
        // publish a sibling and all other siblings of it
        //
        cms.publishResource(destination3, true, new CmsShellReport(cms.getRequestContext().getLocale()));
        // the file and its siblings must be now available in the online project
        cms.getRequestContext().setCurrentProject(onlineProject);
        try {
            cms.readResource(destination3);
        } catch (CmsException e) {
            fail("Resource " + destination3 + " not found in online project:" +e);
        }
        try {
            cms.readResource(destination4);
        } catch (CmsException e) {
            fail("Resource " + destination4 + " not found in online project:" +e);
        }
        assertFilter(cms, destination3, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);  
        assertFilter(cms, destination4, OpenCmsTestResourceFilter.FILTER_PUBLISHRESOURCE);  
        
        // check if the file in the offline project is unchancged now
        cms.getRequestContext().setCurrentProject(offlineProject);
        assertState(cms, destination3, CmsResource.STATE_UNCHANGED);
        assertState(cms, destination4, CmsResource.STATE_UNCHANGED);
    }  
    
    /**
     * Test publishing files within a new unpublished folder.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testPublishNewFilesInNewFolder() throws Throwable {
        
        CmsObject cms = getCmsObject();     
        echo("Testing publishing new files in new folder");
        
        String source = "/folder1/image1.gif";
        String newFolder = "/new_folder/";

⌨️ 快捷键说明

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