@Test
  public void do_switch_role_when_user_has_no_selected_role() throws Exception {
    user =
        new RichUserDetailsFactory()
            .addBodRoles(BodRole.createNewUser())
            .addUserGroup(new UserGroupFactory().setId("urn:user-group").create())
            .create();
    Security.setUserDetails(user);

    PhysicalResourceGroup pGroup = new PhysicalResourceGroupFactory().setActive(true).create();

    when(virtualResourceGroupServiceMock.findByAdminGroup("urn:user-group"))
        .thenReturn(Optional.empty());
    when(physicalResourceGroupServiceMock.find(2L)).thenReturn(Optional.of(pGroup));

    mockMvc
        .perform(
            post("/request")
                .param("physicalResourceGroupId", "2")
                .param("userGroupId", "urn:user-group")
                .param("bandwidth", "1111")
                .param("userLabel", "port")
                .param("message", "I want!"))
        .andExpect(view().name("redirect:/user"));

    assertThat(
        "Context should not be cleared",
        SecurityContextHolder.getContext().getAuthentication(),
        nullValue());

    verify(virtualResourceGroupServiceMock).save(any(VirtualResourceGroup.class));
    verify(virtualPortServiceMock)
        .requestCreateVirtualPort(eq(user), any(VirtualPortCreateRequestLink.class));
  }
  @Test
  public void request_virtual_port_without_email_should_continue() throws Exception {
    RichUserDetails user = new RichUserDetailsFactory().setEmail("").create();
    Security.setUserDetails(user);

    mockMvc
        .perform(get("/request"))
        .andExpect(model().attributeExists("userGroupViews"))
        .andExpect(view().name("virtualports/selectTeamForLocalVirtualPort"));
  }
  @Before
  public void setupAndLogin() {
    mockMvc = standaloneSetup(subject).build();

    UserGroup group1 = new UserGroupFactory().setName("A").setId("urn:user-group").create();
    UserGroup group2 = new UserGroupFactory().setName("B").create();
    UserGroup group3 = new UserGroupFactory().setName("C").create();
    user =
        new RichUserDetailsFactory()
            .addUserRole()
            .addUserGroup(group3)
            .addUserGroup(group1)
            .addUserGroup(group2)
            .create();
    Security.setUserDetails(user);
  }
 @Before
 public void setUp() {
   user = new RichUserDetailsFactory().create();
   Security.setUserDetails(user);
 }