Skip to main content
Skip table of contents

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

JAVA
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:

  1. 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.
  2. 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.
  3. Because the project was created with the 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.
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.