use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class MellonAutoLoginProcessorTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Profile profile = getProfile();
when(tenantService.getTenant(TENANT_NAME)).thenReturn(getTenant());
when(profileService.createProfile(TENANT_NAME, USERNAME, null, EMAIL, true, null, getAttributes(), null)).thenReturn(profile);
when(tenantsResolver.getTenants()).thenReturn(new String[] { TENANT_NAME });
when(authenticationManager.authenticateUser(profile)).thenReturn(new DefaultAuthentication(TICKET, profile));
processor = new MellonAutoLoginProcessor();
processor.setTenantService(tenantService);
processor.setProfileService(profileService);
processor.setTenantsResolver(tenantsResolver);
processor.setAuthenticationManager(authenticationManager);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileControllerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
String query = String.format(FINAL_QUERY_FORMAT, USERNAME1);
Profile profile1 = getProfile(TENANT_NAME1, PROFILE_ID1, USERNAME1, PROFILE_ADMIN_ROLE);
Profile profile2 = getProfile(TENANT_NAME1, PROFILE_ID2, USERNAME2, PROFILE_ADMIN_ROLE);
Profile profile3 = getProfile(TENANT_NAME1, PROFILE_ID3, USERNAME3, SUPERADMIN_ROLE);
Profile profile4 = getProfile(TENANT_NAME1, PROFILE_ID4, USERNAME4, TENANT_ADMIN_ROLE);
when(profileService.getProfileCountByQuery(TENANT_NAME1, query)).thenReturn(1L);
when(profileService.getProfilesByQuery(TENANT_NAME1, query, null, null, null, null, new String[0])).thenReturn(Arrays.asList(profile1));
when(profileService.getProfile(PROFILE_ID1.toString(), new String[0])).thenReturn(profile1);
when(profileService.getProfile(PROFILE_ID3.toString(), new String[0])).thenReturn(profile3);
when(profileService.getProfile(PROFILE_ID4.toString(), new String[0])).thenReturn(profile4);
when(profileService.createProfile(TENANT_NAME1, USERNAME2, null, null, false, SetUtils.asSet(PROFILE_ADMIN_ROLE), new HashMap<String, Object>(), null)).thenReturn(profile2);
SubjectResolver<Profile> subjectResolver = new CurrentUserSubjectResolver();
TenantPermissionResolver tenantPermissionResolver = new TenantPermissionResolver();
ProfilePermissionResolver profilePermissionResolver = new ProfilePermissionResolver();
PermissionEvaluatorImpl<Profile, String> tenantPermissionEvaluator = new PermissionEvaluatorImpl<>();
tenantPermissionEvaluator.setSubjectResolver(subjectResolver);
tenantPermissionEvaluator.setPermissionResolver(tenantPermissionResolver);
PermissionEvaluatorImpl<Profile, Profile> profilePermissionEvaluator = new PermissionEvaluatorImpl<>();
profilePermissionEvaluator.setSubjectResolver(subjectResolver);
profilePermissionEvaluator.setPermissionResolver(profilePermissionResolver);
controller = new ProfileController();
controller.setProfileService(profileService);
controller.setTenantPermissionEvaluator(tenantPermissionEvaluator);
controller.setProfilePermissionEvaluator(profilePermissionEvaluator);
setCurrentRequestContext();
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileControllerTest method getProfile.
private Profile getProfile(String tenantName, ObjectId id, String username, String role) {
Profile profile = new Profile();
profile.setId(id);
profile.setTenant(tenantName);
profile.setUsername(username);
profile.getRoles().add(role);
return profile;
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class ProfileControllerTest method testUpdateProfile.
@Test
public void testUpdateProfile() throws Exception {
Profile currentUser = getProfile(TENANT_NAME1, PROFILE_ID1, USERNAME1, PROFILE_ADMIN_ROLE);
setCurrentUser(currentUser);
Map<String, String> model = controller.updateProfile(currentUser);
assertNotNull(model);
assertEquals(1, model.size());
assertEquals(String.format(MSG_PROFILE_UPDATED_FORMAT, PROFILE_ID1.toString()), model.get(MODEL_MESSAGE));
verify(profileService).updateProfile(PROFILE_ID1.toString(), USERNAME1, null, null, false, SetUtils.asSet(PROFILE_ADMIN_ROLE), new HashMap<String, Object>(), ProfileConstants.NO_ATTRIBUTE);
}
use of org.craftercms.profile.api.Profile in project profile by craftercms.
the class TenantControllerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Tenant tenant1 = getTenant(TENANT_ID1, TENANT_NAME1, SUPERADMIN_ROLE, TENANT_ADMIN_ROLE, PROFILE_ADMIN_ROLE);
Tenant tenant2 = getTenant(TENANT_ID2, TENANT_NAME2, TENANT_ADMIN_ROLE, PROFILE_ADMIN_ROLE);
Tenant tenant3 = getTenant(TENANT_ID3, TENANT_NAME3, PROFILE_ADMIN_ROLE);
when(tenantService.getAllTenants()).thenReturn(Arrays.asList(tenant1, tenant2));
when(tenantService.getTenant(TENANT_NAME1)).thenReturn(tenant1);
when(tenantService.getTenant(TENANT_NAME2)).thenReturn(tenant2);
when(tenantService.createTenant(tenant3)).thenReturn(tenant3);
SubjectResolver<Profile> subjectResolver = new CurrentUserSubjectResolver();
TenantPermissionResolver permissionResolver = new TenantPermissionResolver();
PermissionEvaluatorImpl<Profile, String> permissionEvaluator = new PermissionEvaluatorImpl<>();
permissionEvaluator.setSubjectResolver(subjectResolver);
permissionEvaluator.setPermissionResolver(permissionResolver);
controller = new TenantController();
controller.setTenantService(tenantService);
controller.setTenantPermissionEvaluator(permissionEvaluator);
setCurrentRequestContext();
}
Aggregations