Class TestEnvironment


  • @OpenApi
    public class TestEnvironment
    extends java.lang.Object
    The class which is used for initializing the MagicDraw test environment(starting the MagicDraw and specifying the necessary variables).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TestEnvironment.ProjectFilenameFilter
      File name filter to filter MagicDraw loadable files (mdzip, mdxml, zip.xml, and etc).
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TestEnvironment()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void addMemoryProfiler()  
      static java.lang.String arrayToString​(java.lang.String[] strings, java.lang.String separator)
      Concat given string array to one string
      static java.lang.String concatPath​(java.lang.String... path)
      Method returns whole path to given project.
      static java.io.File createFileInArtifactsDir​(java.lang.String artifactsDirectory, java.lang.String fileName)  
      static java.io.File createFileNameWithPrefix​(java.io.File file, java.lang.String prefix)
      Insert specific prefix after file name before file extension.
      private static void disableAllDialogs()  
      static void ensureFrameVisible()
      Ensures that main frame is visible
      static java.lang.String extractFileName​(java.lang.String filePath)  
      static java.io.File getArtifactDir()
      Get artifacts directory.
      static java.io.File getArtifactsDirectory​(java.lang.String directory)
      Creates and returns artifacts directory
      static java.util.List<java.io.File> getFiles​(java.io.File rootDirectory, java.io.FilenameFilter filter, java.util.Collection<java.lang.String> skipNames)
      Collects files from root directory and inner directories recursively except those specified to skip.
      static java.io.File getFileWithExtension​(java.io.File file, java.lang.String extension)
      Replace MagicDraw project file extension by the given one.
      static java.io.File getOutputDir​(java.lang.Class clazz)
      Get default directory for specific test case output.
      static java.io.File getOutputDir​(java.lang.String name)
      Get default directory for specific test case output.
      static java.util.List<java.io.File> getProjects​(java.io.File rootDirectory)
      Collects MagicDraw project files from specific directory and from its inner directories recursively.
      static java.util.List<java.io.File> getProjects​(java.io.File rootDirectory, java.util.Collection<java.lang.String> skipNames)
      Collects MagicDraw projects files from root directory and inner directories recursively except those specified to skip.
      static java.util.List<java.io.File> getProjects​(java.lang.String directory)
      Collects MagicDraw projects recursively from the given directory of resource directory.
      static java.io.File getRelativeOutputFile​(java.lang.Class clazz, java.io.File resourceFile)
      Creates output file relative to given resource file in specific test case output directory.
      static java.io.File getRelativeOutputFile​(java.lang.Class clazz, java.io.File resourceFile, boolean createDir)  
      static java.io.File getRelativeOutputFile​(java.lang.Class clazz, java.lang.String resourceFilePath, boolean createDir)  
      static java.io.File getResourceDir()
      Returns test framework resources directory specified by "tests.resources" system property.
      private static java.lang.String getTCArtifactsDir()  
      static boolean isIgnoredFile​(java.io.File file)
      Check if given file should be skipped as some test case data.
      static void parseArguments​(java.lang.String[] args)  
      static java.lang.String[] splitFileName​(java.lang.String fileName)
      Splits MagicDraw project file name to file name and extension.
      static void startMagicDrawUML()
      Starts MagicDraw in a test mode if it is not started yet.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SKIP_MEMORY_TEST

        public static final java.lang.String SKIP_MEMORY_TEST
        See Also:
        Constant Field Values
      • RUN_OPEN_FILE_HANDLE_TEST_NAME

        public static final java.lang.String RUN_OPEN_FILE_HANDLE_TEST_NAME
        See Also:
        Constant Field Values
      • GLOBAL_SKIPMEMTEST

        public static final java.lang.String GLOBAL_SKIPMEMTEST
        See Also:
        Constant Field Values
      • GLOBAL_RUNMEMTEST

        public static final java.lang.String GLOBAL_RUNMEMTEST
        See Also:
        Constant Field Values
      • SKIP_MEM_TEST

        public static final boolean SKIP_MEM_TEST
      • RUN_OPEN_FILE_HANDLER_TEST

        public static final boolean RUN_OPEN_FILE_HANDLER_TEST
      • TESTS_RESOURCES_PROPERTY

        public static final java.lang.String TESTS_RESOURCES_PROPERTY
        See Also:
        Constant Field Values
      • TESTS_OUTPUT_PROPERTY

        public static final java.lang.String TESTS_OUTPUT_PROPERTY
        See Also:
        Constant Field Values
      • TEAMCITY_BUILD_WORKING_DIR

        public static final java.lang.String TEAMCITY_BUILD_WORKING_DIR
        See Also:
        Constant Field Values
    • Constructor Detail

      • TestEnvironment

        private TestEnvironment()
    • Method Detail

      • startMagicDrawUML

        public static void startMagicDrawUML()
        Starts MagicDraw in a test mode if it is not started yet.
      • disableAllDialogs

        private static void disableAllDialogs()
      • getTCArtifactsDir

        private static java.lang.String getTCArtifactsDir()
      • addMemoryProfiler

        private static void addMemoryProfiler()
      • parseArguments

        public static void parseArguments​(java.lang.String[] args)
      • getResourceDir

        @OpenApi
        public static java.io.File getResourceDir()
        Returns test framework resources directory specified by "tests.resources" system property. Resources directory is a central place for all resources required by test cases.
        Returns:
        File representing test framework resources directory.
      • getRelativeOutputFile

        @OpenApi
        public static java.io.File getRelativeOutputFile​(java.lang.Class clazz,
                                                         java.io.File resourceFile)
        Creates output file relative to given resource file in specific test case output directory.
        Parameters:
        clazz - test case class to create related output file for.
        resourceFile - resource file to create related output file for.
        Returns:
        output file in given test case output directory with name related to given resource file.
      • getRelativeOutputFile

        public static java.io.File getRelativeOutputFile​(java.lang.Class clazz,
                                                         java.io.File resourceFile,
                                                         boolean createDir)
      • getRelativeOutputFile

        public static java.io.File getRelativeOutputFile​(java.lang.Class clazz,
                                                         java.lang.String resourceFilePath,
                                                         boolean createDir)
      • getOutputDir

        @OpenApi
        public static java.io.File getOutputDir​(java.lang.Class clazz)
        Get default directory for specific test case output. Output directory is created if it does not exist. Output directory is located in parent directory if specified by "tests.output" system property or MagicDraw install root otherwise.
        Parameters:
        clazz - Test case class to get output directory for.
        Returns:
        File representing output directory for test case.
      • extractFileName

        public static java.lang.String extractFileName​(java.lang.String filePath)
      • getOutputDir

        public static java.io.File getOutputDir​(java.lang.String name)
        Get default directory for specific test case output. Output directory is created if it does not exist. Output directory is located in parent directory if specified by "tests.output" system property or MagicDraw install root otherwise.
        Parameters:
        name - directory name.
        Returns:
        File representing output directory for test case.
      • getProjects

        @OpenApi
        public static java.util.List<java.io.File> getProjects​(java.io.File rootDirectory)
        Collects MagicDraw project files from specific directory and from its inner directories recursively.
        Parameters:
        rootDirectory - Root directory to collect project files recursively from.
        Returns:
        List of MagicDraw projects Files.
      • createFileNameWithPrefix

        @OpenApi
        public static java.io.File createFileNameWithPrefix​(java.io.File file,
                                                            java.lang.String prefix)
        Insert specific prefix after file name before file extension. For instance my_projectPREFIX.mdzip.
        Parameters:
        file - file to insert prefix to.
        prefix - prefix to insert.
        Returns:
        File representing new file there name has prefix inserted.
      • getFileWithExtension

        @OpenApi
        public static java.io.File getFileWithExtension​(java.io.File file,
                                                        java.lang.String extension)
        Replace MagicDraw project file extension by the given one.
        Parameters:
        file - File to replace extension.
        extension - new extension.
        Returns:
        new File with replaced given extension.
      • getFiles

        @OpenApi
        public static java.util.List<java.io.File> getFiles​(java.io.File rootDirectory,
                                                            java.io.FilenameFilter filter,
                                                            @CheckForNull
                                                            java.util.Collection<java.lang.String> skipNames)
        Collects files from root directory and inner directories recursively except those specified to skip. Files needed to skip might be also listed in skip.txt file located in root or nested directories.
        Parameters:
        rootDirectory - Root directory to collect project files recursively from.
        filter - only files matching this filter will be returned
        skipNames - the Collection of project file names to skip. Project file is skipped if it name contains any name defined in skipNames collection or skip.txt file.
        Returns:
        The list of MagicDraw project files collected.
      • getProjects

        @OpenApi
        public static java.util.List<java.io.File> getProjects​(java.io.File rootDirectory,
                                                               @CheckForNull
                                                               java.util.Collection<java.lang.String> skipNames)
        Collects MagicDraw projects files from root directory and inner directories recursively except those specified to skip. Projects needed to skip might be also listed in skip.txt file located in root or nested directories.
        Parameters:
        rootDirectory - Root directory to collect project files recursively from.
        skipNames - the Collection of project file names to skip. Project file is skipped if it name contains any name defined in skipNames collection or skip.txt file.
        Returns:
        The list of MagicDraw project files collected.
      • isIgnoredFile

        public static boolean isIgnoredFile​(java.io.File file)
        Check if given file should be skipped as some test case data.
        Parameters:
        file - file
        Returns:
        true if file should be skipped
      • getProjects

        @OpenApi
        public static java.util.List<java.io.File> getProjects​(java.lang.String directory)
        Collects MagicDraw projects recursively from the given directory of resource directory.
        Parameters:
        directory - directory name in the resource directory
        Returns:
        List of MagicDraw project files found in the given resource directory and its nested directories.
      • ensureFrameVisible

        public static void ensureFrameVisible()
        Ensures that main frame is visible
      • splitFileName

        @CheckForNull
        @OpenApi
        public static java.lang.String[] splitFileName​(java.lang.String fileName)
        Splits MagicDraw project file name to file name and extension.
        Parameters:
        fileName - MagicDraw project file name to split.
        Returns:
        String[2] = {fileName, fileExtension}
      • getArtifactDir

        public static java.io.File getArtifactDir()
        Get artifacts directory.
        Returns:
        artifacts dir.
      • getArtifactsDirectory

        @CheckForNull
        public static java.io.File getArtifactsDirectory​(java.lang.String directory)
        Creates and returns artifacts directory
        Parameters:
        directory - directory
        Returns:
        created directory
      • concatPath

        public static java.lang.String concatPath​(java.lang.String... path)
        Method returns whole path to given project. eg. getProjectPath("menu", "browser", "transform.mdzip") -> path_to_MD\core_resources\menu\browser\transform.mdzip
        Parameters:
        path - path
        Returns:
        Generated project path
      • createFileInArtifactsDir

        public static java.io.File createFileInArtifactsDir​(java.lang.String artifactsDirectory,
                                                            java.lang.String fileName)
      • arrayToString

        public static java.lang.String arrayToString​(java.lang.String[] strings,
                                                     java.lang.String separator)
        Concat given string array to one string
        Parameters:
        strings - array e.g. {"s1","s2","s3"}
        separator - e.g. "/"
        Returns:
        "s1/s2/s3/"