Search in sources :

Example 1 with UserProfile

use of org.entando.entando.aps.system.services.userprofile.model.UserProfile in project entando-core by entando.

the class UserProfileManagerIntegrationTest method createProfile.

private IUserProfile createProfile(String name, String surname, String email, Date birthdate, String language) {
    IUserProfile profile = this._profileManager.getDefaultProfileType();
    MonoTextAttribute nameAttr = (MonoTextAttribute) profile.getAttribute("fullname");
    nameAttr.setText(name + " " + surname);
    MonoTextAttribute emailAttr = (MonoTextAttribute) profile.getAttribute("email");
    emailAttr.setText(email);
    DateAttribute birthdateAttr = (DateAttribute) profile.getAttribute("birthdate");
    birthdateAttr.setDate(birthdate);
    MonoTextAttribute languageAttr = (MonoTextAttribute) profile.getAttribute("language");
    languageAttr.setText(language);
    ((UserProfile) profile).setPublicProfile(true);
    return profile;
}
Also used : UserProfile(org.entando.entando.aps.system.services.userprofile.model.UserProfile) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 2 with UserProfile

use of org.entando.entando.aps.system.services.userprofile.model.UserProfile in project entando-core by entando.

the class ProfileTypeControllerIntegrationTest method testAddUpdateUserProfileType_1.

@Test
public void testAddUpdateUserProfileType_1() throws Exception {
    try {
        Assert.assertNull(this.userProfileManager.getEntityPrototype("AAA"));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        InputStream isJsonPost = this.getClass().getResourceAsStream("1_POST_valid.json");
        String jsonPost = FileTextReader.getText(isJsonPost);
        ResultActions result1 = mockMvc.perform(post("/profileTypes").content(jsonPost).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result1.andExpect(status().isOk());
        Assert.assertNotNull(this.userProfileManager.getEntityPrototype("AAA"));
        UserProfile addedType = (UserProfile) this.userProfileManager.getEntityPrototype("AAA");
        Assert.assertEquals("Profile Type AAA", addedType.getTypeDescription());
        Assert.assertEquals(1, addedType.getAttributeList().size());
        InputStream isJsonPutInvalid = this.getClass().getResourceAsStream("1_PUT_invalid.json");
        String jsonPutInvalid = FileTextReader.getText(isJsonPutInvalid);
        ResultActions result2 = mockMvc.perform(put("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).content(jsonPutInvalid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result2.andExpect(status().isBadRequest());
        InputStream isJsonPutValid = this.getClass().getResourceAsStream("1_PUT_valid.json");
        String jsonPutValid = FileTextReader.getText(isJsonPutValid);
        ResultActions result3 = mockMvc.perform(put("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3.andExpect(status().isOk());
        addedType = (UserProfile) this.userProfileManager.getEntityPrototype("AAA");
        Assert.assertEquals("Profile Type AAA Modified", addedType.getTypeDescription());
        Assert.assertEquals(2, addedType.getAttributeList().size());
        ResultActions result4 = mockMvc.perform(delete("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).header("Authorization", "Bearer " + accessToken));
        result4.andExpect(status().isOk());
        Assert.assertNull(this.userProfileManager.getEntityPrototype("AAA"));
    } finally {
        if (null != this.userProfileManager.getEntityPrototype("AAA")) {
            ((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("AAA");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserProfile(org.entando.entando.aps.system.services.userprofile.model.UserProfile) InputStream(java.io.InputStream) ResultActions(org.springframework.test.web.servlet.ResultActions) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 3 with UserProfile

use of org.entando.entando.aps.system.services.userprofile.model.UserProfile in project entando-core by entando.

the class UserProfileManagerTest method createFakeProfile.

private IApsEntity createFakeProfile(String defaultProfileTypeCode) {
    UserProfile userProfile = new UserProfile();
    MonoTextAttribute monoTextAttribute = new MonoTextAttribute();
    monoTextAttribute.setName("Name");
    monoTextAttribute.setHandler(new MonoTextAttributeHandler());
    userProfile.addAttribute(monoTextAttribute);
    userProfile.setTypeCode(defaultProfileTypeCode);
    return userProfile;
}
Also used : UserProfile(org.entando.entando.aps.system.services.userprofile.model.UserProfile) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) MonoTextAttributeHandler(com.agiletec.aps.system.common.entity.parse.attribute.MonoTextAttributeHandler) MonoTextAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)

Example 4 with UserProfile

use of org.entando.entando.aps.system.services.userprofile.model.UserProfile in project entando-core by entando.

the class ProfileTypeControllerIntegrationTest method testAddUpdateUserProfileType_2.

@Test
public void testAddUpdateUserProfileType_2() throws Exception {
    try {
        Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        InputStream isJsonPostInvalid = this.getClass().getResourceAsStream("2_POST_invalid.json");
        String jsonPostInvalid = FileTextReader.getText(isJsonPostInvalid);
        ResultActions result1 = mockMvc.perform(post("/profileTypes").content(jsonPostInvalid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result1.andExpect(status().isBadRequest());
        Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
        InputStream isJsonPostValid = this.getClass().getResourceAsStream("2_POST_valid.json");
        String jsonPostValid = FileTextReader.getText(isJsonPostValid);
        ResultActions result2 = mockMvc.perform(post("/profileTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result2.andExpect(status().isOk());
        UserProfile addedDataObject = (UserProfile) this.userProfileManager.getEntityPrototype("TST");
        Assert.assertNotNull(addedDataObject);
        Assert.assertEquals(3, addedDataObject.getAttributeList().size());
        ResultActions result2_bis = mockMvc.perform(post("/profileTypes").content(jsonPostValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result2_bis.andExpect(status().isConflict());
        InputStream isJsonPutValid = this.getClass().getResourceAsStream("2_PUT_valid.json");
        String jsonPutValid = FileTextReader.getText(isJsonPutValid);
        ResultActions result3 = mockMvc.perform(put("/profileTypes/{profileTypeCode}", new Object[] { "AAA" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3.andExpect(status().isBadRequest());
        ResultActions result3_bis = mockMvc.perform(put("/profileTypes/{profileTypeCode}", new Object[] { "TST" }).content(jsonPutValid).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
        result3_bis.andExpect(status().isOk());
        UserProfile modifiedDataObject = (UserProfile) this.userProfileManager.getEntityPrototype("TST");
        Assert.assertNotNull(modifiedDataObject);
        Assert.assertEquals(5, modifiedDataObject.getAttributeList().size());
        ResultActions result4 = mockMvc.perform(delete("/profileTypes/{profileTypeCode}", new Object[] { "TST" }).header("Authorization", "Bearer " + accessToken));
        result4.andExpect(status().isOk());
        Assert.assertNull(this.userProfileManager.getEntityPrototype("TST"));
    } finally {
        if (null != this.userProfileManager.getEntityPrototype("TST")) {
            ((IEntityTypesConfigurer) this.userProfileManager).removeEntityPrototype("TST");
        }
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) UserProfile(org.entando.entando.aps.system.services.userprofile.model.UserProfile) InputStream(java.io.InputStream) ResultActions(org.springframework.test.web.servlet.ResultActions) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Aggregations

UserProfile (org.entando.entando.aps.system.services.userprofile.model.UserProfile)4 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)2 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)2 UserDetails (com.agiletec.aps.system.services.user.UserDetails)2 InputStream (java.io.InputStream)2 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)2 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)2 Test (org.junit.Test)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)1 MonoTextAttributeHandler (com.agiletec.aps.system.common.entity.parse.attribute.MonoTextAttributeHandler)1