You can simulate a logged-in user in the MDriven Designer System Prototyper when you need to test logic that reads the current user without performing a real login.
What simulated login does
The System Prototyper does not identify a user or request credentials. To test user-dependent logic, set the CurrentUser on SysSingleton when the prototype starts.
SysSingleton is the application root object used to hold login information. CurrentUser is assigned a SysUser object from the model.
For example, if an action allows only the current user to see that user's records, simulating login as someusername lets you test that action in the prototyper.
Simulate a user at prototype startup
- Ensure that the model contains a
SysUserwith the username you want to test. The SysUserAuthentication pattern provides theSysUserclass. - Open the System Prototyper in MDriven Designer.
- Locate the Exp to run on start box.
- Enter an OCL expression that finds the user and assigns it to
CurrentUser:
SysSingleton.oclSingleton.CurrentUser := SysUser.allinstances->select(username='someusername')->first- Replace
someusernamewith the username of the test user in your model. - Start the prototype. The startup expression runs and your logic can read
SysSingleton.oclSingleton.CurrentUseras the selected user.
How the expression works
| Expression part | Meaning |
|---|---|
SysSingleton.oclSingleton
|
Gets the singleton object that stores application-level login information. |
SysUser.allinstances
|
Gets the available SysUser objects.
|
->select(username='someusername')
|
Selects users whose username equals the specified test value.
|
->first
|
Uses the first selected user. |
CurrentUser := ...
|
Assigns that user as the prototype's current user. |
Test user-specific logic
Use the simulated current user wherever your model logic needs to identify the user. For example, an expression can compare a record's user with the simulated user:
self.Owner = SysSingleton.oclSingleton.CurrentUserChange the username in Exp to run on start and restart the prototype to test the same logic as another user.
Limits
This technique is for the MDriven Designer System Prototyper. It does not authenticate a password, create a web login session, or implement access control in a deployed Turnkey application.
For registration, password login, external login, and authorization in a Turnkey application, use SysUserAuthentication and the guidance in Turnkey user login. For programmatic login scenarios, see Log in with code.
