Package com.nomagic.magicdraw.tests
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.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
mDoNotUseSilentMode
Specifies if test should be run with MainFrame.setSilentMode(false)private boolean
memoryTestReady
Used to identify when to start memory test.private java.lang.Throwable
mFailure
If test fails it sets this Throwable.private boolean
mRunOnEventDispatcher
Specifies if test should be executed on event dispatcher thread.private boolean
skipMemoryTest
Used to skip individual tests.
-
Constructor Summary
Constructors Constructor Description MagicDrawTestCase()
Default test case initialization for executing test* methods.MagicDrawTestCase(java.lang.String method)
Creates MagicDrawTestCase for executing specific test method.MagicDrawTestCase(java.lang.String method, java.lang.String testName)
Creates MagicDrawTestCase of specific name for executing specific test method.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
checkMemoryLeaks()
Force memory leaks test execution.void
closeAllProjects()
Close all currently opened MagicDraw projects with performing memory leaks test.void
closeProject(Project project)
Close opened MagicDraw project.protected void
compareProjects(Project source, Project target, boolean saveSourceProject)
Compare given projects.protected void
compareProjects(ProjectsComparator comparator, Project source, Project target, boolean saveSourceProject)
Compare given projects.Project
createProject()
Create a new projectprotected ProjectsComparator
createProjectComparator(java.lang.String logText)
Creates project comparator with default model and diagram comparators implementation.private void
doRunAndCheckFailure()
protected void
doRunTest()
Override this if you want to change runTest() behaviorprotected java.io.File
getArtifactDir()
Retrieves artifacts directory for temporary test case files.static java.io.File
getFileWithExtension(java.io.File projectFile, java.lang.String extension)
Computes test case specific properties file according given project file.protected org.apache.log4j.Logger
getLogger()
Gets logger for Test related output logging.private static Project
getProjectByName(java.lang.String projectPath)
static java.io.File
getPropertiesFile(java.io.File projectFile)
Computes test case specific properties file according given project file.protected java.util.List<java.lang.String>
getRequiredPlugins()
Is used to specify plug-ins required by test case.protected java.lang.String
getRequiredPluginsDescription()
Formats textual message about available plug-ins status(loaded/enabled).protected org.apache.logging.log4j.Logger
getTestLogger()
static java.io.File
getXmlFile(java.io.File projectFile)
Computes test case specific properties file according given project file.static void
invokeAndWaitOnDispatcher(java.lang.Runnable r)
Executes runnable on dispatcher thread and waits till runnable is done.boolean
isDoNotUseSilentMode()
Check if silent mode is not used for starting MagicDraw.boolean
isFailed()
Check if test has failed because of JUnit assertion or any other exception.protected boolean
isMemoryTestReady()
Check if memory leaks test might be performed.private static boolean
isProjectLoaded(java.lang.String projectPath)
protected boolean
isRequiredPluginsLoaded()
Check if all plug-ins required by this test case are loaded and enabled.boolean
isSkipMemoryTest()
static Project
loadProject(java.lang.String file)
Opens MagicDraw project by absolute project file name.static Project
loadProject(java.lang.String projectPath, boolean failIfProjectHasErrors)
Opens MagicDraw project by absolute project file name.static Project
loadProject(java.lang.String projectPath, boolean failIfProjectHasErrors, boolean loadAllDiagrams)
Opens MagicDraw project by absolute project file name.protected static Project
loadProjectWithDiagramsLoadMode(java.lang.String absolutePath, com.nomagic.magicdraw.core.diagram.DiagramLoadingModeManager.DiagramLoadMode diagramsLoadMode)
static Project
loadWithDiagramsLoadMode(com.nomagic.magicdraw.core.diagram.DiagramLoadingModeManager.DiagramLoadMode diagramsLoadMode, java.util.concurrent.Callable<Project> callable)
static Project
newProject()
Create a new project from a default templateprotected Project
openProject(java.lang.String projectFile)
Opens MagicDraw project by its absolute file name.protected Project
openProject(java.lang.String projectFile, boolean loadAllDiagram)
Opens MagicDraw project by its absolute file name.void
run(junit.framework.TestResult result)
protected void
runTest()
Runs test on event dispatcher.protected void
saveProject(Project project, java.io.File file)
Save opened MagicDraw project to specific file.protected void
saveProject(Project project, java.lang.String filePath)
void
setDoNotUseSilentMode(boolean doNotUseSilentMode)
Specify if MagicDraw should show GUI modal dialogs during startup and features testing.static void
setInvalidModelHandler(Project project, java.util.List<java.lang.String> problemsInfo1)
void
setMemoryTestReady(boolean memoryTestReady)
Specify if memory leaks test is ready, so it might be performed at the end of the test.void
setRunOnEventDispatcher(boolean runOnEventDispatcher)
Sets if test case should be executed on event dispatching thread.void
setRunOnEventDispather(boolean runOnEventDispatcher)
Deprecated.spelling error in name, use set #setRunOnEventDispatchervoid
setSkipMemoryTest(boolean skipMemoryTest)
Set to true in order to skip memory leaks test.protected void
setUp()
protected void
setUpTest()
Override to prepare test case after MagicDraw application started.protected void
startMagicDraw()
Starts MagicDraw in a test mode if it is not started yet.protected void
tearDown()
Dispose test case and performs memory leaks test.protected void
tearDownTest()
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
-
-
-
-
Field Detail
-
memoryTestReady
private boolean memoryTestReady
Used to identify when to start memory test. Some tests do several test cases on the same project.
-
skipMemoryTest
private boolean skipMemoryTest
Used to skip individual tests. e.c. by specifying project names in skipmemtest.txt file.
-
mRunOnEventDispatcher
private boolean mRunOnEventDispatcher
Specifies if test should be executed on event dispatcher thread.
-
mDoNotUseSilentMode
private boolean mDoNotUseSilentMode
Specifies if test should be run with MainFrame.setSilentMode(false)
-
mFailure
private java.lang.Throwable mFailure
If test fails it sets this Throwable.
-
-
Constructor Detail
-
MagicDrawTestCase
@OpenApi public MagicDrawTestCase()
Default test case initialization for executing test* methods.
-
MagicDrawTestCase
@OpenApi public MagicDrawTestCase(java.lang.String method)
Creates MagicDrawTestCase for executing specific test method.- Parameters:
method
- test method name to execute.
-
MagicDrawTestCase
@OpenApi public MagicDrawTestCase(java.lang.String method, @CheckForNull java.lang.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 Detail
-
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 #setRunOnEventDispatcherSets 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.
-
isSkipMemoryTest
public final boolean isSkipMemoryTest()
-
getRequiredPlugins
@OpenApi protected java.util.List<java.lang.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 java.lang.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.
-
run
public void run(junit.framework.TestResult result)
- Specified by:
run
in interfacejunit.framework.Test
- Overrides:
run
in classjunit.framework.TestCase
-
startMagicDraw
protected void startMagicDraw()
Starts MagicDraw in a test mode if it is not started yet.
-
setUp
protected final void setUp() throws java.lang.Exception
- Overrides:
setUp
in classjunit.framework.TestCase
- Throws:
java.lang.Exception
-
setUpTest
@OpenApi protected void setUpTest() throws java.lang.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:
java.lang.Exception
- from default JUnit setUp()
-
tearDown
protected final void tearDown() throws java.lang.Exception
Dispose test case and performs memory leaks test.- Overrides:
tearDown
in classjunit.framework.TestCase
- Throws:
java.lang.Exception
-
tearDownTest
@OpenApi protected void tearDownTest() throws java.lang.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:
java.lang.Exception
- from default JUnit tearDown()
-
createProject
public Project createProject()
Create a new project- Returns:
- new project
-
newProject
public static Project newProject()
Create a new project from a default template- Returns:
- new project
-
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.
-
getArtifactDir
protected java.io.File getArtifactDir()
Retrieves artifacts directory for temporary test case files.- Returns:
- File which represent directory for temporary test case files.
-
invokeAndWaitOnDispatcher
@OpenApi public static void invokeAndWaitOnDispatcher(java.lang.Runnable r)
Executes runnable on dispatcher thread and waits till runnable is done.- Parameters:
r
- Runnable to execute.
-
getPropertiesFile
@OpenApi public static java.io.File getPropertiesFile(java.io.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 java.io.File getXmlFile(java.io.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 java.io.File getFileWithExtension(java.io.File projectFile, java.lang.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(java.lang.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(java.lang.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(java.lang.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.
-
isProjectLoaded
private static boolean isProjectLoaded(java.lang.String projectPath)
-
getProjectByName
private static Project getProjectByName(java.lang.String projectPath)
-
getLogger
@OpenApi protected org.apache.log4j.Logger getLogger()
Gets logger for Test related output logging.- Returns:
- log4j Logger for TEST category.
- See Also:
Logger
-
getTestLogger
protected org.apache.logging.log4j.Logger getTestLogger()
-
loadProjectWithDiagramsLoadMode
protected static Project loadProjectWithDiagramsLoadMode(java.lang.String absolutePath, com.nomagic.magicdraw.core.diagram.DiagramLoadingModeManager.DiagramLoadMode diagramsLoadMode)
-
loadWithDiagramsLoadMode
public static Project loadWithDiagramsLoadMode(com.nomagic.magicdraw.core.diagram.DiagramLoadingModeManager.DiagramLoadMode diagramsLoadMode, java.util.concurrent.Callable<Project> callable)
-
runTest
protected final void runTest() throws java.lang.Throwable
Runs test on event dispatcher. To override default behavior override doRunTest() method.- Overrides:
runTest
in classcom.nomagic.magicdraw.tests.NamedTestCase
- Throws:
java.lang.Throwable
-
doRunAndCheckFailure
private void doRunAndCheckFailure()
-
doRunTest
protected void doRunTest() throws java.lang.Throwable
Override this if you want to change runTest() behavior- Throws:
java.lang.Throwable
-
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 java.lang.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(java.lang.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(java.lang.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, java.io.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.
-
saveProject
protected void saveProject(Project project, java.lang.String filePath)
-
compareProjects
protected void compareProjects(Project source, Project target, boolean saveSourceProject)
Compare given projects. Save diagrams graphical differences and source project if projects are not equal. Source project and graphical diagram differences are saved to Test case relative output directoryTestEnvironment.getRelativeOutputFile(Class, java.io.File)
.- Parameters:
source
- source projecttarget
- target projectsaveSourceProject
- save source project into default output dir if comparing fails- See Also:
TestEnvironment.getRelativeOutputFile(Class, java.io.File)
-
compareProjects
protected void compareProjects(ProjectsComparator comparator, Project source, Project target, boolean saveSourceProject)
Compare given projects. Save diagrams graphical differences and source project if projects are not equal. Source project and graphical diagram differences are saved to Test case relative output directoryTestEnvironment.getRelativeOutputFile(Class, java.io.File)
.- Parameters:
comparator
- custom project comparatorsource
- source projecttarget
- target projectsaveSourceProject
- save source project into default output dir if comparing fails- See Also:
TestEnvironment.getRelativeOutputFile(Class, java.io.File)
-
setInvalidModelHandler
public static void setInvalidModelHandler(Project project, java.util.List<java.lang.String> problemsInfo1)
-
-