Search in sources :

Example 86 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class LabelControllerUnitTest method testUpdateEmpyLanguages.

@Test
public void testUpdateEmpyLanguages() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ObjectMapper mapper = new ObjectMapper();
    LabelRequest labelRequest = new LabelRequest();
    labelRequest.setTitles(new HashMap<>());
    String payload = mapper.writeValueAsString(labelRequest);
    ResultActions result = mockMvc.perform(put("/labels/{labelCode}", new Object[] { "PAGE" }).content(payload).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) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 87 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class LanguageControllerIntegrationTest method testGetLangValidAssignable.

@Test
public void testGetLangValidAssignable() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/languages/{code}", new Object[] { "de" }).header("Authorization", "Bearer " + accessToken));
    // System.out.println(result.andReturn().getResponse().getContentAsString());
    result.andExpect(status().isOk());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 88 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class LanguageControllerIntegrationTest method testDeactivateDefaultLang.

@Test
public void testDeactivateDefaultLang() throws Exception {
    String langCode = this.langManager.getDefaultLang().getCode();
    try {
        LanguageDto lang = this.languageService.getLanguage(langCode);
        assertThat(lang, is(not(nullValue())));
        assertThat(lang.isActive(), is(true));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        String payload = "{\"isActive\": true}";
        ResultActions result = mockMvc.perform(put("/languages/{code}", new Object[] { langCode }).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        LanguageDto updatedLang = this.languageService.getLanguage(langCode);
        assertThat(updatedLang, is(not(nullValue())));
        assertThat(updatedLang.isActive(), is(true));
        // --
        payload = "{\"isActive\": false}";
        result = mockMvc.perform(put("/languages/{code}", new Object[] { langCode }).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isConflict());
        result.andExpect(jsonPath("$.errors[0].code", is("1")));
        updatedLang = this.languageService.getLanguage(langCode);
        assertThat(updatedLang, is(not(nullValue())));
        assertThat(updatedLang.isActive(), is(true));
    } finally {
        this.languageService.updateLanguage(langCode, true);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) LanguageDto(org.entando.entando.aps.system.services.language.LanguageDto) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 89 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class LanguageControllerIntegrationTest method testGetLangs.

@Test
public void testGetLangs() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/languages").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    // System.out.println(result.andReturn().getResponse().getContentAsString());
    /**
     * The response should have the correct CORS headers and the CORS
     * configuration should reflect the one set in
     * org.entando.entando.aps.servlet.CORSFilter class
     */
    result.andExpect(header().string("Access-Control-Allow-Origin", "*"));
    result.andExpect(header().string("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"));
    result.andExpect(header().string("Access-Control-Allow-Headers", "Content-Type, Authorization"));
    result.andExpect(header().string("Access-Control-Max-Age", "3600"));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 90 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class LanguageControllerUnitTest method testUpdatePayloadOk.

@Test
public void testUpdatePayloadOk() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String payload = "{\"isActive\": false}";
    ResultActions result = mockMvc.perform(put("/languages/{code}", new Object[] { "de" }).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
    Mockito.verify(languageService, Mockito.times(1)).updateLanguage("de", false);
    result.andExpect(status().isOk());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) 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)271 Test (org.junit.Test)150 ResultActions (org.springframework.test.web.servlet.ResultActions)142 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)77 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)71 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 Group (com.agiletec.aps.system.services.group.Group)15 ArrayList (java.util.ArrayList)15 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)14 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)13 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)12 HttpSession (javax.servlet.http.HttpSession)12 RestListRequest (org.entando.entando.web.common.model.RestListRequest)12 HashMap (java.util.HashMap)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)9 IPage (com.agiletec.aps.system.services.page.IPage)8 JspException (javax.servlet.jsp.JspException)8 Page (com.agiletec.aps.system.services.page.Page)7