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.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault test case initialization for executing test* methods.MagicDrawTestCase(String method) 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 TypeMethodDescriptionprotected voidForce memory leaks test execution.voidClose all currently opened MagicDraw projects with performing memory leaks test.voidcloseProject(Project project) Close opened MagicDraw project.protected voidcompareProjects(Project source, Project target, boolean saveSourceProject) Compare given projects.protected voidcompareProjects(ProjectsComparator comparator, Project source, Project target, boolean saveSourceProject) Compare given projects.Create a new projectprotected ProjectsComparatorcreateProjectComparator(String logText) Creates project comparator with default model and diagram comparators implementation.protected voidOverride this if you want to change runTest() behaviorprotected FileRetrieves artifacts directory for temporary test case files.static FilegetFileWithExtension(File projectFile, String extension) Computes test case specific properties file according given project file.protected org.apache.log4j.LoggerGets logger for Test related output logging.static FilegetPropertiesFile(File projectFile) Computes test case specific properties file according given project file.Is used to specify plug-ins required by test case.protected StringFormats textual message about available plug-ins status(loaded/enabled).protected org.apache.logging.log4j.Loggerstatic FilegetXmlFile(File projectFile) Computes test case specific properties file according given project file.static voidExecutes runnable on dispatcher thread and waits till runnable is done.final booleanCheck if silent mode is not used for starting MagicDraw.booleanisFailed()Check if test has failed because of JUnit assertion or any other exception.protected final booleanCheck if memory leaks test might be performed.protected booleanCheck if all plug-ins required by this test case are loaded and enabled.final booleanstatic ProjectloadProject(String file) Opens MagicDraw project by absolute project file name.static ProjectloadProject(String projectPath, boolean failIfProjectHasErrors) Opens MagicDraw project by absolute project file name.static ProjectloadProject(String projectPath, boolean failIfProjectHasErrors, boolean loadAllDiagrams) Opens MagicDraw project by absolute project file name.protected static ProjectloadProjectWithDiagramsLoadMode(String absolutePath, com.nomagic.magicdraw.core.diagram.DiagramLoadingModeManager.DiagramLoadMode diagramsLoadMode) static ProjectloadWithDiagramsLoadMode(com.nomagic.magicdraw.core.diagram.DiagramLoadingModeManager.DiagramLoadMode diagramsLoadMode, Callable<Project> callable) static ProjectCreate a new project from a default templateprotected ProjectopenProject(String projectFile) Opens MagicDraw project by its absolute file name.protected ProjectopenProject(String projectFile, boolean loadAllDiagram) Opens MagicDraw project by its absolute file name.voidrun(junit.framework.TestResult result) protected final voidrunTest()Runs test on event dispatcher.protected voidsaveProject(Project project, File file) Save opened MagicDraw project to specific file.protected voidsaveProject(Project project, String filePath) final voidsetDoNotUseSilentMode(boolean doNotUseSilentMode) Specify if MagicDraw should show GUI modal dialogs during startup and features testing.static voidsetInvalidModelHandler(Project project, List<String> problemsInfo1) final voidsetMemoryTestReady(boolean memoryTestReady) Specify if memory leaks test is ready, so it might be performed at the end of the test.final voidsetRunOnEventDispatcher(boolean runOnEventDispatcher) Sets if test case should be executed on event dispatching thread.final voidsetRunOnEventDispather(boolean runOnEventDispatcher) Deprecated.spelling error in name, use set #setRunOnEventDispatcherfinal voidsetSkipMemoryTest(boolean skipMemoryTest) Set to true in order to skip memory leaks test.protected final voidsetUp()protected voidOverride to prepare test case after MagicDraw application started.protected voidStarts MagicDraw in a test mode if it is not started yet.protected final voidtearDown()Dispose test case and performs memory leaks test.protected voidTear down test case after it execution.Methods inherited from class com.nomagic.magicdraw.tests.NamedTestCase
getFullTestName, getMethodName, getTestName, getTestNamePrefix, isOverridingTestName, setMethodName, setTestNameMethods 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
-
Constructor Details
-
MagicDrawTestCase
@OpenApi public MagicDrawTestCase()Default test case initialization for executing test* methods. -
MagicDrawTestCase
Creates MagicDrawTestCase for executing specific test method.- Parameters:
method- test method name to execute.
-
MagicDrawTestCase
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
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
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
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:
runin interfacejunit.framework.Test- Overrides:
runin classjunit.framework.TestCase
-
startMagicDraw
protected void startMagicDraw()Starts MagicDraw in a test mode if it is not started yet. -
getApplicationArguments
-
setUp
- Overrides:
setUpin classjunit.framework.TestCase- Throws:
Exception
-
setUpTest
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()
-
tearDown
Dispose test case and performs memory leaks test.- Overrides:
tearDownin classjunit.framework.TestCase- Throws:
Exception
-
tearDownTest
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()
-
createProject
Create a new project- Returns:
- new project
-
newProject
Create a new project from a default template- Returns:
- new project
-
closeProject
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
Retrieves artifacts directory for temporary test case files.- Returns:
- File which represent directory for temporary test case files.
-
invokeAndWaitOnDispatcher
Executes runnable on dispatcher thread and waits till runnable is done.- Parameters:
r- Runnable to execute.
-
getPropertiesFile
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
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
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
Opens MagicDraw project by absolute project file name.- Parameters:
file- absolute file name of project to open.- Returns:
- Opened project.
-
loadProject
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
-
getTestLogger
protected org.apache.logging.log4j.Logger getTestLogger() -
loadProjectWithDiagramsLoadMode
-
loadWithDiagramsLoadMode
-
runTest
Runs test on event dispatcher. To override default behavior override doRunTest() method.- Overrides:
runTestin classcom.nomagic.magicdraw.tests.NamedTestCase- Throws:
Throwable
-
doRunTest
Override this if you want to change runTest() behavior- Throws:
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
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
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
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
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
-
compareProjects
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:
-
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:
-
setInvalidModelHandler
-