Search in sources :

Example 1 with UserSettingsRequest

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserSettingsRequest(org.entando.entando.web.usersettings.model.UserSettingsRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 2 with UserSettingsRequest

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);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserSettingsRequest(org.entando.entando.web.usersettings.model.UserSettingsRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 3 with UserSettingsRequest

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserSettingsRequest(org.entando.entando.web.usersettings.model.UserSettingsRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 4 with UserSettingsRequest

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserSettingsRequest(org.entando.entando.web.usersettings.model.UserSettingsRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 5 with UserSettingsRequest

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserSettingsRequest(org.entando.entando.web.usersettings.model.UserSettingsRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Aggregations

UserDetails (com.agiletec.aps.system.services.user.UserDetails)5 UserSettingsRequest (org.entando.entando.web.usersettings.model.UserSettingsRequest)5 Test (org.junit.Test)5 ResultActions (org.springframework.test.web.servlet.ResultActions)5 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)4 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)1