Class MavenTestHelper

java.lang.Object
com.graphql_java_generator.plugin.test.helper.MavenTestHelper

@Component public class MavenTestHelper extends Object
  • Constructor Details

    • MavenTestHelper

      public MavenTestHelper()
  • Method Details

    • getModulePathFile

      public File getModulePathFile()
      Returns the root path for this module. The issue here, is that the current path is the root path for this module, if the build is done only for this module. But if the build is done for the whole project, the current path is one level above (that is: the root for the whole project)
      Returns:
    • getFile

      public File getFile(String path)
      Returns a File, from a local name
      Parameters:
      path - A local name, relative to the current project's root
      Returns:
    • getTargetResourceFolder

      public File getTargetResourceFolder(String unitTestName)
      Get the folder where the resources should be generated, calculated from the given test name.
      For instance, for test 'Basic', the folder would be something like File("${project_folder}/target/junittest/basic/generated-resources")
      Parameters:
      unitTestName -
      Returns:
    • getTargetSourceFolder

      public File getTargetSourceFolder(String unitTestName)
      Get the folder where the source should be generated, calculated from the given test name.
      For instance, for test 'Basic', the folder would be something like File("${project_folder}/target/junittest/basic/generated-src")
      Parameters:
      unitTestName -
      Returns:
    • getTargetRuntimeClassesBaseSourceFolder

      public File getTargetRuntimeClassesBaseSourceFolder(String unitTestName)
      Gets the base folder for runtime classes calculated for the given test name
      Parameters:
      unitTestName -
      Returns:
    • getTestRutimeSourcesJarFile

      public File getTestRutimeSourcesJarFile()
      Resolve the file for runtime sources to be used in IDE tests related to code generation
      Returns:
    • deleteDirectoryAndContentIfExists

      public boolean deleteDirectoryAndContentIfExists(File file) throws IllegalArgumentException
      Remove a folder and all its content. This method checks that this folder is in a target subfolder. That is: it contains 'target' in it.
      Parameters:
      file - The folder to delete (including its content, subfolders...
      Returns:
      true if the file was removed. false if the file didn't exist
      Throws:
      IllegalArgumentException - If it's not a target folder
    • readFile

      public String readFile(String relativePath)
      Read a file, and returns its content as a string
      Parameters:
      relativePath - The relative path from the project's base dir (e.g.: /src/test/resources/test.txt or src/test/resources/test.txt)
      Returns:
      The content of the file, which is expected to be a text file
    • readFile

      public String readFile(File file)
      Read a file, and returns its content as a string
      Parameters:
      file - The file to read
      Returns:
      The content of the file, which is expected to be a text file