Class OBBaseTest

    • Field Detail

      • watchFailures

        public org.junit.rules.TestWatcher watchFailures
        Add a TestWatcher rule to be able to catch test failures allowing them to fail. This will be used to commit or rollback DAL session after on test finalization. Note failed method is invoked after invoking any method annotated with @After, that's why commit/rollback is performed on this rule's finished method which is invoked after failed.

        protected static final String TEST_CLIENT_ID
        Record ID of Client "F&B International Group"
        See Also:
        Constant Field Values
      • TEST_ORG_ID

        protected static final String TEST_ORG_ID
        Record ID of Organization "F&B España - Región Norte"
        See Also:
        Constant Field Values
      • TEST_US_ORG_ID

        protected static final String TEST_US_ORG_ID
        Record ID of Organization "F&B US West Coast"
        See Also:
        Constant Field Values

        protected static final String TEST_WAREHOUSE_ID
        Record ID of Warehouse "España Región Norte"
        See Also:
        Constant Field Values
      • TEST_ROLE_ID

        protected static final String TEST_ROLE_ID
        Record ID of Role "F&B International Group Admin"
        See Also:
        Constant Field Values

        protected static final String TEST_PRODUCT_ID
        Record ID of Product "Zumo de Fresa Bio 0,33L"
        See Also:
        Constant Field Values

        protected static Map<String,​String[]> TEST_ORG_TREE
        Map representation of current Organization tree for Client TEST_CLIENT_ID
      • QA_TEST_ORG_ID

        protected static final String QA_TEST_ORG_ID
        Record ID of the Main organization of QA Test client
        See Also:
        Constant Field Values

        protected static final String QA_TEST_ADMIN_USER_ID
        Record ID of the "Admin" user of QA Test client
        See Also:
        Constant Field Values

        protected static final String TEST_BP_CATEGORY_ID
        Record ID of the "Customer" Business Partner Category
        See Also:
        Constant Field Values

        protected static final String TEST_LOCATION_ID
        Record ID of the geographical location "c\ de la Costa 54, San Sebastián 12784"
        See Also:
        Constant Field Values
    • Constructor Detail

      • OBBaseTest

        public OBBaseTest()
    • Method Detail

      • initializeTestLogAppender

        protected static void initializeTestLogAppender()
      • testDone

        public void testDone()
                      throws Exception
        Test log appender is reset and switched off. This method also cleans the mock servlet context when it applies.
        testDone in class MockableBaseTest
      • shouldMockServletContext

        protected boolean shouldMockServletContext()
        true if the test case should mock the servlet context. Otherwise, return false.
      • setTestLogAppenderLevel

        protected void setTestLogAppenderLevel​(org.apache.logging.log4j.Level level)
        Defines the threshold Level that will make messages to be tracked by TestLogAppender. Note after test completion appender is reset and its level is set back to Level.OFF disabling in this manner subsequent logging track.
      • setLogStackTraces

        protected void setLogStackTraces​(boolean log)
        Include in messages possible stack traces for logged Throwables
      • getTestLogAppender

        protected TestLogAppender getTestLogAppender()
        Returns log appender in order to be possible to do assertions on it
      • initializeDalLayer

        protected void initializeDalLayer​(Map<String,​org.hibernate.dialect.function.SQLFunction> sqlFunctions)
                                   throws Exception
        Initializes the DAL layer, can be overridden to add specific initialization behavior.
        sqlFunctions - a Map with SQL functions to be registered in Hibernate during the DAL layer initialization. It can be null if not needed.
      • staticInitializeDalLayer

        protected static void staticInitializeDalLayer()
                                                throws Exception
      • initializeDisabledTestCases

        protected static void initializeDisabledTestCases()
      • setSystemAdministratorContext

        protected void setSystemAdministratorContext()
        Set the current user to the 0 user.
      • setTestUserContext

        protected void setTestUserContext()
        Sets the current user to the TEST_USER_ID user.
      • setTestAdminContext

        protected void setTestAdminContext()
        Sets the current user to the 100 user as F&B Group Admin
      • setQAAdminContext

        protected static void setQAAdminContext()
        Sets the current user to the 100 user as QA Admin
      • getRandomUser

        protected User getRandomUser()
        Gets a random User (Record ID) from the available ones in the test client. The ID is one different than TEST_USER_ID
        A record ID of a available user
      • reportException

        protected void reportException​(Exception e)
        Prints the stacktrace of the exception to System.err. Handles the case that the exception is a SQLException which has the real causing exception in the SQLException.getNextException() method.
        e - the exception to report.
      • isErrorOccured

        public boolean isErrorOccured()
      • rollback

        public void rollback()
        Does a rollback of the transaction;
      • commitTransaction

        public void commitTransaction()
        Commits the transaction to the database.
      • getOneInstance

        protected <T extends BaseOBObject> T getOneInstance​(Class<T> clz)
        Convenience method, gets an instance for the passed Class from the database. If there are no records for that class then an exception is thrown. If there is more than one result then an arbitrary instance is returned (the first one in the un-ordered resultset).
        Type Parameters:
        T - the specific class to query for.
        clz - instances
        an instance of clz.
      • addReadWriteAccess

        protected void addReadWriteAccess​(Class<?> clz)
        Extends the read and write access of the current user to also include the passed class. This can be used to circumvent restrictive access which is not usefull for the test itself.
        clz - after this call the current user (in the OBContext) will have read/write access to this class.
      • count

        protected <T extends BaseOBObject> int count​(Class<T> clz)
        Counts the total occurences in the database for the passed class. Note that active, client and organization filtering applies.
        Type Parameters:
        T - a class type parameter
        clz - the class to count occurences for
        the number of occurences which are active and belong to the current client/organization