Class JcmsTestCaseUtil
- java.lang.Object
-
- com.jalios.jcms.test.JcmsTestCaseUtil
-
- All Implemented Interfaces:
JcmsConstants
,JaliosConstants
public abstract class JcmsTestCaseUtil extends java.lang.Object implements JcmsConstants
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
A_VERY_LONG_TEXT
static long
ASYNC_TEST__ITERATION_WAIT_TIME
static long
ASYNC_TEST__MAX_ITERATION
static long
ASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILURE
static java.lang.String
MEMBER_DEFAULT_PWD
Convenient one-time crypted password as a constant, since each crypt operation takes some milliseconds.static java.lang.String
MEMBER_DEFAULT_PWD_VALUE
Default Member password clear value.-
Fields inherited from interface com.jalios.util.JaliosConstants
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
-
Fields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, ADMIN_NOTES_PROP, ADVANCED_TAB, AJAX_MODE_ATTR, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, CLASS_PROPERTY, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, COUNTRY_SPRITE, CS_TYPOLOGY_ROOT_CAT_VID, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DEFAULT_PHOTO_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, GLYPH_ICON_PREFIX, ICON_ARCHIVE, ICON_ICON_PREFIX, ICON_LOCK, ICON_LOCK_STRONG, ICON_PREFIX_PROP, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, IS_IN_FRONT_OFFICE, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JCMS_TOASTR_COLLECTION, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LANG_SPRITE, LOG_FILE, LOG_TOPIC_SECURITY, LOGGER_PROP, LOGGER_XMLPROP, MBR_PHOTO_DIR, MDATE_SEARCH, MONITOR_XML, OP_CREATE, OP_CREATE_STR, OP_DEEP_COPY, OP_DEEP_COPY_STR, OP_DEEP_DELETE, OP_DEEP_DELETE_STR, OP_DELETE, OP_DELETE_STR, OP_MERGE, OP_MERGE_STR, OP_UPDATE, OP_UPDATE_STR, ORGANIZATION_ROOT_GROUP_PROP, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_PROP_PREFIX, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_PROP_PREFIX, PHOTO_LARGE_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_PROP_PREFIX, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_PROP_PREFIX, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_PROP_PREFIX, PHOTO_TINY_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, RAW_CONTENT_ICON_PREFIX, READ_RIGHT_TAB, REVISION, SDATE_SEARCH, SEARCHENGINE_ALARM, SECURITY_LOG_FILE, SESSION_AUTHORIZED_FILENAMES_SET, SPRITE_ICON_PREFIX, STATS_REPORT_DIR, STATUS_PROP, STORE_XML, SUCCESS_MSG, SVG_ICON_PREFIX, SVGINLINE_ICON_PREFIX, TEMPLATE_TAB, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, TTCARD_MEDIA_HEIGHT, TTCARD_MEDIA_WIDTH, TYPES_ICON_ALT_PROP, TYPES_ICON_SUFFIX_PROP, TYPES_ICON_TITLE_PROP, TYPES_PREFIX_PROP, TYPES_THUMB_SUFFIX_PROP, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, UPLOAD_PERMISSION_COUNT_PROP_PREFIX, UPLOAD_PERMISSION_SIZE_PROP_PREFIX, URL_REGEXP, VID_LOGGED_MEMBER, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML
-
-
Constructor Summary
Constructors Constructor Description JcmsTestCaseUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addMemberInGroupTx(Group group, java.lang.String memberId)
Checks and performs update given Member by adding him in given Group.static void
addParentGroupTx(Group group, Group parentGroup)
Add given parent Group on given Group.static java.util.Set<Group>
addReadRights(Publication pub, Group... groups)
Convenient method to add read right Groups on given publication.static java.util.Set<Member>
addReadRights(Publication pub, Member... members)
Convenient method to add read right Members on given publication.static void
assertNotSameData(Data expectedData, Data actualData)
Assert 2 datas are not the same.static void
assertNotSameData(java.lang.String message, Data expectedData, Data actualData)
Assert 2 datas are not the same.static void
assertSameData(Data expectedData, Data actualData)
Assert 2 datas are the same.static void
assertSameData(java.lang.String message, boolean expectedSameData, Data expectedData, Data actualData)
Assert 2 datas are or are not the same.static void
assertSameData(java.lang.String message, Data expectedData, Data actualData)
Assert 2 datas are the same.static <T> java.util.HashSet<T>
asSet(T... array)
Convenient shorthand forUtil.getHashSet(Object...)
.static void
beginTransaction()
static <T extends Data>
java.lang.StringcheckAndCreate(T data, java.util.function.Consumer<T> beforePerformConsumer)
Delegates tocheckAndCreate(Data, Consumer, Member)
with data's author as create opAuthor.static <T extends Data>
java.lang.StringcheckAndCreate(T data, java.util.function.Consumer<T> beforePerformConsumer, Member opAuthor)
Checks and creates the given data instance.static void
checkAndDelete(Data data, Member opAuthor)
static void
checkAndDeleteTx(java.lang.String dataId)
static void
checkAndDeleteTx(java.lang.String dataId, java.lang.String opAuthorId)
static <T extends Data>
voidcheckAndUpdate(T data)
Checks and performs update of given data update instance.static <T extends Data>
voidcheckAndUpdate(T data, java.util.function.Consumer<T> beforePerformConsumer)
Delegates tocheckAndUpdate(Data, Consumer, Member)
with data's author as update opAuthor, or default admin as update opAuthor if data author is null.static <T extends Data>
voidcheckAndUpdate(T data, java.util.function.Consumer<T> beforePerformConsumer, Member opAuthor)
Checks and updates the given data instance.static <T extends Data>
voidcheckAndUpdateTx(java.lang.String dataId, java.util.function.Consumer<T> beforePerformConsumer)
static <T extends Data>
voidcheckAndUpdateTx(java.lang.String dataId, java.util.function.Consumer<T> beforePerformConsumer, java.lang.String opAuthorId)
static void
commitTransaction()
static void
configureLoggerAppender(org.apache.log4j.Logger logger)
static Group
createACLGroup(java.lang.String resource)
static generated.Article
createArticle(Member writer, Workspace ws, boolean deleteOnTearDown)
static Category
createCategory(java.lang.String name, Category parent)
static DBFileDocument
createDBFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
static DBMember
createDBMember(java.lang.String name)
static DBMember
createDBMember(java.lang.String name, boolean deleteOnTearDown)
static DBMember
createDBMember(java.lang.String name, boolean deleteOnTearDown, Group... groups)
static DBMember
createDBMember(java.lang.String name, Group... groups)
static java.lang.String
createDBMemberTx(java.lang.String name)
Creates a DB member in a dedicated transaction.static java.lang.String
createDBMemberTx(java.lang.String name, Group... groups)
Creates a DB member in a dedicated transaction.static void
createFile(java.io.File file, java.lang.String content)
static java.lang.String
createFile(java.lang.String filename)
static FileDocument
createFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
static Group
createGroupTx(java.lang.String name)
Creates a new group inside a new transaction that is commited at the end of process.static Group
createGroupTx(java.lang.String name, java.util.Collection<Group> parentGroups)
Creates a new group inside a new transaction that is commited at the end of process.static generated.Media
createMedia(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
static Member
createMember(java.lang.String name)
static Member
createMember(java.lang.String name, boolean deleteOnTearDown)
static Member
createMember(java.lang.String name, boolean deleteOnTearDown, Group... groups)
static Member
createMember(java.lang.String name, Group... groups)
static java.lang.String
createMemberTx(java.lang.String name)
Creates a JStore member in a dedicated transaction.static AbstractShortcut
createShortcut(Publication pub, Member writer, Workspace ws, boolean deleteOnTearDown)
static AbstractShortcut
createShortcut(java.lang.String link, Member writer, Workspace ws, boolean deleteOnTearDown)
static generated.SmallNews
createSmallNews(Member writer, Workspace ws, boolean deleteOnTearDown)
static void
createWorkspace(Workspace workspace)
Utility method to create the given Workspace by admin Member.static void
createWorkspace(Workspace workspace, Member author)
Utility method to create the given Workspace by admin Member.static java.lang.String
dataToDebugString(Data data)
Produces a String representation of given Data for debug, log purpose.static void
deleteAll(java.lang.Class<? extends DBData> dbDataClazz)
static void
deleteAllAlerts()
static void
deleteAllAlerts(Member mbr)
Delete all alerts for given Member in a dedicated transaction.static void
deleteAllAlertsTx(java.lang.String mid)
Delete all alerts for Member with given id in a dedicated transaction.static void
deleteData(Data... array)
static void
deleteData(java.lang.String... ids)
static void
deleteOnTearDown(Data data)
Adds given Data in list of Data to be deleted on test's tearDown.static void
deleteOnTearDown(Workspace ws, java.util.Set<Data> initialDataSet)
Deletes on tear down the workspace, and all its Datas, but not those contained in optional initialDataSet.
The initialDataSet should be initialized before the Workspace was created, using for example :static void
deleteOnTearDown(java.lang.String id)
Adds given Data's id in list of Data to be deleted on test's tearDown.static java.lang.Object
deserialize(java.io.File file)
Deserialize the given file into a new object which is returned.static void
disableJSync()
Disable JSync in Junit prop.static void
disableLdap()
Disable LDAP in Junit prop.static void
enableJSync()
Enable JSync in Junit prop.static void
enableLdap()
Enable LDAP in Junit prop.static void
enableVerboseForbidden()
Enabled LevelLevel.ALL
on several classes to help diagnose a FORBIDDEN operation (it is probably be logged in trace or debug level).static generated.Article
getArticle(Member writer, Workspace ws)
static java.lang.String
getControllerStatusDebugString(ControllerStatus actualStatus)
static DBFileDocument
getDBFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
static FileDocument
getFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
static generated.Media
getMedia(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
static javax.servlet.http.HttpServletRequest
getMockHttpServletRequest()
Convenient Method to return a new instance of a fake http servlet request.static javax.servlet.http.HttpServletRequest
getMockHttpServletRequest(javax.servlet.http.HttpSession session)
Convenient Method to return a new instance of a fake http servlet request using the specified mock sessionstatic javax.servlet.http.HttpServletResponse
getMockHttpServletResponse()
Convenient Method to return a new instance of a fake http servlet response.static javax.servlet.http.HttpServletResponse
getMockHttpServletResponse(javax.servlet.http.HttpSession session)
Convenient Method to return a new instance of a fake http servlet response using the specified mock sessionstatic javax.servlet.http.HttpSession
getMockHttpSession()
Convenient Method to return a new instance of a fake http session.static JcmsJspContext
getMockJcmsJspContext()
Retrieve a mock explorer JcmsJspContext.static JcmsJspContext
getMockJcmsJspContext(javax.servlet.http.HttpServletRequest request)
Retrieve a mock explorer JcmsJspContext based on the specified requeststatic javax.servlet.ServletContext
getMockServletContext()
Convenient Method to return the fake servlet context used for this JCMS test.static java.io.File
getResourceFile(java.lang.Class<?> clazz, java.lang.String name)
Retrieves a new File instance pointing to the specified resource name.static AbstractShortcut
getShortcut(Member writer, Workspace ws)
static AbstractShortcut
getShortcut(Publication pub, Member writer, Workspace ws)
static AbstractShortcut
getShortcut(java.lang.String link, Member writer, Workspace ws)
protected static generated.SmallNews
getSmallNews(Member writer, Workspace ws, boolean insertDateInContent)
static java.util.Set<Data>
getWorkspaceDeleteOnTearDownSet(Workspace ws, java.util.Set<Data> initialDataSet)
Returns a collection of Datas (bound to the Workspace) that have been created since the workspace creation.static boolean
ignoreUnstableTest()
static void
logC3P0Data()
Retrieve current C3P0 information from JXM and log them.static void
publishPublicationTransaction(java.lang.String pubId, Member opAuthor)
Delegates toupdatePstatusTransaction(String, Member, int)
using pstatusWorkflowConstants.PUBLISHED_PSTATUS
.static void
removeMemberFromGroupTx(Group group, java.lang.String memberId)
Checks and performs update given Member by removing hime from given Group.static void
restoreAuthenticationRequired()
Restores property "channel.is-authentication-required".static void
restoreGuestAccountsEnabled()
Resets forcedChannel.isGuestAccountsEnabled()
.static void
restoreIncomingMail()
Restores property "mail.incoming.enabled".static void
restoreProperties(JProperties properties)
Restores given JProperties.static void
restoreProperties(java.util.Collection<java.lang.String> names)
Restores given properties represented by their names.static void
restoreProperty(java.lang.String name)
Restores given property.static void
restoreReadRightsGroups(Publication pub, java.util.Collection<Group> initialAuthorizedGroups)
static void
restoreReadRightsMembers(Publication pub, java.util.Collection<Member> initialAuthorizedMembers)
static void
restoreRootLogger(org.apache.log4j.Logger rootLogger, org.apache.log4j.Level level)
Restores given level (backup before modification) on logger if both not null.static java.io.File
serialize(java.lang.Object obj)
Serialize the given object into a temp file and return this file.static void
setAuthenticationRequired(boolean isAuthRequired)
Sets property "channel.is-authentication-required" toisAuthRequired
.static void
setGuestAccountsEnabled(boolean enabled)
ForcesChannel.isGuestAccountsEnabled()
to return given value.static void
setIncomingMail(boolean enabled)
Sets property "mail.incoming.enabled" toenabled
.static void
setLogLevel(java.lang.String packageOrClass, org.apache.log4j.Level level)
static void
setProperties(JProperties properties)
Sets given JProperties.static void
setProperties(java.util.Map<java.lang.String,java.lang.String> map)
static void
setProperty(java.lang.String name, java.lang.String value)
static org.apache.log4j.Logger
setupRootLogger()
Configures the root logger (adds a console appender, seeBasicConfigurator.configure()
) if it has no appender defined yet (seeUtil.hasAppenderDefined(Logger)
).static org.apache.log4j.Logger
setupRootLogger(org.apache.log4j.Level level)
First, setups root logger.static void
sleep(long millis)
static void
updateMemberEmailTransaction(java.lang.String mid, java.lang.String authorMid, java.lang.String emailAddress)
Checks and performs update given Member with given email address.static void
updatePstatusTransaction(java.lang.String pubId, Member opAuthor, int newPstatus)
Checks and performs update the publication (makes an update instance) with given pstatus.static void
updateTitleTransaction(java.lang.String pubId, Member opAuthor, java.lang.String newTitle)
Checks and performs update the publication (makes an update instance) with given title.static void
updateWorkspaceTypeWorkflow(Workspace ws, java.lang.Class<? extends Data> typeClass, java.lang.Object workflowToUse)
An utility method to update the given Workspace, with the chosen Workflow associated to the given Type.static void
updateWorkspaceTypeWorkflow(Workspace ws, java.util.HashMap<java.lang.Class<?>,java.lang.Object> subTypeMap)
An utility method to update the given Workspace typeMap.static java.lang.String
voteForPubTransaction(java.lang.String pubId, java.lang.String voterId)
Adds a 1 point vote on given pub by given member.static void
waitForAlarm(long time, AlarmManager alarmMgr, boolean reallyWaitFor, java.lang.String logPrefix)
static void
waitForDBTimePrecision()
wait 1 ms if the DB support time with ms precision, otherwise 1 sstatic void
waitForFileAvailability(java.io.File file)
static void
waitForLuceneIndexation(boolean checkFileContentIndexing, Publication... pubs)
static void
waitForLuceneIndexation(Publication... pubs)
Wait for the specified publication(s) to be indexed in all the lucene publication index in its current version as returned byPublication.getVersionString()
.static void
waitForMemberLuceneIndexation(Member... mbrs)
Wait for the specified Members(s) to be indexed in the lucene member index in its current mdate as returned byBasicStorable.getMdate()
.static void
waitForMemberLuceneIndexation(java.lang.String... ids)
Wait for the specified Members(s) to be indexed in the lucene member index in its current mdate as returned byBasicStorable.getMdate()
.
-
-
-
Field Detail
-
A_VERY_LONG_TEXT
public static java.lang.String A_VERY_LONG_TEXT
-
ASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILURE
public static long ASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILURE
-
ASYNC_TEST__ITERATION_WAIT_TIME
public static long ASYNC_TEST__ITERATION_WAIT_TIME
-
ASYNC_TEST__MAX_ITERATION
public static long ASYNC_TEST__MAX_ITERATION
-
MEMBER_DEFAULT_PWD_VALUE
public static final java.lang.String MEMBER_DEFAULT_PWD_VALUE
Default Member password clear value.- Since:
- jcms-10.0.7 JCMS-9172
- See Also:
- Constant Field Values
-
MEMBER_DEFAULT_PWD
public static final java.lang.String MEMBER_DEFAULT_PWD
Convenient one-time crypted password as a constant, since each crypt operation takes some milliseconds.Password value (
MEMBER_DEFAULT_PWD_VALUE
) is crypted byChannel.crypt(String)
.Should be used to enable Member(s) when specific password content is not needed.
member1.setPassword(JcmsTestCaseUtil.MEMBER_DEFAULT_PWD); ... memberN.setPassword(JcmsTestCaseUtil.MEMBER_DEFAULT_PWD);
Instead of:member1.setPassword(channel.crypt("P@ssw0rd")); ... memberN.setPassword(channel.crypt("testMyHander.other-P@ssw0rd"));
- Since:
- jcms-10.0.7 JCMS-9172
-
-
Method Detail
-
configureLoggerAppender
public static void configureLoggerAppender(org.apache.log4j.Logger logger)
-
enableVerboseForbidden
public static void enableVerboseForbidden()
Enabled LevelLevel.ALL
on several classes to help diagnose a FORBIDDEN operation (it is probably be logged in trace or debug level).- Since:
- jcms-10.0.6
-
setLogLevel
public static void setLogLevel(java.lang.String packageOrClass, org.apache.log4j.Level level)
-
getMockServletContext
public static javax.servlet.ServletContext getMockServletContext()
Convenient Method to return the fake servlet context used for this JCMS test.- Returns:
- a ServletContext
- See Also:
MockServletContext
-
getMockHttpSession
public static javax.servlet.http.HttpSession getMockHttpSession()
Convenient Method to return a new instance of a fake http session.- Returns:
- a HttpSession
- See Also:
HttpSession
-
getMockHttpServletRequest
public static javax.servlet.http.HttpServletRequest getMockHttpServletRequest()
Convenient Method to return a new instance of a fake http servlet request.- Returns:
- a HttpServletRequest
- See Also:
MockHttpServletRequest
-
getMockHttpServletRequest
public static javax.servlet.http.HttpServletRequest getMockHttpServletRequest(javax.servlet.http.HttpSession session)
Convenient Method to return a new instance of a fake http servlet request using the specified mock session- Parameters:
session
- the session- Returns:
- a HttpServletRequest
- See Also:
MockHttpServletRequest
-
getMockHttpServletResponse
public static javax.servlet.http.HttpServletResponse getMockHttpServletResponse()
Convenient Method to return a new instance of a fake http servlet response.- Returns:
- a HttpServletResponse
- See Also:
MockHttpServletResponse
-
getMockHttpServletResponse
public static javax.servlet.http.HttpServletResponse getMockHttpServletResponse(javax.servlet.http.HttpSession session)
Convenient Method to return a new instance of a fake http servlet response using the specified mock session- Parameters:
session
- the session- Returns:
- a HttpServletResponse
- See Also:
MockHttpServletResponse
-
getMockJcmsJspContext
public static JcmsJspContext getMockJcmsJspContext()
Retrieve a mock explorer JcmsJspContext.- Returns:
- a new instance of JcmsJspContext
- Since:
- jcms-5.7.3
-
getMockJcmsJspContext
public static JcmsJspContext getMockJcmsJspContext(javax.servlet.http.HttpServletRequest request)
Retrieve a mock explorer JcmsJspContext based on the specified request- Parameters:
request
- the mock request to use, if null a new mock request is created- Returns:
- a new instance of JcmsJspContext
- Since:
- jcms-5.7.3
-
serialize
public static java.io.File serialize(java.lang.Object obj) throws java.lang.Exception
Serialize the given object into a temp file and return this file.- Parameters:
obj
- the Object to be serialized- Returns:
- the file where the object has been serialized.
- Throws:
java.lang.Exception
- if an error occurs
-
deserialize
public static java.lang.Object deserialize(java.io.File file) throws java.lang.Exception
Deserialize the given file into a new object which is returned.- Parameters:
file
- the file- Returns:
- the object
- Throws:
java.lang.Exception
- if an error occurs
-
beginTransaction
public static void beginTransaction()
-
commitTransaction
public static void commitTransaction()
-
deleteData
public static void deleteData(Data... array)
-
deleteData
public static void deleteData(java.lang.String... ids)
-
getControllerStatusDebugString
public static java.lang.String getControllerStatusDebugString(ControllerStatus actualStatus)
-
deleteOnTearDown
public static void deleteOnTearDown(Data data)
Adds given Data in list of Data to be deleted on test's tearDown.- Parameters:
data
- data to be deleted at the end of a Test
-
deleteOnTearDown
public static void deleteOnTearDown(java.lang.String id)
Adds given Data's id in list of Data to be deleted on test's tearDown.- Parameters:
id
- a data id which Data is to delete at the end of a Test- Since:
- jcms-10.0.3
-
deleteOnTearDown
public static void deleteOnTearDown(Workspace ws, java.util.Set<Data> initialDataSet)
Deletes on tear down the workspace, and all its Datas, but not those contained in optional initialDataSet.
The initialDataSet should be initialized before the Workspace was created, using for example :Set<Data> initialDataSet = channel.getAllDataSet();
Then, the workspace is created, using :
Workspace workspace = new Workspace(); ... workspace.performCreate(admin);
Then you might want to delete it on tear down, using :deleteOnTearDown(workspace, initialDataSet);
Deleted datas will be :
- all the workspace's publications
- the following datas that are not in initialDataSet :
- the workspace's categories, and their CategoryRights
- the workspace's groups
- Parameters:
ws
- the workspace to delete.initialDataSet
- a Set of Datas not to delete, since already existing before the start of the test- Since:
- jcms-7.1.3, jcms-8.0.0
-
getWorkspaceDeleteOnTearDownSet
public static java.util.Set<Data> getWorkspaceDeleteOnTearDownSet(Workspace ws, java.util.Set<Data> initialDataSet)
Returns a collection of Datas (bound to the Workspace) that have been created since the workspace creation.Helper method to retrieve datas to delete when the Workspace needs to be deleted.
- Parameters:
ws
- the workspace to retrieve its created Data to deleteinitialDataSet
- the collection of existing datas before workspace has been created.- Returns:
- datas bound to the workspace, and that have been created since the workspace creation.
- Since:
- jcms-9.0.3
-
deleteAll
public static void deleteAll(java.lang.Class<? extends DBData> dbDataClazz)
-
deleteAllAlerts
public static void deleteAllAlerts()
-
deleteAllAlerts
public static void deleteAllAlerts(Member mbr)
Delete all alerts for given Member in a dedicated transaction.If member is a
DBMember
, see alsodeleteAllAlertsTx(String)
to pass member identifier instead of DBMember instance.- Parameters:
mbr
- member to delete all its alerts
-
deleteAllAlertsTx
public static void deleteAllAlertsTx(java.lang.String mid)
Delete all alerts for Member with given id in a dedicated transaction.- Parameters:
mid
- if of member to delete all its alerts- Since:
- jcms-10.0.6
-
getResourceFile
public static java.io.File getResourceFile(java.lang.Class<?> clazz, java.lang.String name)
Retrieves a new File instance pointing to the specified resource name. Example :File testFile1 = getResourceFile("com/company/jcms/MyFeature_testFile1.txt");
Current implementation is to invoke class loader of current class :return new File(clazzInstance.getClass().getClassLoader().getResource(name).getFile());
- Parameters:
clazz
- the clazz where to find the filename
- the name of the resource, a '/
'-separated path name that identifies the resource. e.g"com/company/jcms/MyFeature_testFile1.txt"
- Returns:
- the file
- Since:
- jcms-10.0.1
-
sleep
public static void sleep(long millis)
- Parameters:
millis
- the length of time to sleep in milliseconds.
-
waitForAlarm
public static void waitForAlarm(long time, AlarmManager alarmMgr, boolean reallyWaitFor, java.lang.String logPrefix)
-
waitForLuceneIndexation
public static void waitForLuceneIndexation(Publication... pubs)
Wait for the specified publication(s) to be indexed in all the lucene publication index in its current version as returned byPublication.getVersionString()
.For this method to work properly with DBData, it must be invoked in a different transaction than the transaction in which the create/update operation of the DBData was performed. Indeed indexing is trigger by the
PublicationSearchEngineListener
during the transaction commit, thus indexing will have been performed only after transaction end.If needed, several verification for the maximum duration specified
ASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILURE
.- Parameters:
pubs
- the publications to found in index.
-
waitForLuceneIndexation
public static void waitForLuceneIndexation(boolean checkFileContentIndexing, Publication... pubs)
-
waitForMemberLuceneIndexation
public static void waitForMemberLuceneIndexation(java.lang.String... ids) throws java.lang.Exception
Wait for the specified Members(s) to be indexed in the lucene member index in its current mdate as returned byBasicStorable.getMdate()
.For this method to work properly with DBMember, it must be invoked in a different transaction than the transaction in which the create/update operation of the DBMember was performed. Indeed indexing is trigger by the
MemberSearchEngineListener
during the transaction commit, thus indexing will have been performed only after transaction end.If needed, several verification for the maximum duration specified
ASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILURE
.- Parameters:
ids
- the ids of Member to found in index.- Throws:
java.lang.Exception
- if index could not be read or member could not be found
-
waitForMemberLuceneIndexation
public static void waitForMemberLuceneIndexation(Member... mbrs) throws java.lang.Exception
Wait for the specified Members(s) to be indexed in the lucene member index in its current mdate as returned byBasicStorable.getMdate()
.For this method to work properly with DBMember, it must be invoked in a different transaction than the transaction in which the create/update operation of the DBMember was performed. Indeed indexing is trigger by the
MemberSearchEngineListener
during the transaction commit, thus indexing will have been performed only after transaction end.If needed, several verification for the maximum duration specified
ASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILURE
.- Parameters:
mbrs
- the Members to found in index.- Throws:
java.lang.Exception
- if index could not be read or member could not be found
-
logC3P0Data
public static void logC3P0Data()
Retrieve current C3P0 information from JXM and log them.
-
waitForDBTimePrecision
public static void waitForDBTimePrecision()
wait 1 ms if the DB support time with ms precision, otherwise 1 s
-
setProperty
public static void setProperty(java.lang.String name, java.lang.String value)
- Parameters:
name
- the property name to setvalue
- the property value to set- Since:
- jcms-8.0.3, jcms-9.0.0
- See Also:
setProperties(JProperties)
-
setProperties
public static void setProperties(java.util.Map<java.lang.String,java.lang.String> map)
- Parameters:
map
- the map of properties to set- Since:
- jcms-8.0.3, jcms-9.0.0
- See Also:
setProperties(JProperties)
-
setProperties
public static void setProperties(JProperties properties)
Sets given JProperties.First call of this method will backup propertys current value, for automatic restore in test tear down.
Example:
// How to disabled channel mails setProperty("mail.enabled", "false"); // How to update several properties JProperties props = new JProperties(); props.put("my-first-property", "true"); props.put("my-second-property", "foo"); setProperties(props); // How to restore properties (If not done, it will be restored automatically during tearDown()) // Using a single String restoreProperty("mail.enabled"); // Restore one property // Using a Collection<String> restoreProperties(Util.getArrayList("my-first-property", "my-second-property"); // Restore several properties // Using a JProperties restoreProperties((JProperties) props); // Restore several properties
Complete Test Case:
If you had to write a unit test which is only relevant when site authentication is required.
Preparing and restoring the environnement at start and end of each test can be painful.
To make this initialization easier, you can do:PrivateSiteTest extends JcmsTestCase { @Override protected void setUp() throws Exception { super.setUp(); logger.info("Channel authentication required: " + channel.isAuthenticationRequired()); // Prints "false" by default setAuthenticationRequired(true); } public void testPrivateSite() { assertTrue("The site must be private to run this test...", channel.isAuthenticationRequired()); ... } private void setAuthenticationRequired(boolean isPrivateSite) { setProperty("channel.is-authentication-required", String.valuedOf(isPrivateSite)); } }
You may also want to restore initial value during the test:PrivateSiteTest extends JcmsTestCase { ... public void testPrivateSite() { assertTrue("The site must be private to run this test...", channel.isAuthenticationRequired()); // ... first test with authentication required restoreAuthenticationRequired(); assertFalse("The site must be public to run this test...", channel.isAuthenticationRequired()); // ... second test with initial authentication required } private void restoreAuthenticationRequired() { restoreProperty("channel.is-authentication-required"); } }
Implementation details:- channel.setProperty is called for each property to set
- then, properties.firePropertiesChange() is called one time
- thus, JPropertiesListener will be called.
- Parameters:
properties
- the JProperties to set- Since:
- jcms-8.0.3, jcms-9.0.0
-
restoreProperty
public static void restoreProperty(java.lang.String name)
Restores given property.- Parameters:
name
- the name of property to restore- Since:
- jcms-8.0.3, jcms-9.0.0
- See Also:
restoreProperties(JProperties)
-
restoreProperties
public static void restoreProperties(java.util.Collection<java.lang.String> names)
Restores given properties represented by their names.- Parameters:
names
- the names of properties to restore- Since:
- jcms-8.0.3, jcms-9.0.0
- See Also:
restoreProperties(JProperties)
-
restoreProperties
public static void restoreProperties(JProperties properties)
Restores given JProperties.- Parameters:
properties
- the JProperties to restore.- Since:
- jcms-8.0.3, jcms-9.0.0
-
setIncomingMail
public static void setIncomingMail(boolean enabled)
Sets property "mail.incoming.enabled" toenabled
.- Parameters:
enabled
- the value to set.- Since:
- jcms-8.0.3, jcms-9.0.0
-
restoreIncomingMail
public static void restoreIncomingMail()
Restores property "mail.incoming.enabled".- Since:
- jcms-8.0.3, jcms-9.0.0
-
setAuthenticationRequired
public static void setAuthenticationRequired(boolean isAuthRequired)
Sets property "channel.is-authentication-required" toisAuthRequired
.- Parameters:
isAuthRequired
- the value to set.- Since:
- jcms-8.0.3, jcms-9.0.0
-
restoreAuthenticationRequired
public static void restoreAuthenticationRequired()
Restores property "channel.is-authentication-required".- Since:
- jcms-8.0.3, jcms-9.0.0
-
enableJSync
public static void enableJSync()
Enable JSync in Junit prop.Sets property "jsync.enabled" to
true
.
-
disableJSync
public static void disableJSync()
Disable JSync in Junit prop.Sets property "jsync.enabled" to
false
.
-
enableLdap
public static void enableLdap()
Enable LDAP in Junit prop.Sets property "ldap.enabled" to
true
.- Since:
- jcms-9.0.3
-
disableLdap
public static void disableLdap()
Disable LDAP in Junit prop.Sets property "ldap.enabled" to
false
.- Since:
- jcms-9.0.3
-
setGuestAccountsEnabled
public static void setGuestAccountsEnabled(boolean enabled) throws java.lang.Exception
ForcesChannel.isGuestAccountsEnabled()
to return given value.- Parameters:
enabled
- true to force enabled state, false disabled state- Throws:
java.lang.Exception
- ...- Since:
- jcms-10.0.6
-
restoreGuestAccountsEnabled
public static void restoreGuestAccountsEnabled() throws java.lang.Exception
Resets forcedChannel.isGuestAccountsEnabled()
.- Throws:
java.lang.Exception
- ...- Since:
- jcms-10.0.6
-
createWorkspace
public static void createWorkspace(Workspace workspace)
Utility method to create the given Workspace by admin Member.Manages deleteOnTearDown, and clears the workspace's id if already set.
Use as follow:
Workspace ws = new Workspace(otherWs); // Bootstraps a Workspace based on another WS ws.setTitle("my test workspace"); // ws customization createWorkspace(ws); // handles deleteOnTearDown
- Parameters:
workspace
- the workspace to create- Since:
- jcms-8.0.3, jcms-9.0.0
-
createWorkspace
public static void createWorkspace(Workspace workspace, Member author)
Utility method to create the given Workspace by admin Member.Manages deleteOnTearDown, and clears the workspace's id if already set.
Use as follow:
Workspace ws = new Workspace(otherWs); // Bootstraps a Workspace based on another WS ws.setTitle("my test workspace"); // ws customization createWorkspace(ws, author); // handles deleteOnTearDown
Utility method to create the given Workspace.Manages deleteOnTearDown.
- Parameters:
workspace
- the workspace to createauthor
- the create operation author- Since:
- jcms-8.0.3, jcms-9.0.0
-
createACLGroup
public static Group createACLGroup(java.lang.String resource)
-
createGroupTx
public static Group createGroupTx(java.lang.String name)
Creates a new group inside a new transaction that is commited at the end of process.- Parameters:
name
- the name of the group to create- Returns:
- the created group
- Since:
- jcms-10.0.6
-
createGroupTx
public static Group createGroupTx(java.lang.String name, java.util.Collection<Group> parentGroups)
Creates a new group inside a new transaction that is commited at the end of process.- Parameters:
name
- the name of the group to createparentGroups
- option parentSet to set on the group- Returns:
- the created group
- Since:
- jcms-10.0.6
-
addParentGroupTx
public static void addParentGroupTx(Group group, Group parentGroup)
Add given parent Group on given Group.- Parameters:
group
- group be added parentGroup as parent, cannot be nullparentGroup
- parent group to add, cannot be null- Since:
- jcms-10.0.6
-
createMember
public static Member createMember(java.lang.String name)
-
createMemberTx
public static java.lang.String createMemberTx(java.lang.String name)
Creates a JStore member in a dedicated transaction.Example of use:
// Create members in transaction, keep ids reference String mbrId = JcmsTestCaseUtil.createMemberTx("JStore member"); String dbMbrId = JcmsTestCaseUtil.createDBMemberTx("DB member"); // Common test for both JStore and DBMember for (String mid : Util.getArrayList(mbrId, dbMbrId)) { beginTransaction(); { // Test stuff assertNotNull(channel.getMember(mid)); } commitTransaction(); }
- Parameters:
name
- name to set- Returns:
- member id
- Since:
- jcms-10.0.6
-
createMember
public static Member createMember(java.lang.String name, boolean deleteOnTearDown)
-
createMember
public static Member createMember(java.lang.String name, boolean deleteOnTearDown, Group... groups)
-
createDBMember
public static DBMember createDBMember(java.lang.String name)
-
createDBMemberTx
public static java.lang.String createDBMemberTx(java.lang.String name)
Creates a DB member in a dedicated transaction.Example of use: see
createMemberTx(String)
- Parameters:
name
- name to set- Returns:
- member id
- Since:
- jcms-10.0.6
-
createDBMemberTx
public static java.lang.String createDBMemberTx(java.lang.String name, Group... groups)
Creates a DB member in a dedicated transaction.Example of use: see
createMemberTx(String)
- Parameters:
name
- name to setgroups
- groups to add member in- Returns:
- member id
- Since:
- jcms-10.0.6
-
createDBMember
public static DBMember createDBMember(java.lang.String name, boolean deleteOnTearDown)
-
createDBMember
public static DBMember createDBMember(java.lang.String name, boolean deleteOnTearDown, Group... groups)
-
createFile
public static java.lang.String createFile(java.lang.String filename)
-
createFile
public static void createFile(java.io.File file, java.lang.String content) throws java.lang.Exception
- Throws:
java.lang.Exception
-
waitForFileAvailability
public static void waitForFileAvailability(java.io.File file) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getFileDocument
public static FileDocument getFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
-
createFileDocument
public static FileDocument createFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
-
getDBFileDocument
public static DBFileDocument getDBFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
-
createDBFileDocument
public static DBFileDocument createDBFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
-
createMedia
public static generated.Media createMedia(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
-
getMedia
public static generated.Media getMedia(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)
-
createArticle
public static generated.Article createArticle(Member writer, Workspace ws, boolean deleteOnTearDown)
-
getSmallNews
protected static generated.SmallNews getSmallNews(Member writer, Workspace ws, boolean insertDateInContent)
-
createSmallNews
public static generated.SmallNews createSmallNews(Member writer, Workspace ws, boolean deleteOnTearDown)
-
getShortcut
public static AbstractShortcut getShortcut(java.lang.String link, Member writer, Workspace ws)
-
getShortcut
public static AbstractShortcut getShortcut(Publication pub, Member writer, Workspace ws)
-
getShortcut
public static AbstractShortcut getShortcut(Member writer, Workspace ws)
- Returns:
- a Shortcut with no pub nor link set.
-
createShortcut
public static AbstractShortcut createShortcut(Publication pub, Member writer, Workspace ws, boolean deleteOnTearDown)
-
createShortcut
public static AbstractShortcut createShortcut(java.lang.String link, Member writer, Workspace ws, boolean deleteOnTearDown)
-
addReadRights
public static java.util.Set<Member> addReadRights(Publication pub, Member... members)
Convenient method to add read right Members on given publication.Can be used as follow:
Set<Member> initialAuthMemberSet = addReadRights(pub, member1, member2); // custom processing here // [...] // Restore restoreReadRightsMembers(pub, initialAuthMemberSet);
- Parameters:
pub
- the pub to add a read right on given Membersmembers
- the member(s) to add in pub's authorizedMemberSet- Returns:
- the initial authorizedMemberSet for restore purpose
-
addReadRights
public static java.util.Set<Group> addReadRights(Publication pub, Group... groups)
Convenient method to add read right Groups on given publication.Can be used as follow:
Set<Group> initialAuthGroupSet = addReadRights(pub, group1, group2); // custom processing here // [...] // Restore restoreReadRightsGroups(pub, initialAuthGroupSet);
- Parameters:
pub
- the pub to add a read right on given Groupsgroups
- the group(s) to add in pub's authorizedGroupSet- Returns:
- the initial authorizedGroupSet for restore purpose
-
restoreReadRightsMembers
public static void restoreReadRightsMembers(Publication pub, java.util.Collection<Member> initialAuthorizedMembers)
- Parameters:
pub
- the pub to restore its initial authorizedMemberSetinitialAuthorizedMembers
- initial authorized members to restore (typically returned byaddReadRights(Publication, Member...)
)
-
restoreReadRightsGroups
public static void restoreReadRightsGroups(Publication pub, java.util.Collection<Group> initialAuthorizedGroups)
- Parameters:
pub
- the pub to restore its initial authorizedGrouSetinitialAuthorizedGroups
- initial authorized groups to restore (typically returned byaddReadRights(Publication, Group...)
)
-
updatePstatusTransaction
public static void updatePstatusTransaction(java.lang.String pubId, Member opAuthor, int newPstatus)
Checks and performs update the publication (makes an update instance) with given pstatus.If pstatus is
WorkflowConstants.PUBLISHED_PSTATUS
, and publication's pdate is null, sets a new pdate.Opens and closes a new transaction.
- Parameters:
pubId
- the id of publication to udpate its pstatusopAuthor
- the author of operationnewPstatus
- the new pstatus to set- Since:
- jcms-10.0.1
- See Also:
Publication.updatePstatus(Member, int, String)
-
publishPublicationTransaction
public static void publishPublicationTransaction(java.lang.String pubId, Member opAuthor)
Delegates toupdatePstatusTransaction(String, Member, int)
using pstatusWorkflowConstants.PUBLISHED_PSTATUS
.- Parameters:
pubId
- the id of publication to udpate its pstatusopAuthor
- the author of operation- Since:
- jcms-10.0.1
- See Also:
updatePstatusTransaction(String, Member, int)
-
updateTitleTransaction
public static void updateTitleTransaction(java.lang.String pubId, Member opAuthor, java.lang.String newTitle)
Checks and performs update the publication (makes an update instance) with given title.Use it as follow:
final String pubId; beginTransaction(); { pubId = createMedia().getId(); } commitTransaction(); JcmsTestCaseUtil.updateTitleTransaction(pubId, admin, "My FOO media");
- Parameters:
pubId
- the id of publication to udpate its pstatusopAuthor
- the author of operationnewTitle
- the new title to set- Since:
- jcms-10.0.6
-
ignoreUnstableTest
public static boolean ignoreUnstableTest()
-
updateWorkspaceTypeWorkflow
public static void updateWorkspaceTypeWorkflow(Workspace ws, java.lang.Class<? extends Data> typeClass, java.lang.Object workflowToUse)
An utility method to update the given Workspace, with the chosen Workflow associated to the given Type.
Note: It is better to make a backup of the Type Workflow in order to restore at the end of the test:
Object wfBackup = myWs.getTypeMap().get(MyType.class); JcmsTestCaseUtil.updateWorkspaceTypeWorkflow(myWs, MyType.class, ""); // ... (processing) JcmsTestCaseUtil.updateWorkspaceTypeWorkflow(myWs, MyType.class, wfBackup);
- Parameters:
ws
- the workspacetypeClass
- the classworkflowToUse
- the workflow Id. Use an empty string if it is just to activate the type.
-
updateWorkspaceTypeWorkflow
public static void updateWorkspaceTypeWorkflow(Workspace ws, java.util.HashMap<java.lang.Class<?>,java.lang.Object> subTypeMap)
An utility method to update the given Workspace typeMap.
Note: It is better to make a backup of the Type Workflow in order to restore at the end of the test:
Object wfBackup = myWs.getTypeMap().get(MyType.class); JcmsTestCaseUtil.updateWorkspaceTypeWorkflow(myWs, MyType.class, ""); // ... (processing) JcmsTestCaseUtil.updateWorkspaceTypeWorkflow(myWs, MyType.class, wfBackup);
Update given workspace's typeMap with given subset typeMap.- Parameters:
ws
- the workspace to apply changessubTypeMap
- the typeMap subset to change
-
voteForPubTransaction
public static java.lang.String voteForPubTransaction(java.lang.String pubId, java.lang.String voterId)
Adds a 1 point vote on given pub by given member.May return null if no pub or no member.
Opens and closes a new transaction.
- Parameters:
pubId
- the publication to vote forvoterId
- the member performing the vote- Returns:
- the created vote identifier if any
- Since:
- jcms-10.0.1
-
dataToDebugString
public static java.lang.String dataToDebugString(Data data)
Produces a String representation of given Data for debug, log purpose.- Parameters:
data
- the data to get the debug string.- Returns:
- the debugging String of the data.
- Since:
- jcms-7.1.3, jcms-8.0.0
- See Also:
JcmsUtil.dataToString(Data)
-
setupRootLogger
public static org.apache.log4j.Logger setupRootLogger()
Configures the root logger (adds a console appender, seeBasicConfigurator.configure()
) if it has no appender defined yet (seeUtil.hasAppenderDefined(Logger)
).- Returns:
- the root logger (see
Logger.getRootLogger()
- Since:
- jcms-10.0.2
-
setupRootLogger
public static org.apache.log4j.Logger setupRootLogger(org.apache.log4j.Level level)
First, setups root logger. (SeesetupRootLogger()
).Then, sets given level if any.
- Parameters:
level
- new level to set- Returns:
- the root logger (see
Logger.getRootLogger()
- Since:
- jcms-10.0.2
- See Also:
setupRootLogger()
-
restoreRootLogger
public static void restoreRootLogger(org.apache.log4j.Logger rootLogger, org.apache.log4j.Level level)
Restores given level (backup before modification) on logger if both not null.- Parameters:
rootLogger
- the root logger to restore with given levellevel
- the level to restore- Since:
- jcms-10.0.2
-
updateMemberEmailTransaction
public static void updateMemberEmailTransaction(java.lang.String mid, java.lang.String authorMid, java.lang.String emailAddress)
Checks and performs update given Member with given email address.Opens and closes a new transaction.
- Parameters:
mid
- the id of Member to be updatedauthorMid
- the id of author of operationemailAddress
- the new email to set- Since:
- jcms-10.0.3
-
addMemberInGroupTx
public static void addMemberInGroupTx(Group group, java.lang.String memberId)
Checks and performs update given Member by adding him in given Group.Opens and closes a new transaction.
opAuthor will be default admin.
- Parameters:
group
- the Group to add the member inmemberId
- the id of Member to update- Since:
- jcms-10.0.6
-
removeMemberFromGroupTx
public static void removeMemberFromGroupTx(Group group, java.lang.String memberId)
Checks and performs update given Member by removing hime from given Group.Opens and closes a new transaction.
opAuthor will be default admin.
- Parameters:
group
- the Group to remove the member frommemberId
- the id of Member to update- Since:
- jcms-10.0.6
-
checkAndCreate
public static <T extends Data> java.lang.String checkAndCreate(T data, java.util.function.Consumer<T> beforePerformConsumer)
Delegates tocheckAndCreate(Data, Consumer, Member)
with data's author as create opAuthor.Should be inside a transaction.
- Type Parameters:
T
- type of data to create- Parameters:
data
- the data instance to createbeforePerformConsumer
- the consumer to be called before creation.- Returns:
- the created's data identifier
- Since:
- jcms-10.0.6
- See Also:
checkAndCreate(Data, Consumer, Member)
-
checkAndCreate
public static <T extends Data> java.lang.String checkAndCreate(T data, java.util.function.Consumer<T> beforePerformConsumer, Member opAuthor)
Checks and creates the given data instance.Allows to modify the data before it gets created.
Calls the consumer on data before
checkAndPerformCreate
is called.Should be inside a transaction. You can use it as follow:
- Define a consumer that will be called before data creation, which allows to update fields that are not available in the getDataInstance method.
- Instanciate a Data using a method that does not allow to set all data's fields
beginTransaction(); { // Here we will override data's title Consumer<TestType> beforePerformConsumer = new Consumer<TestType>() { @Override public void accept(TestType pub) { pub.setTitle("My custom title"); } }; // Here we instanciate a TestType for which we cannot define a custom title. pubId = JcmsTestCaseUtil.checkAndCreate(getTestType(author, srcWorkspace), beforePerformConsumer, admin); } commitTransaction();
Or shorter:beginTransaction(); { // Here we pass an inline consumer: JcmsTestCaseUtil.checkAndCreate(getTestType(author, srcWorkspace), pub -> pub.setTitle("My custom title"), admin); } commitTransaction();
- Type Parameters:
T
- type of data to create- Parameters:
data
- the data instance to createbeforePerformConsumer
- the consumer to be called before creation.opAuthor
- the member to use for opCreate- Returns:
- the created's data identifier
- Since:
- jcms-10.0.6
-
checkAndUpdate
public static <T extends Data> void checkAndUpdate(T data)
Checks and performs update of given data update instance.Delegates to
checkAndUpdate(Data, Consumer)
.- Type Parameters:
T
- type of data to work with- Parameters:
data
- the data instance to update- Since:
- jcms-10.0.6
- See Also:
checkAndUpdate(Data, Consumer, Member)
-
checkAndUpdate
public static <T extends Data> void checkAndUpdate(T data, java.util.function.Consumer<T> beforePerformConsumer)
Delegates tocheckAndUpdate(Data, Consumer, Member)
with data's author as update opAuthor, or default admin as update opAuthor if data author is null.- Type Parameters:
T
- type of data to work with- Parameters:
data
- the data instance to updatebeforePerformConsumer
- the optional consumer to be called before update.- Since:
- jcms-10.0.6
- See Also:
checkAndUpdate(Data, Consumer, Member)
-
checkAndUpdate
public static <T extends Data> void checkAndUpdate(T data, java.util.function.Consumer<T> beforePerformConsumer, Member opAuthor)
Checks and updates the given data instance.Allows to modify the data before it gets updated.
Calls the consumer on data before
checkAndPerformUpdate
is called.The consumer will receive the "updated instance" to work on.
Should be inside a transaction. You can use it as follow:
- Define a consumer that will work on data's updated instance before it opUpdate is called.
- Pass an existing data instance (the original instance, not an update instance) to modify before update.
Member member = createMbr("Foo", defaultGroup); beginTransaction(); { // Here we will override member's email Consumer<Member> beforePerformConsumer = new Consumer<Member>() { @Override public void accept(Member member) { member.setEmail("foo@bar.baz"); } }; // Here we pass an existing Data to modifiy before opUpdate is called JcmsTestCaseUtil.checkAndUpdate(member, beforePerformConsumer, admin); } commitTransaction();
Or shorter:Member member = createMbr("Foo", defaultGroup); beginTransaction(); { // Here we pass an inline consumer: JcmsTestCaseUtil.checkAndUpdate(member, updated -> ((Member) updated).setEmail("foo@bar.baz"), admin); } commitTransaction();
This is equivalent to:Member member = createMbr("Foo", defaultGroup); beginTransaction(); { Member udpate = (Member) data.getUpdateInstance(); udpate.setEmail("foo@bar.baz"); assertStatusOK(update.checkAndPerformUpdate(admin)); } commitTransaction();
- Type Parameters:
T
- type of data to work with- Parameters:
data
- the data instance to createbeforePerformConsumer
- the optional consumer to be called before update.opAuthor
- the member to use for opUpdate- Since:
- jcms-10.0.6
-
checkAndUpdateTx
public static <T extends Data> void checkAndUpdateTx(java.lang.String dataId, java.util.function.Consumer<T> beforePerformConsumer)
-
checkAndUpdateTx
public static <T extends Data> void checkAndUpdateTx(java.lang.String dataId, java.util.function.Consumer<T> beforePerformConsumer, java.lang.String opAuthorId)
-
checkAndDeleteTx
public static void checkAndDeleteTx(java.lang.String dataId)
-
checkAndDeleteTx
public static void checkAndDeleteTx(java.lang.String dataId, java.lang.String opAuthorId)
-
asSet
public static <T> java.util.HashSet<T> asSet(T... array)
Convenient shorthand forUtil.getHashSet(Object...)
.Never returns null.
- Type Parameters:
T
- type of element- Parameters:
array
- elements to return in a new Set- Returns:
- a set with given elements
- Since:
- jcms-10.0.6
-
assertSameData
public static void assertSameData(Data expectedData, Data actualData)
Assert 2 datas are the same.- Since:
- jcms-10.0.6
- See Also:
assertSameData(String, boolean, Data, Data)
-
assertSameData
public static void assertSameData(java.lang.String message, Data expectedData, Data actualData)
Assert 2 datas are the same.- Since:
- jcms-10.0.6
- See Also:
assertSameData(String, boolean, Data, Data)
-
assertNotSameData
public static void assertNotSameData(Data expectedData, Data actualData)
Assert 2 datas are not the same.- Since:
- jcms-10.0.6
- See Also:
assertSameData(String, boolean, Data, Data)
-
assertNotSameData
public static void assertNotSameData(java.lang.String message, Data expectedData, Data actualData)
Assert 2 datas are not the same.- Since:
- jcms-10.0.6
- See Also:
assertSameData(String, boolean, Data, Data)
-
assertSameData
public static void assertSameData(java.lang.String message, boolean expectedSameData, Data expectedData, Data actualData)
Assert 2 datas are or are not the same.Gives more details about expected and actual datas, than a simple assertEquals.
- Parameters:
message
- optional contextual messageexpectedSameData
- if true, both data must be the sameexpectedData
- the expected dataactualData
- the actual data- Since:
- jcms-10.0.6
-
-