Class Utility


  • public class Utility
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int retryCountSeconds  
    • Constructor Summary

      Constructors 
      Constructor Description
      Utility()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.io.File assertFileDoesNotExist​(java.lang.String filePath)
      Verify file from specified filePath doesn't exist
      static java.io.File assertFileExists​(java.lang.String filePath)
      Verify file from specified filePath exists
      static void assertIsEmpty​(java.io.File folder)
      Asserting folder/File is empty based on its size
      static java.lang.String buildPath​(java.lang.String parent, java.lang.String... paths)
      Helper for building strings of the resource passed as parameter
      static java.io.File checkFileInPath​(java.lang.String fileName, java.lang.String path)
      Search recursively in path
      static void checkObjectIsInitialized​(java.lang.Object model, java.lang.String message)  
      static java.lang.String cmisDocTypeToExtentions​(org.alfresco.dataprep.CMISUtil.DocumentType cmisDocumentType)  
      static java.lang.String convertBackslashToSlash​(java.lang.String value)  
      static void deleteFolder​(java.io.File folder)  
      static java.lang.Process executeCommandOnUnix​(java.lang.String command)
      Execute any Terminal commands Example: executeOnWin("ls -la")
      static java.lang.String executeOnUnix​(java.lang.String command)
      Execute any Terminal commands Example: executeOnWin("ls -la")
      static void executeOnUnixNoWait​(java.lang.String command)  
      static void executeOnWin​(java.lang.String command)
      Example: executeOnWin("mkdir 'a'")
      static java.lang.String executeOnWinAndReturnOutput​(java.lang.String command)
      Method to retrieve a process output as String
      static java.lang.String getEnvironmentPropertyFile()  
      static java.io.File getFileWithSize​(java.lang.String fileName, int sizeMB)
      Create a new File with specific size (MB)
      static java.io.File getMountedApp​(java.io.File fromLocation)  
      static java.lang.String getOSName()  
      static java.lang.String getParentPath​(java.lang.String fullPath)
      If we have "/test/something/now" this method will return "/test/something"
      static java.util.Properties getProperties​(java.lang.Class<?> classz, java.lang.String propertieFileName)  
      static java.lang.String getResourceTestDataContent​(java.lang.String fileName)  
      static java.io.File getResourceTestDataFile​(java.lang.String fileName)  
      static java.lang.String getSystemOrFileProperty​(java.lang.String key, java.util.Properties properties)  
      static java.io.File getTestResourceFile​(java.lang.String filePath)
      Return a file from the filePath location
      static java.lang.String getTextFromClipboard()
      Get text copied to System Clipboard
      static boolean isProcessRunning​(java.lang.String processName)
      Check if process identified by is currently running
      static boolean isPropertyEnabled​(java.lang.String key)
      Check if property identified by key in *.properties file is enabled or not
      static boolean isWinServiceRunning​(java.lang.String serviceName)  
      static void killProcessExcludingMaven​(java.lang.String processName)
      Kill process excluding Maven
      static void killProcessName​(java.lang.String processName)
      Kill a process using it's name.
      static java.lang.String prettyPrintJsonString​(java.lang.String unformattetJson)
      Pretty prints unformatted JSON
      static java.lang.String removeLastSlash​(java.lang.String sourcePath)
      If the path ends with /, methods return the path without last /
      static java.io.File setNewFile​(FileModel fileModel)
      Get new File with content based on file model.
      static void sleep​(int interval, int maxTime, RetryOperation callback)
      We will wait until the interval is passed from current run and retry until the maxTime is reached
      static java.lang.String splitGuidVersion​(java.lang.String guidWithVersion)  
      static java.lang.String toUrlParams​(java.lang.String url, java.util.Map<java.lang.String,​java.lang.String> params)
      Generate URL query string from key value parameters
      static void waitToLoopTime​(int seconds, java.lang.String... info)
      We will wait until the are passed from current run
      static void waitUntilProcessFinishes​(java.lang.String processName, int timeout, int loopTime)
      Wait until process finish to run
      static boolean waitUntilProcessIsRunning​(java.lang.String processName)
      Wait until process is running, or the retryCountSeconds is reached
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • retryCountSeconds

        public static int retryCountSeconds
    • Constructor Detail

      • Utility

        public Utility()
    • Method Detail

      • checkObjectIsInitialized

        public static void checkObjectIsInitialized​(java.lang.Object model,
                                                    java.lang.String message)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getTestResourceFile

        public static java.io.File getTestResourceFile​(java.lang.String filePath)
                                                throws TestConfigurationException
        Return a file from the filePath location
        Parameters:
        filePath -
        Returns:
        file object
        Throws:
        java.lang.Exception
        TestConfigurationException
      • getResourceTestDataContent

        public static java.lang.String getResourceTestDataContent​(java.lang.String fileName)
                                                           throws java.lang.Exception
        Parameters:
        fileName -
        Returns:
        the content of filename found in test/resources/testdata/
        Throws:
        java.lang.Exception
      • convertBackslashToSlash

        public static java.lang.String convertBackslashToSlash​(java.lang.String value)
      • cmisDocTypeToExtentions

        public static java.lang.String cmisDocTypeToExtentions​(org.alfresco.dataprep.CMISUtil.DocumentType cmisDocumentType)
      • buildPath

        public static java.lang.String buildPath​(java.lang.String parent,
                                                 java.lang.String... paths)
        Helper for building strings of the resource passed as parameter
        Parameters:
        parent -
        paths -
        Returns:
        concatenated paths of + each
      • getParentPath

        public static java.lang.String getParentPath​(java.lang.String fullPath)
        If we have "/test/something/now" this method will return "/test/something"
        Parameters:
        fullPath -
      • removeLastSlash

        public static java.lang.String removeLastSlash​(java.lang.String sourcePath)
        If the path ends with /, methods return the path without last /
        Parameters:
        sourcePath -
        Returns:
        sourcePath without last slash
      • isPropertyEnabled

        public static boolean isPropertyEnabled​(java.lang.String key)
        Check if property identified by key in *.properties file is enabled or not
        Parameters:
        key -
        Returns:
      • waitToLoopTime

        public static void waitToLoopTime​(int seconds,
                                          java.lang.String... info)
        We will wait until the are passed from current run
        Parameters:
        seconds -
      • sleep

        public static void sleep​(int interval,
                                 int maxTime,
                                 RetryOperation callback)
                          throws java.lang.Exception
        We will wait until the interval is passed from current run and retry until the maxTime is reached
        Parameters:
        interval -
        maxTime -
        callback -
        Throws:
        java.lang.Exception
      • prettyPrintJsonString

        public static java.lang.String prettyPrintJsonString​(java.lang.String unformattetJson)
        Pretty prints unformatted JSON
        Parameters:
        unformattetJson -
        Returns:
      • toUrlParams

        public static java.lang.String toUrlParams​(java.lang.String url,
                                                   java.util.Map<java.lang.String,​java.lang.String> params)
                                            throws java.io.UnsupportedEncodingException
        Generate URL query string from key value parameters
        Parameters:
        url -
        params -
        Returns:
        Throws:
        java.io.UnsupportedEncodingException
      • getEnvironmentPropertyFile

        public static java.lang.String getEnvironmentPropertyFile()
        Returns:
        the environment property file if nothing specified, default.properties is used if -Denvironment=local then local.properties is used.
      • splitGuidVersion

        public static java.lang.String splitGuidVersion​(java.lang.String guidWithVersion)
      • checkFileInPath

        public static java.io.File checkFileInPath​(java.lang.String fileName,
                                                   java.lang.String path)
        Search recursively in path
        Parameters:
        fileName -
        path -
      • getFileWithSize

        public static java.io.File getFileWithSize​(java.lang.String fileName,
                                                   int sizeMB)
                                            throws java.lang.Exception
        Create a new File with specific size (MB)
        Parameters:
        fileName -
        sizeMB -
        Returns:
        File
        Throws:
        java.lang.Exception
      • getSystemOrFileProperty

        public static java.lang.String getSystemOrFileProperty​(java.lang.String key,
                                                               java.util.Properties properties)
      • executeOnUnixNoWait

        public static void executeOnUnixNoWait​(java.lang.String command)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • executeOnUnix

        public static java.lang.String executeOnUnix​(java.lang.String command)
        Execute any Terminal commands Example: executeOnWin("ls -la")
        Parameters:
        command -
        Returns:
        output as string
      • executeCommandOnUnix

        public static java.lang.Process executeCommandOnUnix​(java.lang.String command)
        Execute any Terminal commands Example: executeOnWin("ls -la")
        Parameters:
        command -
        Returns:
        process
      • executeOnWin

        public static void executeOnWin​(java.lang.String command)
                                 throws java.lang.Exception
        Example: executeOnWin("mkdir 'a'")
        Parameters:
        command -
        Throws:
        java.lang.Exception
      • assertFileExists

        public static java.io.File assertFileExists​(java.lang.String filePath)
        Verify file from specified filePath exists
        Parameters:
        filePath - full path of the file
        Returns:
        File new file object found
      • assertFileDoesNotExist

        public static java.io.File assertFileDoesNotExist​(java.lang.String filePath)
        Verify file from specified filePath doesn't exist
        Parameters:
        filePath - full path of the file
        Returns:
        File new file object
      • deleteFolder

        public static void deleteFolder​(java.io.File folder)
                                 throws java.lang.Exception
        Throws:
        java.lang.Exception
      • killProcessName

        public static void killProcessName​(java.lang.String processName)
                                    throws java.io.IOException
        Kill a process using it's name.
        Parameters:
        processName -
        Throws:
        java.io.IOException
      • killProcessExcludingMaven

        public static void killProcessExcludingMaven​(java.lang.String processName)
                                              throws java.io.IOException
        Kill process excluding Maven
        Parameters:
        processName -
        Throws:
        java.io.IOException
      • setNewFile

        public static java.io.File setNewFile​(FileModel fileModel)
        Get new File with content based on file model. The new file will be deleted in the end.
        Parameters:
        fileModel - FileModel
        Returns:
        new File
      • isProcessRunning

        public static boolean isProcessRunning​(java.lang.String processName)
        Check if process identified by is currently running
        Parameters:
        processName -
        Returns:
      • getTextFromClipboard

        public static java.lang.String getTextFromClipboard()
                                                     throws java.io.IOException,
                                                            java.awt.datatransfer.UnsupportedFlavorException
        Get text copied to System Clipboard
        Returns:
        Throws:
        java.io.IOException
        java.awt.datatransfer.UnsupportedFlavorException
      • executeOnWinAndReturnOutput

        public static java.lang.String executeOnWinAndReturnOutput​(java.lang.String command)
                                                            throws java.lang.Exception
        Method to retrieve a process output as String
        Parameters:
        command -
        Returns:
        process output in String format
        Throws:
        java.lang.Exception
      • assertIsEmpty

        public static void assertIsEmpty​(java.io.File folder)
        Asserting folder/File is empty based on its size
        Parameters:
        folder -
      • waitUntilProcessIsRunning

        public static boolean waitUntilProcessIsRunning​(java.lang.String processName)
        Wait until process is running, or the retryCountSeconds is reached
        Parameters:
        processName -
      • waitUntilProcessFinishes

        public static void waitUntilProcessFinishes​(java.lang.String processName,
                                                    int timeout,
                                                    int loopTime)
        Wait until process finish to run
        Parameters:
        processName -
        timeout -
        loopTime -
      • getOSName

        public static java.lang.String getOSName()
                                          throws java.io.IOException
        Returns:
        OS Name.
        Throws:
        java.io.IOException
      • isWinServiceRunning

        public static boolean isWinServiceRunning​(java.lang.String serviceName)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception