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:
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:
mainAdminInterface()
object, the mainAdmin
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, the mainUser
account will also be added as an owner.