Class JcmsTestCase4

  • All Implemented Interfaces:
    JcmsConstants, JaliosConstants
    Direct Known Subclasses:
    FileParserTestCase

    public abstract class JcmsTestCase4
    extends java.lang.Object
    implements JcmsConstants
    Provides a base class for development of JCMS unit tests with JUnit4.
    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 of WEB-INF/data/store.xml.release if it exists, otherwise copy of WEB-INF/data/store.xml
    • WEB-INF/data/custom.prop.junit : copy of WEB-INF/data/custom.prop.release if it exists, otherwise copy of WEB-INF/data/custom.prop

    Also, if file WEB-INF/data/junit.prop exists, its content is appended to the junit file WEB-INF/data/custom.prop.junit.

    Warning!: Even though, store.xml and custom.prop are 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())
    You can retrieve mock objects for testing using methods provided in this class :
    • getMockHttpSession()
    • getMockHttpServletRequest() or getMockHttpServletRequest(HttpSession)
    • getMockJcmsJspContext() or getMockJcmsJspContext(HttpServletRequest)
    Convenient static "assert" methods not provided in the JUnit API are provided in Assert class.
    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.JcmsTestCase4 {
        private static final Logger logger = Logger.getLogger(MyFeatureTest.class.getName());
        
        Data testData = null; 
        
        @Before
        protected void setUp() throws Exception {
          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
        }
      
        @Test
        public void articleMethod1BehavesCorrectly() {
          HttpSession testSession = getMockHttpSession();
          assertTrue(MyFeature.method1(getMockHttpServletRequest(testSession), testData));
          assertFalse(MyFeature.method1(getMockHttpServletRequest(testSession), testData));
          ...
        }
        
        @After
        protected void tearDown() throws Exception {
          if (testData != null) {
            logger.info("Deleting article created for MyFeature test...");
            testData.performDelete(admin); 
          }
        }
      }
     
    • Field Detail

      • channel

        protected static Channel channel
      • admin

        protected static Member admin
      • defaultWorkspace

        protected static Workspace defaultWorkspace
      • defaultGroup

        protected static Group defaultGroup
      • watchman

        public org.junit.rules.TestWatcher watchman
    • Constructor Detail

      • JcmsTestCase4

        public JcmsTestCase4()
    • Method Detail

      • setUpJcmsTestCase

        public final void setUpJcmsTestCase()
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • tearDownJcmsTestCase

        public final void tearDownJcmsTestCase()
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • beginTransaction

        protected static void beginTransaction()
      • commitTransaction

        protected static void commitTransaction()
      • deleteAllAlerts

        protected static void deleteAllAlerts()
      • deleteAll

        protected static void deleteAll​(java.lang.Class<? extends DBData> dbDataClazz)
      • deleteAllAlerts

        protected static void deleteAllAlerts​(Member mbr)