Package com.jalios.jcms.test
Class Assert
java.lang.Object
com.jalios.jcms.test.Assert
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
ConstructorsModifierConstructorDescriptionprotectedAssert()Protect constructor since it is a static only class -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertAlert(Alert expectedAlert, Alert actualAlert) static voidassertCanBeReadBy(Publication pub, Member mbr) static voidassertCanBeReadBy(Publication pub, Member mbr, boolean searchInGroup) static voidassertCanDeleteOther(Member mbr, Data data) static voidassertCannotBeReadBy(Publication pub, Member mbr, boolean searchInGroup, RightInfo.Explanation explanation) static voidassertCannotBeReadBy(Publication pub, Member mbr, RightInfo.Explanation explanation) static voidassertCannotDeleteOther(Member mbr, Data data, RightInfo.Explanation explanation) static voidassertCannotUpdateOther(Member mbr, Data data, RightInfo.Explanation explanation) static voidassertCannotWorkOn(Member mbr, Publication pub, RightInfo.Explanation explanation) static voidassertCanUpdateOther(Member mbr, Data data) static voidassertCanWorkOn(Member mbr, Publication pub) static <T> voidassertCmpEquals(Comparator<T> comparator, T o1, T o2) static <T> voidassertCmpGreater(Comparator<T> comparator, T o1, T o2) static <T> voidassertCmpLower(Comparator<T> comparator, T o1, T o2) static <T> voidassertCmpOpposite(Comparator<T> comparator, T o1, T o2) static <T> voidassertCmpSame(Comparator<T> c1, Comparator<T> c2, T o1, T o2) static voidassertContains(boolean isExpectedContained, Collection<?> collection, Object object) static voidassertContains(String message, boolean isExpectedContained, Collection<?> collection, Object object) static voidassertContainsAll(String message, Collection<?> expectedElements, Collection<?> actualElements) Assert that all elements inexpectedElementsare contained inactualElements, butactualElementscan contain others elements not inexpectedElements.static voidassertContainsAll(Collection<?> expectedElements, Collection<?> actualElements) static voidassertContainsNone(String message, Collection<?> expectedElements, Collection<?> actualElements) Assert that all elements inexpectedElementsare contained inactualElements, butactualElementscan contain others elements not inexpectedElements.static voidassertDateRange(Date date, Date lowerDate, Date upperDate) Assert the given date d1 is in range {d2, d3}static voidassertDateRangeStrict(Date date, Date lowerDate, Date upperDate) Assert the given date date is in the range {lowerDate, upperDate}static voidAsserts given publication have no attached workspaces.static voidassertException(Exception ex, Class<?> expectedExceptionClazz, String message) Assert an expected Exception has been thrown.static voidassertIsEmpty(Object obj) static voidassertIsEmpty(String message, Object obj) static voidassertIsSameXml(String expectedXml, String xmlString) Assert given xml string are identicial ( except normalized spaces).static voidassertIsSimilarXml(String expectedXml, String xmlString) Assert given xml string are similar (normalized spaces and child present by in different order)static voidAsserts member is disabled.static voidassertMemberIsDisabled(String message, Member mbr) Asserts member is disabled.static voidAsserts member is disabled.static voidassertMemberIsDisabledTx(String message, String mid) Asserts member is disabled.static voidAsserts member is enabled.static voidassertMemberIsEnabled(String message, Member mbr) Asserts member is enabled.static voidassertMemberIsEnabledTx(String message, String mid) Asserts member is enabled.static voidassertMemberPhotoExists(boolean expectedPhotoExists, Member mbr) Asserts member photo file exist or not.static voidassertMemberPhotoExists(String message, boolean expectedPhotoExists, Member mbr) Asserts member photo file exist or not.static voidassertMemberPhotoExistsTx(boolean expectedHasPhoto, String mid) Asserts member has a photo field specified.static voidassertMemberPhotoExistsTx(String message, boolean expectedPhotoExists, String mid) Asserts member photo file exist or not.static voidassertNoStaticChannelField(Class<?> clazz) Checks given class does not declare a static Channel field.static voidassertNotEmpty(Object obj) static voidassertNotEmpty(String message, Object obj) static voidassertNotSameContent(Object[] array1, Object[] array2) static voidassertNotSameContent(String message, Object[] array1, Object[] array2) static voidassertNotSameContent(String message, Collection<?> col1, Collection<?> col2) static voidassertNotSameContent(String message, Date date1, Date date2) static voidassertNotSameContent(String message, List<?> list1, List<?> list2) static voidassertNotSameContent(String message, Map<?, ?> map1, Map<?, ?> map2) static voidassertNotSameContent(String message, Set<?> set1, Set<?> set2) static voidassertNotSameContent(Date date1, Date date2) static voidassertNotSameContent(List<?> list1, List<?> list2) static voidassertNotSameContent(Map<?, ?> map1, Map<?, ?> map2) static voidassertNotSameContent(Set<?> set1, Set<?> set2) static voidassertObjectIsGarbageCollected(WeakReference<? extends Object> wRef, long timeout, boolean heapDump) Check that the specified Object (referenced through a WeakReference) is garbage collected in the designated time.static voidassertPluginActive(boolean expected, String pluginName) static voidassertProcessStatus(BackgroundProcess process, BackgroundProcess.Status expected) static voidassertProcessStatusOK(BackgroundProcess process) static voidassertRange(long value, long minValue, long maxValue, boolean strict) Assert the given value lesser than minValue and graeter than maxValue.static voidassertResult(CheckResult result) Allows to throw assertions errors for multiple tests at a time.static voidassertResult(String message, CheckResult result) Allows to throw assertions errors for multiple tests at a time.static voidassertSameAttachWorkspaceSet(Publication pub, Publication other) static voidassertSameAttachWorkspaceSet(Publication pub, Set<Workspace> expectedSet) static voidassertSameContent(Object[] array1, Object[] array2) static voidassertSameContent(String message, Object[] array1, Object[] array2) static voidassertSameContent(String message, Collection<?> expected, Collection<?> actual) static voidassertSameContent(String message, Date date1, Date date2) static voidassertSameContent(String message, List<?> list1, List<?> list2) static voidassertSameContent(String message, Map<?, ?> map1, Map<?, ?> map2) static voidassertSameContent(Collection<?> set1, Collection<?> set2) static voidassertSameContent(Date date1, Date date2) static voidassertSameContent(List<?> list1, List<?> list2) static voidassertSameContent(Map<?, ?> map1, Map<?, ?> map2) static voidassertSameContent(Set<?> set1, Set<?> set2) static voidassertSameDateList(List<Date> expectedDateList, List<Date> actualDateList) Assert both Set of Date are exactly the same, disregarding any difference related to java.sql.Timestamp vs java.util.Datestatic voidassertSameDateSet(Set<Date> expectedDateSet, Set<Date> actualDateSet) Assert both Set of Date are exactly the same, disregarding any difference related to java.sql.Timestamp vs java.util.Datestatic voidassertSameHtml(String htmlFragment1, String htmlFragment2) Asserts that the two specified HTML fragment are the same.static voidassertSameHtml(String message, String htmlFragment1, String htmlFragment2) Asserts that the two specified HTML fragment are the same.static voidstatic voidstatic voidassertStatusHasFailed(String prop, ControllerStatus status) static voidassertStatusHasFailed(String msg, String prop, ControllerStatus status) static voidassertStatusOK(ControllerStatus status) static voidassertStatusOK(String msg, ControllerStatus status) static voidassertTypesDisabled(Workspace ws, Class<?>... classes) Assert given types are disabled in the given Workspace.static voidassertTypesEnabled(Workspace ws, Class<?>... classes) Assert given types are enabled in the given Workspace.getDateList(List<Date> dateList) Return a new List containing only java.util.Date if the specified Date is a timestamp.getDateSet(Set<Date> dateSet) Return a new Set containing only java.util.Date if the specified Date is a timestamp.
-
Constructor Details
-
Assert
protected Assert()Protect constructor since it is a static only class
-
-
Method Details
-
assertProcessStatusOK
-
assertProcessStatus
public static void assertProcessStatus(BackgroundProcess process, BackgroundProcess.Status expected) -
assertStatusOK
-
assertStatusOK
-
assertStatusForbidden
-
assertStatusHasFailed
-
assertStatusHasFailed
-
assertStatusHasFailed
-
assertCanBeReadBy
-
assertCannotBeReadBy
public static void assertCannotBeReadBy(Publication pub, Member mbr, RightInfo.Explanation explanation) -
assertCanBeReadBy
-
assertCannotBeReadBy
public static void assertCannotBeReadBy(Publication pub, Member mbr, boolean searchInGroup, RightInfo.Explanation explanation) -
assertCanUpdateOther
-
assertCannotUpdateOther
public static void assertCannotUpdateOther(Member mbr, Data data, RightInfo.Explanation explanation) -
assertCanDeleteOther
-
assertCannotDeleteOther
public static void assertCannotDeleteOther(Member mbr, Data data, RightInfo.Explanation explanation) -
assertCanWorkOn
-
assertCannotWorkOn
public static void assertCannotWorkOn(Member mbr, Publication pub, RightInfo.Explanation explanation) -
assertMemberIsDisabledTx
Asserts member is disabled.- Parameters:
mid- id of member to work on- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberIsDisabledTx
Asserts member is disabled.- Parameters:
message- an optionnal contextual messagemid- id of member to work on- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberIsEnabled
Asserts member is enabled.- Parameters:
mbr- member to work on- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberIsEnabledTx
Asserts member is enabled.- Parameters:
message- an optionnal contextual messagemid- id of member to work on- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberIsEnabled
Asserts member is enabled.- Parameters:
message- an optionnal contextual messagembr- member to work on, must not be null- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberIsDisabled
Asserts member is disabled.- Parameters:
mbr- member to work on- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberIsDisabled
Asserts member is disabled.- Parameters:
message- an optionnal contextual messagembr- member to work on, must not be null- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberPhotoExistsTx
Asserts member has a photo field specified.- Parameters:
expectedHasPhoto- weither a photo is expected or notmid- id of member to work on- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberPhotoExistsTx
public static void assertMemberPhotoExistsTx(String message, boolean expectedPhotoExists, String mid) Asserts member photo file exist or not.- Parameters:
message- an optionnal contextual messageexpectedPhotoExists- weither photo file is expected to exist or notmid- id of member to work on- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberPhotoExists
Asserts member photo file exist or not.- Parameters:
expectedPhotoExists- weither photo file is expected to exist or notmbr- member to work on, must not be null- Since:
- jcms-10.0.8 JCMS-10422
-
assertMemberPhotoExists
Asserts member photo file exist or not.- Parameters:
message- an optionnal contextual messageexpectedPhotoExists- weither photo file is expected to exist or notmbr- member to work on, must not be null- Since:
- jcms-10.0.8 JCMS-10422
-
assertCmpGreater
-
assertCmpLower
-
assertCmpEquals
-
assertCmpOpposite
-
assertCmpSame
-
assertSameContent
-
assertSameContent
-
assertNotSameContent
-
assertNotSameContent
-
assertSameHtml
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
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
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
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
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
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
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
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
- Since:
- jcms-9.0.3
-
assertSameContent
- Since:
- jcms-9.0.3
-
assertNotSameContent
- Since:
- jcms-9.0.3
-
assertSameContent
-
assertNotSameContent
-
assertNotSameContent
-
assertContainsAll
- Parameters:
expectedElements- all elements must be contained byactualElementsactualElements- the collection to assert it contains all elements inexpectedElements- Since:
- jcms-10.0
- See Also:
-
assertContainsAll
public static void assertContainsAll(String message, Collection<?> expectedElements, Collection<?> actualElements) Assert that all elements inexpectedElementsare contained inactualElements, butactualElementscan contain others elements not inexpectedElements.- Parameters:
message- optional messageexpectedElements- all elements must be contained byactualElementsactualElements- the collection to assert it contains all elements inexpectedElements- Since:
- jcms-10.0
-
assertContainsNone
public static void assertContainsNone(String message, Collection<?> expectedElements, Collection<?> actualElements) Assert that all elements inexpectedElementsare contained inactualElements, butactualElementscan contain others elements not inexpectedElements.- Parameters:
message- optional messageexpectedElements- all elements must be contained byactualElementsactualElements- the collection to assert it contains all elements inexpectedElements- Since:
- jcms-10.0.8
-
assertSameContent
-
assertSameContent
-
assertNotSameContent
-
assertNotSameContent
-
assertSameContent
-
assertSameContent
-
assertNotSameContent
-
assertNotSameContent
-
assertSameContent
-
assertSameContent
-
assertNotSameContent
-
assertNotSameContent
-
assertContains
public static void assertContains(boolean isExpectedContained, Collection<?> collection, Object object) -
assertContains
public static void assertContains(String message, boolean isExpectedContained, Collection<?> collection, Object object) -
assertIsEmpty
-
assertIsEmpty
-
assertNotEmpty
-
assertNotEmpty
-
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
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
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(WeakReference<? extends 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
-
assertAlert
-
assertTypesEnabled
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
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
Allows to throw assertions errors for multiple tests at a time.- Parameters:
result- the assertions in error wrapper.- Since:
- jcms-10.0.1
-
assertResult
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
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
-
assertSameAttachWorkspaceSet
-
assertEmptyAttachWorkspaceSet
Asserts given publication have no attached workspaces.- Parameters:
pub- publication to test- Since:
- jcms-10.0.7 JCMS-9347
-
assertPluginActive
- Parameters:
expected- if active must be true or falsepluginName- plugin to test- Since:
- jcms-10.0.8 / JCMS-10693
-
assertException
Assert an expected Exception has been thrown.Test exception's type and message if provided. Example:
Exception exception = null; try { // call client code that should throw an exception } catch (Exception ex) { exception = ex; } finally { Assert.assertException(exception, IllegalArgumentException.class, "FooBar must not be null."); }- Parameters:
ex- the catched exceptionexpectedExceptionClazz- the type of the expected Exception.message- Optional: expected exception's message.- Since:
- jcms-10.0.8
-