Class JcmsTestCase
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- com.jalios.jcms.test.JcmsTestCase
-
- All Implemented Interfaces:
JcmsConstants,JaliosConstants,junit.framework.Test
public abstract class JcmsTestCase extends junit.framework.TestCase implements JcmsConstants
Provides a super class for development of JCMS unit tests with JUnit3.
Extending this class will automatically provides a working JCMS during execution of all your unit tests.The launched instance of JCMS will be using the following 3 files :
WEB-INF/data/store.xml.junit: copy ofWEB-INF/data/store.xml.releaseif it exists, otherwise copy ofWEB-INF/data/store.xmlWEB-INF/data/custom.prop.junit: copy ofWEB-INF/data/custom.prop.releaseif it exists, otherwise copy ofWEB-INF/data/custom.prop
Also, if file
WEB-INF/data/junit.propexists, its content is appended to the junit fileWEB-INF/data/custom.prop.junit.Warning!: Even though,
store.xmlandcustom.propare not modified by launching a test case using this class, beware that a real JCMS is being launched, thus some other legitimate file might be modified (monitor.xml, logs, stats, lucene index, etc).Some useful protected variables are provided to your subclass for easier Data manipulation in your test cases :
admin: default administrator (channel.getDefaultAdmin())defaultWorkspace: default workspace (channel.getDefaultWorkspace())defaultGroup: default group (channel.getDefaultGroup())
- getMockHttpSession()
- getMockHttpServletRequest() or getMockHttpServletRequest(HttpSession)
- getMockJcmsJspContext() or getMockJcmsJspContext(HttpServletRequest)
By extending this class you can use any log4j logger starting with"unittests.", the log message will be appendended to standard console.Example :
public class MyFeatureTest extends com.jalios.jcms.test.JcmsTestCase { private static final Logger logger = Logger.getLogger(MyFeatureTest.class.getName()); Data testData = null; protected void setUp() throws Exception { super.setUp(); logger.info("Creating new article for MyFeature test..."); Article article = new Article(); article.setWorkspace(defaultWorkspace); article.setTitle("en", "Article Title en " + new Date()); article.performCreate(admin); testData = article } public void testMethod1() { HttpSession testSession = getMockHttpSession(); assertTrue(MyFeature.method1(getMockHttpServletRequest(testSession), testData)); assertFalse(MyFeature.method1(getMockHttpServletRequest(testSession), testData)); ... } protected void tearDown() throws Exception { super.tearDown(); if (testData != null) { logger.info("Deleting article created for MyFeature test..."); testData.performDelete(admin); } } }- Since:
- jcms-5.7.4
--@deprecated use
JcmsTestCase4
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringA_VERY_LONG_TEXTprotected static Memberadminprotected static longASYNC_TEST__ITERATION_WAIT_TIMEprotected static longASYNC_TEST__MAX_ITERATIONprotected static longASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILUREprotected static ChannelchannelSingleton used for testingprotected static GroupdefaultGroupprotected static WorkspacedefaultWorkspaceprotected static FriendlyURLFilterfriendlyURLFilterInstance of the FriendlyURLFilter being used for testingprotected static java.lang.String[]langsArray of all channel languages (channel.getLanguageList())-
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
-
-
Constructor Summary
Constructors Constructor Description JcmsTestCase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidassertAlert(Alert expectedAlert, Alert actualAlert)protected voidassertCanBeReadBy(Publication pub, Group grp)Deprecated.since JCMS-8577protected voidassertCanBeReadBy(Publication pub, Member mbr)protected voidassertCanBeReadBy(Publication pub, Member mbr, boolean searchInGroup)protected voidassertCanDeleteOther(Member mbr, Data data)protected voidassertCannotBeReadBy(Publication pub, Group grp, RightInfo.Explanation restriction)Deprecated.since JCMS-8577protected voidassertCannotBeReadBy(Publication pub, Member mbr, boolean searchInGroup, RightInfo.Explanation explanation)protected voidassertCannotBeReadBy(Publication pub, Member mbr, RightInfo.Explanation explanation)protected voidassertCannotDeleteOther(Member mbr, Data data, RightInfo.Explanation explanation)protected voidassertCannotUpdateOther(Member mbr, Data data, RightInfo.Explanation explanation)protected voidassertCannotWorkOn(Member mbr, Publication pub, RightInfo.Explanation explanation)protected voidassertCanUpdateOther(Member mbr, Data data)protected voidassertCanWorkOn(Member mbr, Publication pub)protected <T> voidassertCmpEquals(java.util.Comparator<T> comparator, T o1, T o2)protected <T> voidassertCmpGreater(java.util.Comparator<T> comparator, T o1, T o2)protected <T> voidassertCmpLower(java.util.Comparator<T> comparator, T o1, T o2)protected <T> voidassertCmpOpposite(java.util.Comparator<T> comparator, T o1, T o2)protected <T> voidassertCmpSame(java.util.Comparator<T> c1, java.util.Comparator<T> c2, T o1, T o2)protected voidassertDateRange(java.util.Date date, java.util.Date lowerDate, java.util.Date upperDate)Assert the given date d1 is in range {d2, d3}protected voidassertDateRangeStrict(java.util.Date date, java.util.Date lowerDate, java.util.Date upperDate)Assert the given date date is in the range {lowerDate, upperDate}protected voidassertIsEmpty(java.lang.Object obj)protected voidassertIsEmpty(java.lang.String message, java.lang.Object obj)protected voidassertIsSameXml(java.lang.String expectedXml, java.lang.String xmlString)Assert given xml string are identicial ( except normalized spaces).protected voidassertIsSimilarXml(java.lang.String expectedXml, java.lang.String xmlString)Assert given xml string are similar (normalized spaces and child present by in different order)protected voidassertNotEmpty(java.lang.Object obj)protected voidassertNotEmpty(java.lang.String message, java.lang.Object obj)protected voidassertNotSameContent(java.lang.Object[] array1, java.lang.Object[] array2)protected voidassertNotSameContent(java.lang.String message, java.lang.Object[] array1, java.lang.Object[] array2)protected voidassertNotSameContent(java.lang.String message, java.util.Collection<?> col1, java.util.Collection<?> col2)protected voidassertNotSameContent(java.lang.String message, java.util.Date date1, java.util.Date date2)protected voidassertNotSameContent(java.lang.String message, java.util.List<?> list1, java.util.List<?> list2)protected voidassertNotSameContent(java.lang.String message, java.util.Map<?,?> map1, java.util.Map<?,?> map2)protected voidassertNotSameContent(java.lang.String message, java.util.Set<?> set1, java.util.Set<?> set2)protected voidassertNotSameContent(java.util.Date date1, java.util.Date date2)protected voidassertNotSameContent(java.util.List<?> list1, java.util.List<?> list2)protected voidassertNotSameContent(java.util.Map<?,?> map1, java.util.Map<?,?> map2)protected voidassertNotSameContent(java.util.Set<?> set1, java.util.Set<?> set2)static voidassertObjectIsGarbageCollected(java.lang.ref.WeakReference<? extends java.lang.Object> wRef, long timeout, boolean heapDump)Check that the specified Object (referenced through a WeakReference) is garbage collected in the designated time.protected voidassertRange(long value, long minValue, long maxValue, boolean strict)Assert the given value lesser than minValue and graeter than maxValue.protected voidassertSameContent(java.lang.Object[] array1, java.lang.Object[] array2)protected voidassertSameContent(java.lang.String message, java.lang.Object[] array1, java.lang.Object[] array2)protected voidassertSameContent(java.lang.String message, java.util.Collection<?> col1, java.util.Collection<?> col2)protected voidassertSameContent(java.lang.String message, java.util.Date date1, java.util.Date date2)protected voidassertSameContent(java.lang.String message, java.util.List<?> list1, java.util.List<?> list2)protected voidassertSameContent(java.lang.String message, java.util.Map<?,?> map1, java.util.Map<?,?> map2)protected voidassertSameContent(java.util.Collection<?> col1, java.util.Collection<?> col2)protected voidassertSameContent(java.util.Date date1, java.util.Date date2)protected voidassertSameContent(java.util.List<?> list1, java.util.List<?> list2)protected voidassertSameContent(java.util.Map<?,?> map1, java.util.Map<?,?> map2)protected voidassertSameContent(java.util.Set<?> set1, java.util.Set<?> set2)protected voidassertSameDateList(java.util.List<java.util.Date> expectedDateList, java.util.List<java.util.Date> actualDateList)protected voidassertSameDateSet(java.util.Set<java.util.Date> expectedDateSet, java.util.Set<java.util.Date> actualDateSet)protected voidassertStatusForbidden(ControllerStatus status)protected voidassertStatusHasFailed(ControllerStatus status)protected voidassertStatusHasFailed(java.lang.String prop, ControllerStatus status)protected voidassertStatusOK(ControllerStatus status)protected voidassertTypesDisabled(Workspace ws, java.lang.Class<?>... classes)Assert given types are disabled in the given Workspace.protected voidassertTypesEnabled(Workspace ws, java.lang.Class<?>... classes)Assert given types are enabled in the given Workspace.protected voidbeginTransaction()protected voidcommitTransaction()protected voidcreateWorkspace(Workspace workspace)Utility method to create the given Workspace by admin Member.protected voidcreateWorkspace(Workspace workspace, Member author)Utility method to create the given Workspace by admin Member.protected java.lang.StringdataToDebugString(Data data)Produces output like:
[(Clazz' simple name) {data.toString()} (id)]protected voiddeleteData(Data... array)protected voiddeleteData(java.lang.String... ids)protected voiddeleteOnTearDown(Data data)protected 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 :protected java.lang.Objectdeserialize(java.io.File file)Deserialize the given file into a new object which is returned.protected voiddisableJSync()Disable JSync in Junit propprotected voiddisableLdap()Disable Ldap in Junit propprotected voidenableJSync()Enable JSync in Junit propprotected voidenableLdap()Enable Ldap in Junit propprotected javax.servlet.http.HttpServletRequestgetMockHttpServletRequest()Convenient Method to return a new instance of a fake http servlet request.protected 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 sessionprotected javax.servlet.http.HttpServletResponsegetMockHttpServletResponse()Convenient Method to return a new instance of a fake http servlet response.protected 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 sessionprotected javax.servlet.http.HttpSessiongetMockHttpSession()Convenient Method to return a new instance of a fake http session.protected JcmsJspContextgetMockJcmsJspContext()Retrieve a mock explorer JcmsJspContext.protected JcmsJspContextgetMockJcmsJspContext(javax.servlet.http.HttpServletRequest request)Retrieve a mock explorer JcmsJspContext based on the specified requestprotected javax.servlet.ServletContextgetMockServletContext()Convenient Method to return the fake servlet context used for this test.protected java.io.FilegetResourceFile(java.lang.String name)Retrieves a new File instance pointing to the specified resource name.protected booleanignoreUnstableTest()protected voidprepareWorkspaceDeletion(Workspace workspace)Remove WkRole which are referenced in other Workspaces to avoid unexpected WkRole deletion (due to Workspace.performDelete)protected voidrestoreAuthenticationRequired()Restores property "channel.is-authentication-required".protected voidrestoreIncomingMail()Restores property "mail.incoming.enabled".protected voidrestoreProperties(JProperties properties)Restores given JProperties.protected voidrestoreProperties(java.util.Collection<java.lang.String> names)Restores given properties represented by their names.protected voidrestoreProperty(java.lang.String name)Restores given property.protected java.io.Fileserialize(java.lang.Object obj)Serialize the given object into a temp file and return this file.protected voidsetAuthenticationRequired(boolean isAuthRequired)Sets property "channel.is-authentication-required" toisAuthRequired.protected voidsetIncomingMail(boolean enabled)Sets property "mail.incoming.enabled" toenabled.protected voidsetProperties(JProperties properties)Sets given JProperties.protected voidsetProperties(java.util.Map<java.lang.String,java.lang.String> map)protected voidsetProperty(java.lang.String name, java.lang.String value)protected voidsetUp()protected voidsleep(long millis)protected voidtearDown()protected voidwaitForAlarm(long time, AlarmManager alarmMgr, boolean reallyWaitFor, java.lang.String logPrefix)protected voidwaitForDBTimePrecision()wait 1 ms if the DB support time with ms precision, otherwise 1 sprotected voidwaitForLuceneIndexation(boolean checkFileContentIndexing, Publication... pubs)protected 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().-
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
-
-
-
-
Field Detail
-
friendlyURLFilter
protected static FriendlyURLFilter friendlyURLFilter
Instance of the FriendlyURLFilter being used for testing
-
channel
protected static Channel channel
Singleton used for testing
-
langs
protected static java.lang.String[] langs
Array of all channel languages (channel.getLanguageList())
-
admin
protected static Member admin
-
defaultWorkspace
protected static Workspace defaultWorkspace
-
defaultGroup
protected static Group defaultGroup
-
A_VERY_LONG_TEXT
protected static java.lang.String A_VERY_LONG_TEXT
-
ASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILURE
protected static long ASYNC_TEST__MAX_WAIT_TIME_BEFORE_FAILURE
-
ASYNC_TEST__ITERATION_WAIT_TIME
protected static long ASYNC_TEST__ITERATION_WAIT_TIME
-
ASYNC_TEST__MAX_ITERATION
protected static long ASYNC_TEST__MAX_ITERATION
-
-
Method Detail
-
setUp
protected void setUp() throws java.lang.Exception- Overrides:
setUpin classjunit.framework.TestCase- Throws:
java.lang.Exception
-
tearDown
protected void tearDown() throws java.lang.Exception- Overrides:
tearDownin classjunit.framework.TestCase- Throws:
java.lang.Exception
-
getMockServletContext
protected javax.servlet.ServletContext getMockServletContext()
Convenient Method to return the fake servlet context used for this test.- Returns:
- a ServletContext
- See Also:
MockServletContext
-
getMockHttpSession
protected javax.servlet.http.HttpSession getMockHttpSession()
Convenient Method to return a new instance of a fake http session.- Returns:
- a HttpSession
- See Also:
HttpSession
-
getMockHttpServletRequest
protected 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
protected 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
protected 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
protected 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
protected JcmsJspContext getMockJcmsJspContext()
Retrieve a mock explorer JcmsJspContext.- Returns:
- a new instance of JcmsJspContext
- Since:
- jcms-5.7.3
-
getMockJcmsJspContext
protected 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
-
assertStatusOK
protected void assertStatusOK(ControllerStatus status)
-
assertStatusForbidden
protected void assertStatusForbidden(ControllerStatus status)
-
assertStatusHasFailed
protected void assertStatusHasFailed(ControllerStatus status)
-
assertStatusHasFailed
protected void assertStatusHasFailed(java.lang.String prop, ControllerStatus status)
-
assertCanBeReadBy
protected void assertCanBeReadBy(Publication pub, Member mbr)
-
assertCannotBeReadBy
protected void assertCannotBeReadBy(Publication pub, Member mbr, RightInfo.Explanation explanation)
-
assertCanBeReadBy
protected void assertCanBeReadBy(Publication pub, Member mbr, boolean searchInGroup)
-
assertCannotBeReadBy
protected void assertCannotBeReadBy(Publication pub, Member mbr, boolean searchInGroup, RightInfo.Explanation explanation)
-
assertCanBeReadBy
@Deprecated protected void assertCanBeReadBy(Publication pub, Group grp)
Deprecated.since JCMS-8577Assert publication can be read by specified group- Parameters:
pub- publication to checkgrp- group to verify
-
assertCannotBeReadBy
protected void assertCannotBeReadBy(Publication pub, Group grp, RightInfo.Explanation restriction)
Deprecated.since JCMS-8577Assert publication can be read by specified group- Parameters:
pub- publication to checkgrp- group to verifyrestriction- the expected explanation
-
assertCannotUpdateOther
protected void assertCannotUpdateOther(Member mbr, Data data, RightInfo.Explanation explanation)
-
assertCannotDeleteOther
protected void assertCannotDeleteOther(Member mbr, Data data, RightInfo.Explanation explanation)
-
assertCanWorkOn
protected void assertCanWorkOn(Member mbr, Publication pub)
-
assertCannotWorkOn
protected void assertCannotWorkOn(Member mbr, Publication pub, RightInfo.Explanation explanation)
-
assertCmpGreater
protected <T> void assertCmpGreater(java.util.Comparator<T> comparator, T o1, T o2)
-
assertCmpLower
protected <T> void assertCmpLower(java.util.Comparator<T> comparator, T o1, T o2)
-
assertCmpEquals
protected <T> void assertCmpEquals(java.util.Comparator<T> comparator, T o1, T o2)
-
assertCmpOpposite
protected <T> void assertCmpOpposite(java.util.Comparator<T> comparator, T o1, T o2)
-
assertCmpSame
protected <T> void assertCmpSame(java.util.Comparator<T> c1, java.util.Comparator<T> c2, T o1, T o2)
-
assertSameContent
protected void assertSameContent(java.lang.Object[] array1, java.lang.Object[] array2)
-
assertSameContent
protected void assertSameContent(java.lang.String message, java.lang.Object[] array1, java.lang.Object[] array2)
-
assertNotSameContent
protected void assertNotSameContent(java.lang.Object[] array1, java.lang.Object[] array2)
-
assertNotSameContent
protected void assertNotSameContent(java.lang.String message, java.lang.Object[] array1, java.lang.Object[] array2)
-
assertSameContent
protected void assertSameContent(java.util.Collection<?> col1, java.util.Collection<?> col2)- Since:
- jcms-9.0.3
-
assertSameContent
protected void assertSameContent(java.lang.String message, java.util.Collection<?> col1, java.util.Collection<?> col2)- Since:
- jcms-9.0.3
-
assertNotSameContent
protected void assertNotSameContent(java.lang.String message, java.util.Collection<?> col1, java.util.Collection<?> col2)- Since:
- jcms-9.0.3
-
assertSameContent
protected void assertSameContent(java.util.Set<?> set1, java.util.Set<?> set2)
-
assertNotSameContent
protected void assertNotSameContent(java.util.Set<?> set1, java.util.Set<?> set2)
-
assertNotSameContent
protected void assertNotSameContent(java.lang.String message, java.util.Set<?> set1, java.util.Set<?> set2)
-
assertSameDateSet
protected void assertSameDateSet(java.util.Set<java.util.Date> expectedDateSet, java.util.Set<java.util.Date> actualDateSet)
-
assertSameContent
protected void assertSameContent(java.util.List<?> list1, java.util.List<?> list2)
-
assertSameContent
protected void assertSameContent(java.lang.String message, java.util.List<?> list1, java.util.List<?> list2)
-
assertSameDateList
protected void assertSameDateList(java.util.List<java.util.Date> expectedDateList, java.util.List<java.util.Date> actualDateList)
-
assertNotSameContent
protected void assertNotSameContent(java.util.List<?> list1, java.util.List<?> list2)
-
assertNotSameContent
protected void assertNotSameContent(java.lang.String message, java.util.List<?> list1, java.util.List<?> list2)
-
assertSameContent
protected void assertSameContent(java.util.Map<?,?> map1, java.util.Map<?,?> map2)
-
assertSameContent
protected void assertSameContent(java.lang.String message, java.util.Map<?,?> map1, java.util.Map<?,?> map2)
-
assertNotSameContent
protected void assertNotSameContent(java.util.Map<?,?> map1, java.util.Map<?,?> map2)
-
assertNotSameContent
protected void assertNotSameContent(java.lang.String message, java.util.Map<?,?> map1, java.util.Map<?,?> map2)
-
assertSameContent
protected void assertSameContent(java.util.Date date1, java.util.Date date2)
-
assertSameContent
protected void assertSameContent(java.lang.String message, java.util.Date date1, java.util.Date date2)
-
assertNotSameContent
protected void assertNotSameContent(java.util.Date date1, java.util.Date date2)
-
assertNotSameContent
protected void assertNotSameContent(java.lang.String message, java.util.Date date1, java.util.Date date2)
-
assertIsEmpty
protected void assertIsEmpty(java.lang.Object obj)
-
assertIsEmpty
protected void assertIsEmpty(java.lang.String message, java.lang.Object obj)
-
assertNotEmpty
protected void assertNotEmpty(java.lang.Object obj)
-
assertNotEmpty
protected void assertNotEmpty(java.lang.String message, java.lang.Object obj)
-
assertRange
protected void assertRange(long value, long minValue, long maxValue, boolean strict)Assert the given value lesser than minValue and graeter than maxValue.- Parameters:
value- the valueminValue- the minValuemaxValue- the maxValuestrict- true if the comparison must be strict- Since:
- jcms-8.0.1
-
assertDateRange
protected void assertDateRange(java.util.Date date, java.util.Date lowerDate, java.util.Date upperDate)Assert the given date d1 is in range {d2, d3}- Parameters:
date- the date to be testedlowerDate- the lower date limit (may be null)upperDate- the upper date limit (may be null)
-
assertDateRangeStrict
protected void assertDateRangeStrict(java.util.Date date, java.util.Date lowerDate, java.util.Date upperDate)Assert the given date date is in the range {lowerDate, upperDate}- Parameters:
date- the date to be testedlowerDate- the lower date limit (may be null)upperDate- the upper date limit (may be null)
-
assertObjectIsGarbageCollected
public static void assertObjectIsGarbageCollected(java.lang.ref.WeakReference<? extends java.lang.Object> wRef, long timeout, boolean heapDump)Check that the specified Object (referenced through a WeakReference) is garbage collected in the designated time. Otherwise throw an assertion failure.IMPORTANT : in order for this method to work properly and success, you must get rid of all strong references of your object in the method callee. For example :
Publication pub1 = createSmallNews(admin, defaultWorkspace); pub1.performDelete(); // 1. Create WeakReference for the object WeakReference<Object> pub1WeakRef = new WeakReference<Object>(pub1); // 2. Remove strong reference for the object pub1 = null; // 3. Test object is garbage collected correctly, requesting a heap dump in case of failure assertObjectIsGarbageCollected(pub1WeakRef, 10*MILLIS_IN_ONE_SECOND, true);
Implementation note : this method will trigger a GC through
System.gc()every second until the timeout has been reached or the object is detected has garbage collected.- Parameters:
wRef- the object WeakReference (required to prevent strong reference of object through callstack)timeout- the timeout after which this method will consider (should be a multiple of 1000 ms with current implementation)heapDump- perform HEAP dump on failure for easier debugging
-
assertTypesEnabled
protected void assertTypesEnabled(Workspace ws, java.lang.Class<?>... classes)
Assert given types are enabled in the given Workspace.- Parameters:
ws- the workspace to testclasses- classes to test they are enabled in ws- Since:
- jcms-8.0.3, jcms-9.0.0
-
assertTypesDisabled
protected void assertTypesDisabled(Workspace ws, java.lang.Class<?>... classes)
Assert given types are disabled in the given Workspace.- Parameters:
ws- the workspace to testclasses- classes to test they are disabled in ws- Since:
- jcms-8.0.3, jcms-9.0.0
-
assertIsSimilarXml
protected void assertIsSimilarXml(java.lang.String expectedXml, java.lang.String xmlString)Assert given xml string are similar (normalized spaces and child present by in different order)- Parameters:
expectedXml- the expected XML stringxmlString- the XML string to check
-
assertIsSameXml
protected void assertIsSameXml(java.lang.String expectedXml, java.lang.String xmlString)Assert given xml string are identicial ( except normalized spaces). In this method child order is check.- Parameters:
expectedXml- the expected XML stringxmlString- the XML string to check
-
getResourceFile
protected java.io.File getResourceFile(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(getClass().getClassLoader().getResource(name).getFile());- Parameters:
name- the name of the resource, a '/'-separated path name that identifies the resource. e.g"com/company/jcms/MyFeature_testFile1.txt"- Returns:
- the file
- See Also:
JcmsTestCaseUtil.getResourceFile(Class, String)
-
serialize
protected 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
protected 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
protected void beginTransaction()
-
commitTransaction
protected void commitTransaction()
-
deleteData
protected void deleteData(Data... array)
-
deleteData
protected void deleteData(java.lang.String... ids)
-
prepareWorkspaceDeletion
protected void prepareWorkspaceDeletion(Workspace workspace)
Remove WkRole which are referenced in other Workspaces to avoid unexpected WkRole deletion (due to Workspace.performDelete)- Parameters:
workspace- the Workspace to be deleted.
-
deleteOnTearDown
protected void deleteOnTearDown(Data data)
-
deleteOnTearDown
protected 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
-
sleep
protected void sleep(long millis)
- Parameters:
millis- the length of time to sleep in milliseconds.
-
waitForAlarm
protected void waitForAlarm(long time, AlarmManager alarmMgr, boolean reallyWaitFor, java.lang.String logPrefix)
-
waitForLuceneIndexation
protected 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
protected void waitForLuceneIndexation(boolean checkFileContentIndexing, Publication... pubs)
-
dataToDebugString
protected java.lang.String dataToDebugString(Data data)
Produces output like:
[(Clazz' simple name) {data.toString()} (id)]- 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
-
waitForDBTimePrecision
protected void waitForDBTimePrecision()
wait 1 ms if the DB support time with ms precision, otherwise 1 s
-
setProperty
protected 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
protected 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
protected void setProperties(JProperties properties)
Sets given JProperties.First call of this method will backup property's current value, for automatic restore in
tearDown().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
protected 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
protected 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
protected void restoreProperties(JProperties properties)
Restores given JProperties.- Parameters:
properties- the JProperties to restore.- Since:
- jcms-8.0.3, jcms-9.0.0
-
setIncomingMail
protected 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
protected void restoreIncomingMail()
Restores property "mail.incoming.enabled".- Since:
- jcms-8.0.3, jcms-9.0.0
-
setAuthenticationRequired
protected 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
protected void restoreAuthenticationRequired()
Restores property "channel.is-authentication-required".- Since:
- jcms-8.0.3, jcms-9.0.0
-
enableJSync
protected void enableJSync()
Enable JSync in Junit prop
-
disableJSync
protected void disableJSync()
Disable JSync in Junit prop
-
enableLdap
protected void enableLdap()
Enable Ldap in Junit prop
-
disableLdap
protected void disableLdap()
Disable Ldap in Junit prop
-
createWorkspace
protected 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
protected 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
-
ignoreUnstableTest
protected boolean ignoreUnstableTest()
-
-