Package com.jalios.jcms.test
Class Assert
- java.lang.Object
-
- com.jalios.jcms.test.Assert
-
public class Assert extends java.lang.Object
A set of assertion methods useful for writing JCMS tests. These methods can be used directly:Assert.assertEquals(...)
, however, readability can be improved if they are referenced through static import:
import static com.jalios.jcms.test.Assert.*; ... assertEquals(...);
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Assert()
Protect constructor since it is a static only class
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
assertAlert(Alert expectedAlert, Alert actualAlert)
static void
assertCanBeReadBy(Publication pub, Group grp)
Deprecated.since JCMS-8577static void
assertCanBeReadBy(Publication pub, Member mbr)
static void
assertCanBeReadBy(Publication pub, Member mbr, boolean searchInGroup)
static void
assertCanDeleteOther(Member mbr, Data data)
static void
assertCannotBeReadBy(Publication pub, Group grp, RightInfo.Explanation restriction)
Deprecated.since JCMS-8577static void
assertCannotBeReadBy(Publication pub, Member mbr, boolean searchInGroup, RightInfo.Explanation explanation)
static void
assertCannotBeReadBy(Publication pub, Member mbr, RightInfo.Explanation explanation)
static void
assertCannotDeleteOther(Member mbr, Data data, RightInfo.Explanation explanation)
static void
assertCannotUpdateOther(Member mbr, Data data, RightInfo.Explanation explanation)
static void
assertCannotWorkOn(Member mbr, Publication pub, RightInfo.Explanation explanation)
static void
assertCanUpdateOther(Member mbr, Data data)
static void
assertCanWorkOn(Member mbr, Publication pub)
static <T> void
assertCmpEquals(java.util.Comparator<T> comparator, T o1, T o2)
static <T> void
assertCmpGreater(java.util.Comparator<T> comparator, T o1, T o2)
static <T> void
assertCmpLower(java.util.Comparator<T> comparator, T o1, T o2)
static <T> void
assertCmpOpposite(java.util.Comparator<T> comparator, T o1, T o2)
static <T> void
assertCmpSame(java.util.Comparator<T> c1, java.util.Comparator<T> c2, T o1, T o2)
static void
assertContains(boolean isExpectedContained, java.util.Collection<?> collection, java.lang.Object object)
static void
assertContains(java.lang.String message, boolean isExpectedContained, java.util.Collection<?> collection, java.lang.Object object)
static void
assertContainsAll(java.lang.String message, java.util.Collection<?> expectedElements, java.util.Collection<?> actualElements)
Assert that all elements inexpectedElements
are contained inactualElements
, butactualElements
can contain others elements not inexpectedElements
.static void
assertContainsAll(java.util.Collection<?> expectedElements, java.util.Collection<?> actualElements)
static void
assertDateRange(java.util.Date date, java.util.Date lowerDate, java.util.Date upperDate)
Assert the given date d1 is in range {d2, d3}static 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}static void
assertEmptyAttachWorkspaceSet(Publication pub)
Asserts given publication have no attached workspaces.static void
assertIsEmpty(java.lang.Object obj)
static void
assertIsEmpty(java.lang.String message, java.lang.Object obj)
static void
assertIsSameXml(java.lang.String expectedXml, java.lang.String xmlString)
Assert given xml string are identicial ( except normalized spaces).static 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)static void
assertNoStaticChannelField(java.lang.Class<?> clazz)
Checks given class does not declare a static Channel field.static void
assertNotEmpty(java.lang.Object obj)
static void
assertNotEmpty(java.lang.String message, java.lang.Object obj)
static void
assertNotSameContent(java.lang.Object[] array1, java.lang.Object[] array2)
static void
assertNotSameContent(java.lang.String message, java.lang.Object[] array1, java.lang.Object[] array2)
static void
assertNotSameContent(java.lang.String message, java.util.Collection<?> col1, java.util.Collection<?> col2)
static void
assertNotSameContent(java.lang.String message, java.util.Date date1, java.util.Date date2)
static void
assertNotSameContent(java.lang.String message, java.util.List<?> list1, java.util.List<?> list2)
static void
assertNotSameContent(java.lang.String message, java.util.Map<?,?> map1, java.util.Map<?,?> map2)
static void
assertNotSameContent(java.lang.String message, java.util.Set<?> set1, java.util.Set<?> set2)
static void
assertNotSameContent(java.util.Date date1, java.util.Date date2)
static void
assertNotSameContent(java.util.List<?> list1, java.util.List<?> list2)
static void
assertNotSameContent(java.util.Map<?,?> map1, java.util.Map<?,?> map2)
static void
assertNotSameContent(java.util.Set<?> set1, java.util.Set<?> set2)
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.static void
assertRange(long value, long minValue, long maxValue, boolean strict)
Assert the given value lesser than minValue and graeter than maxValue.static void
assertResult(CheckResult result)
Allows to throw assertions errors for multiple tests at a time.static void
assertResult(java.lang.String message, CheckResult result)
Allows to throw assertions errors for multiple tests at a time.static void
assertSameAttachWorkspaceSet(Publication pub, Publication other)
static void
assertSameAttachWorkspaceSet(Publication pub, java.util.Set<Workspace> expectedSet)
static void
assertSameContent(java.lang.Object[] array1, java.lang.Object[] array2)
static void
assertSameContent(java.lang.String message, java.lang.Object[] array1, java.lang.Object[] array2)
static void
assertSameContent(java.lang.String message, java.util.Collection<?> expected, java.util.Collection<?> actual)
static void
assertSameContent(java.lang.String message, java.util.Date date1, java.util.Date date2)
static void
assertSameContent(java.lang.String message, java.util.List<?> list1, java.util.List<?> list2)
static void
assertSameContent(java.lang.String message, java.util.Map<?,?> map1, java.util.Map<?,?> map2)
static void
assertSameContent(java.util.Collection<?> set1, java.util.Collection<?> set2)
static void
assertSameContent(java.util.Date date1, java.util.Date date2)
static void
assertSameContent(java.util.List<?> list1, java.util.List<?> list2)
static void
assertSameContent(java.util.Map<?,?> map1, java.util.Map<?,?> map2)
static void
assertSameContent(java.util.Set<?> set1, java.util.Set<?> set2)
static void
assertSameDateList(java.util.List<java.util.Date> expectedDateList, java.util.List<java.util.Date> actualDateList)
Assert both Set of Date are exactly the same, disregarding any difference related to java.sql.Timestamp vs java.util.Datestatic void
assertSameDateSet(java.util.Set<java.util.Date> expectedDateSet, java.util.Set<java.util.Date> actualDateSet)
Assert both Set of Date are exactly the same, disregarding any difference related to java.sql.Timestamp vs java.util.Datestatic void
assertSameHtml(java.lang.String htmlFragment1, java.lang.String htmlFragment2)
Asserts that the two specified HTML fragment are the same.static void
assertSameHtml(java.lang.String message, java.lang.String htmlFragment1, java.lang.String htmlFragment2)
Asserts that the two specified HTML fragment are the same.static void
assertStatusForbidden(ControllerStatus status)
static void
assertStatusHasFailed(ControllerStatus status)
static void
assertStatusHasFailed(java.lang.String prop, ControllerStatus status)
static void
assertStatusHasFailed(java.lang.String msg, java.lang.String prop, ControllerStatus status)
static void
assertStatusOK(ControllerStatus status)
static void
assertStatusOK(java.lang.String msg, ControllerStatus status)
static void
assertTypesDisabled(Workspace ws, java.lang.Class<?>... classes)
Assert given types are disabled in the given Workspace.static void
assertTypesEnabled(Workspace ws, java.lang.Class<?>... classes)
Assert given types are enabled in the given Workspace.protected static java.util.List<java.util.Date>
getDateList(java.util.List<java.util.Date> dateList)
Return a new List containing only java.util.Date if the specified Date is a timestamp.protected static java.util.Set<java.util.Date>
getDateSet(java.util.Set<java.util.Date> dateSet)
Return a new Set containing only java.util.Date if the specified Date is a timestamp.
-
-
-
Method Detail
-
assertStatusOK
public static void assertStatusOK(ControllerStatus status)
-
assertStatusOK
public static void assertStatusOK(java.lang.String msg, ControllerStatus status)
-
assertStatusForbidden
public static void assertStatusForbidden(ControllerStatus status)
-
assertStatusHasFailed
public static void assertStatusHasFailed(ControllerStatus status)
-
assertStatusHasFailed
public static void assertStatusHasFailed(java.lang.String prop, ControllerStatus status)
-
assertStatusHasFailed
public static void assertStatusHasFailed(java.lang.String msg, java.lang.String prop, ControllerStatus status)
-
assertCanBeReadBy
public static void assertCanBeReadBy(Publication pub, Member mbr)
-
assertCannotBeReadBy
public static void assertCannotBeReadBy(Publication pub, Member mbr, RightInfo.Explanation explanation)
-
assertCanBeReadBy
public static void assertCanBeReadBy(Publication pub, Member mbr, boolean searchInGroup)
-
assertCannotBeReadBy
public static void assertCannotBeReadBy(Publication pub, Member mbr, boolean searchInGroup, RightInfo.Explanation explanation)
-
assertCanBeReadBy
@Deprecated public static 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
@Deprecated public static 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
public static void assertCannotUpdateOther(Member mbr, Data data, RightInfo.Explanation explanation)
-
assertCannotDeleteOther
public static void assertCannotDeleteOther(Member mbr, Data data, RightInfo.Explanation explanation)
-
assertCanWorkOn
public static void assertCanWorkOn(Member mbr, Publication pub)
-
assertCannotWorkOn
public static void assertCannotWorkOn(Member mbr, Publication pub, RightInfo.Explanation explanation)
-
assertCmpGreater
public static <T> void assertCmpGreater(java.util.Comparator<T> comparator, T o1, T o2)
-
assertCmpLower
public static <T> void assertCmpLower(java.util.Comparator<T> comparator, T o1, T o2)
-
assertCmpEquals
public static <T> void assertCmpEquals(java.util.Comparator<T> comparator, T o1, T o2)
-
assertCmpOpposite
public static <T> void assertCmpOpposite(java.util.Comparator<T> comparator, T o1, T o2)
-
assertCmpSame
public static <T> void assertCmpSame(java.util.Comparator<T> c1, java.util.Comparator<T> c2, T o1, T o2)
-
assertSameContent
public static void assertSameContent(java.lang.Object[] array1, java.lang.Object[] array2)
-
assertSameContent
public static void assertSameContent(java.lang.String message, java.lang.Object[] array1, java.lang.Object[] array2)
-
assertNotSameContent
public static void assertNotSameContent(java.lang.Object[] array1, java.lang.Object[] array2)
-
assertNotSameContent
public static void assertNotSameContent(java.lang.String message, java.lang.Object[] array1, java.lang.Object[] array2)
-
assertSameHtml
public static void assertSameHtml(java.lang.String htmlFragment1, java.lang.String htmlFragment2)
Asserts that the two specified HTML fragment are the same. disregarding white space (when not relevant).- Parameters:
htmlFragment1
- the first HTML fragment to comparehtmlFragment2
- the second HTML fragment to compare- Since:
- jcms-10.0.0
-
assertSameHtml
public static void assertSameHtml(java.lang.String message, java.lang.String htmlFragment1, java.lang.String htmlFragment2)
Asserts that the two specified HTML fragment are the same. disregarding white space (when not relevant).- Parameters:
message
- a message displayed when assertion failshtmlFragment1
- the first HTML fragment to comparehtmlFragment2
- the second HTML fragment to compare- Since:
- jcms-10.0.0
-
assertIsSimilarXml
public static 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
public static 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
-
getDateSet
protected static java.util.Set<java.util.Date> getDateSet(java.util.Set<java.util.Date> dateSet)
Return a new Set containing only java.util.Date if the specified Date is a timestamp.- Parameters:
dateSet
- the Set of Date object to check/convert- Returns:
- a new instance of Set, may return null if specified dateSet is null.
- Since:
- jcms-10.0.2
-
getDateList
protected static java.util.List<java.util.Date> getDateList(java.util.List<java.util.Date> dateList)
Return a new List containing only java.util.Date if the specified Date is a timestamp.- Parameters:
dateList
- the List of Date object to check/convert- Returns:
- a new instance of List, may return null if specified dateSet is null.
- Since:
- jcms-10.0.2
-
assertSameDateSet
public static void assertSameDateSet(java.util.Set<java.util.Date> expectedDateSet, java.util.Set<java.util.Date> actualDateSet)
Assert both Set of Date are exactly the same, disregarding any difference related to java.sql.Timestamp vs java.util.Date- Parameters:
expectedDateSet
- expected valuesactualDateSet
- actual values- Since:
- jcms-10.0.2
-
assertSameDateList
public static void assertSameDateList(java.util.List<java.util.Date> expectedDateList, java.util.List<java.util.Date> actualDateList)
Assert both Set of Date are exactly the same, disregarding any difference related to java.sql.Timestamp vs java.util.Date- Parameters:
expectedDateList
- expected valuesactualDateList
- actual values- Since:
- jcms-10.0.2
-
assertSameContent
public static void assertSameContent(java.util.Collection<?> set1, java.util.Collection<?> set2)
- Since:
- jcms-9.0.3
-
assertSameContent
public static void assertSameContent(java.lang.String message, java.util.Collection<?> expected, java.util.Collection<?> actual)
- Since:
- jcms-9.0.3
-
assertNotSameContent
public static void assertNotSameContent(java.lang.String message, java.util.Collection<?> col1, java.util.Collection<?> col2)
- Since:
- jcms-9.0.3
-
assertSameContent
public static void assertSameContent(java.util.Set<?> set1, java.util.Set<?> set2)
-
assertNotSameContent
public static void assertNotSameContent(java.util.Set<?> set1, java.util.Set<?> set2)
-
assertNotSameContent
public static void assertNotSameContent(java.lang.String message, java.util.Set<?> set1, java.util.Set<?> set2)
-
assertContainsAll
public static void assertContainsAll(java.util.Collection<?> expectedElements, java.util.Collection<?> actualElements)
- Parameters:
expectedElements
- all elements must be contained byactualElements
actualElements
- the collection to assert it contains all elements inexpectedElements
- Since:
- jcms-10.0
- See Also:
assertContainsAll(String, Collection, Collection)
-
assertContainsAll
public static void assertContainsAll(java.lang.String message, java.util.Collection<?> expectedElements, java.util.Collection<?> actualElements)
Assert that all elements inexpectedElements
are contained inactualElements
, butactualElements
can contain others elements not inexpectedElements
.- Parameters:
message
- optional messageexpectedElements
- all elements must be contained byactualElements
actualElements
- the collection to assert it contains all elements inexpectedElements
- Since:
- jcms-10.0
-
assertSameContent
public static void assertSameContent(java.util.List<?> list1, java.util.List<?> list2)
-
assertSameContent
public static void assertSameContent(java.lang.String message, java.util.List<?> list1, java.util.List<?> list2)
-
assertNotSameContent
public static void assertNotSameContent(java.util.List<?> list1, java.util.List<?> list2)
-
assertNotSameContent
public static void assertNotSameContent(java.lang.String message, java.util.List<?> list1, java.util.List<?> list2)
-
assertSameContent
public static void assertSameContent(java.util.Map<?,?> map1, java.util.Map<?,?> map2)
-
assertSameContent
public static void assertSameContent(java.lang.String message, java.util.Map<?,?> map1, java.util.Map<?,?> map2)
-
assertNotSameContent
public static void assertNotSameContent(java.util.Map<?,?> map1, java.util.Map<?,?> map2)
-
assertNotSameContent
public static void assertNotSameContent(java.lang.String message, java.util.Map<?,?> map1, java.util.Map<?,?> map2)
-
assertSameContent
public static void assertSameContent(java.util.Date date1, java.util.Date date2)
-
assertSameContent
public static void assertSameContent(java.lang.String message, java.util.Date date1, java.util.Date date2)
-
assertNotSameContent
public static void assertNotSameContent(java.util.Date date1, java.util.Date date2)
-
assertNotSameContent
public static void assertNotSameContent(java.lang.String message, java.util.Date date1, java.util.Date date2)
-
assertContains
public static void assertContains(boolean isExpectedContained, java.util.Collection<?> collection, java.lang.Object object)
-
assertContains
public static void assertContains(java.lang.String message, boolean isExpectedContained, java.util.Collection<?> collection, java.lang.Object object)
-
assertIsEmpty
public static void assertIsEmpty(java.lang.Object obj)
-
assertIsEmpty
public static void assertIsEmpty(java.lang.String message, java.lang.Object obj)
-
assertNotEmpty
public static void assertNotEmpty(java.lang.Object obj)
-
assertNotEmpty
public static void assertNotEmpty(java.lang.String message, java.lang.Object obj)
-
assertRange
public static 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
public static 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
public static 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
public static 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
public static 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
-
assertResult
public static void assertResult(CheckResult result)
Allows to throw assertions errors for multiple tests at a time.- Parameters:
result
- the assertions in error wrapper.- Since:
- jcms-10.0.1
-
assertResult
public static void assertResult(java.lang.String message, CheckResult result)
Allows to throw assertions errors for multiple tests at a time.- Parameters:
message
- an optional contextual messageresult
- the assertions in error wrapper.- Since:
- jcms-10.0.4
-
assertNoStaticChannelField
public static void assertNoStaticChannelField(java.lang.Class<?> clazz)
Checks given class does not declare a static Channel field.This kind of declaration may break site / feature initialization.
- Parameters:
clazz
- class to test- Since:
- jcms-10.0.2
-
assertSameAttachWorkspaceSet
public static void assertSameAttachWorkspaceSet(Publication pub, Publication other)
-
assertSameAttachWorkspaceSet
public static void assertSameAttachWorkspaceSet(Publication pub, java.util.Set<Workspace> expectedSet)
-
assertEmptyAttachWorkspaceSet
public static void assertEmptyAttachWorkspaceSet(Publication pub)
Asserts given publication have no attached workspaces.- Parameters:
pub
- publication to test- Since:
- jcms-10.0.7 JCMS-9347
-
-