Class Utility

java.lang.Object
org.alfresco.utility.Utility

public class Utility extends Object
  • Field Details

    • retryCountSeconds

      public static int retryCountSeconds
  • Constructor Details

    • Utility

      public Utility()
  • Method Details

    • checkObjectIsInitialized

      public static void checkObjectIsInitialized(Object model, String message) throws TestObjectNotDefinedException
      Check if the model object is null or not.
      Parameters:
      model - The object to check.
      message - The message to return if there's an issue.
      Throws:
      TestObjectNotDefinedException - if the model object is null.
    • getTestResourceFile

      public static File getTestResourceFile(String filePath) throws TestConfigurationException
      Return a file from the filePath location
      Parameters:
      filePath -
      Returns:
      file object
      Throws:
      Exception
      TestConfigurationException
    • getResourceTestDataFile

      public static File getResourceTestDataFile(String fileName) throws TestConfigurationException
      Throws:
      TestConfigurationException
    • getResourceTestDataContent

      public static String getResourceTestDataContent(String fileName) throws TestConfigurationException
      Parameters:
      fileName -
      Returns:
      the content of filename found in test/resources/testdata/
      Throws:
      TestConfigurationException - If the file cannot be read.
    • convertBackslashToSlash

      public static String convertBackslashToSlash(String value)
    • cmisDocTypeToExtentions

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

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

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

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

      public static Properties getProperties(Class<?> classz, String propertieFileName) throws TestConfigurationException
      Throws:
      TestConfigurationException
    • isPropertyEnabled

      public static boolean isPropertyEnabled(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, 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 InterruptedException
      We will wait until the interval is passed from current run and retry until the maxTime is reached
      Parameters:
      interval -
      maxTime -
      callback -
      Throws:
      InterruptedException - if the thread was interrupted while sleeping.
    • prettyPrintJsonString

      public static String prettyPrintJsonString(String unformattedJson)
      Pretty prints unformatted JSON
      Parameters:
      unformattedJson -
      Returns:
    • toUrlParams

      public static String toUrlParams(String url, Map<String,String> params)
      Generate URL query string from key value parameters
      Parameters:
      url -
      params -
      Returns:
    • getEnvironmentPropertyFile

      public static 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 String splitGuidVersion(String guidWithVersion)
    • checkFileInPath

      public static File checkFileInPath(String fileName, String path)
      Search recursively in path
      Parameters:
      fileName -
      path -
    • getFileWithSize

      public static File getFileWithSize(String fileName, int sizeMB)
      Create a new File with specific size (MB)
      Parameters:
      fileName -
      sizeMB -
      Returns:
      File
      Throws:
      DataPreparationException - If there is an error preparing the file.
    • getSystemOrFileProperty

      public static String getSystemOrFileProperty(String key, Properties properties)
    • executeOnUnixNoWait

      public static void executeOnUnixNoWait(String command) throws IOException
      Throws:
      IOException
    • executeOnUnix

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

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

      public static void executeOnWin(String command) throws IOException
      Example: executeOnWin("mkdir 'a'")
      Parameters:
      command -
      Throws:
      IOException
    • assertFileExists

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

      public static File assertFileDoesNotExist(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(File folder) throws IOException
      Throws:
      IOException
    • killProcessName

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

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

      public static 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(String processName)
      Check if process identified by is currently running
      Parameters:
      processName -
      Returns:
    • getMountedApp

      public static File getMountedApp(File fromLocation) throws TestConfigurationException
      Parameters:
      fromLocation -
      Returns:
      File mounted on
      Throws:
      TestConfigurationException
    • getTextFromClipboard

      public static String getTextFromClipboard() throws IOException, UnsupportedFlavorException
      Get text copied to System Clipboard
      Returns:
      Throws:
      IOException
      UnsupportedFlavorException
    • executeOnWinAndReturnOutput

      public static String executeOnWinAndReturnOutput(String command)
      Method to retrieve a process output as String
      Parameters:
      command -
      Returns:
      process output in String format
    • assertIsEmpty

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

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

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

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

      public static boolean isWinServiceRunning(String serviceName) throws IOException
      Throws:
      IOException