/** Test cache management */ public void testCacheManagement() throws ActivityStorageException { Identity rootIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "root"); Identity johnIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "john"); // Identity maryIdentity = // identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, // "mary"); // Identity demoIdentity = // identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, // "demo"); Profile rootProfile = rootIdentity.getProfile(); Profile johnProfile = johnIdentity.getProfile(); // Profile maryProfile = maryIdentity.getProfile(); // Profile demoProfile = demoIdentity.getProfile(); final String newFirstName = "New First Name"; rootProfile.setProperty(Profile.FIRST_NAME, newFirstName); identityManager.saveProfile(rootProfile); Identity gotRootIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "root", true); assertNotNull("gotRootIdentity.getId() must not be null", gotRootIdentity.getId()); assertEquals( "gotRootIdentity.getProfile().getProperty(Profile.FIRST_NAME) must be updated: " + newFirstName, newFirstName, gotRootIdentity.getProfile().getProperty(Profile.FIRST_NAME)); try { identityManager.updateAvatar(johnProfile); } catch (Exception e1) { assert false : "can't update avatar" + e1; } Identity gotJohnIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "john"); tearDownIdentityList.add(johnIdentity); tearDownIdentityList.add(rootIdentity); // an activity for avatar created, clean it up here ActivityManager activityManager = (ActivityManager) getContainer().getComponentInstanceOfType(ActivityManager.class); end(); begin(); List<ExoSocialActivity> johnActivityList = activityManager.getActivities(gotJohnIdentity, 0, 10); assertEquals("johnActivityList.size() must be 1", 1, johnActivityList.size()); }
/** Test {@link IdentityManager#updateProfile(Profile)} */ public void testUpdateProfile() throws Exception { Identity rootIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, "root"); Profile profile = rootIdentity.getProfile(); profile.setProperty(Profile.POSITION, "CEO"); identityManager.updateProfile(profile); Identity identityUpdated = identityManager.getOrCreateIdentity( rootIdentity.getProviderId(), rootIdentity.getRemoteId(), false); assertEquals("CEO", identityUpdated.getProfile().getProperty(Profile.POSITION)); end(); begin(); List<ExoSocialActivity> rootActivityList = activityManager.getActivities(rootIdentity); tearDownIdentityList.add(rootIdentity); }
/** Test {@link IdentityManager#getOrCreateIdentity(String, String)} */ public void testGetOrCreateIdentity() { final String username1 = "john"; final String username2 = "root"; Identity gotIdentity1; Identity gotIdentity2; // load profile = true { gotIdentity1 = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username1, true); Profile profile1 = gotIdentity1.getProfile(); assertNotNull("gotIdentity1.getId() must not be null", gotIdentity1.getId()); assertNotNull("profile1.getId() must not be null", profile1.getId()); assertNotNull( "profile1.getProperty(Profile.FIRST_NAME) must not be null", profile1.getProperty(Profile.FIRST_NAME)); assertNotNull( "profile1.getProperty(Profile.LAST_NAME must not be null", profile1.getProperty(Profile.LAST_NAME)); assertFalse( "profile1.getFullName().isEmpty() must return false", profile1.getFullName().isEmpty()); assertNotNull("gotIdentity1.getId() must not be null", gotIdentity1.getId()); Identity regotIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username1, true); assertNotNull("regotIdentity.getId() must not be null", regotIdentity.getId()); assertNotNull( "regotIdentity.getProfile().getId() must not be null", regotIdentity.getProfile().getId()); } // load profile = false { gotIdentity2 = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, username2, false); assertNotNull("gotIdentity2.getId() must not be null", gotIdentity2.getId()); assertNotNull( "gotIdentity2.getProfile().getId() must not be null", gotIdentity2.getProfile().getId()); } ActivityManager activityManager = (ActivityManager) getContainer().getComponentInstanceOfType(ActivityManager.class); assertEquals( "activityManager.getActivities(gotIdentity1).size() must be 0", 0, activityManager.getActivities(gotIdentity1).size()); assertEquals( "activityManager.getActivities(gotIdentity2).size() must be 0", 0, activityManager.getActivities(gotIdentity2).size()); // FIXME hoatle fix the problem of getIdentity from a provider but also // saved on JCR /* * GlobalId globalId1 = new GlobalId(OrganizationIdentityProvider.NAME + * GlobalId.SEPARATOR + username1); GlobalId globalId2 = new * GlobalId(OrganizationIdentityProvider.NAME + GlobalId.SEPARATOR + * username2); * tearDownIdentityList.add(identityManager.getIdentity(globalId1 * .toString())); //identity.getId() = null ???? * tearDownIdentityList.add(identityManager * .getIdentity(globalId2.toString())); //identity.getId() = null ???? */ tearDownIdentityList.add(identityManager.getIdentity(gotIdentity1.getId())); tearDownIdentityList.add(identityManager.getIdentity(gotIdentity2.getId())); }