1 31 32 package org.opencms.file; 33 34 import org.opencms.security.I_CmsPrincipal; 35 import org.opencms.test.OpenCmsTestCase; 36 import org.opencms.test.OpenCmsTestProperties; 37 38 import junit.extensions.TestSetup; 39 import junit.framework.Test; 40 import junit.framework.TestSuite; 41 42 49 public class TestExists extends OpenCmsTestCase { 50 51 56 public TestExists(String arg0) { 57 super(arg0); 58 } 59 60 65 public static Test suite() { 66 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 67 68 TestSuite suite = new TestSuite(); 69 suite.setName(TestExists.class.getName()); 70 71 suite.addTest(new TestExists("testExistsForExistingFile")); 72 suite.addTest(new TestExists("testExistsForUnexistingFile")); 73 suite.addTest(new TestExists("testExistsForUnauthorizedFile")); 74 75 TestSetup wrapper = new TestSetup(suite) { 76 77 protected void setUp() { 78 setupOpenCms("simpletest", "/sites/default/"); 79 } 80 81 protected void tearDown() { 82 removeOpenCms(); 83 } 84 }; 85 86 return wrapper; 87 } 88 89 94 public void testExistsForExistingFile() throws Throwable { 95 96 CmsObject cms = getCmsObject(); 97 echo("Testing the availability of a file that exists and with proper permissions"); 98 String filename = "index.html"; 99 100 assertEquals(true, cms.existsResource(filename)); 101 } 102 103 108 public void testExistsForUnexistingFile() throws Throwable { 109 110 CmsObject cms = getCmsObject(); 111 echo("Testing the availability of a file that does not exist"); 112 String filename = "xxx.yyy"; 113 114 assertEquals(false, cms.existsResource(filename)); 115 } 116 117 122 public void testExistsForUnauthorizedFile() throws Throwable { 123 124 CmsObject cms = getCmsObject(); 125 126 echo("Testing the availability of a file that exists but with not enough permissions"); 127 128 cms.createGroup("Testgroup", "A test group", 0, null); 129 CmsGroup testGroup = cms.readGroup("Testgroup"); 130 cms.createUser("testuser", "test", "A test user", null); 131 CmsUser testUser = cms.readUser("testuser"); 132 133 String resName = "index.html"; 134 135 cms.lockResource(resName); 136 cms.chacc(resName, I_CmsPrincipal.PRINCIPAL_GROUP, testGroup.getName(), "-r-w-v-c-i"); 137 cms.chacc(resName, I_CmsPrincipal.PRINCIPAL_USER, testUser.getName(), "-r-w-v-c-i"); 138 cms.unlockResource(resName); 139 cms.publishProject(); 140 141 cms.loginUser("testuser", "test"); 142 assertEquals(false, cms.existsResource(resName)); 143 } 144 145 } 146 | Popular Tags |