org.opencms.file
Class TestLinkRewriter

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.opencms.test.OpenCmsTestCase
              extended by org.opencms.file.TestLinkRewriter
All Implemented Interfaces:
junit.framework.Test

public class TestLinkRewriter
extends OpenCmsTestCase

Test class for the CmsLinkRewriter class.


Nested Class Summary
 class TestLinkRewriter.ExpectErrorLogHandler
          A log handler which detects whether an error message containing a given string is written to the log.
 
Nested classes/interfaces inherited from class org.opencms.test.OpenCmsTestCase
OpenCmsTestCase.ConnectionData
 
Field Summary
 
Fields inherited from class org.opencms.test.OpenCmsTestCase
ARTICLE_TYPEID, DB_MYSQL, DB_ORACLE, m_additionalConnection, m_configuration, m_currentResourceStrorage, m_defaultConnection, m_defaultTablespace, m_indexTablespace, m_resourceStorages, m_setupConnection, m_tempTablespace
 
Constructor Summary
TestLinkRewriter(String name)
          Creates a new test suite instance.
 
Method Summary
 void assertSetEquals(Set expected, Set actual)
          Helper method to compare sets by sorting them and converting them to strings first.
 String canonicalize(String path)
          Converts a path to a canonical form.
 void copyAndAdjust(String target)
          Copies the /system/base folder to a given path and adjusts the links for that path.
 void createFolder(String path)
          Creates a folder at a given path.
 void delete(String directory)
          Helper method for deleting a directory.
 Set<String> getBaseLinks(String root)
          Gets the set of relation strings which a given folder should have if it had been copied from /system/base and had its links adjusted afterwards.
 List<CmsRelation> getLinksBetween(String firstFolder, String secondFolder)
          Gets a list of relations from resources in one subtree to resources in another.
 Set<String> getMultiBaseLinks(String root)
          Returns the links for the multibase adjustment test, relocated to a given root path.
 String getRelationCode(CmsRelation relation)
          Converts a single relation to a string of the form TYPE:SOURCE:TARGET.
 Set<String> getRelationSet(Collection<CmsRelation> relations)
          Helper method to convert a collection of relations to a set of strings.
protected  Set<String> links(String source, String target)
          Gets the string representations of relations between two subtrees.
static junit.framework.Test suite()
          Returns the test suite.
 void testAdjustWithMissingFile()
          Tests that the link rewriting process can handle missing files in the target folder structure.
 void testCopy()
          Tests whether the link rewriting works in the system folder.
 void testCopyToSite()
          Tests whether the link rewriting works in the current site.
 void testEncodingConversion()
          Tests whether the encoding is converted correctly when rewriting links.
 void testFailIfTargetIsSubdirectory()
          Tests that the link rewriting fails if one of two folder arguments is a subfolder of the other.
 void testMultiCopy()
          Tests relation adjustments for multiple source files.
 void testNotAbort()
          Tests that an error when rewriting a file will not throw an exception, but will be written to the log.
 void testVerifySetup()
          Test to verify that the files under /system/base have been created correctly by the test setup (not really necessary, just to make sure that e.g.
 
Methods inherited from class org.opencms.test.OpenCmsTestCase
addTestDataPath, assertAce, assertAcl, assertAcl, assertContains, assertContainsNot, assertContent, assertDateContent, assertDateContentAfter, assertDateCreated, assertDateCreatedAfter, assertDateExpired, assertDateLastModified, assertDateLastModifiedAfter, assertDateReleased, assertEquals, assertEquals, assertEquals, assertFilter, assertFilter, assertFilter, assertFilter, assertFlags, assertHistory, assertHistoryForRestored, assertIsFolder, assertIsIdentical, assertIsNotIdentical, assertLock, assertLock, assertLock, assertModifiedInCurrentProject, assertPermissionString, assertProject, assertPropertyChanged, assertPropertyChanged, assertPropertydefinitionExist, assertPropertydefinitions, assertPropertyEqual, assertPropertyNew, assertPropertyNew, assertPropertyRemoved, assertPropertyRemoved, assertRelation, assertResourceId, assertResourceType, assertSiblingCount, assertSiblingCountIncremented, assertState, assertStructureId, assertType, assertUserCreated, assertUserLastModified, assertVersion, checkErrors, createStorage, deleteFile, echo, generateContent, generateContent, generateName, generateProperties, generateResources, generateSetupTestWrapper, generateUsers, getCmsObject, getConnectionName, getDatabaseProduct, getDbProduct, getPreCalculatedState, getReplacer, getSetupDataPath, getSetupDb, getTestDataPath, importData, importResources, importTestResource, initTestDataPath, removeDatabase, removeDatabase, removeOpenCms, removeStorage, resetMapping, restart, restartOpenCms, setMapping, setupDatabase, setupDatabase, setupOpenCms, setupOpenCms, setupOpenCms, setupOpenCms, setupOpenCms, storeResources, storeResources, switchStorage
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TestLinkRewriter

public TestLinkRewriter(String name)
Creates a new test suite instance.

Parameters:
name -
Method Detail

suite

public static junit.framework.Test suite()
Returns the test suite.

Returns:
the test suite

assertSetEquals

public void assertSetEquals(Set expected,
                            Set actual)
Helper method to compare sets by sorting them and converting them to strings first.

Parameters:
expected - the expected value
actual - the actual value to check

canonicalize

public String canonicalize(String path)
Converts a path to a canonical form.

Parameters:
path - the path to convert
Returns:
the canonical form of the path

copyAndAdjust

public void copyAndAdjust(String target)
                   throws CmsException
Copies the /system/base folder to a given path and adjusts the links for that path.

Parameters:
target - the target path
Throws:
CmsException - if something goes wrong

createFolder

public void createFolder(String path)
                  throws CmsException
Creates a folder at a given path.

Parameters:
path - the path of the folder
Throws:
CmsException - if something goes wrong

delete

public void delete(String directory)
            throws CmsException
Helper method for deleting a directory.

Parameters:
directory - the directory to remove
Throws:
CmsException - if something goes wrong

getBaseLinks

public Set<String> getBaseLinks(String root)
Gets the set of relation strings which a given folder should have if it had been copied from /system/base and had its links adjusted afterwards.

Parameters:
root - the target folder
Returns:
the relation strings

getLinksBetween

public List<CmsRelation> getLinksBetween(String firstFolder,
                                         String secondFolder)
                                  throws CmsException
Gets a list of relations from resources in one subtree to resources in another.

Parameters:
firstFolder - the root folder of the first subtree
secondFolder - the root folder of the second subtree
Returns:
the list of relations between the two subtrees
Throws:
CmsException - if something goes wrong

getMultiBaseLinks

public Set<String> getMultiBaseLinks(String root)
Returns the links for the multibase adjustment test, relocated to a given root path.

Parameters:
root - the new root path
Returns:
the set of re-rooted links for the multibase test

getRelationCode

public String getRelationCode(CmsRelation relation)
Converts a single relation to a string of the form TYPE:SOURCE:TARGET.

Parameters:
relation - the relation
Returns:
the string representing the relation

getRelationSet

public Set<String> getRelationSet(Collection<CmsRelation> relations)
Helper method to convert a collection of relations to a set of strings.

Parameters:
relations - the relations
Returns:
a set of strings representing the relations

testAdjustWithMissingFile

public void testAdjustWithMissingFile()
                               throws Exception
Tests that the link rewriting process can handle missing files in the target folder structure.

Throws:
Exception

testCopy

public void testCopy()
              throws Exception
Tests whether the link rewriting works in the system folder.

Throws:
Exception

testCopyToSite

public void testCopyToSite()
                    throws Exception
Tests whether the link rewriting works in the current site.

Throws:
Exception

testEncodingConversion

public void testEncodingConversion()
                            throws Exception
Tests whether the encoding is converted correctly when rewriting links.

Throws:
Exception

testFailIfTargetIsSubdirectory

public void testFailIfTargetIsSubdirectory()
                                    throws Exception
Tests that the link rewriting fails if one of two folder arguments is a subfolder of the other.

Throws:
Exception

testMultiCopy

public void testMultiCopy()
                   throws CmsException
Tests relation adjustments for multiple source files.

Throws:
CmsException

testNotAbort

public void testNotAbort()
                  throws Exception
Tests that an error when rewriting a file will not throw an exception, but will be written to the log.

Throws:
Exception

testVerifySetup

public void testVerifySetup()
                     throws Exception
Test to verify that the files under /system/base have been created correctly by the test setup (not really necessary, just to make sure that e.g. a faulty manifest.xml is not the cause of other test failures).

Throws:
Exception

links

protected Set<String> links(String source,
                            String target)
                     throws CmsException
Gets the string representations of relations between two subtrees.

Parameters:
source - the root of the first subtree
target - the root of the second subtree
Returns:
the set of the string representations of the relations
Throws:
CmsException - if something goes wrong