public class TestUtils
extends java.lang.Object
| Modifier and Type | Method and Description | 
|---|---|
| static boolean | arraySearch(java.lang.Object[] search,
           java.lang.String methodName,
           java.lang.Object key)Search an array by calling the passsed in method name with the key as the checker | 
| static void | disableLocalizationDebugMode()Turns of the Config setting for L10N debug mode | 
| static void | disableLocalizationLogging()Disable the *** ERROR: Message with id: [asciiString] not found.***
 errors. | 
| static void | enableLocalizationDebugMode()Sets the Config to indicate we want to be in
 Debug mode for Localization. | 
| static void | enableLocalizationLogging()Enable the *** ERROR: Message with id: [asciiString] not found.***
 errors. | 
| static boolean | equalTest(java.lang.Object o1,
         java.lang.Object o2)Used to test the equals contract on objects. | 
| static java.net.URL | findTestData(java.lang.String path)method to find a file relative to the calling class. | 
| static void | flushAndEvict(java.lang.Object obj)Util to flush and evict an object from the Hibernate Session | 
| static java.lang.Object | getPrivateField(java.lang.Object o,
               java.lang.String fieldName)Get a private field from a class. | 
| static RhnMockHttpServletRequest | getRequestWithSessionAndUser()Get a request with a Session and a User. | 
| static boolean | isLocalized(java.lang.String checkMe)Check the string to see if it passed through the LocalizationService. | 
| static java.lang.Object | lookupFromCacheById(java.lang.Long id,
                   java.lang.String queryname)Helper method to get a single object from the 2nd level cache by id | 
| static java.lang.Object | lookupFromCacheByLabel(java.lang.String label,
                      java.lang.String queryname)Helper method to get a single object from the 2nd level cache by label | 
| static java.lang.Object | lookupTestObject(java.lang.String query)Finds a single instance of a persistent object. | 
| static java.util.List | lookupTestObjects(java.lang.String query)Finds a list of persistent objects. | 
| static void | printWhoCalledMe(int depth)Print the first few lines from a stacktrace so we can figure out who the caller
 is. | 
| static java.lang.String | randomString()Return a random 13 letter string. | 
| static java.lang.String | readAll(java.io.InputStream stream)Read whole stream into a string. | 
| static java.lang.String | readAll(java.net.URL url)Connect to  urland return the contents
 of that location as a string. | 
| static java.lang.Object | reload(java.lang.Class objClass,
      java.io.Serializable id)Util to reload an object from the DB using Hibernate. | 
| static java.lang.Object | reload(java.lang.Object obj)Util to reload an object using Hibernate | 
| static int | removeObject(java.lang.Object toRemove)Removes an object from the database. | 
| static DataResult | runTestQuery(java.lang.String mode,
            java.util.Map params)Run a test query | 
| static void | saveAndFlush(java.lang.Object obj)Helper method to save objects to the database and flush
 the session. | 
| static java.lang.Object | saveAndReload(java.lang.Object o)Save and reload an object from DB | 
| static boolean | validateUIMessage(ActionHelper ah,
                 java.lang.String key)Check the request in the ActionHelper to validate that there is a UI
 message in the session. | 
| static void | writeByteArrayToFile(java.io.File file,
                    byte[] array)Write a byte array to a file | 
public static java.net.URL findTestData(java.lang.String path)
                                 throws java.lang.ClassNotFoundException,
                                        java.io.IOException
path - the path, relative to caller's locationjava.lang.ClassNotFoundException - if the calling class can not be found
 (i.e., should not happen)java.io.IOException - if the specified file in an archive (eg. jar) and
 it cannot be copied to a temporary locationpublic static void writeByteArrayToFile(java.io.File file,
                                        byte[] array)
file - to write bytearray toarray - to write outpublic static java.lang.String readAll(java.io.InputStream stream)
                                throws java.io.IOException
stream - the stream to consumejava.io.IOException - if reading the file failspublic static java.lang.String readAll(java.net.URL url)
                                throws java.io.IOException
url and return the contents
 of that location as a string.url - the URL to read fromnull
 if url is nulljava.io.IOException - if reading the file failspublic static RhnMockHttpServletRequest getRequestWithSessionAndUser()
public static java.lang.Object lookupTestObject(java.lang.String query)
                                         throws java.lang.Exception
query - The query to find the persistent object should
 be formulated to ensure a single object is returned or
 an error will occur.java.lang.Exception - if there was a Hibernate related exceptionpublic static java.util.List lookupTestObjects(java.lang.String query)
                                        throws java.lang.Exception
query - The query to find the persistent objects.java.lang.Exception - if there was a Hibernate related exceptionpublic static java.lang.Object lookupFromCacheById(java.lang.Long id,
                                                   java.lang.String queryname)
                                            throws java.lang.Exception
id - Id of the object you wantqueryname - Queryname for the query you want to run.
        queryname *MUST* have an :id attribute in it.java.lang.Exception - exceptionpublic static java.lang.Object lookupFromCacheByLabel(java.lang.String label,
                                                      java.lang.String queryname)
                                               throws java.lang.Exception
label - Label of the object you wantqueryname - Queryname for the query you want to run.
        queryname *MUST* have a :label attribute in it.java.lang.Exception - exceptionpublic static void printWhoCalledMe(int depth)
depth - the number of lines of the stacktrace you want to seepublic static void flushAndEvict(java.lang.Object obj)
                          throws org.hibernate.HibernateException
obj - to flushorg.hibernate.HibernateException - if something bad happenspublic static java.lang.Object reload(java.lang.Class objClass,
                                      java.io.Serializable id)
                               throws org.hibernate.HibernateException
objClass - of object being looked upid - of objectorg.hibernate.HibernateException - if something goes wrong.public static java.lang.Object reload(java.lang.Object obj)
                               throws org.hibernate.HibernateException
obj - to be reloadedorg.hibernate.HibernateException - if something bad happens.public static void saveAndFlush(java.lang.Object obj)
                         throws org.hibernate.HibernateException
obj - object to save.org.hibernate.HibernateException - HibernateExceptionpublic static int removeObject(java.lang.Object toRemove)
toRemove - Object to be removed.public static void enableLocalizationDebugMode()
public static void disableLocalizationDebugMode()
public static void disableLocalizationLogging()
public static void enableLocalizationLogging()
public static boolean isLocalized(java.lang.String checkMe)
checkMe - String to check if it was l10nedpublic static boolean validateUIMessage(ActionHelper ah, java.lang.String key)
ah - actionhelper used in the testkey - to the i18n resourcepublic static java.lang.String randomString()
public static DataResult runTestQuery(java.lang.String mode, java.util.Map params)
mode - to runparams - mappublic static boolean arraySearch(java.lang.Object[] search,
                                  java.lang.String methodName,
                                  java.lang.Object key)
search - arraymethodName - to call on each object in the array (can be toString())key - to compare topublic static java.lang.Object saveAndReload(java.lang.Object o)
o - to save and reload.public static java.lang.Object getPrivateField(java.lang.Object o,
                                               java.lang.String fieldName)
o - to checkfieldName - to findpublic static boolean equalTest(java.lang.Object o1,
                                java.lang.Object o2)
o1 - object1o2 - object2