Preparing a simulation project and Configs in MagicDraw
To prepare a simulation project and Configs in MagicDraw
Create a simulation model with Behaviors, e.g., TestVerdictKind.mdzip.
Apply «TestCase» to the Behaviors so the pass/fail status will be returned to the VerdictKind Activity parameters.
Create Simulation Configs and set those Behaviors as executionTarget of those Simulation Configs.
Note
title
Note
All required resources must be available for the Simulation Configs, e.g., loadCSV and fmu. All features preventing simulation from the start/terminate, e.g., false autoStart, context without Classifier Behavior, chart windows at the end of execution, or output parameters at the end of execution (running Activity) will also be automatically started/terminated.
Run each Simulation Config to verify that an expected result, either pass or fail, must be returned.
Preparing a simulation project and Configs in MagicDraw.
Running a project through simulate command line
To run a project through simulate command line
Run the command line console, e.g., cmd on Windows.
In the console, type any commands to go to the local installation of MagicDraw.
Go to the plugins\com.nomagic.magicdraw.simulation folder.
Use the following simulate command syntax: simulate -project “[Path of an MDZIP project]” -config “[Config]”.
At the last line of the command prompt, pass or fail appears. You can also see the details of execution through the Simulation Log File.
Running the project through the simulate command line.
Creating a JUnit test case and configuration file
To create a JUnit test case and configuration file
Include the JUnit library in the Java project by creating a new Java project and adding the JUnit 4 library in current location using the Eclipse's JUnit.
Specify a Project Name, e.g., Test Simulation Command Line.
Go to Advanced Project Options, click Advanced, and select Use custom workspace.
In the Directory box, specify a path to the directory that contains run_junit.xml (Ant configuration file).
Go to Build and click Add build step. Select Invoke Ant.
In the Targets box, type build.
Select Advanced. In the Build File box, type run_junit.xml.
In the Properties box, specify md.root=[MagicDraw installation directory] and properties.files.dir=[Path containing the properties files], as shown in the example above.
Tip
title
Tip
The path containing the property files can be either an absolute (full) path, e.g., C:\Users\User\Desktop\TestSimulationCommandLine\tests or relative path, e.g., tests.
Go to Post-build Actions and click Add post-build action. Select Publish JUnit test result report.
In the Test report XMLs box, specify a path to JUnit XML files, e.g., test-reports/**TEST*.xml.
Run the build. Test Result will be shown and allows you to view more details for those test cases.
Test Result of the simulation command line is shown on the Jenkins page.
Simulate command arguments and parameters
Examples of the simulate command lines are as follows:
On Windows: simulate.bat -project "../../samples/simulation/HingeMonteCarloAnalysis.mdzip" -config "Monte Carlo Analysis"
On Mac OS: sh simulate.sh -project "../../samples/simulation/HingeMonteCarloAnalysis.mdzip" -config "Monte Carlo Analysis"
Type of argument
Parameter
Description
Mandatory arguments
-project
Specify the file name with the path to the project. Both relative and absolute paths are supported.
-config
Specify the Simulation Configuration without a qualified name to run.
Note
title
Note
If there are multiple Simulation Configurations with the same name (e.g., in different Packages), a warning message will be displayed in the Simulation log, and the first Simulation Configuration will be used.
If the -properties option is specified, the argument is the name of a properties file, and the mandatory argument is no longer required.
A properties file contains -project and -config, along with the specified data of each parameter.
Optional arguments
-inputs elementNameListWithValue
Specify one or more properties with values that will be provided to the Simulation Configuration.
-inputsFile propertiesFileName
Specify the name of the properties file containing the parameters with values that will be provided to the Simulation Configuration.
Note
title
Note
If you provide both -inputs and -inputFile arguments, parameters are collected from both arguments.
-outputs elementNameList
Specify one or more properties whose values should be obtained during the simulation.
-outputsTemplate propertiesFileName
Specify the properties file that contains the parameters whose values should be obtained during the simulation.
Note
title
Note
If you provide both -outputs and -outputTemplate arguments, parameters are collected from both arguments.
-outputsFile propertiesFileName
Specify the properties file which will contain the output parameters with values after the simulation. The specified file will contain the parameters provided in the -outputTemplate and/or -outputs argument.
Optional (server) arguments
-server
Specify the name or IP address (and port) of the server.
-leaveprojectopen
Set to true to leave the project open per property file after simulating the project in a series of project simulations. The default value is false.
-login
Specify the login name to log in to the server.
-password
Specify the password to log in to the server.
-spassword
Specify the encrypted password to log in on to the server.
Note
title
Note
To generate an encrypted password for this option, use the following command line (the characters of the encrypted password will be returned, e.g., 49034c0439….):
generate -generatepassword “Administrator”
-ssl
Set to true to use and enable Secured Connection (SSL). The default value is false.
-pversion
Specify the version of the server project.
-tag
Specify the tag name of the server project.
Note
title
Note
-tag can't be used with -pversion.
If multiple projects are returned, only the latest version will be run.
-readonly
Set to true (the default value) to open the project as historical in the latest version without specifying -pversion.
Specify other values to open the latest version normally.
Teamwork Cloud arguments
-branch
Specify the branch of the Teamwork Cloud project.
Note
title
Note
-branch and -pversion cannot be specified in the same command.
If -pversion and -tag are not specified, the latest version of the specified branch will be returned.
-updatemodule
Set to true to update used projects. The default value is false.
Simulate command arguments with projects in Teamwork Cloud
To use simulate command arguments with projects in Teamwork Cloud, the projects must be added to Teamwork Cloud. The following examples demonstrate how to use the simulate command to run a model from Teamwork Cloud.
Scenario
Command argument
Simulate a project with an encrypted password and enable a secured connection (-spassword, -ssl).
Simulate multiple projects in a single command with better performance (-leaveprojectopen).
Tip
title
Tip
When large-size projects need to be loaded and closed for many property files, it takes longer time to simulate projects. In this case, you can use -leaveprojectopen as an option to reduce memory for loading each project.
Simulate a project in Teamwork Cloud while specifying the properties file that will be provided to the Simulation Configuration (-inputsFile), the properties file containing the parameters whose values should be obtained (-outputsTemplate), and the properties file that will contain output parameters with their values after the simulation (-outputsFile).