Search in sources :

Example 81 with UserDetails

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

the class LabelControllerIntegrationTest method testUpdateLabelWithUnexistingLang.

@Test
public void testUpdateLabelWithUnexistingLang() throws Exception {
    String code = "THIS_LABEL_HAS_NO_NAME";
    ObjectMapper mapper = new ObjectMapper();
    try {
        assertThat(this.ii18nManager.getLabelGroup(code), is(nullValue()));
        ApsProperties labels = new ApsProperties();
        labels.put(this.langManager.getDefaultLang().getCode(), "hello");
        this.ii18nManager.addLabelGroup(code, labels);
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        LabelRequest request = new LabelRequest();
        request.setKey(code);
        Map<String, String> languages = new HashMap<>();
        languages.put(langManager.getDefaultLang().getCode(), "hello");
        languages.put("kk", "hello");
        request.setTitles(languages);
        String payLoad = mapper.writeValueAsString(request);
        ResultActions result = mockMvc.perform(put("/labels/{code}", code).content(payLoad).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(status().isBadRequest());
    } finally {
        this.ii18nManager.deleteLabelGroup(code);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApsProperties(com.agiletec.aps.util.ApsProperties) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 82 with UserDetails

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

the class LabelControllerIntegrationTest method testAddLabelWithInvalidLang.

@Test
public void testAddLabelWithInvalidLang() throws Exception {
    String code = "THIS_LABEL_HAS_NO_NAME";
    ObjectMapper mapper = new ObjectMapper();
    try {
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        assertThat(this.ii18nManager.getLabelGroup(code), is(nullValue()));
        LabelRequest request = new LabelRequest();
        request.setKey(code);
        Map<String, String> languages = new HashMap<>();
        languages.put(langManager.getDefaultLang().getCode(), "hello");
        languages.put("de", "hello");
        request.setTitles(languages);
        String payLoad = mapper.writeValueAsString(request);
        ResultActions result = mockMvc.perform(post("/labels").content(payLoad).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(status().isBadRequest());
    } finally {
        this.ii18nManager.deleteLabelGroup(code);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 83 with UserDetails

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

the class LabelControllerIntegrationTest method testAddLabelWithoutDefaultLang.

@Test
public void testAddLabelWithoutDefaultLang() throws Exception {
    String code = "THIS_LABEL_HAS_NO_NAME";
    ObjectMapper mapper = new ObjectMapper();
    try {
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        assertThat(this.ii18nManager.getLabelGroup(code), is(nullValue()));
        LabelRequest request = new LabelRequest();
        request.setKey(code);
        Map<String, String> languages = new HashMap<>();
        languages.put(langManager.getDefaultLang().getCode(), "hello");
        languages.put("en", "hello");
        languages.put("de", "hello");
        languages.put("KK", "hello");
        request.setTitles(languages);
        String payLoad = mapper.writeValueAsString(request);
        ResultActions result = mockMvc.perform(post("/labels").content(payLoad).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(status().isBadRequest());
    } finally {
        this.ii18nManager.deleteLabelGroup(code);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 84 with UserDetails

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

the class LabelControllerIntegrationTest method testGetLabels2.

@Test
public void testGetLabels2() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/labels").param("direction", FieldSearchFilter.DESC_ORDER).param("filter[0].attribute", "value").param("filter[0].value", "gina").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    result.andExpect(jsonPath("$.payload", hasSize(3)));
}
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 85 with UserDetails

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

the class LabelControllerIntegrationTest method testAddLabelWithMissingDefaultLang.

@Test
public void testAddLabelWithMissingDefaultLang() throws Exception {
    String code = "THIS_LABEL_HAS_NO_NAME";
    ObjectMapper mapper = new ObjectMapper();
    try {
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        assertThat(this.ii18nManager.getLabelGroup(code), is(nullValue()));
        LabelRequest request = new LabelRequest();
        request.setKey(code);
        Map<String, String> languages = new HashMap<>();
        languages.put("en", "hello");
        request.setTitles(languages);
        String payLoad = mapper.writeValueAsString(request);
        ResultActions result = mockMvc.perform(post("/labels").content(payLoad).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(status().isBadRequest());
    } finally {
        this.ii18nManager.deleteLabelGroup(code);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

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