GroupElem { public Integer getId() { return id; } GroupElem(String profile, Integer id); String getProfile(); Integer getId();  }
@Test public void getUserGroups() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); final User editorUser = _userRepo.findOneByUsername("testuser-editor"); final Group sampleGroup = _groupRepo.findByName("sample"); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform(get("/srv/api/users/" + editorUser.getId() + "/groups") .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isOk()) .andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[0].id.groupId", is(sampleGroup.getId()))) .andExpect(content().contentType(API_JSON_EXPECTED_ENCODING)); }
@Test public void deleteExistingUser() throws Exception { User userToDelete = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(userToDelete); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform(delete("/srv/api/users/" + userToDelete.getId()) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(204)); userToDelete = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNull(userToDelete); }
@Test public void resetPassword() throws Exception { User user = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(user); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform(post("/srv/api/users/" + user.getId() + "/actions/forget-password") .param("password", "newpassword") .param("password2", "newpassword") .contentType(API_JSON_EXPECTED_ENCODING) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(204)); }
@Test public void resetPasswordNotEqual() throws Exception { User user = _userRepo.findOneByUsername("testuser-editor"); Assert.assertNotNull(user); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); this.mockMvc.perform(post("/srv/api/users/" + user.getId() + "/actions/forget-password") .contentType(API_JSON_EXPECTED_ENCODING) .param("password", "newpassword") .param("password2", "newpassword2") .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(jsonPath("$.description", is("Passwords should be equal"))) .andExpect(status().is(400)); }