use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserControllerIntegrationTest method testUpdateUser.
@Test
public void testUpdateUser() throws Exception {
String validUsername = "test_test";
String validPassword = "password";
try {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String mockJson = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"" + validPassword + "\"}";
this.executeUserPost(mockJson, accessToken, status().isOk());
String invalidBody1 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"$invalid%%\"}";
ResultActions resultInvalid1 = this.executeUserPut(invalidBody1, validUsername, accessToken, status().isBadRequest());
System.out.println(resultInvalid1.andReturn().getResponse().getContentAsString());
resultInvalid1.andExpect(jsonPath("$.payload", Matchers.hasSize(0)));
resultInvalid1.andExpect(jsonPath("$.errors", Matchers.hasSize(1)));
resultInvalid1.andExpect(jsonPath("$.errors[0].code", is("3")));
resultInvalid1.andExpect(jsonPath("$.metaData.size()", is(0)));
String invalidBody2 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"upasswordvelylong_.veryverylong\"}";
ResultActions resultInvalid2 = this.executeUserPut(invalidBody2, validUsername, accessToken, status().isBadRequest());
resultInvalid2.andExpect(jsonPath("$.errors[0].code", is("3")));
String invalidBody3 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"" + validPassword + "\"}";
ResultActions resultInvalid3 = this.executeUserPut(invalidBody3, "invalidUsername", accessToken, status().isConflict());
resultInvalid3.andExpect(jsonPath("$.errors[0].code", is("2")));
String valid1 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"reset\": true}";
ResultActions resultValid1 = this.executeUserPut(valid1, validUsername, accessToken, status().isOk());
String responseValid1 = resultValid1.andReturn().getResponse().getContentAsString();
System.out.println("resp:" + responseValid1);
resultValid1.andExpect(jsonPath("$.payload.username", is(validUsername)));
UserDetails authUser = this.authenticationProviderManager.getUser(validUsername, validPassword);
Assert.assertNotNull(authUser);
String valid2 = "{\"username\": \"" + validUsername + "\",\"status\": \"active\",\"password\": \"12345678\",\"reset\": true}";
ResultActions resultValid2 = this.executeUserPut(valid2, validUsername, accessToken, status().isOk());
String responseValid2 = resultValid2.andReturn().getResponse().getContentAsString();
System.out.println("resp:" + responseValid2);
resultValid2.andExpect(jsonPath("$.payload.username", is(validUsername)));
authUser = this.authenticationProviderManager.getUser(validUsername, validPassword);
Assert.assertNull(authUser);
authUser = this.authenticationProviderManager.getUser(validUsername, "12345678");
Assert.assertNotNull(authUser);
} catch (Throwable e) {
throw e;
} finally {
this.userManager.removeUser(validUsername);
}
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserProfileControllerTest method testAddProfile.
@Test
public void testAddProfile() throws Exception {
when(this.userProfileService.addUserProfile(any(EntityDto.class), any(BindingResult.class))).thenReturn(Mockito.mock(EntityDto.class));
String mockJson = "{\n" + " \"id\": \"user\",\n" + " \"typeCode\": \"" + SystemConstants.DEFAULT_PROFILE_TYPE_CODE + "\",\n" + " \"attributes\": [\n" + " {\"code\": \"fullname\", \"value\": \"User\"},\n" + " {\"code\": \"email\", \"value\": \"test@example.com\"}\n" + " ]}";
ResultActions result = performPostUserProfiles(mockJson);
result.andExpect(status().isOk());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserProfileControllerTest method shouldGetNewlyCreatedProfile.
@Test
public void shouldGetNewlyCreatedProfile() throws Exception {
when(this.userManager.getUser("user_without_profile")).thenReturn(Mockito.mock(UserDetails.class));
when(this.userProfileManager.getDefaultProfileType()).thenReturn(Mockito.mock(IUserProfile.class));
ResultActions result = performGetUserProfiles("user_without_profile");
result.andExpect(status().isOk());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class UserProfileControllerTest method testUnexistingProfile.
@Test
public void testUnexistingProfile() throws Exception {
ResultActions result = performGetUserProfiles("user_without_profile");
result.andExpect(status().isNotFound());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class ProfileTypeControllerIntegrationTest method executeProfileAttributeDelete.
private ResultActions executeProfileAttributeDelete(String typeCode, String attributeCode, String accessToken, ResultMatcher expected) throws Exception {
ResultActions result = mockMvc.perform(delete("/profileTypes/{profileTypeCode}/attribute/{attributeCode}", new Object[] { typeCode, attributeCode }).header("Authorization", "Bearer " + accessToken));
result.andExpect(expected);
return result;
}
Aggregations