use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerUnitTest method shouldAddUserAuthorities.
@Test
public void shouldAddUserAuthorities() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String mockJson = "[{\"group\":\"group1\", \"role\":\"role1\"},{\"group\":\"group2\", \"role\":\"role2\"}]";
List<UserAuthorityDto> authorities = (List<UserAuthorityDto>) this.createMetadata(mockJson, List.class);
when(this.controller.getUserValidator().getGroupManager().getGroup(any(String.class))).thenReturn(mockedGroup());
when(this.controller.getUserValidator().getRoleManager().getRole(any(String.class))).thenReturn(mockedRole());
when(this.controller.getUserService().addUserAuthorities(any(String.class), any(UserAuthoritiesRequest.class))).thenReturn(authorities);
ResultActions result = mockMvc.perform(put("/users/{target}/authorities", "mockuser").sessionAttr("user", user).content(mockJson).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method testGetUserProfileAttributeTypes_2.
@Test
public void testGetUserProfileAttributeTypes_2() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/profileTypeAttributes").param("pageSize", "5").param("sort", "code").param("direction", "DESC").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload", Matchers.hasSize(5)));
result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
result.andExpect(jsonPath("$.metaData.lastPage", is(3)));
result.andExpect(jsonPath("$.metaData.totalItems", is(15)));
result.andExpect(jsonPath("$.payload[0]", is("Timestamp")));
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method testGetUserProfileAttributeType_1.
@Test
public void testGetUserProfileAttributeType_1() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/profileTypeAttributes/{attributeTypeCode}", new Object[] { "Monotext" }).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.code", is("Monotext")));
result.andExpect(jsonPath("$.payload.simple", is(true)));
result.andExpect(jsonPath("$.errors", Matchers.hasSize(0)));
result.andExpect(jsonPath("$.metaData.size()", is(0)));
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method testGetUserProfileTypesWithoutPermission.
@Test
public void testGetUserProfileTypesWithoutPermission() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("normal_user", "0x24").build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/profileTypes").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isForbidden());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method executeProfileAttributePut.
private ResultActions executeProfileAttributePut(String fileName, String typeCode, String attributeCode, String accessToken, ResultMatcher expected) throws Exception {
InputStream isJsonPutValid = this.getClass().getResourceAsStream(fileName);
String jsonPutValid = FileTextReader.getText(isJsonPutValid);
ResultActions result = mockMvc.perform(put("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { typeCode, attributeCode }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(expected);
return result;
}
Aggregations