Ejemplo n.º 1
0
  @Test
  public void testGetExistingAccount() throws Exception {
    Set<Authority> authorities = new HashSet<>();
    Authority authority = new Authority();
    authority.setName(AuthoritiesConstants.ADMIN);
    authorities.add(authority);

    User user = new User();
    user.setLogin("test");
    user.setFirstName("john");
    user.setLastName("doe");
    user.setEmail("*****@*****.**");
    user.setAuthorities(authorities);
    when(mockUserService.getUserWithAuthorities()).thenReturn(user);

    restUserMockMvc
        .perform(get("/api/account").accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.login").value("test"))
        .andExpect(jsonPath("$.firstName").value("john"))
        .andExpect(jsonPath("$.lastName").value("doe"))
        .andExpect(jsonPath("$.email").value("*****@*****.**"))
        .andExpect(jsonPath("$.authorities").value(AuthoritiesConstants.ADMIN));
  }
Ejemplo n.º 2
0
  @Test
  public void testGetUnknownAccount() throws Exception {
    when(mockUserService.getUserWithAuthorities()).thenReturn(null);

    restUserMockMvc
        .perform(get("/api/account").accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isInternalServerError());
  }