org.opencms.test
Class OpenCmsTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.opencms.test.OpenCmsTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
TestADEPublish, TestAvailability, TestCache, TestCategories, TestCategoryResourceCollectors, TestChacc, TestChangeProperties, TestChflags, TestChtype, TestCmsEvents, TestCmsExternalLinksValidator, TestCmsFlexResponse, TestCmsGallerySearchBasic, TestCmsHtmlConverter, TestCmsImportExport, TestCmsImportExportNonexistentUser, TestCmsJspContentAccessBean, TestCmsJspVfsAccessBean, TestCmsLinkManager, TestCmsMail, TestCmsPrincipal, TestCmsSchedulerInSystem, TestCmsSearch, TestCmsSearchAdvancedFeatures, TestCmsSearchFields, TestCmsSearchInDocuments, TestCmsSearchOffline, TestCmsSearchSpecialFeatures, TestCmsSetupBean, TestCmsSetupDb, TestCmsSetupXmlHelper, TestCmsShell, TestCmsStaticExportManager, TestCmsSystemInfo, TestCmsUUID, TestCmsXmlContainerPage, TestCmsXmlContent75Features, TestCmsXmlContentChoice, TestCmsXmlContentLinks, TestCmsXmlContentSchemaModifications, TestCmsXmlContentWithVfs, TestCmsXmlEntityResolver, TestCmsXmlPage, TestCmsXmlPageInSystem, TestCmsXmlSaxWriter, TestConcurrentOperations, TestConfig, TestConfiguration, TestConfigurationOptions, TestContentNotification, TestCopy, TestCounters, TestCreateWriteResource, TestDecorator, TestDefaultResourceCollectors, TestDeletion, TestExists, TestExportFile, TestFill, TestGroupOperations, TestHistory, TestJspLinkMacros, TestLinkParseableResourceTypes, TestLinkRewriter, TestLinkValidation, TestLiveConfig, TestLock, TestLoginAndPasswordHandler, TestMemoryMonitor, TestModuleDeleteThread, TestModuleIssues, TestModuleOperations, TestMoveRename, TestMoveRename2, TestMoveRename3, TestNavPosCalculator, TestOpenCmsSingleton, TestOrganizationalUnits, TestPermissions, TestPriorityResourceCollectors, TestProjectHistory, TestProjects, TestProperty, TestPropertyDefinition, TestPropertyFile, TestPublishHistory, TestPublishing, TestPublishIssues, TestPublishManager, TestQueryProperties, TestReadResource, TestReadResourceTree, TestReplace, TestResourceFilter, TestResourceOperations, TestResponsibles, TestRestoreFromHistory, TestRoles, TestSecure, TestSiblings, TestSiteConfiguration, TestSubscriptionManager, TestSynchronize, TestTouch, TestUndelete, TestUndoChanges, TestUrlNameMapping, TestUser, TestWorkplace, TestXmlDocumentExtraction

public class OpenCmsTestCase
extends junit.framework.TestCase

Extends the JUnit standard with methods to handle an OpenCms database test instance.

The required configuration files are located in the ${test.data.path}/WEB-INF folder structure.

To run this test you might have to change the database connection values in the provided ${test.data.path}/WEB-INF/config/opencms.properties file.

Since:
6.0.0

Nested Class Summary
protected static class OpenCmsTestCase.ConnectionData
          Class to bundle the connection information.
 
Field Summary
static int ARTICLE_TYPEID
          test article type id constant.
static String DB_MYSQL
          Key for tests on MySql database.
static String DB_ORACLE
          Key for tests on Oracle database.
protected static OpenCmsTestCase.ConnectionData m_additionalConnection
          Additional connection data.
static CmsParameterConfiguration m_configuration
          The OpenCms/database configuration.
 OpenCmsTestResourceStorage m_currentResourceStrorage
          The current resource storage.
protected static OpenCmsTestCase.ConnectionData m_defaultConnection
          The user connection data.
static String m_defaultTablespace
          Name of the default tablespace (oracle only).
static String m_indexTablespace
          Name of the index tablespace (oracle only).
static HashMap<String,OpenCmsTestResourceStorage> m_resourceStorages
          The internal storages.
protected static OpenCmsTestCase.ConnectionData m_setupConnection
          The setup connection data.
static String m_tempTablespace
          Name of the temporary tablespace (oracle only).
 
Constructor Summary
OpenCmsTestCase(String arg0)
          Default JUnit constructor.
OpenCmsTestCase(String arg0, boolean initialize)
          JUnit constructor.
 
Method Summary
protected static void addTestDataPath(String dataPath)
          Adds an additional path to the list of test data configuration files.
 void assertAce(CmsObject cms, String resourceName, CmsAccessControlEntry ace)
          Compares an access control entry of a resource with a given access control entry.
 void assertAcl(CmsObject cms, String resourceName, CmsUUID principal, CmsPermissionSet permission)
          Compares an access control list of a resource with a given access control permission.
 void assertAcl(CmsObject cms, String modifiedResource, String resourceName, CmsUUID principal, CmsPermissionSet permission)
          Compares an access control list of a resource with a given access control permission.
 void assertContains(String content, String pattern)
          Tests if a pattern can be found in a content string.
 void assertContainsNot(String content, String pattern)
          Tests if a pattern cannot be found in a content string.
 void assertContent(CmsObject cms, String resourceName, byte[] content)
          Compares the current content of a (file) resource with a given content.
 void assertDateContent(CmsObject cms, String resourceName, long dateContent)
          Tests if the current content date of a resource is equals to the given date.
 void assertDateContentAfter(CmsObject cms, String resourceName, long dateContent)
          Tests if the the current date content of a resource is later than the given date.
 void assertDateCreated(CmsObject cms, String resourceName, long dateCreated)
          Compares the current date created of a resource with a given date.
 void assertDateCreatedAfter(CmsObject cms, String resourceName, long dateCreated)
          Tests if the the creation date of a resource is later then a given date.
 void assertDateExpired(CmsObject cms, String resourceName, long dateExpired)
          Compares the current expiration date of a resource with a given date.
 void assertDateLastModified(CmsObject cms, String resourceName, long dateLastModified)
          Compares the current date last modified of a resource with a given date.
 void assertDateLastModifiedAfter(CmsObject cms, String resourceName, long dateLastModified)
          Tests if the the current date last modified of a resource is later than the given date.
 void assertDateReleased(CmsObject cms, String resourceName, long dateReleased)
          Compares the current release date of a resource with a given date.
 void assertEquals(CmsException e1, CmsException e2)
          Tests if the given exceptions are equal (or both null).
 void assertEquals(CmsPublishJobBase j1, CmsPublishJobBase j2, boolean comparePublishLists, boolean compareTime)
          Tests if the given jobs are internally equal.
 void assertEquals(Document d1, Document d2)
          Tests if the given xml document objects are equals (or both null).
 void assertFilter(CmsObject cms, CmsResource resource, OpenCmsTestResourceFilter filter)
          Compares a given resource to its stored version containing the state before a CmsObject method was called.
 void assertFilter(CmsObject cms, OpenCmsTestResourceStorageEntry storedResource, CmsResource res, OpenCmsTestResourceFilter filter)
          Compares a stored Cms resource with another Cms resource instance using a specified filter.
 void assertFilter(CmsObject cms, String resourceName, OpenCmsTestResourceFilter filter)
          Compares a resource to its stored version containing the state before a CmsObject method was called.
 void assertFilter(CmsObject cms, String resourceName1, String resourceName2, OpenCmsTestResourceFilter filter)
          Compares a resource to another given resource using a specified filter.
 void assertFlags(CmsObject cms, String resourceName, int flag)
          Tests whether a resource has currently a specified flag set.
 void assertHistory(CmsObject cms, String resourcename, int versionCount)
          Checks if the given resource has the correct history count, also check if all entries in the history can be read.
 void assertHistoryForRestored(CmsObject cms, String resourcename, int versionCount)
          Checks if the given resource has the correct history count, also check if all entries in the history can be read.
 void assertIsFolder(CmsObject cms, String resourceName)
          Ensures that the given resource is a folder.
 void assertIsIdentical(Object o1, Object o2)
          Tests if the specified object is identical with another object.
 void assertIsNotIdentical(Object o1, Object o2)
          Tests if the specified object is not identical with another object.
 void assertLock(CmsObject cms, String resourceName)
          Validates if a specified resource is somehow locked to the current user.
 void assertLock(CmsObject cms, String resourceName, CmsLockType lockType)
          Validates if a specified resource has a lock of a given type for the current user.
 void assertLock(CmsObject cms, String resourceName, CmsLockType lockType, CmsUser user)
          Validates if a specified resource has a lock of a given type and is locked for a principal.
 void assertModifiedInCurrentProject(CmsObject cms, String resourceName, boolean shouldHaveRedFlag)
          Validates the project status of a resource, i.e.
 void assertPermissionString(CmsObject cms, String resourceName, I_CmsPrincipal principal, String permissionString)
          Asserts the given permission string with the access control entry for the given resource and principal.
 void assertProject(CmsObject cms, String resourceName, CmsProject project)
          Compares the current project of a resource with a given CmsProject.
 void assertPropertyChanged(CmsObject cms, String resourceName, CmsProperty property)
          Compares the current properties of a resource with the stored values and a given, changed property.
 void assertPropertyChanged(CmsObject cms, String resourceName, List<CmsProperty> excludeList)
          Compares the current properties of a resource with the stored values and a list of changed property.
 void assertPropertydefinitionExist(CmsObject cms, CmsPropertyDefinition propertyDefinition)
          Tests if a properetydefintion does exist.
 void assertPropertydefinitions(CmsObject cms, List<CmsPropertyDefinition> propertyDefintions, CmsPropertyDefinition exclude)
          Tests the list the propertydefinitions are identical to a given list except one exlclude propertydefintion.
 void assertPropertyEqual(CmsObject cms, String resourceName)
          Compares the current properties of a resource with the stored values.
 void assertPropertyNew(CmsObject cms, String resourceName, CmsProperty property)
          Compares the current properties of a resource with the stored values and a given, new property.
 void assertPropertyNew(CmsObject cms, String resourceName, List excludeList)
          Compares the current properties of a resource with the stored values and a list of new property.
 void assertPropertyRemoved(CmsObject cms, String resourceName, CmsProperty property)
          Compares the current properties of a resource with the stored values and a given, deleted property.
 void assertPropertyRemoved(CmsObject cms, String resourceName, List excludeList)
          Compares the current properties of a resource with the stored values and a list of deleted properties.
 void assertRelation(CmsRelation expected, CmsRelation actual)
          Asserts the equality of the two given relations.
 void assertResourceId(CmsObject cms, String resourceName, CmsUUID resourceId)
          Compares the current resource id of a resource with a given id.
 void assertResourceType(CmsObject cms, String resourceName, int resourceType)
          Ensures that the given resource is of a certain type.
 void assertSiblingCount(CmsObject cms, String resourceName, int count)
          Validates if the current sibling count of a resource matches the given number.
 void assertSiblingCountIncremented(CmsObject cms, String resourceName, int increment)
          Validates if the current sibling count of a resource has been incremented compared to it's previous sibling count.
 void assertState(CmsObject cms, String resourceName, CmsResourceState state)
          Compares the current state of a resource with a given state.
 void assertStructureId(CmsObject cms, String resourceName, CmsUUID structureId)
          Compares the current structure id of a resource with a given id.
 void assertType(CmsObject cms, String resourceName, int type)
          Compares the current type of a resource with a given type.
 void assertUserCreated(CmsObject cms, String resourceName, CmsUser user)
          Compares the user who created a resource with a given user.
 void assertUserLastModified(CmsObject cms, String resourceName, CmsUser user)
          Compares the current user last modified of a resource with a given user.
 void assertVersion(CmsObject cms, String resourceName, int version)
          Tests if the current version of a resource is equals to the given version number.
protected static void checkErrors(org.opencms.setup.CmsSetupDb setupDb)
          Check the setup DB for errors that might have occurred.
 void createStorage(String name)
          Creates a new storage object.
protected  void deleteFile(String absolutePath)
          Deletes the given file from the rfs.
protected  void echo(String message)
          Writes a message to the current output stream.
static int generateContent(CmsObject cms, String vfsFolder, int numberOfFiles, double fileTypeDistribution)
          Generates a sub tree of folders with files.
static int generateContent(CmsObject cms, String vfsFolder, int maxWidth, int maxDepth, int maxProps, double propertyDistribution, int maxNumberOfFiles, double fileTypeDistribution)
          Generates a sub tree of folders with files.
static String generateName(int maxLen)
          Generate a new random name.
static List<CmsProperty> generateProperties(CmsObject cms, int maxProps, int propValueLength, double propertyDistribution)
          Generates random properties.
static int generateResources(CmsObject cms, String rfsName, String vfsFolder, int n, int type, int maxProps, double propertyDistribution)
          Generates n new resources in a given folder.
static junit.framework.Test generateSetupTestWrapper(Class<? extends junit.framework.Test> testClass, String importFolder, String targetFolder)
          Generates a wrapper for a test class which handles setting up the OpenCms instance.
static void generateUsers(CmsObject cms, String groupName, int n)
          Generates n new users for a given group.
protected  CmsObject getCmsObject()
          Returns an initialized CmsObject with admin user permissions, running in the "/sites/default" site root.
 String getConnectionName()
          Should return the additional connection name.
 String getDatabaseProduct()
          Returns the name of the database product.
static String getDbProduct()
          Returns the currently used database/configuration.
 CmsResourceState getPreCalculatedState(String resourceName)
          Gets an precalculate resource state from the storage.
protected static Map<String,String> getReplacer(OpenCmsTestCase.ConnectionData connectionData)
          Returns an initialized replacer map.
protected static String getSetupDataPath()
          Returns the path to the data files used by the setup wizard.
protected static org.opencms.setup.CmsSetupDb getSetupDb(OpenCmsTestCase.ConnectionData connection)
          Returns an initialized DB setup object.
protected static String getTestDataPath(String filename)
          Returns the path to a file in the test data configuration, or null if the given file can not be found.
static void importData(String importFolder, String targetFolder)
          Does a database import from the given RFS folder to the given VFS folder.
protected static void importResources(CmsObject cms, String importFile, String targetPath)
          Imports a resource into the Cms.
protected static CmsResource importTestResource(CmsObject cms, String rfsPath, String vfsPath, int type, List<CmsProperty> properties)
          Imports a resource from the RFS test directories to the VFS.
static void initTestDataPath()
          Initializes the path to the test data configuration files using the default path.
protected static void removeDatabase()
          Removes the OpenCms database test instance.
protected static void removeDatabase(OpenCmsTestCase.ConnectionData setupConnection, OpenCmsTestCase.ConnectionData defaultConnection, boolean handleErrors)
          Removes the OpenCms database test instance.
static void removeOpenCms()
          Removes the initialized OpenCms database and all temporary files created during the test run.
protected  void removeStorage(String name)
          Removes and deletes a storage object.
 void resetMapping()
          Resets the mapping for resourcenames.
protected  void restart()
          Restarts the cms.
static void restartOpenCms()
          Restarts the OpenCms shell.
 void setMapping(String source, String target)
          Sets the mapping for resourcenames.
protected static void setupDatabase()
          Creates a new OpenCms test database including the tables.
protected static void setupDatabase(OpenCmsTestCase.ConnectionData setupConnection, OpenCmsTestCase.ConnectionData defaultConnection, boolean handleErrors)
          Creates a new OpenCms test database including the tables.
static CmsObject setupOpenCms(String importFolder, String targetFolder)
          Sets up a complete OpenCms instance with configuration from the config-ori folder, creating the usual projects, and importing a default database.
static CmsObject setupOpenCms(String importFolder, String targetFolder, boolean publish)
          Sets up a complete OpenCms instance with configuration from the config-ori folder, creating the usual projects, and importing a default database.
static CmsObject setupOpenCms(String importFolder, String targetFolder, String specialConfigFolder)
          Sets up a complete OpenCms instance with configuration from the config-ori folder, creating the usual projects, and importing a default database.
static CmsObject setupOpenCms(String importFolder, String targetFolder, String configFolder, boolean publish)
          Sets up a complete OpenCms instance, creating the usual projects, and importing a default database.
static CmsObject setupOpenCms(String importFolder, String targetFolder, String configFolder, String specialConfigFolder, boolean publish)
          Sets up a complete OpenCms instance, creating the usual projects, and importing a default database.
 void storeResources(CmsObject cms, String resourceName)
          Stores the state (e.g.
 void storeResources(CmsObject cms, String resourceName, boolean storeSubresources)
          Stores the state (e.g.
 void switchStorage(String name)
          Switches the internal resource storage.
 
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
 

Field Detail

ARTICLE_TYPEID

public static final int ARTICLE_TYPEID
test article type id constant.

See Also:
Constant Field Values

DB_MYSQL

public static final String DB_MYSQL
Key for tests on MySql database.

See Also:
Constant Field Values

DB_ORACLE

public static final String DB_ORACLE
Key for tests on Oracle database.

See Also:
Constant Field Values

m_configuration

public static CmsParameterConfiguration m_configuration
The OpenCms/database configuration.


m_defaultTablespace

public static String m_defaultTablespace
Name of the default tablespace (oracle only).


m_indexTablespace

public static String m_indexTablespace
Name of the index tablespace (oracle only).


m_resourceStorages

public static HashMap<String,OpenCmsTestResourceStorage> m_resourceStorages
The internal storages.


m_tempTablespace

public static String m_tempTablespace
Name of the temporary tablespace (oracle only).


m_additionalConnection

protected static OpenCmsTestCase.ConnectionData m_additionalConnection
Additional connection data.


m_defaultConnection

protected static OpenCmsTestCase.ConnectionData m_defaultConnection
The user connection data.


m_setupConnection

protected static OpenCmsTestCase.ConnectionData m_setupConnection
The setup connection data.


m_currentResourceStrorage

public OpenCmsTestResourceStorage m_currentResourceStrorage
The current resource storage.

Constructor Detail

OpenCmsTestCase

public OpenCmsTestCase(String arg0)
Default JUnit constructor.

Parameters:
arg0 - JUnit parameters

OpenCmsTestCase

public OpenCmsTestCase(String arg0,
                       boolean initialize)
JUnit constructor.

Parameters:
arg0 - JUnit parameters
initialize - indicates if the configuration will be initialized
Method Detail

generateContent

public static int generateContent(CmsObject cms,
                                  String vfsFolder,
                                  int numberOfFiles,
                                  double fileTypeDistribution)
                           throws Exception
Generates a sub tree of folders with files.

Parameters:
cms - the cms context
vfsFolder - name of the folder
numberOfFiles - the number of files to generate
fileTypeDistribution - a percentage: x% binary files and (1-x)% text files
Returns:
the number of files generated
Throws:
Exception - if something goes wrong

generateContent

public static int generateContent(CmsObject cms,
                                  String vfsFolder,
                                  int maxWidth,
                                  int maxDepth,
                                  int maxProps,
                                  double propertyDistribution,
                                  int maxNumberOfFiles,
                                  double fileTypeDistribution)
                           throws Exception
Generates a sub tree of folders with files.

Parameters:
cms - the cms context
vfsFolder - where to create the subtree
maxWidth - an upper bound for the number of subfolder a folder should have
maxDepth - an upper bound for depth of the genearted subtree
maxProps - upper bound for number of properties to create for each resource
propertyDistribution - a percentage: x% shared props and (1-x)% individuals props
maxNumberOfFiles - upper bound for the number of files in each folder
fileTypeDistribution - a percentage: x% binary files and (1-x)% text files
Returns:
the number of really written files
Throws:
Exception - if something goes wrong

generateName

public static String generateName(int maxLen)
Generate a new random name.

Parameters:
maxLen - upper bound for the length of the name
Returns:
a random name

generateProperties

public static List<CmsProperty> generateProperties(CmsObject cms,
                                                   int maxProps,
                                                   int propValueLength,
                                                   double propertyDistribution)
                                            throws CmsException
Generates random properties.

Parameters:
cms - the cms context
maxProps - upper bound for number of properties to create for each resource
propValueLength - upper bound for the number of char for the values
propertyDistribution - a percentage: x% shared props and (1-x)% individuals props
Returns:
a list of CmsProperty objects
Throws:
CmsException - if something goes wrong

generateResources

public static int generateResources(CmsObject cms,
                                    String rfsName,
                                    String vfsFolder,
                                    int n,
                                    int type,
                                    int maxProps,
                                    double propertyDistribution)
                             throws Exception
Generates n new resources in a given folder.

Parameters:
cms - the cms context
rfsName - the rfs file for the content
vfsFolder - the folder to create the resources in
n - number of resources to generate
type - the type of the resource
maxProps - upper bound for number of properties to create for each resource
propertyDistribution - a percentage: x% shared props and (1-x)% individuals props
Returns:
the number of really written files
Throws:
Exception - if something goes wrong

generateSetupTestWrapper

public static junit.framework.Test generateSetupTestWrapper(Class<? extends junit.framework.Test> testClass,
                                                            String importFolder,
                                                            String targetFolder)
Generates a wrapper for a test class which handles setting up the OpenCms instance.

Parameters:
testClass - the test class to wrap
importFolder - the RFS folder with the test data to import
targetFolder - the VFS target folder for the test data
Returns:
the wrapped test

generateUsers

public static void generateUsers(CmsObject cms,
                                 String groupName,
                                 int n)
                          throws CmsException
Generates n new users for a given group.

Parameters:
cms - the cms context
groupName - the group name, group will be creating if group does not exists
n - number of users to generate
Throws:
CmsException - if something goes wrong

getDbProduct

public static String getDbProduct()
Returns the currently used database/configuration.

Returns:
he currently used database/configuration

importData

public static void importData(String importFolder,
                              String targetFolder)
Does a database import from the given RFS folder to the given VFS folder.

Parameters:
importFolder - the RFS folder to import from
targetFolder - the VFS folder to import into

initTestDataPath

public static void initTestDataPath()
Initializes the path to the test data configuration files using the default path.


removeOpenCms

public static void removeOpenCms()
Removes the initialized OpenCms database and all temporary files created during the test run.


restartOpenCms

public static void restartOpenCms()
Restarts the OpenCms shell.


setupOpenCms

public static CmsObject setupOpenCms(String importFolder,
                                     String targetFolder)
Sets up a complete OpenCms instance with configuration from the config-ori folder, creating the usual projects, and importing a default database.

Parameters:
importFolder - the folder to import in the "real" FS
targetFolder - the target folder of the import in the VFS
Returns:
an initialized OpenCms context with "Admin" user in the "Offline" project with the site root set to "/"

setupOpenCms

public static CmsObject setupOpenCms(String importFolder,
                                     String targetFolder,
                                     boolean publish)
Sets up a complete OpenCms instance with configuration from the config-ori folder, creating the usual projects, and importing a default database.

Parameters:
importFolder - the folder to import in the "real" FS
targetFolder - the target folder of the import in the VFS
publish - flag to signalize if the publish script should be called
Returns:
an initialized OpenCms context with "Admin" user in the "Offline" project with the site root set to "/"

setupOpenCms

public static CmsObject setupOpenCms(String importFolder,
                                     String targetFolder,
                                     String specialConfigFolder)
Sets up a complete OpenCms instance with configuration from the config-ori folder, creating the usual projects, and importing a default database.

Parameters:
importFolder - the folder to import in the "real" FS
targetFolder - the target folder of the import in the VFS
specialConfigFolder - the folder that contains the special configuration files for this setup
Returns:
an initialized OpenCms context with "Admin" user in the "Offline" project with the site root set to "/"

setupOpenCms

public static CmsObject setupOpenCms(String importFolder,
                                     String targetFolder,
                                     String configFolder,
                                     boolean publish)
Sets up a complete OpenCms instance, creating the usual projects, and importing a default database.

Parameters:
importFolder - the folder to import in the "real" FS
targetFolder - the target folder of the import in the VFS
configFolder - the folder to copy the configuration files
publish - publish only if set
Returns:
an initialized OpenCms context with "Admin" user in the "Offline" project with the site root set to "/"

setupOpenCms

public static CmsObject setupOpenCms(String importFolder,
                                     String targetFolder,
                                     String configFolder,
                                     String specialConfigFolder,
                                     boolean publish)
Sets up a complete OpenCms instance, creating the usual projects, and importing a default database.

Parameters:
importFolder - the folder to import in the "real" FS
targetFolder - the target folder of the import in the VFS
configFolder - the folder to copy the standard configuration files from
specialConfigFolder - the folder that contains the special configuration fiiles for this setup
publish - publish only if set
Returns:
an initialized OpenCms context with "Admin" user in the "Offline" project with the site root set to "/"

addTestDataPath

protected static void addTestDataPath(String dataPath)
Adds an additional path to the list of test data configuration files.

Parameters:
dataPath - the path to add

checkErrors

protected static void checkErrors(org.opencms.setup.CmsSetupDb setupDb)
Check the setup DB for errors that might have occurred.

Parameters:
setupDb - the setup DB object to check

getReplacer

protected static Map<String,String> getReplacer(OpenCmsTestCase.ConnectionData connectionData)
Returns an initialized replacer map.

Parameters:
connectionData - the connection data to derive the replacer information
Returns:
an initialized replacer map

getSetupDataPath

protected static String getSetupDataPath()
Returns the path to the data files used by the setup wizard.

Whenever possible use this path to ensure that the files used for testing are actually the same as for the setup.

Returns:
the path to the data files used by the setup wizard

getSetupDb

protected static org.opencms.setup.CmsSetupDb getSetupDb(OpenCmsTestCase.ConnectionData connection)
Returns an initialized DB setup object.

Parameters:
connection - the connection data
Returns:
the initialized setup DB object

getTestDataPath

protected static String getTestDataPath(String filename)
Returns the path to a file in the test data configuration, or null if the given file can not be found.

This methods searches the given file in all configured test data paths. It returns the file found first.

Parameters:
filename - the file name to look up
Returns:
the path to a file in the test data configuration

importResources

protected static void importResources(CmsObject cms,
                                      String importFile,
                                      String targetPath)
                               throws CmsException
Imports a resource into the Cms.

Parameters:
cms - an initialized CmsObject
importFile - the name (absolute Path) of the import resource (zip or folder)
targetPath - the name (absolute Path) of the target folder in the VFS
Throws:
CmsException - if something goes wrong

importTestResource

protected static CmsResource importTestResource(CmsObject cms,
                                                String rfsPath,
                                                String vfsPath,
                                                int type,
                                                List<CmsProperty> properties)
                                         throws Exception
Imports a resource from the RFS test directories to the VFS.

The imported resource will be automatically unlocked.

Parameters:
cms - the current users OpenCms context
rfsPath - the RTF path of the resource to import, must be a path accessibly by the current class loader
vfsPath - the VFS path for the imported resource
type - the type for the imported resource
properties - the properties for the imported resource
Returns:
the imported resource
Throws:
Exception - if the import fails

removeDatabase

protected static void removeDatabase()
Removes the OpenCms database test instance.


removeDatabase

protected static void removeDatabase(OpenCmsTestCase.ConnectionData setupConnection,
                                     OpenCmsTestCase.ConnectionData defaultConnection,
                                     boolean handleErrors)
Removes the OpenCms database test instance.

Parameters:
setupConnection - the setup connection
defaultConnection - the default connection
handleErrors - flag to indicate if errors should be handled/checked

setupDatabase

protected static void setupDatabase()
Creates a new OpenCms test database including the tables.

Any existing instance of the test database is forcefully removed first.


setupDatabase

protected static void setupDatabase(OpenCmsTestCase.ConnectionData setupConnection,
                                    OpenCmsTestCase.ConnectionData defaultConnection,
                                    boolean handleErrors)
Creates a new OpenCms test database including the tables.

Parameters:
setupConnection - the setup connection
defaultConnection - the default connection
handleErrors - flag to indicate if errors should be handled/checked

assertAce

public void assertAce(CmsObject cms,
                      String resourceName,
                      CmsAccessControlEntry ace)
Compares an access control entry of a resource with a given access control entry.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
ace - the access control entry to compare or null if to compare with the stored values

assertAcl

public void assertAcl(CmsObject cms,
                      String resourceName,
                      CmsUUID principal,
                      CmsPermissionSet permission)
Compares an access control list of a resource with a given access control permission.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
principal - the principal of the permission set or null if to compare with the stored values
permission - the permission set to compare

assertAcl

public void assertAcl(CmsObject cms,
                      String modifiedResource,
                      String resourceName,
                      CmsUUID principal,
                      CmsPermissionSet permission)
Compares an access control list of a resource with a given access control permission.

Parameters:
cms - the CmsObject
modifiedResource - the name of the which had its permissions changed
resourceName - the name of the resource to compare
principal - the principal of the permission set or null if to compare with the stored values
permission - the permission set to compare

assertContains

public void assertContains(String content,
                           String pattern)
Tests if a pattern can be found in a content string.

Fails if the pattern is not found.

Parameters:
content - the content string
pattern - the pattern to search for

assertContainsNot

public void assertContainsNot(String content,
                              String pattern)
Tests if a pattern cannot be found in a content string.

Fails if the pattern is found.

Parameters:
content - the content string
pattern - the pattern to search for

assertContent

public void assertContent(CmsObject cms,
                          String resourceName,
                          byte[] content)
Compares the current content of a (file) resource with a given content.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
content - the content to compare

assertDateContent

public void assertDateContent(CmsObject cms,
                              String resourceName,
                              long dateContent)
Tests if the current content date of a resource is equals to the given date.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
dateContent - the content date

assertDateContentAfter

public void assertDateContentAfter(CmsObject cms,
                                   String resourceName,
                                   long dateContent)
Tests if the the current date content of a resource is later than the given date.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
dateContent - the content date

assertDateCreated

public void assertDateCreated(CmsObject cms,
                              String resourceName,
                              long dateCreated)
Compares the current date created of a resource with a given date.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
dateCreated - the creation date

assertDateCreatedAfter

public void assertDateCreatedAfter(CmsObject cms,
                                   String resourceName,
                                   long dateCreated)
Tests if the the creation date of a resource is later then a given date.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
dateCreated - the creation date

assertDateExpired

public void assertDateExpired(CmsObject cms,
                              String resourceName,
                              long dateExpired)
Compares the current expiration date of a resource with a given date.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
dateExpired - the expiration date

assertDateLastModified

public void assertDateLastModified(CmsObject cms,
                                   String resourceName,
                                   long dateLastModified)
Compares the current date last modified of a resource with a given date.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
dateLastModified - the last modification date

assertDateLastModifiedAfter

public void assertDateLastModifiedAfter(CmsObject cms,
                                        String resourceName,
                                        long dateLastModified)
Tests if the the current date last modified of a resource is later than the given date.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
dateLastModified - the last modification date

assertDateReleased

public void assertDateReleased(CmsObject cms,
                               String resourceName,
                               long dateReleased)
Compares the current release date of a resource with a given date.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
dateReleased - the release date

assertEquals

public void assertEquals(CmsException e1,
                         CmsException e2)
Tests if the given exceptions are equal (or both null).

Parameters:
e1 - first exception to compare
e2 - second exception to compare

assertEquals

public void assertEquals(CmsPublishJobBase j1,
                         CmsPublishJobBase j2,
                         boolean comparePublishLists,
                         boolean compareTime)
Tests if the given jobs are internally equal.

(May have different wrapper classes)

Parameters:
j1 - first job to compare
j2 - second job to compare
comparePublishLists - if the publish lists should be compared, too
compareTime - if the timestamps should be compared, too

assertEquals

public void assertEquals(Document d1,
                         Document d2)
Tests if the given xml document objects are equals (or both null).

Parameters:
d1 - first document to compare
d2 - second document to compare

assertFilter

public void assertFilter(CmsObject cms,
                         CmsResource resource,
                         OpenCmsTestResourceFilter filter)
Compares a given resource to its stored version containing the state before a CmsObject method was called.

Parameters:
cms - the CmsObject
resource - the resource to compare
filter - the filter contianing the flags defining which attributes to compare

assertFilter

public void assertFilter(CmsObject cms,
                         OpenCmsTestResourceStorageEntry storedResource,
                         CmsResource res,
                         OpenCmsTestResourceFilter filter)
Compares a stored Cms resource with another Cms resource instance using a specified filter.

Parameters:
cms - the current user's Cms object
storedResource - a stored Cms resource representing the state before an operation
res - a Cms resource representing the state after an operation
filter - a filter to compare both resources

assertFilter

public void assertFilter(CmsObject cms,
                         String resourceName,
                         OpenCmsTestResourceFilter filter)
                  throws CmsException
Compares a resource to its stored version containing the state before a CmsObject method was called.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
filter - the filter contianing the flags defining which attributes to compare
Throws:
CmsException - if something goes wrong

assertFilter

public void assertFilter(CmsObject cms,
                         String resourceName1,
                         String resourceName2,
                         OpenCmsTestResourceFilter filter)
Compares a resource to another given resource using a specified filter.

Parameters:
cms - the current user's Cms object
resourceName1 - resource #1
resourceName2 - resource #2
filter - the filter contianing the flags defining which attributes to compare

assertFlags

public void assertFlags(CmsObject cms,
                        String resourceName,
                        int flag)
Tests whether a resource has currently a specified flag set.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
flag - a flag to check

assertHistory

public void assertHistory(CmsObject cms,
                          String resourcename,
                          int versionCount)
                   throws Exception
Checks if the given resource has the correct history count, also check if all entries in the history can be read.

Parameters:
cms - the current user OpenCms context
resourcename - the name of the resource to check the history for
versionCount - the expected version number of the resource
Throws:
Exception - if the test fails

assertHistoryForRestored

public void assertHistoryForRestored(CmsObject cms,
                                     String resourcename,
                                     int versionCount)
                              throws Exception
Checks if the given resource has the correct history count, also check if all entries in the history can be read.

Use this method only for resources that has been restored.

Parameters:
cms - the current user OpenCms context
resourcename - the name of the resource to check the history for
versionCount - the expected version number of the resource
Throws:
Exception - if the test fails

assertIsFolder

public void assertIsFolder(CmsObject cms,
                           String resourceName)
Ensures that the given resource is a folder.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to check for a folder

assertIsIdentical

public void assertIsIdentical(Object o1,
                              Object o2)
Tests if the specified object is identical with another object.

Parameters:
o1 - an object
o2 - another object

assertIsNotIdentical

public void assertIsNotIdentical(Object o1,
                                 Object o2)
Tests if the specified object is not identical with another object.

Parameters:
o1 - an object
o2 - another object

assertLock

public void assertLock(CmsObject cms,
                       String resourceName)
Validates if a specified resource is somehow locked to the current user.

Parameters:
cms - the current user's Cms object
resourceName - the name of the resource to validate

assertLock

public void assertLock(CmsObject cms,
                       String resourceName,
                       CmsLockType lockType)
Validates if a specified resource has a lock of a given type for the current user.

Parameters:
cms - the current user's Cms object
resourceName - the name of the resource to validate
lockType - the type of the lock
See Also:
CmsLockType

assertLock

public void assertLock(CmsObject cms,
                       String resourceName,
                       CmsLockType lockType,
                       CmsUser user)
Validates if a specified resource has a lock of a given type and is locked for a principal.

Parameters:
cms - the current user's Cms object
resourceName - the name of the resource to validate
lockType - the type of the lock
user - the user to check the lock with
See Also:
CmsLockType

assertModifiedInCurrentProject

public void assertModifiedInCurrentProject(CmsObject cms,
                                           String resourceName,
                                           boolean shouldHaveRedFlag)
Validates the project status of a resource, i.e. if a resource has a "red flag" or not.

Parameters:
cms - the current user's Cms object
resourceName - the name of the resource to validate
shouldHaveRedFlag - true, if the resource should currently have a red flag

assertPermissionString

public void assertPermissionString(CmsObject cms,
                                   String resourceName,
                                   I_CmsPrincipal principal,
                                   String permissionString)
                            throws CmsException
Asserts the given permission string with the access control entry for the given resource and principal.

Parameters:
cms - the cms object
resourceName - the resource name
principal - the principal
permissionString - the permission string to compare
Throws:
CmsException - if something goes wrong

assertProject

public void assertProject(CmsObject cms,
                          String resourceName,
                          CmsProject project)
Compares the current project of a resource with a given CmsProject.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
project - the project

assertPropertyChanged

public void assertPropertyChanged(CmsObject cms,
                                  String resourceName,
                                  CmsProperty property)
Compares the current properties of a resource with the stored values and a given, changed property.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
property - the changed property

assertPropertyChanged

public void assertPropertyChanged(CmsObject cms,
                                  String resourceName,
                                  List<CmsProperty> excludeList)
Compares the current properties of a resource with the stored values and a list of changed property.

Parameters:
cms - an initialized CmsObject
resourceName - the name of the resource to compare
excludeList - a list of CmsProperties to exclude

assertPropertydefinitionExist

public void assertPropertydefinitionExist(CmsObject cms,
                                          CmsPropertyDefinition propertyDefinition)
Tests if a properetydefintion does exist.

Parameters:
cms - the CmsObject
propertyDefinition - the propertsdefinition

assertPropertydefinitions

public void assertPropertydefinitions(CmsObject cms,
                                      List<CmsPropertyDefinition> propertyDefintions,
                                      CmsPropertyDefinition exclude)
Tests the list the propertydefinitions are identical to a given list except one exlclude propertydefintion.

Parameters:
cms - the CmsObject
propertyDefintions - the list of propertydefintions
exclude - the exclude propertydefinition

assertPropertyEqual

public void assertPropertyEqual(CmsObject cms,
                                String resourceName)
Compares the current properties of a resource with the stored values.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare

assertPropertyNew

public void assertPropertyNew(CmsObject cms,
                              String resourceName,
                              CmsProperty property)
Compares the current properties of a resource with the stored values and a given, new property.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
property - the changed property

assertPropertyNew

public void assertPropertyNew(CmsObject cms,
                              String resourceName,
                              List excludeList)
Compares the current properties of a resource with the stored values and a list of new property.

Parameters:
cms - an initialized CmsObject
resourceName - the name of the resource to compare
excludeList - a list of CmsProperties to exclude

assertPropertyRemoved

public void assertPropertyRemoved(CmsObject cms,
                                  String resourceName,
                                  CmsProperty property)
Compares the current properties of a resource with the stored values and a given, deleted property.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
property - the deleted property

assertPropertyRemoved

public void assertPropertyRemoved(CmsObject cms,
                                  String resourceName,
                                  List excludeList)
Compares the current properties of a resource with the stored values and a list of deleted properties.

Parameters:
cms - an initialized CmsObject
resourceName - the name of the resource to compare
excludeList - a list of CmsProperties to exclude

assertRelation

public void assertRelation(CmsRelation expected,
                           CmsRelation actual)
Asserts the equality of the two given relations.

Parameters:
expected - the expected relation
actual - the actual result

assertResourceId

public void assertResourceId(CmsObject cms,
                             String resourceName,
                             CmsUUID resourceId)
Compares the current resource id of a resource with a given id.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
resourceId - the id

assertResourceType

public void assertResourceType(CmsObject cms,
                               String resourceName,
                               int resourceType)
Ensures that the given resource is of a certain type.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to check
resourceType - the resource type to check for

assertSiblingCount

public void assertSiblingCount(CmsObject cms,
                               String resourceName,
                               int count)
Validates if the current sibling count of a resource matches the given number.

Parameters:
cms - the current user's Cms object
resourceName - the name of the resource to compare
count - the number of additional siblings

assertSiblingCountIncremented

public void assertSiblingCountIncremented(CmsObject cms,
                                          String resourceName,
                                          int increment)
Validates if the current sibling count of a resource has been incremented compared to it's previous sibling count.

Parameters:
cms - the current user's Cms object
resourceName - the name of the resource to compare
increment - the number of additional siblings compared to the original state

assertState

public void assertState(CmsObject cms,
                        String resourceName,
                        CmsResourceState state)
Compares the current state of a resource with a given state.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
state - the state

assertStructureId

public void assertStructureId(CmsObject cms,
                              String resourceName,
                              CmsUUID structureId)
Compares the current structure id of a resource with a given id.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
structureId - the id

assertType

public void assertType(CmsObject cms,
                       String resourceName,
                       int type)
Compares the current type of a resource with a given type.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
type - the type

assertUserCreated

public void assertUserCreated(CmsObject cms,
                              String resourceName,
                              CmsUser user)
Compares the user who created a resource with a given user.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
user - the last modification user

assertUserLastModified

public void assertUserLastModified(CmsObject cms,
                                   String resourceName,
                                   CmsUser user)
Compares the current user last modified of a resource with a given user.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
user - the last modification user

assertVersion

public void assertVersion(CmsObject cms,
                          String resourceName,
                          int version)
Tests if the current version of a resource is equals to the given version number.

Parameters:
cms - the CmsObject
resourceName - the name of the resource to compare
version - the version number to check

createStorage

public void createStorage(String name)
Creates a new storage object.

Parameters:
name - the name of the storage

getConnectionName

public String getConnectionName()
Should return the additional connection name.

Returns:
the name of the additional connection

getDatabaseProduct

public String getDatabaseProduct()
Returns the name of the database product.

Returns:
returns either oracle or mysql

getPreCalculatedState

public CmsResourceState getPreCalculatedState(String resourceName)
                                       throws Exception
Gets an precalculate resource state from the storage.

Parameters:
resourceName - the name of the resource to get the state
Returns:
precalculated resource state
Throws:
Exception - in case something goes wrong

resetMapping

public void resetMapping()
Resets the mapping for resourcenames.


setMapping

public void setMapping(String source,
                       String target)
Sets the mapping for resourcenames.

Parameters:
source - the source resource name
target - the target resource name

storeResources

public void storeResources(CmsObject cms,
                           String resourceName)
Stores the state (e.g. attributes, properties, content, lock state and ACL) of a resource in the internal resource storage.

If the resourceName is the name of a folder in the vfs, all subresoruces are stored as well.

Parameters:
cms - an initialized CmsObject
resourceName - the name of the resource in the vfs

storeResources

public void storeResources(CmsObject cms,
                           String resourceName,
                           boolean storeSubresources)
Stores the state (e.g. attributes, properties, content, lock state and ACL) of a resource in the internal resource storage.

If the resourceName is the name of a folder in the vfs and storeSubresources is true, all subresoruces are stored as well.

Parameters:
cms - an initialized CmsObject
resourceName - the name of the resource in the vfs
storeSubresources - indicates to store subresources of folders

switchStorage

public void switchStorage(String name)
                   throws CmsException
Switches the internal resource storage.

Parameters:
name - the name of the storage
Throws:
CmsException - if the storage was not found

deleteFile

protected void deleteFile(String absolutePath)
Deletes the given file from the rfs.

Parameters:
absolutePath - the absolute path of the file

echo

protected void echo(String message)
Writes a message to the current output stream.

Parameters:
message - the message to write

getCmsObject

protected CmsObject getCmsObject()
                          throws CmsException
Returns an initialized CmsObject with admin user permissions, running in the "/sites/default" site root.

Returns:
an initialized CmsObject with admin user permissions
Throws:
CmsException - in case of OpenCms access errors

removeStorage

protected void removeStorage(String name)
Removes and deletes a storage object.

Parameters:
name - the name of the storage

restart

protected void restart()
Restarts the cms.