Package org.jboss.resteasy.utils
Class TestUtil
- java.lang.Object
-
- org.jboss.resteasy.utils.TestUtil
-
public class TestUtil extends Object
Base util class for RESTEasy testing.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.logging.log4j.Logger
logger
-
Constructor Summary
Constructors Constructor Description TestUtil()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addOtherLibrary(org.jboss.shrinkwrap.api.spec.WebArchive archive, String dependency)
Adds additional dependency needed for the deployment tests.protected org.jboss.shrinkwrap.api.spec.WebArchive
addPackageInfo(org.jboss.shrinkwrap.api.spec.WebArchive war, Class<?> clazz)
Add package info to deployment.static org.wildfly.extras.creaper.core.online.OnlineManagementClient
clientInit()
static org.wildfly.extras.creaper.core.online.OnlineManagementClient
clientInit(int portOffset)
static void
countViolations(ResteasyViolationException e, int totalCount, int propertyCount, int classCount, int parameterCount, int returnValueCount)
Check count of violations in ResteasyViolationException.static void
countViolations(ViolationReport e, int propertyCount, int classCount, int parameterCount, int returnValueCount)
static org.jboss.shrinkwrap.api.Archive<?>
finishContainerPrepare(org.jboss.shrinkwrap.api.spec.WebArchive war, Map<String,String> contextParams, Class<?>... resources)
Finish preparing war deployment and deploy it.static org.jboss.shrinkwrap.api.Archive<?>
finishContainerPrepare(org.jboss.shrinkwrap.api.spec.WebArchive war, Map<String,String> contextParams, List<Class<?>> singletons, Class<?>... resources)
Finish preparing war deployment and deploy it.static URI
generateUri(URI base, String path)
Generate a URI based on the URL passed appending the path if its value is notnull
.static URI
generateUri(URL base, String path)
Generate a URI based on the URL passed appending the path if its value is notnull
.static String
getErrorMessageForKnownIssue(String jira)
static String
getErrorMessageForKnownIssue(String jira, String message)
static String
getJbossHome()
static String
getJbossHome(boolean onServer)
static String
getManagementHost()
Returns the host name defined by thewildfly.management.host
system property,node
system property orlocalhost
by default.static int
getManagementPort()
Returns the management port defined by thewildfly.management.port
or9990
by default.static int
getManagementPort(int offset)
Returns the management port by thewildfly.management.port
or9990
by default plus the offset.static String
getResourcePath(Class<?> c, String name)
Get resource in test scope for some class.static String
getStandaloneDir(boolean onServer, String containerQualifier)
Get the path to the containers base dir for standalone mode (configuration, logs, etc..).static String
getStandaloneDir(String containerQualifier)
Get the path to the containers base dir for standalone mode (configuration, logs, etc..).static ResteasyConstraintViolation
getViolationByMessage(List<ResteasyConstraintViolation> list, String message)
static ResteasyConstraintViolation
getViolationByMessageAndValue(List<ResteasyConstraintViolation> list, String message, Object value)
static ResteasyConstraintViolation
getViolationByPath(List<ResteasyConstraintViolation> list, String path)
static int
getWarningCount(String findedString, boolean onServer)
Get count of lines with specific string in logstatic int
getWarningCount(String findedString, boolean onServer, String containerQualifier)
Get count of lines with specific string in logstatic int
getWarningCount(String findedString, boolean onServer, String containerQualifier, boolean useRegexp)
Get count of lines with specific string or regexp in logstatic boolean
isIbmJdk()
static boolean
isModularJvm()
Indicates whether or not the current JVM is a modular (Java 9+) JVM.static boolean
isOpenJDK()
static boolean
isOracleJDK()
static boolean
isWildFly9x()
static boolean
isWindows()
static org.jboss.shrinkwrap.api.spec.WebArchive
prepareArchive(String deploymentName)
Initialize deployment.static org.jboss.shrinkwrap.api.spec.WebArchive
prepareArchiveWithApplication(String deploymentName, Class<? extends javax.ws.rs.core.Application> clazz)
static List<String>
readServerLogLines()
Read server log file from standalone/log/server.logstatic List<String>
readServerLogLines(boolean onServer)
static List<String>
readServerLogLines(boolean onServer, String containerQualifier)
static String
readString(InputStream in)
Convert input stream to String.static File
resolveDependency(String dependency)
Get specified single dependencystatic org.wildfly.extras.creaper.core.online.ModelNodeResult
runCmd(org.wildfly.extras.creaper.core.online.OnlineManagementClient client, String cmd)
-
-
-
Method Detail
-
prepareArchive
public static org.jboss.shrinkwrap.api.spec.WebArchive prepareArchive(String deploymentName)
Initialize deployment.- Returns:
- Deployment.
-
prepareArchiveWithApplication
public static org.jboss.shrinkwrap.api.spec.WebArchive prepareArchiveWithApplication(String deploymentName, Class<? extends javax.ws.rs.core.Application> clazz)
-
finishContainerPrepare
public static org.jboss.shrinkwrap.api.Archive<?> finishContainerPrepare(org.jboss.shrinkwrap.api.spec.WebArchive war, Map<String,String> contextParams, Class<?>... resources)
Finish preparing war deployment and deploy it. Add classes in @resources to deployment. Also all sub-classes of classes in @resources are added to deployment. But only classes in @resources (not sub-classes of classes in @resources) can be used as resources (getClasses function of TestApplication class return only classes in @resources).- Parameters:
resources
- classes used in deployment as resources
-
finishContainerPrepare
public static org.jboss.shrinkwrap.api.Archive<?> finishContainerPrepare(org.jboss.shrinkwrap.api.spec.WebArchive war, Map<String,String> contextParams, List<Class<?>> singletons, Class<?>... resources)
Finish preparing war deployment and deploy it. Add classes in @resources to deployment. Also all sub-classes of classes in @resources are added to deployment. But only classes in @resources (not sub-classes of classes in @resources) can be used as resources (getClasses function of TestApplication class return only classes in @resources).- Parameters:
singletons
- classes used in deployment as singletonsresources
- classes used in deployment as resources
-
getManagementHost
public static String getManagementHost()
Returns the host name defined by thewildfly.management.host
system property,node
system property orlocalhost
by default.- Returns:
- the management host name
-
getManagementPort
public static int getManagementPort()
Returns the management port defined by thewildfly.management.port
or9990
by default.- Returns:
- the management port
-
getManagementPort
public static int getManagementPort(int offset)
Returns the management port by thewildfly.management.port
or9990
by default plus the offset.- Parameters:
offset
- the offset for the default port- Returns:
- the offset management port
-
clientInit
public static org.wildfly.extras.creaper.core.online.OnlineManagementClient clientInit() throws IOException
- Throws:
IOException
-
clientInit
public static org.wildfly.extras.creaper.core.online.OnlineManagementClient clientInit(int portOffset) throws IOException
- Throws:
IOException
-
runCmd
public static org.wildfly.extras.creaper.core.online.ModelNodeResult runCmd(org.wildfly.extras.creaper.core.online.OnlineManagementClient client, String cmd) throws Exception
- Throws:
Exception
-
addPackageInfo
protected org.jboss.shrinkwrap.api.spec.WebArchive addPackageInfo(org.jboss.shrinkwrap.api.spec.WebArchive war, Class<?> clazz)
Add package info to deployment.- Parameters:
clazz
- Package info is for package of this class.
-
readString
public static String readString(InputStream in) throws IOException
Convert input stream to String.- Parameters:
in
- Input stream- Returns:
- Converted string
- Throws:
IOException
-
getErrorMessageForKnownIssue
public static String getErrorMessageForKnownIssue(String jira, String message)
-
getJbossHome
public static String getJbossHome()
-
getJbossHome
public static String getJbossHome(boolean onServer)
-
getStandaloneDir
public static String getStandaloneDir(String containerQualifier)
Get the path to the containers base dir for standalone mode (configuration, logs, etc..). When arquillian.xml contains more containers that could be started simultaneously the parameter containerQualifier is used to determine which base dir to get.- Parameters:
containerQualifier
- container qualifier or null if the arquillian.xml contains max 1 container available to be running at time- Returns:
- absolute path to base dir
-
getStandaloneDir
public static String getStandaloneDir(boolean onServer, String containerQualifier)
Get the path to the containers base dir for standalone mode (configuration, logs, etc..). When arquillian.xml contains more containers that could be started simultaneously the parameter containerQualifier is used to determine which base dir to get.- Parameters:
onServer
- whether the check is made from client side (the path is constructed) or from deployment (the path is read from actual runtime value)containerQualifier
- container qualifier or null if the arquillian.xml contains max 1 container available to be running at time; this has no effect when onServer is true- Returns:
- absolute path to base dir
-
isOpenJDK
public static boolean isOpenJDK()
-
isWildFly9x
public static boolean isWildFly9x()
-
isOracleJDK
public static boolean isOracleJDK()
-
isIbmJdk
public static boolean isIbmJdk()
-
isModularJvm
public static boolean isModularJvm()
Indicates whether or not the current JVM is a modular (Java 9+) JVM.- Returns:
true
if this is a modular JVM, otherwisefalse
-
getResourcePath
public static String getResourcePath(Class<?> c, String name)
Get resource in test scope for some class. Example: class org.test.MyTest and name "my_resource.txt" returns "src/test/resource/org/test/my_resource.txt"
-
readServerLogLines
public static List<String> readServerLogLines()
Read server log file from standalone/log/server.log
-
readServerLogLines
public static List<String> readServerLogLines(boolean onServer, String containerQualifier)
-
getWarningCount
public static int getWarningCount(String findedString, boolean onServer)
Get count of lines with specific string in log
-
getWarningCount
public static int getWarningCount(String findedString, boolean onServer, String containerQualifier)
Get count of lines with specific string in log
-
getWarningCount
public static int getWarningCount(String findedString, boolean onServer, String containerQualifier, boolean useRegexp)
Get count of lines with specific string or regexp in log
-
countViolations
public static void countViolations(ResteasyViolationException e, int totalCount, int propertyCount, int classCount, int parameterCount, int returnValueCount)
Check count of violations in ResteasyViolationException.
-
countViolations
public static void countViolations(ViolationReport e, int propertyCount, int classCount, int parameterCount, int returnValueCount)
-
getViolationByMessage
public static ResteasyConstraintViolation getViolationByMessage(List<ResteasyConstraintViolation> list, String message)
-
getViolationByMessageAndValue
public static ResteasyConstraintViolation getViolationByMessageAndValue(List<ResteasyConstraintViolation> list, String message, Object value)
-
getViolationByPath
public static ResteasyConstraintViolation getViolationByPath(List<ResteasyConstraintViolation> list, String path)
-
resolveDependency
public static File resolveDependency(String dependency)
Get specified single dependency- Parameters:
dependency
-- Returns:
- Dependency gav
-
addOtherLibrary
public static void addOtherLibrary(org.jboss.shrinkwrap.api.spec.WebArchive archive, String dependency)
Adds additional dependency needed for the deployment tests. Specified by parameter in the format 'groupId:artifactId:version'- Parameters:
archive
-dependency
-
-
isWindows
public static boolean isWindows()
-
generateUri
public static URI generateUri(URL base, String path) throws URISyntaxException
Generate a URI based on the URL passed appending the path if its value is notnull
.- Parameters:
base
- the base URLpath
- the path to append- Returns:
- the newly create URI
- Throws:
URISyntaxException
- If the given string violates RFC 2396, as augmented by the above deviations- See Also:
URI
-
generateUri
public static URI generateUri(URI base, String path) throws URISyntaxException
Generate a URI based on the URL passed appending the path if its value is notnull
.- Parameters:
base
- the base URLpath
- the path to append- Returns:
- the newly create URI
- Throws:
URISyntaxException
- If the given string violates RFC 2396, as augmented by the above deviations- See Also:
URI
-
-