Search in sources :

Example 16 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method getTenant2Profile.

private Profile getTenant2Profile() {
    Profile profile = new Profile();
    profile.setId(PROFILE2_ID);
    profile.setTenant(TENANT2_NAME);
    profile.setUsername(USERNAME2);
    profile.setPassword(CryptoUtils.hashPassword(PASSWORD2));
    profile.setEmail(EMAIL2);
    profile.setRoles(new HashSet<>(ROLES2));
    profile.setVerified(false);
    profile.setEnabled(false);
    profile.setAttributes(getAttributes());
    return profile;
}
Also used : Profile(org.craftercms.profile.api.Profile)

Example 17 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method testGetProfile.

@Test
public void testGetProfile() throws Exception {
    Profile expected = getTenant1Profile();
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.getProfile(PROFILE1_ID.toString());
    assertEqualProfiles(expected, actual);
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 18 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method testEnableProfile.

@Test
public void testEnableProfile() throws Exception {
    Profile expected = getTenant2Profile();
    expected.setEnabled(true);
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.enableProfile(PROFILE2_ID.toString());
    assertEqualProfiles(expected, actual);
    ArgumentMatcher<Object> setParamMatcher = new ArgumentMatcher<Object>() {

        @Override
        public boolean matches(Object argument) {
            Map<String, Object> param = (Map<String, Object>) argument;
            return param.size() == 2 && param.get("enabled").equals(true) && param.containsKey("lastModified");
        }
    };
    verify(tenantPermissionEvaluator).isAllowed(TENANT2_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findById(PROFILE2_ID.toString(), new String[0]);
    verify(profileRepository).update(eq(PROFILE2_ID.toString()), eq("{$set: #}"), eq(false), eq(false), argThat(setParamMatcher));
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) Mockito.anyString(org.mockito.Mockito.anyString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 19 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method testGetProfilesByAttribute.

@Test
public void testGetProfilesByAttribute() throws Exception {
    List<Profile> expected = getAllTenant1Profiles();
    for (Profile profile : expected) {
        profile.setAttributes(getAttributesWithoutPrivateAttribute());
    }
    List<Profile> actual = profileService.getProfilesByAttributeValue(TENANT1_NAME, ATTRIB_NAME_FIRST_NAME, FIRST_NAME, SORT_BY, SortOrder.ASC);
    assertEqualProfileLists(expected, actual);
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findByTenantAndAttributeValue(TENANT1_NAME, ATTRIB_NAME_FIRST_NAME, FIRST_NAME, SORT_BY, SortOrder.ASC);
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 20 with Profile

use of org.craftercms.profile.api.Profile in project profile by craftercms.

the class ProfileServiceImplTest method testGetProfileByUsername.

@Test
public void testGetProfileByUsername() throws Exception {
    Profile expected = getTenant1Profile();
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.getProfileByUsername(TENANT1_NAME, USERNAME1);
    assertEqualProfiles(expected, actual);
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findByTenantAndUsername(TENANT1_NAME, USERNAME1, new String[0]);
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Aggregations

Profile (org.craftercms.profile.api.Profile)110 Test (org.junit.Test)54 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)19 MongoDataException (org.craftercms.commons.mongo.MongoDataException)15 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)15 LinkedHashMap (java.util.LinkedHashMap)13 VerificationToken (org.craftercms.profile.api.VerificationToken)13 DefaultAuthentication (org.craftercms.security.authentication.impl.DefaultAuthentication)12 Authentication (org.craftercms.security.authentication.Authentication)11 Date (java.util.Date)10 Map (java.util.Map)10 ObjectId (org.bson.types.ObjectId)9 RequestContext (org.craftercms.commons.http.RequestContext)9 ArgumentMatcher (org.mockito.ArgumentMatcher)9 Mockito.anyString (org.mockito.Mockito.anyString)9 RequestSecurityProcessorChain (org.craftercms.security.processors.RequestSecurityProcessorChain)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 Tenant (org.craftercms.profile.api.Tenant)5 Ticket (org.craftercms.profile.api.Ticket)4