use of org.entando.entando.web.usersettings.model.UserSettingsRequest in project entando-core by entando.
the class UserSettigsControllerUnitTest method testUpdateSettingsWithEmptyParams.
@Test
public void testUpdateSettingsWithEmptyParams() throws Throwable {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
UserSettingsRequest userSettingsRequest = new UserSettingsRequest();
ResultActions result = mockMvc.perform(put("/usersettings").content(mapper.writeValueAsString(userSettingsRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isBadRequest());
}
use of org.entando.entando.web.usersettings.model.UserSettingsRequest in project entando-core by entando.
the class UserSettingsControllerIntegrationTest method testUpdateSettings.
@Test
public void testUpdateSettings() throws Throwable {
String xmlParams = this.configInterface.getConfigItem(SystemConstants.CONFIG_ITEM_PARAMS);
try {
Map<String, String> params = this.getSystemParams();
assertEquals("false", params.get(UserSettingsDto.EXTENDED_PRIVACY_MODULE_ENABLED));
assertEquals("false", params.getOrDefault(SystemConstants.CONFIG_PARAM_GRAVATAR_INTEGRATION_ENABLED, "false"));
assertEquals("6", params.get(UserSettingsDto.MAX_MONTHS_SINCE_LASTACCESS));
assertEquals("3", params.get(UserSettingsDto.MAX_MONTHS_SINCE_LASTPASSWORDCHANGE));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/userSettings").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.restrictionsActive", is(Boolean.parseBoolean(params.get(UserSettingsDto.EXTENDED_PRIVACY_MODULE_ENABLED)))));
result.andExpect(jsonPath("$.payload.enableGravatarIntegration", is(Boolean.parseBoolean(params.get(SystemConstants.CONFIG_PARAM_GRAVATAR_INTEGRATION_ENABLED)))));
result.andExpect(jsonPath("$.payload.lastAccessPasswordExpirationMonths", is(Integer.valueOf(params.get(UserSettingsDto.MAX_MONTHS_SINCE_LASTACCESS)))));
result.andExpect(jsonPath("$.payload.maxMonthsPasswordValid", is(Integer.valueOf(params.get(UserSettingsDto.MAX_MONTHS_SINCE_LASTPASSWORDCHANGE)))));
// -------------
UserSettingsRequest userSettingsRequest = new UserSettingsRequest();
userSettingsRequest.setExtendedPrivacyModuleEnabled(true);
userSettingsRequest.setGravatarIntegrationEnabled(true);
userSettingsRequest.setMaxMonthsSinceLastAccess(60);
userSettingsRequest.setMaxMonthsSinceLastPasswordChange(30);
result = mockMvc.perform(put("/userSettings").contentType(MediaType.APPLICATION_JSON_VALUE).content(mapper.writeValueAsString(userSettingsRequest)).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.restrictionsActive", is(true)));
result.andExpect(jsonPath("$.payload.enableGravatarIntegration", is(true)));
result.andExpect(jsonPath("$.payload.lastAccessPasswordExpirationMonths", is(60)));
result.andExpect(jsonPath("$.payload.maxMonthsPasswordValid", is(30)));
// -------------
userSettingsRequest = new UserSettingsRequest();
userSettingsRequest.setExtendedPrivacyModuleEnabled(false);
userSettingsRequest.setGravatarIntegrationEnabled(false);
userSettingsRequest.setMaxMonthsSinceLastAccess(6);
userSettingsRequest.setMaxMonthsSinceLastPasswordChange(3);
result = mockMvc.perform(put("/userSettings").contentType(MediaType.APPLICATION_JSON_VALUE).content(mapper.writeValueAsString(userSettingsRequest)).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
} finally {
this.configInterface.updateConfigItem(SystemConstants.CONFIG_ITEM_PARAMS, xmlParams);
}
}
use of org.entando.entando.web.usersettings.model.UserSettingsRequest in project entando-core by entando.
the class UserSettigsControllerUnitTest method testUpdateSettingsWithInvalidParams.
@Test
public void testUpdateSettingsWithInvalidParams() throws Throwable {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
UserSettingsRequest userSettingsRequest = new UserSettingsRequest();
userSettingsRequest.setMaxMonthsSinceLastAccess(-6);
userSettingsRequest.setMaxMonthsSinceLastPasswordChange(-3);
ResultActions result = mockMvc.perform(put("/usersettings").content(mapper.writeValueAsString(userSettingsRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isBadRequest());
}
use of org.entando.entando.web.usersettings.model.UserSettingsRequest in project entando-core by entando.
the class UserSettingsControllerUnitTest method testUpdateSettingsWithEmptyParams.
@Test
public void testUpdateSettingsWithEmptyParams() throws Throwable {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
UserSettingsRequest userSettingsRequest = new UserSettingsRequest();
ResultActions result = mockMvc.perform(put("/userSettings").content(mapper.writeValueAsString(userSettingsRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
}
use of org.entando.entando.web.usersettings.model.UserSettingsRequest in project entando-core by entando.
the class UserSettingsControllerUnitTest method testUpdateSettingsWithInvalidParams.
@Test
public void testUpdateSettingsWithInvalidParams() throws Throwable {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
UserSettingsRequest userSettingsRequest = new UserSettingsRequest();
userSettingsRequest.setMaxMonthsSinceLastAccess(-6);
userSettingsRequest.setMaxMonthsSinceLastPasswordChange(-3);
ResultActions result = mockMvc.perform(put("/userSettings").content(mapper.writeValueAsString(userSettingsRequest)).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
}
Aggregations