Class MavenTargetDirectoryRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule
    Direct Known Subclasses:
    MavenTestEnv

    public class MavenTargetDirectoryRule
    extends Object
    implements org.junit.rules.TestRule
    This rule permits to get some technical path information about maven target directory during a test. This is useful for treatments that manipulates file creation, deletion, etc.

    The resource maven.properties has to be in the test resource path in order to make this rule functional.

    Author:
    Yohann Chastagnier
    • Constructor Detail

      • MavenTargetDirectoryRule

        public MavenTargetDirectoryRule​(Object testInstance)
        Mandatory constructor.
        Parameters:
        testInstance - the instance of the current test in order to use class loader mechanism in right context.
      • MavenTargetDirectoryRule

        public MavenTargetDirectoryRule​(Class<?> testInstanceClass)
        Mandatory constructor.
        Parameters:
        testInstanceClass - the instance class of the current test in order to use class loader mechanism in right context.
    • Method Detail

      • getSilverpeasVersion

        public String getSilverpeasVersion()
        Gets the silverpeas version.
        Returns:
        the silverpeas version.
      • getBuildDirFile

        public File getBuildDirFile()
        Gets the target directory of the test.
        Returns:
        the target directory of the test.
      • getWildflyHomeFile

        public File getWildflyHomeFile()
        Gets the resource path of test execution context.
        Returns:
        the resource path.
      • getResourceTestDirFile

        public File getResourceTestDirFile()
        Gets the path of the Wildfly home directory.
        Returns:
        the Wildfly home directory.
      • getValue

        public String getValue​(String property)
        Gets the value of a custom property defined in the maven.properties file and used in the test.
        Parameters:
        property - the name of the property in the maven.properties file.
        Returns:
        the value of the property.
      • getOptionalValue

        public Optional<String> getOptionalValue​(String property)
        Gets the value of a custom property possibly defined in the maven.properties file and used in the test. Be cautious that empty value for a property is considered by this method as no property.
        Parameters:
        property - the name of the property in the maven.properties file.
        Returns:
        the value of the property or nothing if such property doesn't exist.
      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • getMavenProperties

        protected Properties getMavenProperties()
        Gets a property from the maven.properties file.
        Returns:
        the value related to the given key.
      • getMavenProperty

        protected static String getMavenProperty​(Properties mavenProperties,
                                                 String key)
        Gets a property from the maven.properties file.
        Parameters:
        key - the key of the property.
        Returns:
        the value related to the given key.
      • loadPropertiesForTestClass

        public static SilverProperties loadPropertiesForTestClass​(Class<?> testClass)
        Loads maven properties from a test class.
        maven.properties has to exist into resources of the project.
        Parameters:
        testClass - the test class for which the maven properties are requested.
        Returns:
        an instance of Properties that containes requested maven properties.
      • getSilverpeasVersion

        public static String getSilverpeasVersion​(Properties mavenProperties)
        Gets the silverpeas version.
        Parameters:
        mavenProperties - the Maven properties
        Returns:
        the silverpeas version.
      • getBuildDirFile

        public static File getBuildDirFile​(Properties mavenProperties)
        Gets the target directory of the test.
        Parameters:
        mavenProperties - the Maven properties
        Returns:
        the target directory of the test.
      • getResourceTestDirFile

        public static File getResourceTestDirFile​(Properties mavenProperties)
        Gets the resource path of test execution context.
        Parameters:
        mavenProperties - the Maven properties
        Returns:
        the resource path.
      • getWildflyHomeFile

        public static File getWildflyHomeFile​(Properties mavenProperties)
        Gets the path of the Wildfly home directory.
        Parameters:
        mavenProperties - the Maven properties
        Returns:
        the Wildfly home directory.