Class TestUtil

java.lang.Object
org.jboss.resteasy.utils.TestUtil

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

    • logger

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

    • TestUtil

      public TestUtil()
  • Method Details

    • 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
    • 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 Supplier<String> getErrorMessageForKnownIssue(String jira, String message)
    • getErrorMessageForKnownIssue

      public static Supplier<String> getErrorMessageForKnownIssue(String jira)
    • getErrorMessageForKnownIssue

      public static Supplier<String> getErrorMessageForKnownIssue(String jira, Throwable throwable)
    • getErrorMessageForKnownIssue

      public static Supplier<String> getErrorMessageForKnownIssue(String jira, String message, Throwable throwable)
    • 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()
    • isOracleJDK

      public static boolean isOracleJDK()
    • isIbmJdk

      public static boolean isIbmJdk()
    • 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)
    • 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 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:
    • 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 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:
    • createBeansXml

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

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

      public static org.jboss.shrinkwrap.api.asset.Asset createWebXml(Class<? extends jakarta.ws.rs.core.Application> application, String mappingPattern, Map<String,String> contextParams)
      Creates a web.xml file.
      Parameters:
      application - the application to add a servlet or null to use annotation scanning
      mappingPattern - the mapping parameter for cases when the application is not annotated with the ApplicationPath or is null, if null no servlet mapping is added
      contextParams - the optional context parameters to add
      Returns:
      a web.xml file
    • createPath

      public static String createPath(boolean addSlashPrefix, CharSequence... paths)
      Creates a URL path for the paths passed in.
      Parameters:
      addSlashPrefix - true if the resulting path should being with a /, if false and the first path argument has a beginning slash, it will not be removed
      paths - the paths used to create the URL path
      Returns:
      a URL path