Class TestUtil


  • public class TestUtil
    extends Object
    Base util class for RESTEasy testing.
    • Field Detail

      • logger

        protected static final org.jboss.logging.Logger logger
    • Constructor Detail

      • TestUtil

        public TestUtil()
    • 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 jakarta.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 singletons
        resources - classes used in deployment as resources
      • getManagementHost

        public static String getManagementHost()
        Returns the host name defined by the wildfly.management.host system property, node system property or localhost by default.
        Returns:
        the management host name
      • getManagementPort

        public static int getManagementPort()
        Returns the management port defined by the wildfly.management.port or 9990 by default.
        Returns:
        the management port
      • getManagementPort

        public static int getManagementPort​(int offset)
        Returns the management port by the wildfly.management.port or 9990 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.
      • getErrorMessageForKnownIssue

        public static String getErrorMessageForKnownIssue​(String jira,
                                                          String message)
      • getErrorMessageForKnownIssue

        public static String getErrorMessageForKnownIssue​(String jira)
      • 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, otherwise false
      • 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)
      • 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)
      • 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 not null.
        Parameters:
        base - the base URL
        path - 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
      • createBeansXml

        public static org.jboss.shrinkwrap.api.asset.Asset createBeansXml()
        Creates a beans.xml file which uses a bean-discovery-mode of "all".
        Returns:
        a beans.xml asset