Class Assert

java.lang.Object
com.jalios.jcms.test.Assert

public class Assert extends 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 Details

    • Assert

      protected Assert()
      Protect constructor since it is a static only class
  • Method Details

    • assertProcessStatusOK

      public static void assertProcessStatusOK(BackgroundProcess process)
    • assertProcessStatus

      public static void assertProcessStatus(BackgroundProcess process, BackgroundProcess.Status expected)
    • assertStatusOK

      public static void assertStatusOK(ControllerStatus status)
    • assertStatusOK

      public static void assertStatusOK(String msg, ControllerStatus status)
    • assertStatusForbidden

      public static void assertStatusForbidden(ControllerStatus status)
    • assertStatusHasFailed

      public static void assertStatusHasFailed(ControllerStatus status)
    • assertStatusHasFailed

      public static void assertStatusHasFailed(String prop, ControllerStatus status)
    • assertStatusHasFailed

      public static void assertStatusHasFailed(String msg, 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)
    • assertCanUpdateOther

      public static void assertCanUpdateOther(Member mbr, Data data)
    • assertCannotUpdateOther

      public static void assertCannotUpdateOther(Member mbr, Data data, RightInfo.Explanation explanation)
    • assertCanDeleteOther

      public static void assertCanDeleteOther(Member mbr, Data data)
    • 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)
    • assertMemberIsDisabledTx

      public static void assertMemberIsDisabledTx(String mid)
      Asserts member is disabled.
      Parameters:
      mid - id of member to work on
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberIsDisabledTx

      public static void assertMemberIsDisabledTx(String message, String mid)
      Asserts member is disabled.
      Parameters:
      message - an optionnal contextual message
      mid - id of member to work on
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberIsEnabled

      public static void assertMemberIsEnabled(Member mbr)
      Asserts member is enabled.
      Parameters:
      mbr - member to work on
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberIsEnabledTx

      public static void assertMemberIsEnabledTx(String message, String mid)
      Asserts member is enabled.
      Parameters:
      message - an optionnal contextual message
      mid - id of member to work on
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberIsEnabled

      public static void assertMemberIsEnabled(String message, Member mbr)
      Asserts member is enabled.
      Parameters:
      message - an optionnal contextual message
      mbr - member to work on, must not be null
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberIsDisabled

      public static void assertMemberIsDisabled(Member mbr)
      Asserts member is disabled.
      Parameters:
      mbr - member to work on
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberIsDisabled

      public static void assertMemberIsDisabled(String message, Member mbr)
      Asserts member is disabled.
      Parameters:
      message - an optionnal contextual message
      mbr - member to work on, must not be null
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberPhotoExistsTx

      public static void assertMemberPhotoExistsTx(boolean expectedHasPhoto, String mid)
      Asserts member has a photo field specified.
      Parameters:
      expectedHasPhoto - weither a photo is expected or not
      mid - 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 message
      expectedPhotoExists - weither photo file is expected to exist or not
      mid - id of member to work on
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberPhotoExists

      public static void assertMemberPhotoExists(boolean expectedPhotoExists, Member mbr)
      Asserts member photo file exist or not.
      Parameters:
      expectedPhotoExists - weither photo file is expected to exist or not
      mbr - member to work on, must not be null
      Since:
      jcms-10.0.8 JCMS-10422
    • assertMemberPhotoExists

      public static void assertMemberPhotoExists(String message, boolean expectedPhotoExists, Member mbr)
      Asserts member photo file exist or not.
      Parameters:
      message - an optionnal contextual message
      expectedPhotoExists - weither photo file is expected to exist or not
      mbr - member to work on, must not be null
      Since:
      jcms-10.0.8 JCMS-10422
    • assertCmpGreater

      public static <T> void assertCmpGreater(Comparator<T> comparator, T o1, T o2)
    • assertCmpLower

      public static <T> void assertCmpLower(Comparator<T> comparator, T o1, T o2)
    • assertCmpEquals

      public static <T> void assertCmpEquals(Comparator<T> comparator, T o1, T o2)
    • assertCmpOpposite

      public static <T> void assertCmpOpposite(Comparator<T> comparator, T o1, T o2)
    • assertCmpSame

      public static <T> void assertCmpSame(Comparator<T> c1, Comparator<T> c2, T o1, T o2)
    • assertSameContent

      public static void assertSameContent(Object[] array1, Object[] array2)
    • assertSameContent

      public static void assertSameContent(String message, Object[] array1, Object[] array2)
    • assertNotSameContent

      public static void assertNotSameContent(Object[] array1, Object[] array2)
    • assertNotSameContent

      public static void assertNotSameContent(String message, Object[] array1, Object[] array2)
    • assertSameHtml

      public static void assertSameHtml(String htmlFragment1, 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 compare
      htmlFragment2 - the second HTML fragment to compare
      Since:
      jcms-10.0.0
    • assertSameHtml

      public static void assertSameHtml(String message, String htmlFragment1, 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 fails
      htmlFragment1 - the first HTML fragment to compare
      htmlFragment2 - the second HTML fragment to compare
      Since:
      jcms-10.0.0
    • assertIsSimilarXml

      public static void assertIsSimilarXml(String expectedXml, String xmlString)
      Assert given xml string are similar (normalized spaces and child present by in different order)
      Parameters:
      expectedXml - the expected XML string
      xmlString - the XML string to check
    • assertIsSameXml

      public static void assertIsSameXml(String expectedXml, String xmlString)
      Assert given xml string are identicial ( except normalized spaces). In this method child order is check.
      Parameters:
      expectedXml - the expected XML string
      xmlString - the XML string to check
    • getDateSet

      protected static Set<Date> getDateSet(Set<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 List<Date> getDateList(List<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(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.Date
      Parameters:
      expectedDateSet - expected values
      actualDateSet - actual values
      Since:
      jcms-10.0.2
    • assertSameDateList

      public static void assertSameDateList(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.Date
      Parameters:
      expectedDateList - expected values
      actualDateList - actual values
      Since:
      jcms-10.0.2
    • assertSameContent

      public static void assertSameContent(Collection<?> set1, Collection<?> set2)
      Since:
      jcms-9.0.3
    • assertSameContent

      public static void assertSameContent(String message, Collection<?> expected, Collection<?> actual)
      Since:
      jcms-9.0.3
    • assertNotSameContent

      public static void assertNotSameContent(String message, Collection<?> col1, Collection<?> col2)
      Since:
      jcms-9.0.3
    • assertSameContent

      public static void assertSameContent(Set<?> set1, Set<?> set2)
    • assertNotSameContent

      public static void assertNotSameContent(Set<?> set1, Set<?> set2)
    • assertNotSameContent

      public static void assertNotSameContent(String message, Set<?> set1, Set<?> set2)
    • assertContainsAll

      public static void assertContainsAll(Collection<?> expectedElements, Collection<?> actualElements)
      Parameters:
      expectedElements - all elements must be contained by actualElements
      actualElements - the collection to assert it contains all elements in expectedElements
      Since:
      jcms-10.0
      See Also:
    • assertContainsAll

      public static void assertContainsAll(String message, Collection<?> expectedElements, Collection<?> actualElements)
      Assert that all elements in expectedElements are contained in actualElements, but actualElements can contain others elements not in expectedElements.
      Parameters:
      message - optional message
      expectedElements - all elements must be contained by actualElements
      actualElements - the collection to assert it contains all elements in expectedElements
      Since:
      jcms-10.0
    • assertContainsNone

      public static void assertContainsNone(String message, Collection<?> expectedElements, Collection<?> actualElements)
      Assert that all elements in expectedElements are contained in actualElements, but actualElements can contain others elements not in expectedElements.
      Parameters:
      message - optional message
      expectedElements - all elements must be contained by actualElements
      actualElements - the collection to assert it contains all elements in expectedElements
      Since:
      jcms-10.0.8
    • assertSameContent

      public static void assertSameContent(List<?> list1, List<?> list2)
    • assertSameContent

      public static void assertSameContent(String message, List<?> list1, List<?> list2)
    • assertNotSameContent

      public static void assertNotSameContent(List<?> list1, List<?> list2)
    • assertNotSameContent

      public static void assertNotSameContent(String message, List<?> list1, List<?> list2)
    • assertSameContent

      public static void assertSameContent(Map<?,?> map1, Map<?,?> map2)
    • assertSameContent

      public static void assertSameContent(String message, Map<?,?> map1, Map<?,?> map2)
    • assertNotSameContent

      public static void assertNotSameContent(Map<?,?> map1, Map<?,?> map2)
    • assertNotSameContent

      public static void assertNotSameContent(String message, Map<?,?> map1, Map<?,?> map2)
    • assertSameContent

      public static void assertSameContent(Date date1, Date date2)
    • assertSameContent

      public static void assertSameContent(String message, Date date1, Date date2)
    • assertNotSameContent

      public static void assertNotSameContent(Date date1, Date date2)
    • assertNotSameContent

      public static void assertNotSameContent(String message, Date date1, Date date2)
    • 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

      public static void assertIsEmpty(Object obj)
    • assertIsEmpty

      public static void assertIsEmpty(String message, Object obj)
    • assertNotEmpty

      public static void assertNotEmpty(Object obj)
    • assertNotEmpty

      public static void assertNotEmpty(String message, 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 value
      minValue - the minValue
      maxValue - the maxValue
      strict - true if the comparison must be strict
      Since:
      jcms-8.0.1
    • assertDateRange

      public static void assertDateRange(Date date, Date lowerDate, Date upperDate)
      Assert the given date d1 is in range {d2, d3}
      Parameters:
      date - the date to be tested
      lowerDate - the lower date limit (may be null)
      upperDate - the upper date limit (may be null)
    • assertDateRangeStrict

      public static void assertDateRangeStrict(Date date, Date lowerDate, Date upperDate)
      Assert the given date date is in the range {lowerDate, upperDate}
      Parameters:
      date - the date to be tested
      lowerDate - 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

      public static void assertAlert(Alert expectedAlert, Alert actualAlert)
    • assertTypesEnabled

      public static void assertTypesEnabled(Workspace ws, Class<?>... classes)
      Assert given types are enabled in the given Workspace.
      Parameters:
      ws - the workspace to test
      classes - classes to test they are enabled in ws
      Since:
      jcms-8.0.3, jcms-9.0.0
    • assertTypesDisabled

      public static void assertTypesDisabled(Workspace ws, Class<?>... classes)
      Assert given types are disabled in the given Workspace.
      Parameters:
      ws - the workspace to test
      classes - 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(String message, CheckResult result)
      Allows to throw assertions errors for multiple tests at a time.
      Parameters:
      message - an optional contextual message
      result - the assertions in error wrapper.
      Since:
      jcms-10.0.4
    • assertNoStaticChannelField

      public static void assertNoStaticChannelField(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, 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
    • assertPluginActive

      public static void assertPluginActive(boolean expected, String pluginName)
      Parameters:
      expected - if active must be true or false
      pluginName - plugin to test
      Since:
      jcms-10.0.8 / JCMS-10693
    • assertException

      public static void assertException(Exception ex, Class<?> expectedExceptionClazz, String message)
      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 exception
      expectedExceptionClazz - the type of the expected Exception.
      message - Optional: expected exception's message.
      Since:
      jcms-10.0.8