Using standard XNAT functionality
The tests define 2 major test accounts to use: a "main" user and "mainAdmin" user. The test framework will set both of these accounts up before any of the tests. If your test class inherits from BaseXnatRestTest
, you can call either mainInterface()
or mainAdminInterface()
within your test to get a grxnat XnatInterface
object already authenticated for the corresponding account. If you need an XnatInterface
instance corresponding to an arbitrary account, you can also use the more general interfaceFor(User user)
method. There's far too much you can do with the XnatInterface
object to explain on one page here, but some examples below may be helpful:
Creating a simple project
final Project project = new Project();
final Subject subject = new Subject(project);
final ImagingSession session = new MRSession(project, subject);
project.addOwner(mainUser);
mainAdminInterface().createProject(project);
There are a few things to point out in this example. First, without line 5, the first 4 lines won't have any real effect. That is, lines 1-4 are essentially building up the "spec" of the desired project, while the project and all of the requested properties are created via REST on line 5. After line 5:
- There should be a new project created in XNAT. The project's ID was not specified, so it will have a randomly generated ID/name/running title.
- The project will have a subject created for it in XNAT. The subject also contains an empty MR session. Just as with the project, the labels will be randomly generated because they were not specified.
- Because the project was created with the
mainAdminInterface()
object, themainAdmin
user will be the account used for authentication. Therefore,mainAdmin
will be an owner on the project (as the creator). However, as requested on line 4, themainUser
account will also be added as an owner.