Package org.alfresco.utility
Class Utility
- java.lang.Object
-
- org.alfresco.utility.Utility
-
public class Utility extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static intretryCountSeconds
-
Constructor Summary
Constructors Constructor Description Utility()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.FileassertFileDoesNotExist(java.lang.String filePath)Verify file from specified filePath doesn't existstatic java.io.FileassertFileExists(java.lang.String filePath)Verify file from specified filePath existsstatic voidassertIsEmpty(java.io.File folder)Asserting folder/File is empty based on its sizestatic java.lang.StringbuildPath(java.lang.String parent, java.lang.String... paths)Helper for building strings of the resource passed as parameterstatic java.io.FilecheckFileInPath(java.lang.String fileName, java.lang.String path)Search recursively in pathstatic voidcheckObjectIsInitialized(java.lang.Object model, java.lang.String message)static java.lang.StringcmisDocTypeToExtentions(org.alfresco.dataprep.CMISUtil.DocumentType cmisDocumentType)static java.lang.StringconvertBackslashToSlash(java.lang.String value)static voiddeleteFolder(java.io.File folder)static java.lang.ProcessexecuteCommandOnUnix(java.lang.String command)Execute any Terminal commands Example: executeOnWin("ls -la")static java.lang.StringexecuteOnUnix(java.lang.String command)Execute any Terminal commands Example: executeOnWin("ls -la")static voidexecuteOnUnixNoWait(java.lang.String command)static voidexecuteOnWin(java.lang.String command)Example: executeOnWin("mkdir 'a'")static java.lang.StringexecuteOnWinAndReturnOutput(java.lang.String command)Method to retrieve a process output as Stringstatic java.lang.StringgetEnvironmentPropertyFile()static java.io.FilegetFileWithSize(java.lang.String fileName, int sizeMB)Create a newFilewith specific size (MB)static java.io.FilegetMountedApp(java.io.File fromLocation)static java.lang.StringgetOSName()static java.lang.StringgetParentPath(java.lang.String fullPath)If we have "/test/something/now" this method will return "/test/something"static java.util.PropertiesgetProperties(java.lang.Class<?> classz, java.lang.String propertieFileName)static java.lang.StringgetResourceTestDataContent(java.lang.String fileName)static java.io.FilegetResourceTestDataFile(java.lang.String fileName)static java.lang.StringgetSystemOrFileProperty(java.lang.String key, java.util.Properties properties)static java.io.FilegetTestResourceFile(java.lang.String filePath)Return a file from the filePath locationstatic java.lang.StringgetTextFromClipboard()Get text copied to System Clipboardstatic booleanisProcessRunning(java.lang.String processName)Check if process identified byis currently running static booleanisPropertyEnabled(java.lang.String key)Check if property identified by key in *.properties file is enabled or notstatic booleanisWinServiceRunning(java.lang.String serviceName)static voidkillProcessExcludingMaven(java.lang.String processName)Kill process excluding Mavenstatic voidkillProcessName(java.lang.String processName)Kill a process using it's name.static java.lang.StringprettyPrintJsonString(java.lang.String unformattetJson)Pretty prints unformatted JSONstatic java.lang.StringremoveLastSlash(java.lang.String sourcePath)If the path ends with /, methods return the path without last /static java.io.FilesetNewFile(FileModel fileModel)Get newFilewith content based on file model.static voidsleep(int interval, int maxTime, RetryOperation callback)We will wait until the interval is passed from current run and retry until the maxTime is reachedstatic java.lang.StringsplitGuidVersion(java.lang.String guidWithVersion)static java.lang.StringtoUrlParams(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> params)Generate URL query string from key value parametersstatic voidwaitToLoopTime(int seconds, java.lang.String... info)We will wait until theare passed from current run static voidwaitUntilProcessFinishes(java.lang.String processName, int timeout, int loopTime)Wait until process finish to runstatic booleanwaitUntilProcessIsRunning(java.lang.String processName)Wait until process is running, or the retryCountSeconds is reached
-
-
-
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 TestConfigurationExceptionReturn a file from the filePath location- Parameters:
filePath-- Returns:
- file object
- Throws:
java.lang.ExceptionTestConfigurationException
-
getResourceTestDataFile
public static java.io.File getResourceTestDataFile(java.lang.String fileName) throws TestConfigurationException- Throws:
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
-
getProperties
public static java.util.Properties getProperties(java.lang.Class<?> classz, java.lang.String propertieFileName) throws TestConfigurationException- Throws:
TestConfigurationException
-
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 theare passed from current run - Parameters:
seconds-
-
sleep
public static void sleep(int interval, int maxTime, RetryOperation callback) throws java.lang.ExceptionWe 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.UnsupportedEncodingExceptionGenerate 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.ExceptionCreate a newFilewith 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.ExceptionExample: 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.IOExceptionKill a process using it's name.- Parameters:
processName-- Throws:
java.io.IOException
-
killProcessExcludingMaven
public static void killProcessExcludingMaven(java.lang.String processName) throws java.io.IOExceptionKill process excluding Maven- Parameters:
processName-- Throws:
java.io.IOException
-
setNewFile
public static java.io.File setNewFile(FileModel fileModel)
Get newFilewith 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 byis currently running - Parameters:
processName-- Returns:
-
getMountedApp
public static java.io.File getMountedApp(java.io.File fromLocation) throws TestConfigurationException- Parameters:
fromLocation-- Returns:
Filemounted on- Throws:
TestConfigurationException
-
getTextFromClipboard
public static java.lang.String getTextFromClipboard() throws java.io.IOException, java.awt.datatransfer.UnsupportedFlavorExceptionGet text copied to System Clipboard- Returns:
- Throws:
java.io.IOExceptionjava.awt.datatransfer.UnsupportedFlavorException
-
executeOnWinAndReturnOutput
public static java.lang.String executeOnWinAndReturnOutput(java.lang.String command) throws java.lang.ExceptionMethod 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
-
-