1 31 32 package org.opencms.file; 33 34 import org.opencms.test.OpenCmsTestCase; 35 import org.opencms.test.OpenCmsTestProperties; 36 import org.opencms.test.OpenCmsTestResourceFilter; 37 38 import junit.extensions.TestSetup; 39 import junit.framework.Test; 40 import junit.framework.TestSuite; 41 42 49 public class TestChflags extends OpenCmsTestCase { 50 51 56 public TestChflags(String arg0) { 57 58 super(arg0); 59 } 60 61 66 public static Test suite() { 67 68 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 69 70 TestSuite suite = new TestSuite(); 71 suite.setName(TestChflags.class.getName()); 72 73 suite.addTest(new TestChflags("testAddFlagInternal")); 74 75 TestSetup wrapper = new TestSetup(suite) { 76 77 protected void setUp() { 78 79 setupOpenCms("simpletest", "/sites/default/"); 80 } 81 82 protected void tearDown() { 83 84 removeOpenCms(); 85 } 86 }; 87 88 return wrapper; 89 } 90 91 96 public void testAddFlagInternal() throws Throwable { 97 98 CmsObject cms = getCmsObject(); 99 100 echo("Tests setting the \"internal\" flag on a resource"); 101 addFlagInternal(this, cms); 102 } 103 104 111 public static void addFlagInternal(OpenCmsTestCase tc, CmsObject cms) throws Throwable { 112 113 String resource1 = "/index.html"; 114 115 CmsResource resource = cms.readResource(resource1, CmsResourceFilter.ALL); 116 tc.storeResources(cms, resource1); 117 118 int existingFlags = resource.getFlags(); 119 int flags = existingFlags; 120 long timestamp = System.currentTimeMillis(); 121 122 assertEquals((existingFlags & CmsResource.FLAG_INTERNAL), 0); 124 125 if ((flags & CmsResource.FLAG_INTERNAL) == 0) { 127 flags += CmsResource.FLAG_INTERNAL; 128 } else { 129 fail("Resource " + resource1 + " has the \"internal\" flag already set!"); 130 } 131 132 cms.lockResource(resource1); 134 cms.chflags(resource1, flags); 135 cms.unlockResource(resource1); 136 137 tc.assertFilter(cms, resource1, OpenCmsTestResourceFilter.FILTER_CHFLAGS); 139 tc.assertDateLastModifiedAfter(cms, resource1, timestamp); 140 tc.assertState(cms, resource1, CmsResource.STATE_CHANGED); 141 tc.assertUserLastModified(cms, resource1, cms.getRequestContext().currentUser()); 142 tc.assertFlags(cms, resource1, CmsResource.FLAG_INTERNAL); 143 tc.assertProject(cms, resource1, cms.getRequestContext().currentProject()); 144 } 145 146 } | Popular Tags |