Class JcmsTestCaseUtil
- java.lang.Object
-
- com.jalios.jcms.test.JcmsTestCaseUtil
-
- All Implemented Interfaces:
JcmsConstants,WorkflowConstants,JaliosConstants
public abstract class JcmsTestCaseUtil extends java.lang.Object implements JcmsConstants, WorkflowConstants
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringA_VERY_LONG_TEXTstatic longASYNC_TEST__ITERATION_WAIT_TIMEstatic longASYNC_TEST__MAX_ITERATIONstatic longASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILUREstatic java.lang.StringMEMBER_DEFAULT_PWDConvenient one-time crypted password as a constant, since each crypt operation takes some milliseconds.static java.lang.StringMEMBER_DEFAULT_PWD_VALUEDefault 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, DATA_DIRECTORY, 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_MINI, PHOTO_MINI_HEIGHT, PHOTO_MINI_PROP_PREFIX, PHOTO_MINI_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, SDATE_SEARCH, SEARCHENGINE_ALARM, SECURITY_LOG_FILE, SESSION_AUTHORIZED_FILENAMES_SET, SPRITE_ICON_PREFIX, STATS_REPORT_DIR, STATUS_PROP, STORE_DIR, 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
-
Fields inherited from interface com.jalios.jcms.WorkflowConstants
ACTION, ACTION_REPEAT, ACTION_TYPE, ACTION_WHEN, ALL_WF, ARCHIVED_PSTATUS, DEFAULT_DRAFT_PSTATUS, EXPIRED_PSTATUS, PUBLISHED_PSTATUS, ROLE, ROLE_DESCRIPTION, ROLE_GROUP, ROLE_GRPID, ROLE_ID, ROLE_MBRID, ROLE_MEMBER, ROLE_NAME, ROLE_TYPE, ROLE_WEIGHT, SCHEDULED_PSTATUS, STATE, STATE_COLOR, STATE_DESCRIPTION, STATE_DURATION, STATE_LABEL, STATE_PSTATUS, STATE_REMINDER, STATE_TARGETPSTATUS, STATE_TYPE, STATESPE, TRANSITION, TRANSITION_GROUP, TRANSITION_ROLEID, TRANSITION_SOURCE, TRANSITION_TARGET, TRASHED_PSTATUS, UNKNOWN_PSTATUS, WF_ATTACHMENT_ID, WF_BASIC_ID, WF_DEFAULT_ID, WF_DIR, WF_ELT_NAME, WF_ID, WF_INIT, WF_LABEL, WF_MDATE, WF_MODERATION_ID, WF_TYPE, WF_VERSION, WF_VERSION_VALUE, WFTYPE_PROCESS, WFTYPE_PUBLISH
-
-
Constructor Summary
Constructors Constructor Description JcmsTestCaseUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddMemberInGroupTx(Group group, java.lang.String memberId)Checks and performs update given Member by adding him in given Group.static voidaddParentGroupTx(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 voidassertNotSameData(Data expectedData, Data actualData)Assert 2 datas are not the same.static voidassertNotSameData(java.lang.String message, Data expectedData, Data actualData)Assert 2 datas are not the same.static voidassertSameData(Data expectedData, Data actualData)Assert 2 datas are the same.static voidassertSameData(java.lang.String message, boolean expectedSameData, Data expectedData, Data actualData)Assert 2 datas are or are not the same.static voidassertSameData(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 voidbeginTransaction()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 voidcheckAndDelete(Data data, Member opAuthor)static voidcheckAndDeleteTx(java.lang.String dataId)static voidcheckAndDeleteTx(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)One-line update statement within a dedicated transaction.static <T extends Data>
voidcheckAndUpdateTx(java.lang.String dataId, java.util.function.Consumer<T> beforePerformConsumer, java.lang.String opAuthorId)One-line update statement within a dedicated transaction.static voidcommitTransaction()static voidconfigureLoggerAppender(org.apache.log4j.Logger logger)static voidcopyPhotoAndSetMemberPhoto(Member member, java.io.File origPhotoFile)Copies unittest mock photo file to a new tempFile.static GroupcreateACLGroup(java.lang.String resource)static generated.ArticlecreateArticle(Member writer, Workspace ws, boolean deleteOnTearDown)static CategorycreateCategory(java.lang.String name, Category parent)static DBFileDocumentcreateDBFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)static DBMembercreateDBMember(java.lang.String name)static DBMembercreateDBMember(java.lang.String name, boolean deleteOnTearDown)static DBMembercreateDBMember(java.lang.String name, boolean deleteOnTearDown, Group... groups)static DBMembercreateDBMember(java.lang.String name, Group... groups)static java.lang.StringcreateDBMemberTx(java.lang.String name)Creates a DB member in a dedicated transaction.static java.lang.StringcreateDBMemberTx(java.lang.String name, Group... groups)Creates a DB member in a dedicated transaction.static voidcreateFile(java.io.File file, java.lang.String content)static java.lang.StringcreateFile(java.lang.String filename)static FileDocumentcreateFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)static GroupcreateGroupTx(java.lang.String name)Creates a new group inside a new transaction that is commited at the end of process.static GroupcreateGroupTx(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.MediacreateMedia(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)static MembercreateMember(java.lang.String name)static MembercreateMember(java.lang.String name, boolean deleteOnTearDown)static MembercreateMember(java.lang.String name, boolean deleteOnTearDown, Group... groups)static MembercreateMember(java.lang.String name, Group... groups)static java.lang.StringcreateMemberTx(java.lang.String name)Creates a JStore member in a dedicated transaction.static java.lang.StringcreateOrganizationGroupTx(java.lang.String name)Creates a group, direct child of organization root group.static generated.PortletQueryForeachcreatePortletQueryForeach(Member writer, Workspace ws, boolean deleteOnTearDown)Creates a new pub instance.static AbstractShortcutcreateShortcut(Publication pub, Member writer, Workspace ws, boolean deleteOnTearDown)static AbstractShortcutcreateShortcut(java.lang.String link, Member writer, Workspace ws, boolean deleteOnTearDown)static generated.SmallNewscreateSmallNews(Member writer, Workspace ws, boolean deleteOnTearDown)static voidcreateWorkspace(Workspace workspace)Utility method to create the given Workspace by admin Member.static voidcreateWorkspace(Workspace workspace, Member author)Utility method to create the given Workspace by admin Member.static java.lang.StringdatasToString(java.util.List<Data> datas)Use as follow:static java.lang.StringdataToDebugString(Data data)Produces a String representation of given Data for debug, log purpose.static voiddeleteAll(java.lang.Class<? extends DBData> dbDataClazz)static voiddeleteAllAlerts()static voiddeleteAllAlerts(Member mbr)Delete all alerts for given Member in a dedicated transaction.static voiddeleteAllAlertsTx(java.lang.String mid)Delete all alerts for Member with given id in a dedicated transaction.static voiddeleteData(Data... array)static voiddeleteData(java.lang.String... ids)static voiddeleteOnTearDown(Data data)Adds given Data in list of Data to be deleted on test's tearDown.static voiddeleteOnTearDown(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 voiddeleteOnTearDown(java.lang.String id)Adds given Data's id in list of Data to be deleted on test's tearDown.static java.lang.Objectdeserialize(java.io.File file)Deserialize the given file into a new object which is returned.static voiddisableJSync()Disable JSync in Junit prop.static voiddisableLdap()Disable LDAP in Junit prop.static voiddisableMemberTx(java.lang.String mid)Performs member disable update in a dedicated transaction using default admin as opAuthor.static voiddisableMemberTx(java.lang.String mid, java.lang.String opAuthorId)Performs member disable update in a dedicated transaction.static voidenableJSync()Enable JSync in Junit prop.static voidenableLdap()Enable LDAP in Junit prop.static voidenableMemberTx(java.lang.String mid)Sets a new password on member to enable it.static voidenableMemberTx(java.lang.String mid, java.lang.String opAuthorId)Sets a new password on member to enable it.static voidenableVerboseForbidden()Enabled LevelLevel.ALLon several classes to help diagnose a FORBIDDEN operation (it is probably be logged in trace or debug level).static generated.ArticlegetArticle(Member writer, Workspace ws)static java.lang.StringgetControllerStatusDebugString(ControllerStatus actualStatus)static DBFileDocumentgetDBFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)static FileDocumentgetFileDocument(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)static generated.MediagetMedia(Member writer, Workspace ws, java.lang.String title, java.lang.String filename)static javax.servlet.http.HttpServletRequestgetMockHttpServletRequest()Convenient Method to return a new instance of a fake http servlet request.static javax.servlet.http.HttpServletRequestgetMockHttpServletRequest(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.HttpServletResponsegetMockHttpServletResponse()Convenient Method to return a new instance of a fake http servlet response.static javax.servlet.http.HttpServletResponsegetMockHttpServletResponse(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.HttpSessiongetMockHttpSession()Convenient Method to return a new instance of a fake http session.static JcmsJspContextgetMockJcmsJspContext()Retrieve a mock explorer JcmsJspContext.static JcmsJspContextgetMockJcmsJspContext(javax.servlet.http.HttpServletRequest request)Retrieve a mock explorer JcmsJspContext based on the specified requeststatic javax.servlet.ServletContextgetMockServletContext()Convenient Method to return the fake servlet context used for this JCMS test.static generated.PortletQueryForeachgetPortletQueryForeach(Member writer, Workspace ws)Get a new, not created yet, pub instance.static java.io.FilegetResourceFile(java.lang.Class<?> clazz, java.lang.String name)Retrieves a new File instance pointing to the specified resource name.static AbstractShortcutgetShortcut(Member writer, Workspace ws)static AbstractShortcutgetShortcut(Publication pub, Member writer, Workspace ws)static AbstractShortcutgetShortcut(java.lang.String link, Member writer, Workspace ws)protected static generated.SmallNewsgetSmallNews(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 booleanignoreUnstableTest()static voidlogC3P0Data()Retrieve current C3P0 information from JXM and log them.static voidpublishPublicationTransaction(java.lang.String pubId, Member opAuthor)Delegates toupdatePstatusTransaction(String, Member, int)using pstatusWorkflowConstants.PUBLISHED_PSTATUS.static voidremoveMemberFromGroupTx(Group group, java.lang.String memberId)Checks and performs update given Member by removing hime from given Group.static voidrestoreAuthenticationRequired()Restores property "channel.is-authentication-required".static voidrestoreGuestAccountsEnabled()Resets forcedChannel.isGuestAccountsEnabled().static voidrestoreIncomingMail()Restores property "mail.incoming.enabled".static voidrestoreProperties(JProperties properties)Restores given JProperties.static voidrestoreProperties(java.util.Collection<java.lang.String> names)Restores given properties represented by their names.static voidrestoreProperty(java.lang.String name)Restores given property.static voidrestoreReadRightsGroups(Publication pub, java.util.Collection<Group> initialAuthorizedGroups)static voidrestoreReadRightsMembers(Publication pub, java.util.Collection<Member> initialAuthorizedMembers)static voidrestoreRootLogger(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.Fileserialize(java.lang.Object obj)Serialize the given object into a temp file and return this file.static voidsetAuthenticationRequired(boolean isAuthRequired)Sets property "channel.is-authentication-required" toisAuthRequired.static voidsetGuestAccountsEnabled(boolean enabled)ForcesChannel.isGuestAccountsEnabled()to return given value.static voidsetIncomingMail(boolean enabled)Sets property "mail.incoming.enabled" toenabled.static voidsetLogLevel(java.lang.String packageOrClass, org.apache.log4j.Level level)static voidsetProperties(JProperties properties)Sets given JProperties.static voidsetProperties(java.util.Map<java.lang.String,java.lang.String> map)static voidsetProperty(java.lang.String name, java.lang.String value)static java.lang.StringsetupOrganizationRootGroupTx()Creates a group and sets it as organization root group in properties.static org.apache.log4j.LoggersetupRootLogger()Configures the root logger (adds a console appender, seeBasicConfigurator.configure()) if it has no appender defined yet (seeUtil.hasAppenderDefined(Logger)).static org.apache.log4j.LoggersetupRootLogger(org.apache.log4j.Level level)First, setups root logger.static voidsleep(long millis)static java.lang.StringtoReflectString(java.lang.Object o)static voidupdateGroupVisibilityTx(java.lang.String grpId, int visibility)static voidupdateMemberAssistantTx(java.lang.String memberId, java.lang.String assistantId)Checks and performs update given Member with given assistant.static voidupdateMemberDeclaredManagerTx(java.lang.String mid, java.lang.String declaredManagerId)Checks and performs update given Member with given declared manager.static voidupdateMemberEmailTransaction(java.lang.String mid, java.lang.String authorMid, java.lang.String emailAddress)Checks and performs update given Member with given email address.static voidupdatePstatusTransaction(java.lang.String pubId, Member opAuthor, int newPstatus)Checks and performs update the publication (makes an update instance) with given pstatus.static voidupdateTitleTransaction(java.lang.String pubId, Member opAuthor, java.lang.String newTitle)Checks and performs update the publication (makes an update instance) with given title.static voidupdateToAccountTx(java.lang.String mid)Performs update of member usage to Account in a dedicated transaction using default admin as opAuthor.static voidupdateToAccountTx(java.lang.String mid, java.lang.String opAuthorId)Performs update of member usage to Account in a dedicated transaction.static voidupdateToContactTx(java.lang.String mid)Performs update of member usage to Contact in a dedicated transaction using default admin as opAuthor.static voidupdateToContactTx(java.lang.String mid, java.lang.String opAuthorId)Performs update of member usage to Contact in a dedicated transaction.static voidupdateToLDAP_accountTx(java.lang.String mid, java.lang.String opAuthorId)Performs member update as LDAP account by setting him a lastLdapSynchro.static voidupdateWorkspaceTypeWorkflow(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 voidupdateWorkspaceTypeWorkflow(Workspace ws, java.util.HashMap<java.lang.Class<?>,java.lang.Object> subTypeMap)An utility method to update the given Workspace typeMap.static java.lang.StringvoteForPubTransaction(java.lang.String pubId, java.lang.String voterId)Adds a 1 point vote on given pub by given member.static voidwaitForAlarm(long time, AlarmManager alarmMgr, boolean reallyWaitFor, java.lang.String logPrefix)static voidwaitForDBTimePrecision()wait 1 ms if the DB support time with ms precision, otherwise 1 sstatic voidwaitForFileAvailability(java.io.File file)static voidwaitForLuceneIndexation(boolean checkFileContentIndexing, Publication... pubs)static voidwaitForLuceneIndexation(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 voidwaitForMemberLuceneIndexation(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 voidwaitForMemberLuceneIndexation(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.ALLon 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.ExceptionSerialize 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.ExceptionDeserialize 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
PublicationSearchEngineListenerduring 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.ExceptionWait 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
MemberSearchEngineListenerduring 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
MemberSearchEngineListenerduring 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 propertiesComplete 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.ExceptionForcesChannel.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.ExceptionResets 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 deleteOnTearDownUtility 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)
-
copyPhotoAndSetMemberPhoto
public static void copyPhotoAndSetMemberPhoto(Member member, java.io.File origPhotoFile)
Copies unittest mock photo file to a new tempFile.Move copy in JCMS webapp (to work with use of getRelativePath(file))
Update member with this photo file in webapp.
- Parameters:
member- the member to set a photoorigPhotoFile- the unittest photo ressource to be copied- Since:
- jcms-10.0.8 JCMS-10422
-
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)
-
getPortletQueryForeach
public static generated.PortletQueryForeach getPortletQueryForeach(Member writer, Workspace ws)
Get a new, not created yet, pub instance.- Parameters:
writer- publication authorws- workpsace- Returns:
- a PortletQueryForeach with title only.
- Since:
- jcms-10.0.8 / JCMS-10823
-
createPortletQueryForeach
public static generated.PortletQueryForeach createPortletQueryForeach(Member writer, Workspace ws, boolean deleteOnTearDown)
Creates a new pub instance.- Parameters:
writer- publication authorws- workpsacedeleteOnTearDown- true for auto delete- Returns:
- a PortletQueryForeach with title only.
- Since:
- jcms-10.0.8 / JCMS-10823
-
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()
-
updateGroupVisibilityTx
public static void updateGroupVisibilityTx(java.lang.String grpId, int visibility)- Parameters:
grpId- group to set new visibilityvisibility- the new visibility to set- Since:
- jcms-10.0.8 / JCMS-10641
-
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)
-
toReflectString
public static java.lang.String toReflectString(java.lang.Object o)
- Parameters:
o- object to render as reflection String- Returns:
- toString multiline representation of object using
ReflectionToStringBuilder. - Since:
- jcms-10.0.8
-
datasToString
public static java.lang.String datasToString(java.util.List<Data> datas)
Use as follow:JcmsTestCaseUtil.datasToString(Util.getArrayList(recommendation, null, member, article))
Produces output like:
[ #1: [Recommendation] [class: com.jalios.jcms.recommendation.Recommendation] [id: 1_Recommendation] [author: Admin] (1_Recommendation), #2: null, #3: [Member] Alice (c_1234) #4: [Article] My article (c_1333) ]
- Parameters:
datas- collection of data to debug- Returns:
- a multiline String representation of a List of Data, with new line and comma separator, with indices
and mapped with
JcmsUtil.dataToString(Data) - Since:
- jcms-10.0.8 / JCMS-10771
-
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
-
updateToLDAP_accountTx
public static void updateToLDAP_accountTx(java.lang.String mid, java.lang.String opAuthorId)Performs member update as LDAP account by setting him a lastLdapSynchro.- Parameters:
mid- id of member to updateopAuthorId- id of opAuthor- Since:
- jcms-10.0.8 / JCMS-10223
-
disableMemberTx
public static void disableMemberTx(java.lang.String mid)
Performs member disable update in a dedicated transaction using default admin as opAuthor.- Parameters:
mid- id of member to disable- Since:
- jcms-10.0.8 / JCMS-9978
-
disableMemberTx
public static void disableMemberTx(java.lang.String mid, java.lang.String opAuthorId)Performs member disable update in a dedicated transaction.- Parameters:
mid- id of member to disableopAuthorId- id of opAuthor- Since:
- jcms-10.0.8 / JCMS-9978
-
enableMemberTx
public static void enableMemberTx(java.lang.String mid)
Sets a new password on member to enable it.- Parameters:
mid- id of member to enable- Since:
- jcms-10.0.8 / JCMS-9978
-
enableMemberTx
public static void enableMemberTx(java.lang.String mid, java.lang.String opAuthorId)Sets a new password on member to enable it.- Parameters:
mid- id of member to enableopAuthorId- id of opAuthor- Since:
- jcms-10.0.8 / JCMS-9978
-
updateToAccountTx
public static void updateToAccountTx(java.lang.String mid)
Performs update of member usage to Account in a dedicated transaction using default admin as opAuthor.- Parameters:
mid- id of member to convert to a Contact- Since:
- jcms-10.0.8 / JCMS-9978
-
updateToAccountTx
public static void updateToAccountTx(java.lang.String mid, java.lang.String opAuthorId)Performs update of member usage to Account in a dedicated transaction.- Parameters:
mid- id of member to convert to a ContactopAuthorId- id of opAuthor- Since:
- jcms-10.0.8 / JCMS-9978
-
updateToContactTx
public static void updateToContactTx(java.lang.String mid)
Performs update of member usage to Contact in a dedicated transaction using default admin as opAuthor.- Parameters:
mid- id of member to convert to a Contact- Since:
- jcms-10.0.8 / JCMS-9978
-
updateToContactTx
public static void updateToContactTx(java.lang.String mid, java.lang.String opAuthorId)Performs update of member usage to Contact in a dedicated transaction.- Parameters:
mid- id of member to convert to a ContactopAuthorId- id of opAuthor- Since:
- jcms-10.0.8 / JCMS-9978
-
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
-
updateMemberDeclaredManagerTx
public static void updateMemberDeclaredManagerTx(java.lang.String mid, java.lang.String declaredManagerId)Checks and performs update given Member with given declared manager.Opens and closes a new transaction.
opAuthor will be default admin.
- Parameters:
mid- the id of Member to be updateddeclaredManagerId- the id of Member to set as declaredManager- Since:
- jcms-10.0.8
-
updateMemberAssistantTx
public static void updateMemberAssistantTx(java.lang.String memberId, java.lang.String assistantId)Checks and performs update given Member with given assistant.Opens and closes a new transaction.
opAuthor will be default admin.
- Parameters:
memberId- the Member to be updatedassistantId- the id of Member to set as assistant- Since:
- jcms-10.0.8
-
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
checkAndPerformCreateis 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
checkAndPerformUpdateis 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 updatebeforePerformConsumer- 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)
One-line update statement within a dedicated transaction.JcmsTestCaseUtil.checkAndUpdateTx(mid, updated -> ((Member) updated).setUsage(Member.USAGE_CONTACT)); JcmsTestCaseUtil.checkAndUpdateTx(pub.getId(), updated -> ((Article) updated).setPicture(doc.getFilename()));
- Type Parameters:
T- type of data to work with- Parameters:
dataId- the ID of data instance to updatebeforePerformConsumer- the optional consumer to be called before update.- See Also:
checkAndUpdateTx(String, Consumer, String)
-
checkAndUpdateTx
public static <T extends Data> void checkAndUpdateTx(java.lang.String dataId, java.util.function.Consumer<T> beforePerformConsumer, java.lang.String opAuthorId)
One-line update statement within a dedicated transaction.JcmsTestCaseUtil.checkAndUpdateTx(mid, updated -> ((Member) updated).setUsage(Member.USAGE_CONTACT), admin.getId()); JcmsTestCaseUtil.checkAndUpdateTx(pub.getId(), updated -> ((Article) updated).setPicture(doc.getFilename()), admin.getId());
- Type Parameters:
T- type of data to work with- Parameters:
dataId- the ID of data instance to updatebeforePerformConsumer- the optional consumer to be called before update.opAuthorId- the ID of member to use for opUpdate- See Also:
checkAndUpdate(Data, Consumer, Member)
-
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
-
setupOrganizationRootGroupTx
public static java.lang.String setupOrganizationRootGroupTx()
Creates a group and sets it as organization root group in properties.- Returns:
- id of created group
- Since:
- jcms-10.0.8 JCMS-10641
- See Also:
JcmsConstants.ORGANIZATION_ROOT_GROUP_PROP,Channel.getOrganizationRootGroup()
-
createOrganizationGroupTx
public static java.lang.String createOrganizationGroupTx(java.lang.String name)
Creates a group, direct child of organization root group.- Parameters:
name- name of new group- Returns:
- id of created group
- Since:
- jcms-10.0.8 JCMS-10641
- See Also:
JcmsConstants.ORGANIZATION_ROOT_GROUP_PROP,Channel.getOrganizationRootGroup()
-
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
-
-