use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class TestUserManager method testUpdateUser.
public void testUpdateUser() throws Throwable {
String username = "UserForTest2";
Date birthdate = this.steBirthdate(1982, 10, 25);
MockUser user = this.createUserForTest(username);
IUserProfile profile = this.createProfile("stefano", "puddu", "spuddu@agiletec.it", birthdate, "it");
user.setProfile(profile);
try {
this._userManager.removeUser(user);
UserDetails extractedUser = this._userManager.getUser(username);
assertNull(extractedUser);
this._userManager.addUser(user);
extractedUser = this._userManager.getUser(username);
assertEquals(user.getUsername(), extractedUser.getUsername());
assertNotNull(extractedUser);
assertEquals(0, extractedUser.getAuthorizations().size());
user.setPassword("changedPassword");
IUserProfile extractedProfile = (IUserProfile) extractedUser.getProfile();
assertNotNull(extractedProfile);
MonoTextAttribute emailAttr = (MonoTextAttribute) ((IUserProfile) extractedProfile).getAttribute("email");
assertEquals("spuddu@agiletec.it", emailAttr.getText());
emailAttr.setText("agiletectest@gmail.com");
user.setProfile(extractedProfile);
this._userManager.updateUser(user);
this._userManager.changePassword(user.getUsername(), user.getUsername());
extractedUser = this._userManager.getUser(username);
assertEquals(user.getUsername(), extractedUser.getUsername());
extractedUser = this._userManager.getUser(username);
assertNotNull(extractedUser);
extractedProfile = (IUserProfile) extractedUser.getProfile();
MonoTextAttribute extractedEmailAttr = (MonoTextAttribute) ((IUserProfile) extractedProfile).getAttribute("email");
assertEquals("agiletectest@gmail.com", extractedEmailAttr.getText());
} catch (Throwable t) {
throw t;
} finally {
this._userManager.removeUser(user);
UserDetails extractedUser = this._userManager.getUser(username);
assertNull(extractedUser);
}
}
use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile 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;
}
use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class UserProfileManagerTest method testGetDefaultProfileType.
@Test
public void testGetDefaultProfileType() throws ApsSystemException {
// @formatter:off
when(entityTypeFactory.extractEntityType(SystemConstants.DEFAULT_PROFILE_TYPE_CODE, UserProfile.class, configItemName, this.entityTypeDom, userProfileManager.getName(), this.entityDom)).thenReturn(this.createFakeProfile(SystemConstants.DEFAULT_PROFILE_TYPE_CODE));
// @formatter:on
IUserProfile userProfile = userProfileManager.getDefaultProfileType();
assertThat(userProfile, is(not(nullValue())));
assertThat(userProfile.getAttributeList().size(), is(1));
}
use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class CurrentUserProfileAttributeTag method getUserProfile.
@Override
protected IUserProfile getUserProfile() throws Throwable {
HttpSession session = this.pageContext.getSession();
UserDetails currentUser = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
if (currentUser == null || currentUser.getUsername().equals(SystemConstants.GUEST_USER_NAME) || null == currentUser.getProfile()) {
_logger.error("User '{}' : Null user, or guest user or user without profile", currentUser);
return null;
}
return (IUserProfile) currentUser.getProfile();
}
use of org.entando.entando.aps.system.services.userprofile.model.IUserProfile in project entando-core by entando.
the class TestUserManager method testAddDeleteUser.
public void testAddDeleteUser() throws Throwable {
String username = "UserForTest1";
MockUser user = this.createUserForTest(username);
Date birthdate = this.steBirthdate(1982, 10, 25);
IUserProfile profile = this.createProfile("stefano", "puddu", "spuddu@agiletec.it", birthdate, "it");
user.setProfile(profile);
try {
this._userManager.removeUser(user);
UserDetails extractedUser = this._userManager.getUser(username);
assertNull(extractedUser);
this._userManager.addUser(user);
extractedUser = this._userManager.getUser(username);
assertEquals(user.getUsername(), extractedUser.getUsername());
assertNotNull(user.getProfile());
assertEquals("spuddu@agiletec.it", ((IUserProfile) user.getProfile()).getValue("email"));
} catch (Throwable t) {
throw t;
} finally {
this._userManager.removeUser(user);
UserDetails extractedUser = this._userManager.getUser(username);
assertNull(extractedUser);
}
}
Aggregations