@Test
public void severalGroups() throws Exception {

    User user = userRepo.findOneByUsername(username);
    assertNull("User already exists", user);
    String group = groupname + "1";
    String profile = Profile.Reviewer.name();
    for (int i = 2; i < 5; i++) {
        group = group + config.getArraySeparator() + groupname + i;
        profile = profile + config.getArraySeparator() + Profile.Editor.name();
    }
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(this.config.getEmailKey(), email);
    request.addHeader(this.config.getFirstnameKey(), firstname);
    request.addHeader(this.config.getGroupKey(), group);
    request.addHeader(this.config.getProfileKey(), profile);
    request.addHeader(this.config.getSurnameKey(), surname);
    request.addHeader(this.config.getUsernameKey(), username);
    utils.setupUser(request, this.config);
    // Checks
    user = userRepo.findOneByUsername(username);
    assertNotNull("User was not created", user);
    assertSame("The profile should be the highest in the list", Profile.Reviewer, user.getProfile());
    List<Integer> idGroups = userGroupRepo.findGroupIds(UserGroupSpecs.hasUserId(user.getId()));
    assertSame("Groups size is wrong", idGroups.size(), 4);
    List<UserGroup> groups = userGroupRepo.findAll(UserGroupSpecs.hasUserId(user.getId()));
    for (UserGroup ug : groups) {
        assertNotSame("No profile can be guest as we have defined a role for all groups.", Profile.Guest,
                ug.getProfile());
    }
}