@Test
public void twoConsecutiveLoginsNoAuthorization() throws Exception {

    config.setUpdateGroup(false);
    config.setUpdateProfile(false);
    User user = userRepo.findOneByUsername(username);
    assertNull("User already exists", user);
    String group = groupname + "1";
    String groups = group + config.getArraySeparator() + group ;
    String profile = Profile.UserAdmin.name() + config.getArraySeparator() + Profile.Administrator.name();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(this.config.getEmailKey(), email);
    request.addHeader(this.config.getFirstnameKey(), firstname);
    request.addHeader(this.config.getGroupKey(), groups);
    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.Administrator, user.getProfile());
    List<Integer> idGroups = userGroupRepo.findGroupIds(UserGroupSpecs.hasUserId(user.getId()));
    assertSame("Groups size is wrong", idGroups.size(), 1);
    assertEquals("The group assigned is wrong", Integer.valueOf(groupRepo.findByName(group).getId()),
            idGroups.get(0));
    // Second round, same user different authorization but the original
    // authorization should be kept (no updateProfile, updateGroups)
    String groupNew = groupname + "3";
    String groupsgroupNew = groupNew + config.getArraySeparator() + groupNew ;
    request = new MockHttpServletRequest();
    request.addHeader(this.config.getEmailKey(), email);
    request.addHeader(this.config.getFirstnameKey(), firstname);
    request.addHeader(this.config.getGroupKey(), groupsgroupNew);
    request.addHeader(this.config.getProfileKey(),
            Profile.Guest.name() + config.getArraySeparator() + Profile.Editor.name());
    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 removed", user);
    idGroups = userGroupRepo.findGroupIds(UserGroupSpecs.hasUserId(user.getId()));
    assertSame("The profile should be the highest in the list", Profile.Administrator, user.getProfile());
    assertSame("Groups size is wrong", idGroups.size(), 1);
    assertEquals("The group assigned is wrong", Integer.valueOf(groupRepo.findByName(group).getId()),
            idGroups.get(0));
}