use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerIntegrationTest method executeUpdatePassword.
private ResultActions executeUpdatePassword(String body, String username, String accessToken, ResultMatcher expected) throws Exception {
ResultActions result = mockMvc.perform(post("/users/{username}/password", new Object[] { username }).content(body).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(expected);
return result;
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerIntegrationTest method testGetUsersDefaultSorting.
@Test
public void testGetUsersDefaultSorting() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/users").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.metaData.pageSize", is(100)));
result.andExpect(jsonPath("$.metaData.sort", is("username")));
result.andExpect(jsonPath("$.metaData.page", is(1)));
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerIntegrationTest method testGetUsersWithoutProfile.
@Test
public void testGetUsersWithoutProfile() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/users").param("withProfile", "0").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
System.out.println("with no profile: " + result.andReturn().getResponse().getContentAsString());
result.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
result.andExpect(jsonPath("$.metaData.additionalParams.withProfile", is("0")));
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerIntegrationTest method testAddUserAuthorities_2.
@Test
public void testAddUserAuthorities_2() throws Exception {
Group group = createGroup(1);
Role role = createRole(1);
String username = "mockuser_1";
UserDetails mockuser = this.createUser(username);
try {
this.groupManager.addGroup(group);
this.roleManager.addRole(role);
this.userManager.addUser(mockuser);
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String mockJson1 = "[{\"group\":\"group1\", \"role\":\"role1\"}]";
ResultActions result1 = mockMvc.perform(post("/users/{target}/authorities", username).content(mockJson1).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result1.andExpect(status().isOk());
result1.andExpect(jsonPath("$.payload[0].group", is("group1")));
List<Authorization> auths = this.authorizationManager.getUserAuthorizations(username);
Assert.assertEquals(1, auths.size());
String mockJson2 = "[{\"group\":\"customers\", \"role\":\"supervisor\"}]";
ResultActions result2 = mockMvc.perform(post("/users/{target}/authorities", username).content(mockJson2).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result2.andExpect(status().isOk());
result2.andExpect(jsonPath("$.payload[0].group", is("customers")));
auths = this.authorizationManager.getUserAuthorizations(username);
Assert.assertEquals(2, auths.size());
ResultActions result3 = mockMvc.perform(get("/users/{target}/authorities", username).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result3.andExpect(status().isOk());
result3.andExpect(jsonPath("$.payload", Matchers.hasSize(2)));
String mockJson4 = "[{\"group\":\"helpdesk\", \"role\":\"pageManager\"}]";
ResultActions result4 = mockMvc.perform(put("/users/{target}/authorities", username).content(mockJson4).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result4.andExpect(status().isOk());
result4.andExpect(jsonPath("$.payload[0].group", is("helpdesk")));
auths = this.authorizationManager.getUserAuthorizations(username);
Assert.assertEquals(1, auths.size());
Assert.assertEquals("helpdesk", auths.get(0).getGroup().getName());
String mockJson5 = "[{\"group\":\"wrong_group\", \"role\":\"pageManager\"}]";
ResultActions result5 = mockMvc.perform(put("/users/{target}/authorities", username).content(mockJson5).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result5.andExpect(status().isBadRequest());
result5.andExpect(jsonPath("$.errors.size()", is(1)));
result5.andExpect(jsonPath("$.errors[0].code", is("2")));
auths = this.authorizationManager.getUserAuthorizations(username);
Assert.assertEquals(1, auths.size());
Assert.assertEquals("helpdesk", auths.get(0).getGroup().getName());
} finally {
this.authorizationManager.deleteUserAuthorizations(username);
this.groupManager.removeGroup(group);
this.roleManager.removeRole(role);
this.userManager.removeUser(username);
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerIntegrationTest method testGetUsersWithProfile.
@Test
public void testGetUsersWithProfile() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/users").param("withProfile", "1").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload", Matchers.hasSize(Matchers.greaterThan(0))));
result.andExpect(jsonPath("$.metaData.additionalParams.withProfile", is("1")));
System.out.println("with profile: " + result.andReturn().getResponse().getContentAsString());
}
Aggregations