public abstract class Utils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Utils.DefaultDateJsonDeserializer
A custom
JsonDeserializer to parse a string value to Date.Currently, it can parse date string as below: DATE_FORMAT_ISO8601 DATE_FORMAT_ACCEPTED_BY_SPRING_MVC Constants.SAFS_LogConstants.FORMAT_DATE_TIME |
static class |
Utils.LongDateJsonDeserializer
A custom
JsonDeserializer to parse a long value to Date.If we create it with an other JsonDeserializer, then it will also try to parse the date with that JsonDeserializer. For example: JsonDeserializer<Date> dateDesrializer = new Utils.LongDateJsonDeserializer (new Utils.DefaultDateJsonDeserializer ()); |
static class |
Utils.WrapperDateJsonDeserializer
A wrapper
JsonDeserializer to parse a value to Date.It wraps a JsonDeserializer and delegate the parse work to it. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DATE_FORMAT_ACCEPTED_BY_SPRING_MVC
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
|
static java.lang.String |
DATE_FORMAT_ISO8601
"yyyy-MM-dd'T'HH:mm:ss'Z'"
|
static java.lang.String |
DEFAULT_JAVA_COMPILER
'javac' the default java compiler.
|
static java.lang.String |
DEFAULT_OUTPUT_DIRECTORY
'bin' the sub-folder containing compiled classes.
|
static java.lang.String |
DEFAULT_SOURCE_DIRECTORY
'src' the sub-folder containing java/groovy source code.
|
static java.lang.String |
FILE_SUFFIX_GROOVY
'.groovy' the suffix of groovy source code.
|
static java.lang.String |
FILE_SUFFIX_JAVA
'.java' the suffix of java source code.
|
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static void |
compile(java.lang.String classnames)
Compile the java/groovy source code.
NOTE: 1. |
static void |
compile(java.lang.String classnames,
java.lang.String sourceDIR,
java.lang.String outDIR,
java.lang.String useClasspath)
Compile java and/or groovy source code.
|
static void |
deleteFromRepository(java.lang.String safsdataServiceID,
RestModel restModel)
Delete a
RestModel from a repository. |
static void |
downloadURL(java.lang.String url,
java.io.File outfile)
Deprecated.
Please use
UtilsIndependent.downloadURL(String, File) instead. |
static void |
downloadURL(java.lang.String url,
java.io.File outfile,
boolean checkContent)
Deprecated.
Please use
UtilsIndependent.downloadURL(String, File, boolean) instead. |
static boolean |
equals(java.lang.Object value1,
java.lang.Object value2)
Compare 2 objects even they are multiple-dimension arrays.
|
static RestModel |
fireEkspresoEvent(java.lang.String safsdataServiceID,
java.lang.String event_type,
java.lang.String parameters) |
static <T> T |
fromJson(com.google.gson.GsonBuilder builder,
java.lang.String jsonString,
java.lang.Class<T> type)
Provide a flexible way to convert a JSON String to a certain type.
User can provide its own GsonBuilder. |
static <T> T |
fromJson(com.google.gson.GsonBuilder builder,
java.lang.String jsonString,
java.lang.reflect.Type type)
Provide a flexible way to convert a JSON String to a certain type.
User can provide its own GsonBuilder. |
static <T> T |
fromJsonString(java.lang.String jsonString,
java.lang.Class<T> type)
Convert a JSON String to a certain type.
Note: It needs com.google.gson.Gson, which is currently included in the selenium-server-standalone jar. |
static java.util.List<RestModel> |
getAllFromRepository(java.lang.String safsdataServiceID,
RestModel model)
Get all of a certain RestModel from data repository.
|
static java.lang.Object[] |
getArray(java.lang.Object array) |
static java.lang.Class<?> |
getFieldClass(java.lang.Object object,
java.lang.String fieldName)
Get the class name of the field's defined type.
|
static java.lang.Class<?> |
getFieldInstanceClass(java.lang.Object object,
java.lang.String fieldName)
Get the class name of the real instance of the field.
|
static java.lang.String |
getFieldInstanceClassName(java.lang.Object object,
java.lang.String fieldName) |
static RestModel |
getFromRepository(java.lang.String safsdataServiceID,
RestModel restModel,
java.lang.String parameters)
Get a RestModel from data repository according to 'parameters'.
|
static <T> T |
getJsonValue(java.lang.String jsonString,
java.lang.String key,
java.lang.Class<T> expectedType)
Get expected value from a json string according to a key.
|
static java.lang.Object |
getMapValue(java.util.Map<?,?> map,
java.lang.Object key,
java.lang.Object defaultValue)
Get the value form the map according to a key.
If the map is null or the value is null, then return the default value. |
static boolean |
getNumLock() |
static java.util.List<GenericProcessMonitor.ProcessInfo> |
getRunningJavaProcess(java.lang.String host,
java.util.List<java.lang.String> fields)
Get a list of running java process.
|
static java.util.List<GenericProcessMonitor.ProcessInfo> |
getRunningJSAFSTestProcess(java.lang.String host,
java.util.List<java.lang.String> fields)
Get a list of process running JSAFS Test.
|
static java.util.List<GenericProcessMonitor.ProcessInfo> |
getRunningSAFSTestProcess(java.lang.String host,
java.util.List<java.lang.String> fields)
Get a list of process running SAFS Test.
|
static java.util.List<GenericProcessMonitor.ProcessInfo> |
getRunningSeleniumPlusTestProcess(java.lang.String host,
java.util.List<java.lang.String> fields)
Get a list of process running SeleniumPlus Test.
|
static java.lang.String |
getRunningTestCommandLine(java.lang.String host)
Get the command-line of a running test (SeleniumPlus, SAFS).
We assume there is only one running test on a machine. |
static java.util.List<GenericProcessMonitor.ProcessInfo> |
getRunningTestProcess(java.lang.String host,
java.util.List<java.lang.String> fields)
Get the running process of SeleniumPlus, SAFS or JSAFS test.
We assume there is only one running test on a machine. |
static boolean |
isJSON(java.lang.String value) |
static boolean |
isURLExist(java.lang.String url)
Deprecated.
Please use
UtilsIndependent.isURLExist(String) instead. |
static void |
main(java.lang.String[] params)
java -ea org.safs.Utils
|
static void |
makeRunAsAdministrator(java.lang.String lnkFileName)
Change the windows .lnk file's property to make it "Run As Administrator".
|
static java.lang.Object |
parseValue(java.lang.Class<?> expectedType,
java.lang.Object value)
Convert the parameter 'value' to an appropriate Object according to the expectedType.
|
static RestModel |
pushToRepository(java.lang.String safsdataServiceID,
RestModel restModel)
Push a
RestModel to a repository. |
static void |
setField(java.lang.Object object,
java.lang.String fieldName,
java.util.LinkedHashMap<java.lang.String,java.util.LinkedHashMap<java.lang.Class<?>,java.lang.Object>> fieldClassNameToConstructorParamsMap)
Set a value to a field.
The value will be normally instantiated according parameter fieldClassNameToConstructorParamsMap if it doesn't contain key FIELD_INSTANCE . |
static void |
setField(java.lang.Object object,
java.lang.String fieldName,
java.lang.Object value)
Set a value to a field.
|
static void |
setNumLock(boolean onOff) |
static java.lang.String |
toJson(com.google.gson.GsonBuilder builder,
java.lang.Object source)
Provide a flexible way to convert an Object to json string.
|
static java.lang.String |
toJson(java.lang.Object source,
java.lang.String dateFormat)
Convert an object to JSON String.
Especially it will convert Date to a certain format specified by parameter 'dateFormat'. |
static java.lang.String |
toJsonForSpring(java.lang.Object source)
Convert an object to JSON string accepted by Spring.
Currently it will make sure the Date will be converted to format DATE_FORMAT_ACCEPTED_BY_SPRING_MVC . |
static java.lang.String |
toJsonString(java.lang.Object source)
Convert an object to JSON String.
Note: It needs com.google.gson.Gson, which is currently included in the selenium-server-standalone jar. |
static java.lang.String |
toString(java.lang.Object object)
Convert an Object to a string, even this object is a multiple dimension array.
|
static RestModel |
updateRepository(java.lang.String safsdataServiceID,
RestModel restModel) |
public static final java.lang.String FILE_SUFFIX_JAVA
public static final java.lang.String FILE_SUFFIX_GROOVY
public static final java.lang.String DEFAULT_SOURCE_DIRECTORY
public static final java.lang.String DEFAULT_OUTPUT_DIRECTORY
public static final java.lang.String DEFAULT_JAVA_COMPILER
public static java.lang.String DATE_FORMAT_ACCEPTED_BY_SPRING_MVC
public static java.lang.String DATE_FORMAT_ISO8601
public static void setNumLock(boolean onOff)
onOff
- boolean, Set keyboard's 'NumLock' on or off.public static boolean getNumLock()
public static void compile(java.lang.String classnames) throws SAFSException
root + "src" (source files folder) + package1 + package2 + "bin" (compiled classes go into this folder--which will be created if not already present.)
classnames
- String, the class names to compile separated by space, such as my.package.ClassA my.pack2.ClassBSAFSException
- if the compilation failed for any reason--including bad parameter values.public static void compile(java.lang.String classnames, java.lang.String sourceDIR, java.lang.String outDIR, java.lang.String useClasspath) throws SAFSException
classnames
- String, the class names to compile separated by space, such as my.package.ClassA my.pack2.ClassBsourceDIR
- String, the root directory off which the sourcecode files reside.outDIR
- String, the root directory off which the compiled classes will be stored. The directory will be created, if necessary.useClasspath
- String, the semi-colon separated CLASSPATH to be used for the compile.SAFSException
- if the compilation failed for any reason--including bad parameter values.public static java.lang.Object getMapValue(java.util.Map<?,?> map, java.lang.Object key, java.lang.Object defaultValue)
map
- Mapkey
- Object,defaultValue
- Object,public static java.lang.Object parseValue(java.lang.Class<?> expectedType, java.lang.Object value) throws SAFSException
expectedType
- Class, the expected field typevalue
- Object, the value to parse.SAFSException
public static java.lang.Object[] getArray(java.lang.Object array) throws SAFSException
array
- Object, an array object.SAFSException
public static java.lang.String toString(java.lang.Object object)
object
- Objectpublic static boolean equals(java.lang.Object value1, java.lang.Object value2)
value1
- Objectvalue2
- Objectpublic static void makeRunAsAdministrator(java.lang.String lnkFileName) throws java.io.IOException
lnkFileName
- String, the full path to a link filejava.io.IOException
public static void setField(java.lang.Object object, java.lang.String fieldName, java.lang.Object value)
object
- Object, the object whose field will be setfieldName
- String, the name of the field to be setvalue
- Object, the value to set. It must be the same type of sub type as the field's.public static void setField(java.lang.Object object, java.lang.String fieldName, java.util.LinkedHashMap<java.lang.String,java.util.LinkedHashMap<java.lang.Class<?>,java.lang.Object>> fieldClassNameToConstructorParamsMap)
FIELD_INSTANCE
.object
- Object, the object whose field will be setfieldName
- String, the name of the field to be setfieldClassNameToConstructorParamsMap
- LinkedHashMap<String, LinkedHashMap<Class<?>, Object>>, the map of pair (fieldClassName, constructor-arguments) to create an instance for a field.FIELD_INSTANCE
, then map's value is a map containing pair(Object.class, value), and the value will be assigned to the field directly.FIELD_INSTANCE
is exclusive in the map, we should NOT put other keys in this map.
setField(Object, String, Object)
,
testReflectField()
public static java.lang.Class<?> getFieldClass(java.lang.Object object, java.lang.String fieldName) throws java.lang.NoSuchFieldException, java.lang.SecurityException
object
- Object, the object from which to get class of a fieldfieldName
- String, the name of the field to get its classjava.lang.NoSuchFieldException
java.lang.SecurityException
public static java.lang.Class<?> getFieldInstanceClass(java.lang.Object object, java.lang.String fieldName) throws java.lang.NoSuchFieldException, java.lang.SecurityException
object
- Object, the object from which to get class of a fieldfieldName
- String, the name of the field to get its classjava.lang.NoSuchFieldException
java.lang.SecurityException
public static java.lang.String getFieldInstanceClassName(java.lang.Object object, java.lang.String fieldName)
object
- Object, the object from which to get class name of the instance of a fieldfieldName
- String, the name of the field to get its instance class namepublic static java.lang.String toJsonString(java.lang.Object source)
source
- Object, to be converted to JSON Stringpublic static java.lang.String toJsonForSpring(java.lang.Object source)
DATE_FORMAT_ACCEPTED_BY_SPRING_MVC
.source
- Object, to be converted to JSON Stringpublic static java.lang.String toJson(java.lang.Object source, java.lang.String dateFormat)
source
- Object, to be converted to JSON StringdateFormat
- String,public static java.lang.String toJson(com.google.gson.GsonBuilder builder, java.lang.Object source)
builder
- GsonBuilder, the user-provided builder.source
- Object, to be converted to json string.public static <T> T fromJsonString(java.lang.String jsonString, java.lang.Class<T> type)
jsonString
- String, the JSON string.type
- Classpublic static <T> T fromJson(com.google.gson.GsonBuilder builder, java.lang.String jsonString, java.lang.Class<T> type)
builder
- GsonBuilder, the user-provided builder.jsonString
- String, the JSON string.type
- Classpublic static <T> T fromJson(com.google.gson.GsonBuilder builder, java.lang.String jsonString, java.lang.reflect.Type type)
builder
- GsonBuilder, the user-provided builder.jsonString
- String, the JSON string.type
- Type, the type of object which "JSON String" to be converted.public static void deleteFromRepository(java.lang.String safsdataServiceID, RestModel restModel) throws SAFSDatabaseException
RestModel
from a repository.safsdataServiceID
- String, the session ID. REST.StartServiceSession( safsDataServiceID, serverURL) should have been called previously.restModel
- RestModel, the model to delete from a repository in safs data service.SAFSDatabaseException
- if we fail to delete the rest model from repository.public static RestModel pushToRepository(java.lang.String safsdataServiceID, RestModel restModel) throws SAFSDatabaseException, SAFSModelCreationException
RestModel
to a repository.safsdataServiceID
- String, the session ID. REST.StartServiceSession( safsDataServiceID, serverURL) should have been called previously.restModel
- RestModel, the model to push to a repository in safs data service.SAFSDatabaseException
- if we fail to push the rest model to repository.SAFSModelCreationException
- if we fail to get rest model (with generated ID) from the http response. But the model has been pushed successfully.public static RestModel updateRepository(java.lang.String safsdataServiceID, RestModel restModel) throws SAFSDatabaseException
safsdataServiceID
- String, the SAFS data service ID.restModel
- RestModel, the model to update in repository.SAFSDatabaseException
- if the http reponse's status is not OK.public static RestModel fireEkspresoEvent(java.lang.String safsdataServiceID, java.lang.String event_type, java.lang.String parameters) throws SAFSDatabaseException
safsdataServiceID
- String, the SAFS data service ID.event_type
- String, the event_type of the EkspresoEvent being fired.parameters
- String, it is used by the "SAFS data service" EkspresoEvent controller.
It can be anything, it depends the "SAFS data service" EkspresoEvent controller.
For example it could be a SAFS event name + historyID, such as "safs_test_start/2", "safs_test_stop/2".SAFSDatabaseException
- if the http reponse's status is not OK.public static RestModel getFromRepository(java.lang.String safsdataServiceID, RestModel restModel, java.lang.String parameters) throws SAFSDatabaseException
safsdataServiceID
- String, the SAFS data service ID.restModel
- RestModel, the model to get from repository.parameters
- String, it is used to select model from repository.
The parameters can be anything, it depends the "SAFS Data service". Normally it could be a model's ID.SAFSDatabaseException
- if the http reponse's status is not OK.public static java.util.List<RestModel> getAllFromRepository(java.lang.String safsdataServiceID, RestModel model) throws SAFSDatabaseException
safsdataServiceID
- String, the SAFS data service ID.model
- RestModel, the model to get from repository.SAFSDatabaseException
- if the http reponse's status is not OK.public static <T> T getJsonValue(java.lang.String jsonString, java.lang.String key, java.lang.Class<T> expectedType) throws SAFSException
jsonString
- String, the json string.key
- String, the key mapping to a value in json string.expectedType
- Class<T>, the expected type of the value got by key from json string.SAFSException
String jsonstring = "{'int':10.0, 'long':12, 'boolean':true}"; Integer intValue = getJsonValue(jsonstring, "int", Integer.class); Long longValue = getJsonValue(jsonstring, "long", Long.class); Boolean boolValue = getJsonValue(jsonstring, "boolean", Boolean.class);
public static boolean isJSON(java.lang.String value)
value
- Stringpublic static java.util.List<GenericProcessMonitor.ProcessInfo> getRunningJavaProcess(java.lang.String host, java.util.List<java.lang.String> fields) throws SAFSException
host
- String, the host name where to get processesfields
- ListSAFSException
public static java.util.List<GenericProcessMonitor.ProcessInfo> getRunningJSAFSTestProcess(java.lang.String host, java.util.List<java.lang.String> fields) throws SAFSException
host
- String, the host name where to get processesfields
- ListSAFSException
public static java.util.List<GenericProcessMonitor.ProcessInfo> getRunningSAFSTestProcess(java.lang.String host, java.util.List<java.lang.String> fields) throws SAFSException
host
- String, the host name where to get processesfields
- ListSAFSException
public static java.util.List<GenericProcessMonitor.ProcessInfo> getRunningSeleniumPlusTestProcess(java.lang.String host, java.util.List<java.lang.String> fields) throws SAFSException
host
- String, the host name where to get processesfields
- ListSAFSException
public static java.util.List<GenericProcessMonitor.ProcessInfo> getRunningTestProcess(java.lang.String host, java.util.List<java.lang.String> fields) throws SAFSException
host
- String, the host name where to get processesfields
- ListSAFSException
public static java.lang.String getRunningTestCommandLine(java.lang.String host) throws SAFSException
host
- String, the host name where to get processSAFSException
@Deprecated public static boolean isURLExist(java.lang.String url)
UtilsIndependent.isURLExist(String)
instead.url
- String, the URL to verify@Deprecated public static void downloadURL(java.lang.String url, java.io.File outfile) throws java.io.IOException
UtilsIndependent.downloadURL(String, File)
instead.url
- String, the URL to downloadoutfile
- File, the destination filejava.io.IOException
@Deprecated public static void downloadURL(java.lang.String url, java.io.File outfile, boolean checkContent) throws java.io.IOException
UtilsIndependent.downloadURL(String, File, boolean)
instead.url
- String, the URL to downloadoutfile
- File, the destination filecheckContent
- boolean, if need to check the response contentjava.io.IOException
public static void main(java.lang.String[] params)
Copyright © SAS Institute. All Rights Reserved.