Class JcmsTestCaseUtil
- All Implemented Interfaces:
JcmsConstants,WorkflowConstants,JaliosConstants
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Stringstatic longstatic longstatic longstatic final StringConvenient one-time crypted password as a constant, since each crypt operation takes some milliseconds.static final StringDefault 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_YEARFields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, 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, GENERATIONAL_STORE_DIRECTORY, 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, PHOTO_XLARGE, PHOTO_XLARGE_HEIGHT, PHOTO_XLARGE_PROP_PREFIX, PHOTO_XLARGE_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_XML, SUCCESS_MSG, SVG_ICON_PREFIX, SVGINLINE_ICON_PREFIX, SVGSPRITE_ICON_PREFIX, TEMPLATE_TAB, THEME_DIR, 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, TYPES_UNKNOWN_CLASS_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_XMLFields inherited from interface com.jalios.jcms.WorkflowConstants
ACTION, ACTION_REPEAT, ACTION_TYPE, ACTION_WHEN, ALL_WF, ARCHIVED_PSTATUS, DEFAULT_DRAFT_PSTATUS, EXPIRED_PSTATUS, INHERIT_WORKFLOW, 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddMemberInGroupTx(Group group, 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.addReadRights(Publication pub, Group... groups) Convenient method to add read right Groups on given publication.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(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(String message, boolean expectedSameData, Data expectedData, Data actualData) Assert 2 datas are or are not the same.static voidassertSameData(String message, Data expectedData, Data actualData) Assert 2 datas are the same.static <T> HashSet<T> asSet(T... array) Convenient shorthand forUtil.getHashSet(Object...).static voidcheckAndCreate(T data, Consumer<T> beforePerformConsumer) Delegates tocheckAndCreate(Data, Consumer, Member)with data's author as create opAuthor.checkAndCreate(T data, Consumer<T> beforePerformConsumer, Member opAuthor) Checks and creates the given data instance.static voidcheckAndDelete(Data data, Member opAuthor) static voidcheckAndDeleteTx(String dataId) static voidcheckAndDeleteTx(String dataId, 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, 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, Consumer<T> beforePerformConsumer, Member opAuthor) Checks and updates the given data instance.static <T extends Data>
voidcheckAndUpdateTx(String dataId, Consumer<T> beforePerformConsumer) One-line update statement within a dedicated transaction.static <T extends Data>
voidcheckAndUpdateTx(String dataId, Consumer<T> beforePerformConsumer, String opAuthorId) One-line update statement within a dedicated transaction.static voidstatic voidconfigureLoggerAppender(org.apache.log4j.Logger logger) static voidcopyPhotoAndSetMemberPhoto(Member member, File origPhotoFile) Copies unittest mock photo file to a new tempFile.static GroupcreateACLGroup(String resource) static generated.ArticlecreateArticle(Member writer, Workspace ws, boolean deleteOnTearDown) static CategorycreateCategory(String name, Category parent) static DBFileDocumentcreateDBFileDocument(Member writer, Workspace ws, String title, String filename) static DBMembercreateDBMember(String name) static DBMembercreateDBMember(String name, boolean deleteOnTearDown) static DBMembercreateDBMember(String name, boolean deleteOnTearDown, Group... groups) static DBMembercreateDBMember(String name, Group... groups) static StringcreateDBMemberTx(String name) Creates a DB member in a dedicated transaction.static StringcreateDBMemberTx(String name, Group... groups) Creates a DB member in a dedicated transaction.static voidcreateFile(File file, String content) static StringcreateFile(String filename) static FileDocumentcreateFileDocument(Member writer, Workspace ws, String title, String filename) static GroupcreateGroupTx(String name) Creates a new group inside a new transaction that is commited at the end of process.static GroupcreateGroupTx(String name, 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, String title, String filename) static MembercreateMember(String name) static MembercreateMember(String name, boolean deleteOnTearDown) static MembercreateMember(String name, boolean deleteOnTearDown, Group... groups) static MembercreateMember(String name, Group... groups) static StringcreateMemberTx(String name) Creates a JStore member in a dedicated transaction.static StringCreates 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(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 StringdatasToString(List<Data> datas) Use as follow:static StringdataToDebugString(Data data) Produces a String representation of given Data for debug, log purpose.static voidstatic voidstatic voiddeleteAllAlerts(Member mbr) Delete all alerts for given Member in a dedicated transaction.static voiddeleteAllAlertsTx(String mid) Delete all alerts for Member with given id in a dedicated transaction.static voiddeleteData(Data... array) static voiddeleteData(String... ids) static voiddeleteOnTearDown(Data data) Adds given Data in list of Data to be deleted on test's tearDown.static voiddeleteOnTearDown(Workspace ws, 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 voidAdds given Data's id in list of Data to be deleted on test's tearDown.static Objectdeserialize(File file) Deserialize the given file into a new object which is returned.static voidDisable JSync in Junit prop.static voidDisable LDAP in Junit prop.static voiddisableMemberTx(String mid) Performs member disable update in a dedicated transaction using default admin as opAuthor.static voiddisableMemberTx(String mid, String opAuthorId) Performs member disable update in a dedicated transaction.static voidEnable JSync in Junit prop.static voidEnable LDAP in Junit prop.static voidenableMemberTx(String mid) Sets a new password on member to enable it.static voidenableMemberTx(String mid, String opAuthorId) Sets a new password on member to enable it.static voidEnabled LevelLevel.ALLon several classes to help diagnose a FORBIDDEN operation (it is probably be logged in trace or debug level).static voidexcludeDataFromTearDownCheck(Data... data) Exclude the specified data from the check performed on tear down, that ensures no data were created but not deleted, or deleted even though it existed prior test and should have been kept.static generated.ArticlegetArticle(Member writer, Workspace ws) static StringgetControllerStatusDebugString(ControllerStatus actualStatus) static DBFileDocumentgetDBFileDocument(Member writer, Workspace ws, String title, String filename) static FileDocumentgetFileDocument(Member writer, Workspace ws, String title, String filename) static generated.Mediastatic javax.servlet.http.HttpServletRequestConvenient 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.HttpServletResponseConvenient 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.HttpSessionConvenient Method to return a new instance of a fake http session.static JcmsJspContextRetrieve a mock explorer JcmsJspContext.static JcmsJspContextgetMockJcmsJspContext(javax.servlet.http.HttpServletRequest request) Retrieve a mock explorer JcmsJspContext based on the specified requeststatic javax.servlet.ServletContextConvenient 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 FilegetResourceFile(Class<?> clazz, 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(String link, Member writer, Workspace ws) protected static generated.SmallNewsgetSmallNews(Member writer, Workspace ws, boolean insertDateInContent) getWorkspaceDeleteOnTearDownSet(Workspace ws, Set<Data> initialDataSet) Returns a collection of Datas (bound to the Workspace) that have been created since the workspace creation.static booleanstatic voidRetrieve current C3P0 information from JXM and log them.static voidpublishPublicationTransaction(String pubId, Member opAuthor) Delegates toupdatePstatusTransaction(String, Member, int)using pstatusWorkflowConstants.PUBLISHED_PSTATUS.static voidremoveMemberFromGroupTx(Group group, String memberId) Checks and performs update given Member by removing hime from given Group.static voidRestores property "channel.is-authentication-required".static voidResets forcedChannel.isGuestAccountsEnabled().static voidRestores property "mail.incoming.enabled".static voidrestoreProperties(JProperties properties) Restores given JProperties.static voidrestoreProperties(Collection<String> names) Restores given properties represented by their names.static voidrestoreProperty(String name) Restores given property.static voidrestoreReadRightsGroups(Publication pub, Collection<Group> initialAuthorizedGroups) static voidrestoreReadRightsMembers(Publication pub, 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 FileSerialize 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(String packageOrClass, org.apache.log4j.Level level) static voidsetProperties(JProperties properties) Sets given JProperties.static voidsetProperties(Map<String, String> map) static voidsetProperty(String name, String value) static StringCreates a group and sets it as organization root group in properties.static org.apache.log4j.LoggerConfigures 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 Stringstatic voidupdateGroupVisibilityTx(String grpId, int visibility) static voidupdateMemberAssistantTx(String memberId, String assistantId) Checks and performs update given Member with given assistant.static voidupdateMemberDeclaredManagerTx(String mid, String declaredManagerId) Checks and performs update given Member with given declared manager.static voidupdateMemberEmailTransaction(String mid, String authorMid, String emailAddress) Checks and performs update given Member with given email address.static voidupdatePstatusTransaction(String pubId, Member opAuthor, int newPstatus) Checks and performs update the publication (makes an update instance) with given pstatus.static voidupdateTitleTransaction(String pubId, Member opAuthor, String newTitle) Checks and performs update the publication (makes an update instance) with given title.static voidupdateToAccountTx(String mid) Performs update of member usage to Account in a dedicated transaction using default admin as opAuthor.static voidupdateToAccountTx(String mid, String opAuthorId) Performs update of member usage to Account in a dedicated transaction.static voidupdateToContactTx(String mid) Performs update of member usage to Contact in a dedicated transaction using default admin as opAuthor.static voidupdateToContactTx(String mid, String opAuthorId) Performs update of member usage to Contact in a dedicated transaction.static voidupdateToLDAP_accountTx(String mid, String opAuthorId) Performs member update as LDAP account by setting him a lastLdapSynchro.static voidupdateWorkspaceTypeWorkflow(Workspace ws, Class<? extends Data> typeClass, Object workflowToUse) An utility method to update the given Workspace, with the chosen Workflow associated to the given Type.static voidupdateWorkspaceTypeWorkflow(Workspace ws, HashMap<Class<?>, Object> subTypeMap) An utility method to update the given Workspace typeMap.static StringvoteForPubTransaction(String pubId, String voterId) Adds a 1 point vote on given pub by given member.static voidwaitForAlarm(long time, AlarmManager alarmMgr, boolean reallyWaitFor, String logPrefix) static voidwait 1 ms if the DB support time with ms precision, otherwise 1 sstatic voidwaitForFileAvailability(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(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 Details
-
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
Default Member password clear value.- Since:
- jcms-10.0.7 JCMS-9172
- See Also:
-
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
-
-
Constructor Details
-
JcmsTestCaseUtil
public JcmsTestCaseUtil()
-
-
Method Details
-
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
-
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:
-
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:
-
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:
-
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:
-
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:
-
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:
-
getMockJcmsJspContext
Retrieve a mock explorer JcmsJspContext.- Returns:
- a new instance of JcmsJspContext
- Since:
- jcms-5.7.3
-
getMockJcmsJspContext
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
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:
Exception- if an error occurs
-
deserialize
Deserialize the given file into a new object which is returned.- Parameters:
file- the file- Returns:
- the object
- Throws:
Exception- if an error occurs
-
beginTransaction
public static void beginTransaction() -
commitTransaction
public static void commitTransaction() -
excludeDataFromTearDownCheck
Exclude the specified data from the check performed on tear down, that ensures no data were created but not deleted, or deleted even though it existed prior test and should have been kept.Invoke when your test purposely :
- created a new data that must persist after your test
- or deleted a data that existed prior the current test but you did it on purpose
- Parameters:
data- the Data that will not be verified on tear down- Since:
- JCMS-11330
-
deleteData
-
deleteData
-
getControllerStatusDebugString
-
deleteOnTearDown
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
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
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
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
-
deleteAllAlerts
public static void deleteAllAlerts() -
deleteAllAlerts
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
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
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, String logPrefix) -
waitForLuceneIndexation
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
-
waitForMemberLuceneIndexation
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:
ids- the ids of Member to found in index.- Throws:
Exception- if index could not be read or member could not be found
-
waitForMemberLuceneIndexation
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:
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
- Parameters:
name- the property name to setvalue- the property value to set- Since:
- jcms-8.0.3, jcms-9.0.0
- See Also:
-
setProperties
- Parameters:
map- the map of properties to set- Since:
- jcms-8.0.3, jcms-9.0.0
- See Also:
-
setProperties
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
Restores given property.- Parameters:
name- the name of property to restore- Since:
- jcms-8.0.3, jcms-9.0.0
- See Also:
-
restoreProperties
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
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
ForcesChannel.isGuestAccountsEnabled()to return given value.- Parameters:
enabled- true to force enabled state, false disabled state- Throws:
Exception- ...- Since:
- jcms-10.0.6
-
restoreGuestAccountsEnabled
Resets forcedChannel.isGuestAccountsEnabled().- Throws:
Exception- ...- Since:
- jcms-10.0.6
-
createCategory
-
createWorkspace
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
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
-
createGroupTx
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
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
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
-
createMemberTx
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
-
createMember
-
createMember
-
createDBMember
-
createDBMemberTx
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
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
-
createDBMember
-
createDBMember
-
copyPhotoAndSetMemberPhoto
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
-
createFile
- Throws:
Exception
-
waitForFileAvailability
- Throws:
Exception
-
getFileDocument
public static FileDocument getFileDocument(Member writer, Workspace ws, String title, String filename) -
createFileDocument
public static FileDocument createFileDocument(Member writer, Workspace ws, String title, String filename) -
getDBFileDocument
public static DBFileDocument getDBFileDocument(Member writer, Workspace ws, String title, String filename) -
createDBFileDocument
public static DBFileDocument createDBFileDocument(Member writer, Workspace ws, String title, String filename) -
createMedia
-
getMedia
-
getArticle
-
createArticle
-
getSmallNews
-
createSmallNews
-
getShortcut
-
getShortcut
-
getShortcut
- 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(String link, Member writer, Workspace ws, boolean deleteOnTearDown) -
getPortletQueryForeach
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
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
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, 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, Collection<Group> initialAuthorizedGroups) - Parameters:
pub- the pub to restore its initial authorizedGrouSetinitialAuthorizedGroups- initial authorized groups to restore (typically returned byaddReadRights(Publication, Group...))
-
updatePstatusTransaction
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:
-
publishPublicationTransaction
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:
-
updateTitleTransaction
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
- 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, Class<? extends Data> typeClass, 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
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
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
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:
-
toReflectString
- Parameters:
o- object to render as reflection String- Returns:
- toString multiline representation of object using
ReflectionToStringBuilder. - Since:
- jcms-10.0.8
-
datasToString
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:
-
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
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
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
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
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
Sets a new password on member to enable it.- Parameters:
mid- id of member to enable- Since:
- jcms-10.0.8 / JCMS-9978
-
enableMemberTx
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
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
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
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
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
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
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
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
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
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
public static <T extends Data> String checkAndCreate(T data, 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
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
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
public static <T extends Data> void checkAndUpdate(T data, 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(String dataId, 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
public static <T extends Data> void checkAndUpdateTx(String dataId, Consumer<T> beforePerformConsumer, 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:
-
checkAndDelete
-
checkAndDeleteTx
-
checkAndDeleteTx
-
asSet
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
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:
-
createOrganizationGroupTx
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:
-
assertSameData
Assert 2 datas are the same.- Since:
- jcms-10.0.6
- See Also:
-
assertSameData
Assert 2 datas are the same.- Since:
- jcms-10.0.6
- See Also:
-
assertNotSameData
Assert 2 datas are not the same.- Since:
- jcms-10.0.6
- See Also:
-
assertNotSameData
Assert 2 datas are not the same.- Since:
- jcms-10.0.6
- See Also:
-
assertSameData
public static void assertSameData(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
-