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);
}
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));
}
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));
}
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]);
}
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));
}
Aggregations