Search in sources :

Example 86 with Profile

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

the class ProfileServiceImplTest method testDisableProfile.

@Test
public void testDisableProfile() throws Exception {
    Profile expected = getTenant1Profile();
    expected.setEnabled(false);
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.disableProfile(PROFILE1_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(false) && param.containsKey("lastModified");
        }
    };
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findById(PROFILE1_ID.toString(), new String[0]);
    verify(profileRepository).update(eq(PROFILE1_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 87 with Profile

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

the class ProfileServiceImplTest method testVerifyProfile.

@Test
public void testVerifyProfile() throws Exception {
    Profile expected = getTenant2Profile();
    expected.setVerified(true);
    expected.setEnabled(true);
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.verifyProfile(VERIFICATION_TOKEN_ID2);
    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() == 3 && param.get("verified").equals(true) && 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));
    verify(verificationService).getToken(VERIFICATION_TOKEN_ID2);
    verify(verificationService).deleteToken(VERIFICATION_TOKEN_ID2);
}
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 88 with Profile

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

the class ProfileServiceImplTest method testGetProfileByQuery.

@Test
public void testGetProfileByQuery() throws Exception {
    Profile expected = getTenant1Profile();
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.getProfileByQuery(TENANT1_NAME, QUERY);
    assertEqualProfiles(expected, actual);
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findOneByQuery(String.format(ProfileServiceImpl.QUERY_FINAL_FORMAT, TENANT1_NAME, QUERY), new String[0]);
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 89 with Profile

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

the class ProfileServiceImplTest method testGetProfilesByIds.

@Test
public void testGetProfilesByIds() throws Exception {
    List<Profile> expected = getAllTenant1Profiles();
    for (Profile profile : expected) {
        profile.setAttributes(getAttributesWithoutPrivateAttribute());
    }
    List<Profile> actual = profileService.getProfilesByIds(TENANT1_PROFILE_IDS, "username", SortOrder.ASC);
    assertEqualProfileLists(expected, actual);
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findByIds(TENANT1_PROFILE_IDS, "username", SortOrder.ASC);
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 90 with Profile

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

the class ProfileServiceImplTest method testGetProfileByRole.

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

Aggregations

Profile (org.craftercms.profile.api.Profile)111 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 Date (java.util.Date)11 Map (java.util.Map)11 ObjectId (org.bson.types.ObjectId)10 RequestContext (org.craftercms.commons.http.RequestContext)9 Authentication (org.craftercms.security.authentication.Authentication)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)6 HashMap (java.util.HashMap)4