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

📄 testproperty.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        CmsProperty property4 = new CmsProperty("Title", CmsProperty.DELETE_VALUE, CmsProperty.DELETE_VALUE);
        removeProperty(this, cms, "/folder1/page2.html", property4);
    }

    /**
     * Tests the writeProperties method.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testWriteProperties() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing writing multiple properties on a resource");
        CmsProperty property2 = new CmsProperty("Title", "OpenCms", null);
        CmsProperty property3 = new CmsProperty("NavPos", "1", null);
        List propertyList1 = new ArrayList();
        propertyList1.add(property2);
        propertyList1.add(property3);
        writeProperties(this, cms, "/folder1/page3.html", propertyList1);
    }

    /**
     * Tests the writePropertyObject method.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testWriteProperty() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing writing one  property on a resource");
        CmsProperty property1 = new CmsProperty("Title", "OpenCms", null);
        writeProperty(this, cms, "/folder1/image1.gif", property1);
    }

    /**
     * Tests the writePropertyObject method for writing of a property on a folder.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testWritePropertyOnFolder() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing writing one property on a folder");
        CmsProperty property10 = new CmsProperty("Title", "OpenCms", null);
        writeProperty(this, cms, "/folder2/", property10);
    }

    /**
     * Tests the writePropertyObject method for writing of a property on a folder.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testReadResourcesWithProperty() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing reading resources with property");

        String typesUri = "/types";
        CmsResource res = cms.readResource(typesUri);
        // now set "exportname" property and try again
        cms.lockResource(typesUri);
        cms.writePropertyObject(typesUri, new CmsProperty(CmsPropertyDefinition.PROPERTY_EXPORTNAME, "myfolder", null));
        // publish the changes
        OpenCms.getPublishManager().publishProject(cms);
        OpenCms.getPublishManager().waitWhileRunning();

        List result = cms.readResourcesWithProperty(CmsPropertyDefinition.PROPERTY_EXPORTNAME);
        assertTrue(result.contains(res));
    }

    /**
     * Test default property creation (from resource type configuration).<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testDefaultPropertyCreation() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing default property creation");

        String resourcename = "/folder1/article_test.html";
        byte[] content = new byte[0];

        // resource 27 is article (xml content) with default properties
        cms.createResource(resourcename, OpenCmsTestCase.ARTICLE_TYPEID, content, null);

        // ensure created resource type
        assertResourceType(cms, resourcename, OpenCmsTestCase.ARTICLE_TYPEID);
        // project must be current project
        assertProject(cms, resourcename, cms.getRequestContext().currentProject());
        // state must be "new"
        assertState(cms, resourcename, CmsResource.STATE_NEW);
        // the user last modified must be the current user
        assertUserLastModified(cms, resourcename, cms.getRequestContext().currentUser());

        CmsProperty property1, property2;
        property1 = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "Test title", null);
        property2 = cms.readPropertyObject(resourcename, CmsPropertyDefinition.PROPERTY_TITLE, false);
        assertTrue(property1.isIdentical(property2));

        property1 = new CmsProperty(
            "template-elements",
            "/system/modules/org.opencms.frontend.templateone.form/pages/form.html",
            null);
        property2 = cms.readPropertyObject(resourcename, "template-elements", false);
        assertTrue(property1.isIdentical(property2));

        property1 = new CmsProperty(
            CmsPropertyDefinition.PROPERTY_DESCRIPTION,
            null,
            "Admin_/folder1/article_test.html_/sites/default/folder1/article_test.html");
        property2 = cms.readPropertyObject(resourcename, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
        assertTrue(property1.isIdentical(property2));

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

        assertState(cms, resourcename, CmsResource.STATE_UNCHANGED);
    }

    /**
     * Tests an issue with shared properties after deletion of the original sibling.<p>
     * 
     * Scenario:
     * A file A has property P set with value V as shared property. Now A is renamed to B. 
     * Then B is published directly with all siblings (A is now deleted and removed).
     * Issue: Property P is now empty in B, but should still have the V value.<p> 
     * 
     * @throws Throwable if something goes wrong
     */
    public void testSharedPropertyIssue1() throws Throwable {

        CmsObject cms = getCmsObject();
        echo("Testing issue with shared properties after deletion of the original sibling");

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

        // create and publish the resource
        String source = "/folder1/testprop.txt";
        String dest = "/folder1/testprop2.txt";

        cms.createResource(source, CmsResourceTypePlain.getStaticTypeId());
        cms.unlockProject(offline.getUuid());
        OpenCms.getPublishManager().publishResource(cms, source);
        OpenCms.getPublishManager().waitWhileRunning();

        // now create the shared property on the source
        cms.lockResource(source);
        CmsProperty descProperty = new CmsProperty(CmsPropertyDefinition.PROPERTY_DESCRIPTION, null, "A shared value");
        cms.writePropertyObject(source, descProperty);
        cms.unlockProject(offline.getUuid());
        OpenCms.getPublishManager().publishResource(cms, source);
        OpenCms.getPublishManager().waitWhileRunning();

        // now move the resource to a new name and publish again, ensure the property is still there
        cms.lockResource(source);
        cms.moveResource(source, dest);
        cms.unlockProject(offline.getUuid());
        OpenCms.getPublishManager().publishResource(cms, dest, true, new CmsShellReport(Locale.ENGLISH));
        OpenCms.getPublishManager().waitWhileRunning();

        CmsProperty resultProperty = cms.readPropertyObject(dest, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
        assertEquals("A shared value", descProperty.getResourceValue());
        assertTrue(
            "Property '" + CmsPropertyDefinition.PROPERTY_DESCRIPTION + "' must be identical",
            descProperty.isIdentical(resultProperty));
    }

    /**
     * Tests the NULL_PROPERTY.<p>
     * 
     * @throws Exception if the test fails
     */
    public void testNullProperty() throws Exception {

        // get the null property
        CmsProperty nullProperty = CmsProperty.getNullProperty();
        // create another property        
        CmsProperty p = new CmsProperty(CmsPropertyDefinition.PROPERTY_TITLE, "Some title", null);
        // do a comparison
        assertFalse("Created property must not be equal to NULL_PROPERTY", p.equals(nullProperty));
        assertFalse("NULL_PROPERTY must not be equal to created Property", nullProperty.equals(p));
        assertTrue("NULL_PROPERTY must be equal to itself", nullProperty.equals(nullProperty));
        assertTrue("NULL_PROPERTY must be identical to itself", nullProperty == CmsProperty.getNullProperty());
    }

    /**
     * Tests changing the values of a frozen property.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testFrozenProperty() throws Throwable {

        CmsProperty property = CmsProperty.getNullProperty();
        if (!property.isFrozen()) {
            fail("NULL_PROPERTY is not frozen!");
        }
        boolean gotException = false;
        try {
            property.setAutoCreatePropertyDefinition(true);
        } catch (CmsRuntimeException e) {
            assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
            gotException = true;
        }
        assertTrue("Operation did not throw the required Exception", gotException);
        gotException = false;
        try {
            property.setFrozen(false);
        } catch (CmsRuntimeException e) {
            assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
            gotException = true;
        }
        assertTrue("Operation did not throw the required Exception", gotException);
        gotException = false;
        try {
            property.setName("SomeString");
        } catch (CmsRuntimeException e) {
            assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
            gotException = true;
        }
        assertTrue("Operation did not throw the required Exception", gotException);
        gotException = false;
        try {
            property.setValue("SomeString", CmsProperty.TYPE_INDIVIDUAL);
        } catch (CmsRuntimeException e) {
            assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
            gotException = true;
        }
        assertTrue("Operation did not throw the required Exception", gotException);
        gotException = false;
        try {
            property.setResourceValue("SomeString");
        } catch (CmsRuntimeException e) {
            assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
            gotException = true;
        }
        assertTrue("Operation did not throw the required Exception", gotException);
        gotException = false;
        try {
            property.setStructureValue("SomeString");
        } catch (CmsRuntimeException e) {
            assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
            gotException = true;
        }
        assertTrue("Operation did not throw the required Exception", gotException);
        gotException = false;
        try {
            property.setResourceValueList(Collections.singletonList("SomeString"));
        } catch (CmsRuntimeException e) {
            assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
            gotException = true;
        }
        assertTrue("Operation did not throw the required Exception", gotException);
        gotException = false;
        try {
            property.setStructureValueList(Collections.singletonList("SomeString"));
        } catch (CmsRuntimeException e) {
            assertEquals(org.opencms.file.Messages.ERR_PROPERTY_FROZEN_1, e.getMessageContainer().getKey());
            gotException = true;
        }
        assertTrue("Operation did not throw the required Exception", gotException);
    }
}

⌨️ 快捷键说明

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