Package org.openbravo.test.base
Class OBBaseTest
- java.lang.Object
-
- org.openbravo.test.base.OBBaseTest
-
- Direct Known Subclasses:
AccessLevelTest
,Ad_isorgincludedTest
,ADCachedMultiThreadTest
,AdminContextTest
,ADOrgPersistInfoCornerCaseOrgTest
,ADOrgPersistInfoSetReadyTest
,ADOrgPersistOrgInfoComplexOrgTreeTest
,AllDataAllowedOrganizationsTest
,AllowedOrganizationsTest
,AuthenticationManagerTest
,BaseDataSourceTestDal
,BaseWSTest
,BOBInClosestOrgTest
,BypassAccessLevelCheck
,CentralBrokerTest
,ClassicSelectorTest
,ClassLoaderTest
,CLocationGetIdentifierTest
,ComputedColumnsTest
,ConversionRateDocUniqueTest
,CrossOrganizationUI
,DalComplexQueryRequisitionTest
,DalComplexQueryTestOrderLine
,DalConnectionProviderTest
,DalCopyTest
,DalFilterTest
,DalLockingTest
,DalPerformanceCriteriaTest
,DalPerformanceExampleTest
,DalPerformanceInventoryLineTest
,DalPerformanceProductTest
,DalPerformanceProxyTest
,DalQueryTest
,DalStoredProcedureTest
,DalUtilTest
,DataQueryServiceTest
,DatasetExportTest
,DatasetServiceTest
,DBModifiedTest
,DBPrefixTest
,DocumentNumberGeneration
,DoOrgClientAccessCheckTest
,DynamicEntityTest
,ErrorTextParserIntegrationTest
,ErrorTextParserTest
,EvaluationTest
,FieldProviderTest
,FinancialAccountTest
,GenerateEntityModelWiki
,GridConfigurationTest
,HiddenUpdateTest
,ImportEntrySizeTest
,IndexesTest
,IsCompletelyInvoicedShipmentMultiLineTest
,IsCompletelyInvoicedShipmentOneLineTest
,Issue29934Test
,IssuesTest
,JsonConversionTest
,JsonRestTest
,JSONSerialization
,KernelUtilTest
,M_inoutlinetrgTest
,MappingGenerationTest
,MimeTypeTest
,MisfirePolicyTest
,ModifyTaxesTest
,OBBindingsTest
,OBContextCollectionsTest
,OBContextTest
,OBDateUtilsTest
,OBPropertiesProviderTest
,OneToManyTest
,OrderProcessTest
,PasswordHashing
,PaymentMethodTest
,PaymentTest_01
,PaymentTest_02
,PaymentTest_03
,PaymentTest_04
,PaymentTest_05
,PaymentTest_06
,PaymentTest_07
,PaymentTest_08
,PaymentTest_09
,PaymentTest_10
,PaymentTest_11
,PerformanceGenerateInstanceTest
,PostDocumentTest
,PreferenceTest
,PriceListTest
,ProductStatusTest
,ReadByNameTest
,RecordID2Test
,ReducedTranslationExportTests
,RuntimeModelTest
,SendEmailTest
,SimpleDalReadTest
,SqlCallableStatement
,SystemServiceTest
,SystemValidatorTest
,TableNameTest
,TaxesTest
,TemplateResolverTest
,TestInfrastructure
,TestUtility
,TrlColumnsOraTypeTest
,UniqueConstraintTest
,UtilsTest
,ValidationTest
,ViewTest
,WeldBaseTest
,WritableReadableOrganizationClientTest
,XMLBaseTest
public class OBBaseTest extends Object
OBBaseTest class which can/should be extended by most other test classes which want to make use of the Openbravo test infrastructure.- Author:
- inigosanchez
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
DOLLAR
ISO code of the US Dollar currencyprotected static String
DOLLAR_ID
Record ID of the US Dollar currencyprotected static String
EURO
ISO code of the Euro currencyprotected static String
EURO_ID
Record ID of the Euro currencyprotected static String
QA_TEST_ADMIN_USER_ID
Record ID of the "Admin" user of QA Test clientprotected static String
QA_TEST_CLIENT_ID
Record ID of the QA Test clientprotected static String
QA_TEST_ORG_ID
Record ID of the Main organization of QA Test clientprotected static String
TEST_BP_CATEGORY_ID
Record ID of the "Customer" Business Partner Categoryprotected static String
TEST_CLIENT_ID
Record ID of Client "F&B International Group"protected static String
TEST_LOCATION_ID
Record ID of the geographical location "c\ de la Costa 54, San Sebastián 12784"protected static String
TEST_ORDER_ID
Record ID of a Order in Draft statusprotected static String
TEST_ORG_ID
Record ID of Organization "F&B España - Región Norte"protected static Map<String,String[]>
TEST_ORG_TREE
Map representation of current Organization tree for ClientTEST_CLIENT_ID
protected static String
TEST_PRODUCT_ID
Record ID of Product "Zumo de Fresa Bio 0,33L"protected static String
TEST_ROLE_ID
Record ID of Role "F&B International Group Admin"protected static String
TEST_US_ORG_ID
Record ID of Organization "F&B US West Coast"protected static String
TEST_USER_ID
Record ID of User "F&BAdmin"protected static String
TEST_WAREHOUSE_ID
Record ID of Warehouse "España Región Norte"protected static String
TEST2_USER_ID
Record ID of User "F&BESRNUser" - Any user with less privileges thanTEST_USER_ID
protected static List<User>
userIds
Record IDs of available users different thanTEST_USER_ID
Note: Initialized to null, need to callgetRandomUser()
at least onceorg.junit.rules.TestWatcher
watchFailures
Add a TestWatcher rule to be able to catch test failures allowing them to fail.
-
Constructor Summary
Constructors Constructor Description OBBaseTest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addReadWriteAccess(Class<?> clz)
Extends the read and write access of the current user to also include the passed class.static void
classSetUp()
Initializes DAL, it also creates a log appender that can be used to assert on logs.void
commitTransaction()
Commits the transaction to the database.protected <T extends BaseOBObject>
intcount(Class<T> clz)
Counts the total occurences in the database for the passed class.protected ConnectionProvider
getConnectionProvider()
protected <T extends BaseOBObject>
TgetOneInstance(Class<T> clz)
Convenience method, gets an instance for the passed Class from the database.protected User
getRandomUser()
Gets a random User (Record ID) from the available ones in the test client.protected TestLogAppender
getTestLogAppender()
Returns log appender in order to be possible to do assertions on itprotected void
initializeDalLayer(Map<String,org.hibernate.dialect.function.SQLFunction> sqlFunctions)
Initializes the DAL layer, can be overridden to add specific initialization behavior.protected static void
initializeDisabledTestCases()
protected static void
initializeTestLogAppender()
boolean
isErrorOccured()
protected void
reportException(Exception e)
Prints the stacktrace of the exception to System.err.void
rollback()
Does a rollback of the transaction;protected void
setLogStackTraces(boolean log)
Include in messages possible stack traces for logged Throwablesprotected static void
setQAAdminContext()
Sets the current user to the 100 user as QA Adminprotected void
setSystemAdministratorContext()
Set the current user to the 0 user.protected void
setTestAdminContext()
Sets the current user to the 100 user as F&B Group Adminprotected void
setTestLogAppenderLevel(org.apache.logging.log4j.Level level)
Defines the thresholdLevel
that will make messages to be tracked byTestLogAppender
.protected void
setTestUserContext()
Sets the current user to theTEST_USER_ID
user.void
setUp()
Sets the current user to theTEST_USER_ID
user.protected void
setUserContext(String userId)
Sets the current user.protected boolean
shouldMockServletContext()
protected static void
staticInitializeDalLayer()
void
testDone()
Test log appender is reset and switched off.
-
-
-
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.
-
TEST_CLIENT_ID
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
-
TEST_WAREHOUSE_ID
protected static final String TEST_WAREHOUSE_ID
Record ID of Warehouse "España Región Norte"- See Also:
- Constant Field Values
-
TEST_USER_ID
protected static final String TEST_USER_ID
Record ID of User "F&BAdmin"- See Also:
- Constant Field Values
-
TEST2_USER_ID
protected static final String TEST2_USER_ID
Record ID of User "F&BESRNUser" - Any user with less privileges thanTEST_USER_ID
- See Also:
- Constant Field Values
-
userIds
protected static List<User> userIds
Record IDs of available users different thanTEST_USER_ID
Note: Initialized to null, need to callgetRandomUser()
at least once
-
TEST_ROLE_ID
protected static final String TEST_ROLE_ID
Record ID of Role "F&B International Group Admin"- See Also:
- Constant Field Values
-
TEST_ORDER_ID
protected static final String TEST_ORDER_ID
Record ID of a Order in Draft status- See Also:
- Constant Field Values
-
TEST_PRODUCT_ID
protected static final String TEST_PRODUCT_ID
Record ID of Product "Zumo de Fresa Bio 0,33L"- See Also:
- Constant Field Values
-
TEST_ORG_TREE
protected static Map<String,String[]> TEST_ORG_TREE
Map representation of current Organization tree for ClientTEST_CLIENT_ID
-
QA_TEST_CLIENT_ID
protected static final String QA_TEST_CLIENT_ID
Record ID of the QA Test client- See Also:
- Constant Field Values
-
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
-
QA_TEST_ADMIN_USER_ID
protected static final String QA_TEST_ADMIN_USER_ID
Record ID of the "Admin" user of QA Test client- See Also:
- Constant Field Values
-
TEST_BP_CATEGORY_ID
protected static final String TEST_BP_CATEGORY_ID
Record ID of the "Customer" Business Partner Category- See Also:
- Constant Field Values
-
TEST_LOCATION_ID
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
-
EURO
protected static final String EURO
ISO code of the Euro currency- See Also:
- Constant Field Values
-
EURO_ID
protected static final String EURO_ID
Record ID of the Euro currency- See Also:
- Constant Field Values
-
DOLLAR
protected static final String DOLLAR
ISO code of the US Dollar currency- See Also:
- Constant Field Values
-
DOLLAR_ID
protected static final String DOLLAR_ID
Record ID of the US Dollar currency- See Also:
- Constant Field Values
-
-
Method Detail
-
classSetUp
public static void classSetUp() throws Exception
Initializes DAL, it also creates a log appender that can be used to assert on logs. This log appender is disabled by default, to activate it set the level withsetTestLogAppenderLevel(Level)
.- Throws:
Exception
- See Also:
TestLogAppender
-
initializeTestLogAppender
protected static void initializeTestLogAppender()
-
setUp
public void setUp() throws Exception
Sets the current user to theTEST_USER_ID
user. This method also mocks the servlet context through theDalContextListener
if the test case is configured to do so.- Throws:
Exception
-
testDone
public void testDone()
Test log appender is reset and switched off. This method also cleans the mock servlet context when it applies.
-
shouldMockServletContext
protected boolean shouldMockServletContext()
- Returns:
true
if the test case should mock the servlet context. Otherwise, returnfalse
.
-
setTestLogAppenderLevel
protected void setTestLogAppenderLevel(org.apache.logging.log4j.Level level)
Defines the thresholdLevel
that will make messages to be tracked byTestLogAppender
. 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.- Parameters:
sqlFunctions
- a Map with SQL functions to be registered in Hibernate during the DAL layer initialization. It can be null if not needed.- Throws:
Exception
-
staticInitializeDalLayer
protected static void staticInitializeDalLayer() throws Exception
- Throws:
Exception
-
initializeDisabledTestCases
protected static void initializeDisabledTestCases()
-
getConnectionProvider
protected ConnectionProvider getConnectionProvider()
-
setSystemAdministratorContext
protected void setSystemAdministratorContext()
Set the current user to the 0 user.
-
setTestUserContext
protected void setTestUserContext()
Sets the current user to theTEST_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
-
setUserContext
protected void setUserContext(String userId)
Sets the current user. For the 0, 100 and 1000000 users this method should not be used. For these users one of the other context-set methods should be used:setTestAdminContext()
,setTestUserContext()
orsetSystemAdministratorContext()
.- Parameters:
userId
- the id of the user to use.
-
getRandomUser
protected User getRandomUser()
Gets a random User (Record ID) from the available ones in the test client. The ID is one different thanTEST_USER_ID
- Returns:
- 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 theSQLException.getNextException()
method.- Parameters:
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.- Parameters:
clz
- instances- Returns:
- 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.- Parameters:
clz
- after this call the current user (in theOBContext
) 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- Parameters:
clz
- the class to count occurences for- Returns:
- the number of occurences which are active and belong to the current client/organization
-
-