1 31 32 package org.opencms.file; 33 34 import org.opencms.file.types.CmsResourceTypePlain; 35 import org.opencms.lock.CmsLock; 36 import org.opencms.test.OpenCmsTestCase; 37 import org.opencms.test.OpenCmsTestProperties; 38 import org.opencms.test.OpenCmsTestResourceFilter; 39 40 import junit.extensions.TestSetup; 41 import junit.framework.Test; 42 import junit.framework.TestSuite; 43 44 51 public class TestReplace extends OpenCmsTestCase { 52 53 58 public TestReplace(String arg0) { 59 super(arg0); 60 } 61 62 67 public static Test suite() { 68 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 69 70 TestSuite suite = new TestSuite(); 71 suite.setName(TestReplace.class.getName()); 72 73 suite.addTest(new TestReplace("testReplaceResourceContent")); 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 testReplaceResourceContent() throws Throwable { 95 96 CmsObject cms = getCmsObject(); 97 echo("Testing replacement of file content"); 98 99 String path = "/types/text.txt"; 100 String contentStr = "Hello this is the new content"; 101 102 long timestamp = System.currentTimeMillis(); 103 104 storeResources(cms, path); 105 cms.lockResource(path); 106 cms.replaceResource(path, CmsResourceTypePlain.getStaticTypeId(), contentStr.getBytes(), null); 107 108 assertProject(cms, path, cms.getRequestContext().currentProject()); 110 assertState(cms, path, CmsResource.STATE_CHANGED); 112 assertDateLastModifiedAfter(cms, path, timestamp); 114 assertUserLastModified(cms, path, cms.getRequestContext().currentUser()); 116 assertLock(cms, path, CmsLock.TYPE_EXCLUSIVE); 118 assertContent(cms, path, contentStr.getBytes()); 120 assertFilter(cms, path, OpenCmsTestResourceFilter.FILTER_REPLACERESOURCE); 122 } 123 } 124 | Popular Tags |