Class MagicDrawTestCase

java.lang.Object
junit.framework.Assert
junit.framework.TestCase
com.nomagic.magicdraw.tests.NamedTestCase
com.nomagic.magicdraw.tests.MagicDrawTestCase
All Implemented Interfaces:
junit.framework.Test

@OpenApi public abstract class MagicDrawTestCase extends com.nomagic.magicdraw.tests.NamedTestCase
Base class for JUnit3 Test Cases which should be run with MagicDraw Application started. Starts new MagicDraw application before each test. Provides methods for opening, saving, closing, and comparing projects.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default test case initialization for executing test* methods.
    Creates MagicDrawTestCase for executing specific test method.
    MagicDrawTestCase(String method, String testName)
    Creates MagicDrawTestCase of specific name for executing specific test method.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Force memory leaks test execution.
    void
    Close all currently opened MagicDraw projects with performing memory leaks test.
    void
    Close opened MagicDraw project.
    Creates project comparator with default model and diagram comparators implementation.
    static File
    getFileWithExtension(File projectFile, String extension)
    Computes test case specific properties file according given project file.
    protected org.apache.log4j.Logger
    Gets logger for Test related output logging.
    static File
    getPropertiesFile(File projectFile)
    Computes test case specific properties file according given project file.
    protected List<String>
    Is used to specify plug-ins required by test case.
    protected String
    Formats textual message about available plug-ins status(loaded/enabled).
    static File
    getXmlFile(File projectFile)
    Computes test case specific properties file according given project file.
    static void
    Executes runnable on dispatcher thread and waits till runnable is done.
    final boolean
    Check if silent mode is not used for starting MagicDraw.
    boolean
    Check if test has failed because of JUnit assertion or any other exception.
    protected final boolean
    Check if memory leaks test might be performed.
    protected boolean
    Check if all plug-ins required by this test case are loaded and enabled.
    static Project
    Opens MagicDraw project by absolute project file name.
    static Project
    loadProject(String projectPath, boolean failIfProjectHasErrors)
    Opens MagicDraw project by absolute project file name.
    static Project
    loadProject(String projectPath, boolean failIfProjectHasErrors, boolean loadAllDiagrams)
    Opens MagicDraw project by absolute project file name.
    protected Project
    openProject(String projectFile)
    Opens MagicDraw project by its absolute file name.
    protected Project
    openProject(String projectFile, boolean loadAllDiagram)
    Opens MagicDraw project by its absolute file name.
    protected void
    saveProject(Project project, File file)
    Save opened MagicDraw project to specific file.
    final void
    setDoNotUseSilentMode(boolean doNotUseSilentMode)
    Specify if MagicDraw should show GUI modal dialogs during startup and features testing.
    final void
    setMemoryTestReady(boolean memoryTestReady)
    Specify if memory leaks test is ready, so it might be performed at the end of the test.
    final void
    setRunOnEventDispatcher(boolean runOnEventDispatcher)
    Sets if test case should be executed on event dispatching thread.
    final void
    setRunOnEventDispather(boolean runOnEventDispatcher)
    Deprecated.
    spelling error in name, use set #setRunOnEventDispatcher
    final void
    setSkipMemoryTest(boolean skipMemoryTest)
    Set to true in order to skip memory leaks test.
    protected void
    Override to prepare test case after MagicDraw application started.
    protected void
    Tear down test case after it execution.

    Methods inherited from class com.nomagic.magicdraw.tests.NamedTestCase

    getFullTestName, getMethodName, getTestName, getTestNamePrefix, isOverridingTestName, setMethodName, setTestName

    Methods inherited from class junit.framework.TestCase

    assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, runBare, setName, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • MagicDrawTestCase

      @OpenApi public MagicDrawTestCase()
      Default test case initialization for executing test* methods.
    • MagicDrawTestCase

      @OpenApi public MagicDrawTestCase(String method)
      Creates MagicDrawTestCase for executing specific test method.
      Parameters:
      method - test method name to execute.
    • MagicDrawTestCase

      @OpenApi public MagicDrawTestCase(String method, @CheckForNull String testName)
      Creates MagicDrawTestCase of specific name for executing specific test method.
      Parameters:
      method - test method name to execute.
      testName - name of created test. All none alpha numerical characters in name will be replaced by underscore character.
  • Method Details

    • setMemoryTestReady

      @OpenApi public final void setMemoryTestReady(boolean memoryTestReady)
      Specify if memory leaks test is ready, so it might be performed at the end of the test. Set it false if you need to disable memory leaks test performing at the end of the test.
      Parameters:
      memoryTestReady - true if memory test is ready
    • setSkipMemoryTest

      @OpenApi public final void setSkipMemoryTest(boolean skipMemoryTest)
      Set to true in order to skip memory leaks test. Memory leaks test is always performed by default after MagicDraw project is closed and after each completed test.
      Parameters:
      skipMemoryTest - true if memory test should be skipped, false otherwise.
    • setRunOnEventDispather

      @OpenApi @Deprecated public final void setRunOnEventDispather(boolean runOnEventDispatcher)
      Deprecated.
      spelling error in name, use set #setRunOnEventDispatcher
      Sets if test case should be executed on event dispatching thread. MagicDrawTestCase is run on event dispatcher thread by default.
      Parameters:
      runOnEventDispatcher - True if test case should be executed on event dispatching thread.
    • setRunOnEventDispatcher

      @OpenApi public final void setRunOnEventDispatcher(boolean runOnEventDispatcher)
      Sets if test case should be executed on event dispatching thread. MagicDrawTestCase is run on event dispatcher thread by default.
      Parameters:
      runOnEventDispatcher - True if test case should be executed on event dispatching thread.
    • setDoNotUseSilentMode

      @OpenApi public final void setDoNotUseSilentMode(boolean doNotUseSilentMode)
      Specify if MagicDraw should show GUI modal dialogs during startup and features testing. MagicDraw is started up in silent mode by default.
      Parameters:
      doNotUseSilentMode - provide true value if GUI dialogs need to be shown during MagicDraw testing.
    • isDoNotUseSilentMode

      @OpenApi public final boolean isDoNotUseSilentMode()
      Check if silent mode is not used for starting MagicDraw. Silent mode prevents confirmation dialogs pop-up during MagicDraw test. MagicDraw is started up in silent mode by default.
      Returns:
      True if MagicDraw is started in Not silent mode.
    • isMemoryTestReady

      @OpenApi protected final boolean isMemoryTestReady()
      Check if memory leaks test might be performed.
      Returns:
      True if memory leaks test is ready and might be performed, false otherwise.
    • getRequiredPlugins

      @OpenApi protected List<String> getRequiredPlugins()
      Is used to specify plug-ins required by test case. Should be overridden in specific MagicDrawTestCase implementation. Default implementation returns empty List.
      Returns:
      List of plug-in IDs required by this test case.
    • getRequiredPluginsDescription

      @OpenApi protected String getRequiredPluginsDescription()
      Formats textual message about available plug-ins status(loaded/enabled).
      Returns:
      String message about required plug-ins status.
    • isRequiredPluginsLoaded

      @OpenApi protected boolean isRequiredPluginsLoaded()
      Check if all plug-ins required by this test case are loaded and enabled.
      Returns:
      True if all required plug-ins are loaded and enabled, false otherwise.
    • setUpTest

      @OpenApi protected void setUpTest() throws Exception
      Override to prepare test case after MagicDraw application started. Test set up should be done here. Do not use default JUnit setUp() instead.
      Throws:
      Exception - from default JUnit setUp()
    • tearDownTest

      @OpenApi protected void tearDownTest() throws Exception
      Tear down test case after it execution. This method is called after test method execution completed but MagicDraw Application not closed yet. Test tear down should be done here. Do not use default JUnit tearDown() instead.
      Throws:
      Exception - from default JUnit tearDown()
    • closeProject

      @OpenApi public void closeProject(Project project)
      Close opened MagicDraw project. Performs memory leaks test after project is closed, so all references to the elements of the closed project should be disposed before method execution.
      Parameters:
      project - MagicDraw Project to close.
    • closeAllProjects

      @OpenApi public void closeAllProjects()
      Close all currently opened MagicDraw projects with performing memory leaks test. All references to the elements of the closed projects should be disposed before method execution.
    • checkMemoryLeaks

      @OpenApi protected void checkMemoryLeaks()
      Force memory leaks test execution.
    • invokeAndWaitOnDispatcher

      @OpenApi public static void invokeAndWaitOnDispatcher(Runnable r)
      Executes runnable on dispatcher thread and waits till runnable is done.
      Parameters:
      r - Runnable to execute.
    • getPropertiesFile

      @OpenApi public static File getPropertiesFile(File projectFile)
      Computes test case specific properties file according given project file. MagicDraw Project properties file pattern "project_name.properties".
      Parameters:
      projectFile - project file
      Returns:
      test case properties file
    • getXmlFile

      @OpenApi public static File getXmlFile(File projectFile)
      Computes test case specific properties file according given project file. MagicDraw Project properties file pattern "project_name.xml".
      Parameters:
      projectFile - project file
      Returns:
      test case properties file
    • getFileWithExtension

      @OpenApi public static File getFileWithExtension(File projectFile, String extension)
      Computes test case specific properties file according given project file. MagicDraw Project properties file pattern "project_name.[extension]".
      Parameters:
      projectFile - project file
      Returns:
      test case properties file
    • loadProject

      @OpenApi public static Project loadProject(String file)
      Opens MagicDraw project by absolute project file name.
      Parameters:
      file - absolute file name of project to open.
      Returns:
      Opened project.
    • loadProject

      @OpenApi public static Project loadProject(String projectPath, boolean failIfProjectHasErrors)
      Opens MagicDraw project by absolute project file name.
      Parameters:
      projectPath - absolute file name of project to open.
      failIfProjectHasErrors - Specifies if test should fail if loaded project has any model inconsistency errors. Recommended to run with silentMode turned on.
      Returns:
      Opened project.
    • loadProject

      @OpenApi public static Project loadProject(String projectPath, boolean failIfProjectHasErrors, boolean loadAllDiagrams)
      Opens MagicDraw project by absolute project file name.
      Parameters:
      projectPath - absolute file name of project to open.
      failIfProjectHasErrors - Specifies if test should fail if loaded project has any model inconsistency errors. Recommended to run with silentMode turned on.
      Returns:
      Opened project.
    • getLogger

      @OpenApi protected org.apache.log4j.Logger getLogger()
      Gets logger for Test related output logging.
      Returns:
      log4j Logger for TEST category.
      See Also:
      • Logger
    • isFailed

      @OpenApi public boolean isFailed()
      Check if test has failed because of JUnit assertion or any other exception.
      Returns:
      True if this test has failed, false otherwise.
    • createProjectComparator

      @OpenApi protected ProjectsComparator createProjectComparator(@CheckForNull String logText)
      Creates project comparator with default model and diagram comparators implementation. Comparator does not compare projects regarding their modules, author information, and diagram info data.
      Parameters:
      logText - information message which should be printed to log at the beginning of comparison.
      Returns:
      new instance of ProjectsComparator with model and diagrams comparators initialized.
    • openProject

      @OpenApi protected Project openProject(String projectFile)
      Opens MagicDraw project by its absolute file name. It reopens the project if project is already opened.
      Parameters:
      projectFile - absolute file name of project to open.
      Returns:
      opened project or null if project cannot be opened.
    • openProject

      @OpenApi protected Project openProject(String projectFile, boolean loadAllDiagram)
      Opens MagicDraw project by its absolute file name. It reopens the project if project is already opened.
      Parameters:
      projectFile - absolute file name of project to open.
      loadAllDiagram - load content of all diagrams in the opened project
      Returns:
      opened project or null if project cannot be opened.
    • saveProject

      @OpenApi protected void saveProject(Project project, File file)
      Save opened MagicDraw project to specific file. S Save is done ins silent mode without any GUI confirmation messages.
      Parameters:
      project - MagicDraw opened project to save.
      file - File to save project.