Class 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 Detail

      • Assert

        protected Assert()
        Protect constructor since it is a static only class
    • 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)
      • assertCanBeReadBy

        public static void assertCanBeReadBy​(Publication pub,
                                             Member mbr,
                                             boolean searchInGroup)
      • assertCanBeReadBy

        @Deprecated
        public static void assertCanBeReadBy​(Publication pub,
                                             Group grp)
        Deprecated.
        since JCMS-8577
        Assert publication can be read by specified group
        Parameters:
        pub - publication to check
        grp - group to verify
      • assertCannotBeReadBy

        @Deprecated
        public static void assertCannotBeReadBy​(Publication pub,
                                                Group grp,
                                                RightInfo.Explanation restriction)
        Deprecated.
        since JCMS-8577
        Assert publication can be read by specified group
        Parameters:
        pub - publication to check
        grp - group to verify
        restriction - the expected explanation
      • assertCanUpdateOther

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

        public static void assertCanDeleteOther​(Member mbr,
                                                Data data)
      • assertCanWorkOn

        public static void assertCanWorkOn​(Member mbr,
                                           Publication pub)
      • 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 compare
        htmlFragment2 - 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 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​(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 string
        xmlString - 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 string
        xmlString - 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 values
        actualDateSet - 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 values
        actualDateList - 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 by actualElements
        actualElements - the collection to assert it contains all elements in expectedElements
        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 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
      • 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 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​(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 tested
        lowerDate - 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 tested
        lowerDate - 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
      • assertAlert

        public static void assertAlert​(Alert expectedAlert,
                                       Alert actualAlert)
      • 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 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,
                                               java.lang.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​(java.lang.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​(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