Search in sources :

Example 21 with Profile

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

the class ProfileServiceImplTest method testGetProfileRange.

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

Example 22 with Profile

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

the class ProfileServiceImplTest method testRemoveAttributes.

@Test
public void testRemoveAttributes() throws Exception {
    Profile expected = getTenant1Profile();
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    expected.getAttributes().remove(ATTRIB_NAME_LAST_NAME);
    Profile actual = profileService.removeAttributes(PROFILE1_ID.toString(), Arrays.asList(ATTRIB_NAME_LAST_NAME));
    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() == 1 && param.containsKey("lastModified");
        }
    };
    ArgumentMatcher<Object> unsetParamMatcher = new ArgumentMatcher<Object>() {

        @Override
        public boolean matches(Object argument) {
            Map<String, Object> param = (Map<String, Object>) argument;
            return param.size() == 1 && param.get("attributes." + ATTRIB_NAME_LAST_NAME).equals("");
        }
    };
    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: #, $unset: #}"), eq(false), eq(false), argThat(setParamMatcher), argThat(unsetParamMatcher));
}
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 23 with Profile

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

the class ProfileServiceImplTest method testAddRoles.

@Test
public void testAddRoles() throws Exception {
    Profile expected = getTenant1Profile();
    expected.getRoles().add(ROLE2);
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.addRoles(PROFILE1_ID.toString(), Collections.singletonList(ROLE2));
    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() == 1 && param.containsKey("lastModified");
        }
    };
    ArgumentMatcher<Object> pushParamMatcher = new ArgumentMatcher<Object>() {

        @Override
        public boolean matches(Object argument) {
            Map<String, Object> param = (Map<String, Object>) argument;
            return param.size() == 1 && param.get("roles").equals(Collections.singletonMap("$each", Collections.singletonList(ROLE2)));
        }
    };
    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: #, $push: #}"), eq(false), eq(false), argThat(setParamMatcher), argThat(pushParamMatcher));
}
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 24 with Profile

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

the class ProfileServiceImplTest method testGetProfilesByQuery.

@Test
public void testGetProfilesByQuery() throws Exception {
    List<Profile> expected = getAllTenant1Profiles();
    for (Profile profile : expected) {
        profile.setAttributes(getAttributesWithoutPrivateAttribute());
    }
    List<Profile> actual = profileService.getProfilesByQuery(TENANT1_NAME, QUERY, SORT_BY, SortOrder.ASC, START, COUNT);
    assertEqualProfileLists(expected, actual);
    verify(tenantPermissionEvaluator).isAllowed(TENANT1_NAME, TenantAction.MANAGE_PROFILES.toString());
    verify(profileRepository).findByQuery(String.format(ProfileServiceImpl.QUERY_FINAL_FORMAT, TENANT1_NAME, QUERY), SORT_BY, SortOrder.ASC, START, COUNT, new String[0]);
}
Also used : Profile(org.craftercms.profile.api.Profile) Test(org.junit.Test)

Example 25 with Profile

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

the class ProfileServiceImplTest method testRemoveRoles.

@Test
public void testRemoveRoles() throws Exception {
    Profile expected = getTenant1Profile();
    expected.getRoles().remove(ROLE1);
    expected.setAttributes(getAttributesWithoutPrivateAttribute());
    Profile actual = profileService.removeRoles(PROFILE1_ID.toString(), Collections.singletonList(ROLE1));
    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() == 1 && param.containsKey("lastModified");
        }
    };
    ArgumentMatcher<Object> pullParamMatcher = new ArgumentMatcher<Object>() {

        @Override
        public boolean matches(Object argument) {
            Map<String, Object> param = (Map<String, Object>) argument;
            return param.size() == 1 && param.get("roles").equals(Collections.singletonMap("$in", Collections.singletonList(ROLE1)));
        }
    };
    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: #, $pull: #}"), eq(false), eq(false), argThat(setParamMatcher), argThat(pullParamMatcher));
}
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)

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