1 31 32 package org.opencms.file; 33 34 import org.opencms.file.types.CmsResourceTypeFolder; 35 import org.opencms.file.types.CmsResourceTypePlain; 36 import org.opencms.lock.CmsLock; 37 import org.opencms.test.OpenCmsTestCase; 38 import org.opencms.test.OpenCmsTestProperties; 39 import org.opencms.test.OpenCmsTestResourceFilter; 40 41 import junit.extensions.TestSetup; 42 import junit.framework.Test; 43 import junit.framework.TestSuite; 44 45 52 public class TestMoveRename extends OpenCmsTestCase { 53 54 59 public TestMoveRename(String arg0) { 60 super(arg0); 61 } 62 63 68 public static Test suite() { 69 OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); 70 71 TestSuite suite = new TestSuite(); 72 suite.setName(TestMoveRename.class.getName()); 73 74 suite.addTest(new TestMoveRename("testMoveSingleResource")); 75 suite.addTest(new TestMoveRename("testMoveSingleNewResource")); 76 suite.addTest(new TestMoveRename("testMultipleMoveResource")); 77 suite.addTest(new TestMoveRename("testRenameNewFolder")); 78 suite.addTest(new TestMoveRename("testMoveFolderToOwnSubfolder")); 79 suite.addTest(new TestMoveRename("testRenameFileUpperLowerCase")); 80 suite.addTest(new TestMoveRename("testRenameFolderUpperLowerCase")); 81 82 TestSetup wrapper = new TestSetup(suite) { 83 84 protected void setUp() { 85 setupOpenCms("simpletest", "/sites/default/"); 86 } 87 88 protected void tearDown() { 89 removeOpenCms(); 90 } 91 }; 92 93 return wrapper; 94 } 95 96 97 102 public void testMultipleMoveResource() throws Throwable { 103 104 CmsObject cms = getCmsObject(); 105 echo("Testing multiple move of a resource"); 106 107 cms.getRequestContext().setSiteRoot("/"); 109 110 String source = "/sites/default/folder1/page1.html"; 111 String destination1 = "/sites/default/folder1/page1_move.html"; 112 String destination2 = "/page1_move.html"; 113 114 storeResources(cms, source); 115 116 cms.lockResource(source); 117 cms.moveResource(source, destination1); 118 cms.moveResource(destination1, destination2); 119 120 122 assertProject(cms, source, cms.getRequestContext().currentProject()); 124 assertState(cms, source, CmsResource.STATE_DELETED); 126 assertLock(cms, source, CmsLock.TYPE_SHARED_EXCLUSIVE); 128 assertPropertyNew(cms, source, new CmsProperty(CmsPropertyDefinition.PROPERTY_INTERNAL, 130 String.valueOf(cms.getRequestContext().currentProject().getId()), null)); 131 assertSiblingCountIncremented(cms, source, 1); 133 assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_MOVE_SOURCE); 135 136 138 assertProject(cms, destination2, cms.getRequestContext().currentProject()); 140 assertState(cms, destination2, CmsResource.STATE_NEW); 142 assertLock(cms, destination2, CmsLock.TYPE_EXCLUSIVE); 144 setMapping(destination2, source); 146 assertSiblingCountIncremented(cms, destination2, 1); 148 assertFilter(cms, destination2, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION); 150 151 152 resetMapping(); 154 cms.changeLock(source); 155 assertLock(cms, source, CmsLock.TYPE_EXCLUSIVE); 156 assertLock(cms, destination2, CmsLock.TYPE_SHARED_EXCLUSIVE); 157 cms.undoChanges(source, false); 158 assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_EXISTING_SIBLING); 159 } 160 161 166 public void testMoveSingleResource() throws Throwable { 167 168 CmsObject cms = getCmsObject(); 169 echo("Testing move of a file"); 170 171 String source = "/folder1/index.html"; 172 String destination = "/folder1/index_move.html"; 173 174 storeResources(cms, source); 175 176 cms.lockResource(source); 177 cms.moveResource(source, destination); 178 179 cms.readResource(source, CmsResourceFilter.ALL); 181 182 184 assertProject(cms, source, cms.getRequestContext().currentProject()); 186 assertState(cms, source, CmsResource.STATE_DELETED); 188 assertLock(cms, source, CmsLock.TYPE_SHARED_EXCLUSIVE); 190 assertPropertyNew(cms, source, new CmsProperty(CmsPropertyDefinition.PROPERTY_INTERNAL, 192 String.valueOf(cms.getRequestContext().currentProject().getId()), null)); 193 assertSiblingCountIncremented(cms, source, 1); 195 assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_MOVE_SOURCE); 197 198 200 assertProject(cms, destination, cms.getRequestContext().currentProject()); 202 assertState(cms, destination, CmsResource.STATE_NEW); 204 assertLock(cms, destination, CmsLock.TYPE_EXCLUSIVE); 206 setMapping(destination, source); 208 assertSiblingCountIncremented(cms, destination, 1); 210 assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION); 212 } 213 214 219 public void testMoveSingleNewResource() throws Throwable { 220 221 CmsObject cms = getCmsObject(); 222 echo("Testing move of a new file"); 223 224 String source = "/folder1/new.html"; 225 String destination = "/folder1/new_move.html"; 226 227 cms.createResource(source, CmsResourceTypePlain.getStaticTypeId()); 229 assertLock(cms, source, CmsLock.TYPE_EXCLUSIVE); 230 231 storeResources(cms, source); 232 233 cms.moveResource(source, destination); 234 235 CmsResource res = null; 237 try { 238 res = cms.readResource(source); 239 } catch (CmsVfsResourceNotFoundException e) { 240 } 242 if (res != null) { 243 fail("New resource still available after move operation!"); 244 } 245 246 248 assertProject(cms, destination, cms.getRequestContext().currentProject()); 250 assertState(cms, destination, CmsResource.STATE_NEW); 252 assertLock(cms, destination, CmsLock.TYPE_EXCLUSIVE); 254 setMapping(destination, source); 256 assertSiblingCount(cms, destination, 1); 258 assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION); 260 } 261 262 267 public void testRenameNewFolder() throws Throwable { 268 269 CmsObject cms = getCmsObject(); 270 echo("Testing rename a new folder with content"); 271 272 cms.getRequestContext().setSiteRoot("/"); 274 275 String source = "/sites/default/folder1"; 276 String newFolder = "/sites/default/newfolder"; 277 String destination = newFolder + "/folder1"; 278 String newFolder2 = "/sites/default/testfolder"; 279 280 cms.createResource(newFolder, CmsResourceTypeFolder.getStaticTypeId()); 281 282 cms.lockResource(source); 283 cms.moveResource(source, destination); 284 cms.moveResource(newFolder, newFolder2); 285 286 try { 287 cms.readResource(newFolder2, CmsResourceFilter.ALL); 288 } catch (CmsVfsResourceNotFoundException e) { 289 echo("ERROR: folder not found, try to create it."); 290 cms.createResource(newFolder2, CmsResourceTypeFolder.getStaticTypeId()); 291 } 292 293 assertState(cms, newFolder2, CmsResource.STATE_NEW); 294 295 cms.undoChanges(source, false); 296 } 297 298 303 public void testMoveFolderToOwnSubfolder() throws Exception { 304 305 CmsObject cms = getCmsObject(); 306 echo("Testing to move a folder in its own subfolder"); 307 308 String source = "/folder1/"; 310 String destination = "/folder1/subfolder11/folder1/"; 311 312 cms.lockResource(source); 313 CmsVfsException error = null; 314 try { 315 cms.moveResource(source, destination); 317 } catch (CmsVfsException e) { 318 error = e; 319 } 320 321 assertNotNull(error); 323 assertSame(error.getMessageContainer().getKey(), Messages.ERR_MOVE_SAME_FOLDER_2); 325 } 326 327 332 public void testRenameFileUpperLowerCase() throws Exception { 333 334 CmsObject cms = getCmsObject(); 335 echo("Testing to rename a file to the same name with a different case"); 336 337 String source = "/folder2/image1.gif"; 339 String destination = "/folder2/Image1.GIF"; 340 341 storeResources(cms, source); 342 343 cms.lockResource(source); 345 cms.moveResource(source, destination); 346 347 CmsResource res = null; 349 try { 350 res = cms.readResource(source); 351 } catch (CmsVfsResourceNotFoundException e) { 352 } 354 if (res != null) { 355 fail("New resource still available after move operation!"); 356 } 357 358 cms.readResource(source, CmsResourceFilter.ALL); 360 361 363 assertProject(cms, source, cms.getRequestContext().currentProject()); 365 assertState(cms, source, CmsResource.STATE_DELETED); 367 assertLock(cms, source, CmsLock.TYPE_SHARED_EXCLUSIVE); 369 assertPropertyNew(cms, source, new CmsProperty(CmsPropertyDefinition.PROPERTY_INTERNAL, 371 String.valueOf(cms.getRequestContext().currentProject().getId()), null)); 372 assertSiblingCountIncremented(cms, source, 1); 374 assertFilter(cms, source, OpenCmsTestResourceFilter.FILTER_MOVE_SOURCE); 376 377 379 assertProject(cms, destination, cms.getRequestContext().currentProject()); 381 assertState(cms, destination, CmsResource.STATE_NEW); 383 assertLock(cms, destination, CmsLock.TYPE_EXCLUSIVE); 385 setMapping(destination, source); 387 assertSiblingCountIncremented(cms, destination, 1); 389 assertFilter(cms, destination, OpenCmsTestResourceFilter.FILTER_MOVE_DESTINATION); 391 } 392 393 398 public void testRenameFolderUpperLowerCase() throws Exception { 399 400 CmsObject cms = getCmsObject(); 401 echo("Testing to rename a folder to the same name with a different case"); 402 403 String source = "/xmlcontent"; 405 String destination = "/XMLcontent"; 406 407 storeResources(cms, source); 408 409 cms.lockResource(source); 411 cms.moveResource(source, destination); 412 413 CmsResource res = null; 415 try { 416 res = cms.readResource(source); 417 } catch (CmsVfsResourceNotFoundException e) { 418 } 420 if (res != null) { 421 fail("New resource still available after move operation!"); 422 } 423 424 cms.readResource(source, CmsResourceFilter.ALL); 426 cms.readResource(destination); 428 429 431 assertProject(cms, source, cms.getRequestContext().currentProject()); 433 assertState(cms, source, CmsResource.STATE_DELETED); 435 assertLock(cms, source, CmsLock.TYPE_EXCLUSIVE); 437 assertSiblingCount(cms, source, 1); 439 440 442 assertProject(cms, destination, cms.getRequestContext().currentProject()); 444 assertState(cms, destination, CmsResource.STATE_NEW); 446 assertLock(cms, destination, CmsLock.TYPE_EXCLUSIVE); 448 assertSiblingCount(cms, source, 1); 450 } 451 } | Popular Tags |