View Javadoc
1   /*
2    * Copyright (C) 2003-2010 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.social.core.jpa.storage;
18  
19  import com.google.caja.util.Lists;
20  import com.google.caja.util.Maps;
21  import org.exoplatform.commons.utils.ListAccess;
22  import org.exoplatform.services.organization.OrganizationService;
23  import org.exoplatform.services.organization.User;
24  import org.exoplatform.services.organization.UserHandler;
25  import org.exoplatform.services.security.ConversationState;
26  import org.exoplatform.services.security.IdentityRegistry;
27  import org.exoplatform.social.core.identity.model.Identity;
28  import org.exoplatform.social.core.identity.model.Profile;
29  import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
30  import org.exoplatform.social.core.jpa.test.AbstractCoreTest;
31  import org.exoplatform.social.core.manager.IdentityManager;
32  import org.exoplatform.social.core.manager.RelationshipManager;
33  import org.exoplatform.social.core.profile.ProfileFilter;
34  import org.exoplatform.social.core.relationship.model.Relationship;
35  import org.exoplatform.social.core.relationship.model.Relationship.Type;
36  
37  import java.util.ArrayList;
38  import java.util.List;
39  import java.util.Map;
40  import java.util.Map.Entry;
41  
42  /**
43   * Unit Tests for {@link RelationshipManager}
44   *
45   */
46  public class RDBMSRelationshipManagerTest extends AbstractCoreTest {
47    private RelationshipManager relationshipManager;
48    private IdentityManager identityManager;
49  
50    private Identity rootIdentity;
51    private Identity johnIdentity;
52    private Identity maryIdentity;
53    private Identity demoIdentity;
54    private Identity ghostIdentity;
55    private Identity paulIdentity;
56  
57  
58    @Override
59    protected void setUp() throws Exception {
60      super.setUp();
61      relationshipManager = getService(RelationshipManager.class);
62      identityManager = getService(IdentityManager.class);
63      assertNotNull("relationshipManager must not be null", relationshipManager);
64      assertNotNull("identityManager must not be null", identityManager);
65  
66      rootIdentity = createIdentity("root");
67      johnIdentity = createIdentity("john");
68      maryIdentity = createIdentity("mary");
69      demoIdentity = createIdentity("demo");
70      ghostIdentity = createIdentity("ghost");
71      paulIdentity = createIdentity("paul");
72  
73      //
74      org.exoplatform.services.security.Identity identity = getService(IdentityRegistry.class).getIdentity("root");
75      ConversationState.setCurrent(new ConversationState(identity));
76    }
77  
78    @Override
79    protected void tearDown() throws Exception {
80      ConversationState.setCurrent(null);
81      super.tearDown();
82    }
83  
84    /**
85     * Test {@link RelationshipManager#getAll(Identity)}
86     * 
87     * @throws Exception
88     */
89    public void testGetAll() throws Exception {
90      relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
91      List<Relationship> senderRelationships = relationshipManager.getAll(johnIdentity);
92      List<Relationship> receiverRelationships = relationshipManager.getAll(demoIdentity);
93  
94      assertEquals(1, senderRelationships.size());
95      assertEquals(1, receiverRelationships.size());
96    }
97    
98    //TODO : comment this test because the indexing is not available for UT
99    public void TestGetConnectionsByFilter() throws Exception {
100     relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
101     relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
102     relationshipManager.inviteToConnect(rootIdentity, maryIdentity);
103     //
104     relationshipManager.confirm(johnIdentity, demoIdentity);
105     relationshipManager.confirm(johnIdentity, maryIdentity);
106     relationshipManager.confirm(rootIdentity, maryIdentity);
107     
108     ProfileFilter filter = new ProfileFilter();
109     ListAccess<Identity> listAccess = relationshipManager.getConnectionsByFilter(maryIdentity, filter);
110     Identity[] identities = listAccess.load(0, 10);
111     assertEquals(2, identities.length);
112   }
113   
114   public void TestPerfomanceGetConnectionsByFilter() throws Exception {
115     UserHandler handler = getService(OrganizationService.class).getUserHandler();
116     User user;
117     String key = "abc_test";
118 
119     for (int i = 0; i < 100; i++) {
120       user = handler.createUserInstance(key + i);
121       user.setPassword("gtn");
122       user.setEmail(key + i + "@mail.com");
123       user.setFirstName("abc" + " " + i);
124       user.setLastName("gtn");
125       if (i % 5 == 0) {
126         user.setLastName("foo");
127       }
128       handler.createUser(user, true);
129     }
130     //
131     Identity identity;
132     for (int i = 0; i < 100; i++) {
133       identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, key + i, true);
134       relationshipManager.inviteToConnect(demoIdentity, identity);
135       relationshipManager.confirm(identity, demoIdentity);
136     }
137     //
138     ProfileFilter filter = new ProfileFilter();
139     filter.setName("abc");
140     long t = System.currentTimeMillis();
141     ListAccess<Identity> listAccess = relationshipManager.getConnectionsByFilter(demoIdentity, filter);
142     Identity[] identities = listAccess.load(0, 110);
143     LOG.info("Time to load " + identities.length + " identities: " + (System.currentTimeMillis() - t) + "ms");
144     assertEquals(100, identities.length);
145     t = System.currentTimeMillis();
146     filter.setName("foo");
147     listAccess = relationshipManager.getConnectionsByFilter(demoIdentity, filter);
148     identities = listAccess.load(0, 110);
149     LOG.info("Time to load " + identities.length + " identities: " + (System.currentTimeMillis() - t) + "ms");
150     assertEquals(20, identities.length);
151   }
152   
153   /**
154    * Test {@link RelationshipManager#getAll(Identity, List)}
155    * 
156    * @throws Exception
157    * @since 1.2.0-Beta3
158    */
159   public void testGetAllWithListIdentities() throws Exception {
160     List<Identity> listIdentities = new ArrayList<Identity>();
161     listIdentities.add(rootIdentity);
162     listIdentities.add(demoIdentity);
163     listIdentities.add(johnIdentity);
164     listIdentities.add(maryIdentity);
165     
166     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
167     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
168     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
169     
170     List<Relationship> rootRelationships = relationshipManager.getAll(rootIdentity, listIdentities);
171     assertNotNull("rootRelationships must not be null", rootRelationships);
172     assertEquals("rootRelationships.size() must return: 3", 3, rootRelationships.size());
173     
174     List<Relationship> maryRelationships = relationshipManager.getAll(maryIdentity, listIdentities);
175     assertNotNull("maryRelationships must not be null", maryRelationships);
176     assertEquals("maryRelationships.size() mut return: 1", 1, maryRelationships.size());
177     
178     List<Relationship> johnRelationships = relationshipManager.getAll(johnIdentity, listIdentities);
179     assertNotNull("johnRelationships must not be null", johnRelationships);
180     assertEquals("johnRelationships.size() mut return: 1", 1, johnRelationships.size());
181   }
182   
183   /**
184    * Test {@link RelationshipManager#getAll(Identity, Type, List)}
185    * 
186    * @throws Exception
187    * @since 1.2.0-Beta3
188    */
189   public void testGetAllWithTypeAndListIdentities() throws Exception {
190     List<Identity> listIdentities = new ArrayList<Identity>();
191     listIdentities.add(rootIdentity);
192     listIdentities.add(demoIdentity);
193     listIdentities.add(johnIdentity);
194     listIdentities.add(maryIdentity);
195 
196     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
197     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
198     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
199 
200     List<Relationship> rootPendingRelationships = relationshipManager.getAll(rootIdentity, Relationship.Type.PENDING, listIdentities);
201     assertNotNull("rootPendingRelationships must not be null", rootPendingRelationships);
202     assertEquals("rootPendingRelationships.size() must return: 3", 3, rootPendingRelationships.size());
203     
204     List<Relationship> maryPendingRelationships = relationshipManager.getAll(maryIdentity, Relationship.Type.PENDING, listIdentities);
205     assertNotNull("maryPendingRelationships must not be null", maryPendingRelationships);
206     assertEquals("maryPendingRelationships.size() mut return: 1", 1, maryPendingRelationships.size());
207     
208     List<Relationship> johnPendingRelationships = relationshipManager.getAll(maryIdentity, Relationship.Type.PENDING, listIdentities);
209     assertNotNull("johnPendingRelationships must not be null", johnPendingRelationships);
210     assertEquals("johnPendingRelationships.size() mut return: 1", 1, johnPendingRelationships.size());
211     
212     relationshipManager.confirm(demoIdentity, rootIdentity);
213     
214     List<Relationship> rootConfirmedRelationships = relationshipManager.getAll(rootIdentity, Relationship.Type.CONFIRMED, listIdentities);
215     assertNotNull("rootConfirmedRelationships must not be null", rootConfirmedRelationships);
216     assertEquals("rootConfirmedRelationships.size() must return: 1", 1, rootConfirmedRelationships.size());
217     
218   }
219   
220   /**
221    * Test {@link RelationshipManager#get(Identity, Identity)}
222    * 
223    * @throws Exception
224    * @since 1.2.0-Beta3
225    */
226   public void testGet() throws Exception {
227     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
228     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
229     
230     rootToDemoRelationship = relationshipManager.get(rootIdentity, demoIdentity);
231     assertNotNull("rootToDemoRelationship must not be null", rootToDemoRelationship);
232     assertEquals("rootToDemoRelationship.getSender() must return: " + rootIdentity, rootIdentity, rootToDemoRelationship.getSender());
233     assertEquals("rootToDemoRelationship.getReceiver() must return: " + demoIdentity, demoIdentity, rootToDemoRelationship.getReceiver());
234     assertEquals("rootToDemoRelationship.getStatus() must return: " + Relationship.Type.PENDING, 
235                  Relationship.Type.PENDING, rootToDemoRelationship.getStatus());
236     
237     relationshipManager.confirm(johnIdentity, rootIdentity);
238     rootToJohnRelationship = relationshipManager.get(johnIdentity, rootIdentity);
239     assertEquals("rootToJohnRelationship.getStatus() must return: ", Relationship.Type.CONFIRMED, 
240                  rootToJohnRelationship.getStatus());
241     
242   }
243   
244   /**
245    * Test {@link RelationshipManager#get(String)}
246    * 
247    * @throws Exception
248    * @since 1.2.0-Beta3
249    */
250   public void testGetWithRelationshipId() throws Exception {
251     Relationship relationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
252     String relationshipId = relationship.getId();
253     
254     relationshipManager.confirm(johnIdentity, rootIdentity);
255     relationship = relationshipManager.get(relationship.getId());
256     assertNotNull("relationship must not be null", relationship);
257     assertEquals("relationship.getStatus() must return: " + Relationship.Type.CONFIRMED, Relationship.Type.CONFIRMED, relationship.getStatus());
258     
259     relationshipManager.delete(relationship);
260 
261     relationship = relationshipManager.get(rootIdentity, johnIdentity);
262     assertNull("relationship must be null", relationship);
263     
264     relationship = relationshipManager.get(relationshipId);
265     assertNull("relationship must be null", relationship);
266   }
267   
268   /**
269    * Test {@link RelationshipManager#update(Relationship)}
270    * 
271    * @throws Exception
272    * @since 1.2.0-Beta3
273    */
274   public void testUpdate() throws Exception {
275     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
276     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
277     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
278     
279     assertEquals("rootToDemoRelationship.getStatus() must return: " + Relationship.Type.PENDING,
280                  Relationship.Type.PENDING, rootToDemoRelationship.getStatus());
281     rootToDemoRelationship.setStatus(Relationship.Type.CONFIRMED);
282     relationshipManager.update(rootToDemoRelationship);
283     rootToDemoRelationship = relationshipManager.get(rootIdentity, demoIdentity);
284     assertEquals("rootToDemoRelationship.getStatus() must return: " + Relationship.Type.CONFIRMED,
285                  Relationship.Type.CONFIRMED, rootToDemoRelationship.getStatus());
286     
287     assertEquals("maryToRootRelationship.getStatus() must return: " + Relationship.Type.PENDING,
288                  Relationship.Type.PENDING, maryToRootRelationship.getStatus());
289     
290   }
291   
292   /**
293    * Test {@link RelationshipManager#inviteToConnect(Identity, Identity)}
294    * 
295    * @throws Exception
296    * @since 1.2.0-Beta3
297    */
298   public void testInviteToConnect() throws Exception {
299     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
300     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
301     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
302     
303     rootToDemoRelationship = relationshipManager.get(rootIdentity, demoIdentity);
304     assertNotNull("rootToDemoRelationship must not be null", rootToDemoRelationship);
305     assertEquals("rootToDemoRelationship.getStatus() must return: " + Relationship.Type.PENDING,
306                  Relationship.Type.PENDING, rootToDemoRelationship.getStatus());
307     
308     maryToRootRelationship = relationshipManager.get(maryIdentity, rootIdentity);
309     assertNotNull("maryToRootRelationship must not be null", maryToRootRelationship);
310     assertEquals("maryToRootRelationship.getStatus() must return: " + Relationship.Type.PENDING,
311                  Relationship.Type.PENDING, maryToRootRelationship.getStatus());
312     
313     rootToJohnRelationship = relationshipManager.get(johnIdentity, rootIdentity);
314     assertNotNull("rootToJohnRelationship must not be null", rootToJohnRelationship);
315     assertEquals("rootToJohnRelationship.getStatus() must return: " + Relationship.Type.PENDING,
316                  Relationship.Type.PENDING, rootToJohnRelationship.getStatus());
317     
318   }
319   
320   /**
321    * Test {@link RelationshipManager#inviteToConnect(Identity, Identity)}
322    *
323    * @throws Exception
324    * @since 1.2.0-Beta3
325   */
326   public void testDupdicateInviteToConnect() throws Exception {
327     Relationship relationship1 = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
328     Relationship relationship2 = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
329     assertEquals("relationShip1 and relationShip2 must be the same",relationship1.getId(), relationship2.getId());
330   }
331   
332   /**
333    * Test {@link RelationshipManager#inviteToConnect(Identity, Identity)}
334    *
335    * @throws Exception
336    * @since 1.2.0-Beta3
337    */
338   public void testDupdicateInviteToConnectWithConfirmedRelationShip() throws Exception {
339     Relationship relationship1 = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
340     assertEquals("RelationShip status must be PENDING",Relationship.Type.PENDING, relationship1.getStatus());
341     relationshipManager.confirm(rootIdentity, demoIdentity);
342     relationship1 = relationshipManager.get(rootIdentity, demoIdentity);
343     assertEquals("RelationShip status must be CONFIRMED",Relationship.Type.CONFIRMED, relationship1.getStatus());
344     Relationship relationship2 = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
345     assertEquals("RelationShip status must be CONFIRMED",Relationship.Type.CONFIRMED, relationship2.getStatus());
346     
347     assertEquals("relationShip1 and relationShip2 must be the same",relationship1.getId(), relationship2.getId());
348     
349   }
350   
351   /**
352    * Test {@link RelationshipManager#confirm(Identity, Identity)}
353    * 
354    * @throws Exception
355    * @since 1.2.0-Beta3
356    */
357   public void testConfirmWithIdentity() throws Exception {
358     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
359     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
360     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
361     
362     rootToJohnRelationship = relationshipManager.get(rootToJohnRelationship.getId());
363     
364     relationshipManager.confirm(rootIdentity, demoIdentity);
365     rootToDemoRelationship = relationshipManager.get(rootIdentity, demoIdentity);
366     assertNotNull("rootToDemoRelationship must not be null", rootToDemoRelationship);
367     assertEquals("rootToDemoRelationship.getStatus() must return: " + Relationship.Type.CONFIRMED,
368                  Relationship.Type.CONFIRMED, rootToDemoRelationship.getStatus());
369     
370     relationshipManager.confirm(maryIdentity, rootIdentity);
371     maryToRootRelationship = relationshipManager.get(maryIdentity, rootIdentity);
372     assertNotNull("maryToRootRelationship must not be null", maryToRootRelationship);
373     assertEquals("maryToRootRelationship.getStatus() must return: " + Relationship.Type.CONFIRMED,
374                  Relationship.Type.CONFIRMED, maryToRootRelationship.getStatus());
375     
376     relationshipManager.confirm(rootIdentity, johnIdentity);
377     rootToJohnRelationship = relationshipManager.get(johnIdentity, rootIdentity);
378     assertNotNull("rootToJohnRelationship must not be null", rootToJohnRelationship);
379     assertEquals("rootToJohnRelationship.getStatus() must return: " + Relationship.Type.CONFIRMED,
380                  Relationship.Type.CONFIRMED, rootToJohnRelationship.getStatus());
381     
382   }
383   
384   /**
385    * Test {@link RelationshipManager#deny(Identity, Identity)}
386    * 
387    * @throws Exception
388    * @since 1.2.0-Beta3
389    */
390   public void testDeny() throws Exception {
391     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
392     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
393     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
394 
395     relationshipManager.confirm(johnIdentity, rootIdentity);
396     relationshipManager.deny(johnIdentity, rootIdentity);
397     assertNull(relationshipManager.get(rootToJohnRelationship.getId()));
398 
399     relationshipManager.deny(demoIdentity, rootIdentity);
400     rootToDemoRelationship = relationshipManager.get(rootIdentity, demoIdentity);
401     assertNull("rootToDemoRelationship must be null", rootToDemoRelationship);
402 
403     relationshipManager.deny(maryIdentity, rootIdentity);
404     maryToRootRelationship = relationshipManager.get(maryIdentity, rootIdentity);
405     assertNull("maryToRootRelationship must be null", maryToRootRelationship);
406 
407     relationshipManager.deny(rootIdentity, johnIdentity);
408     rootToJohnRelationship = relationshipManager.get(rootIdentity, johnIdentity);
409     assertNull("rootToJohnRelationship must be null", rootToJohnRelationship);
410   }
411   
412   /**
413    * Test {@link RelationshipManager#ignore(Identity, Identity)}
414    * 
415    * @throws Exception
416    * @since 1.2.0-Beta3
417    */
418   public void testIgnore() throws Exception {
419     Relationship relationship = relationshipManager.get(rootIdentity, demoIdentity);
420     assertNull(relationship);
421 
422     //
423     relationshipManager.ignore(rootIdentity, demoIdentity);
424     relationship = relationshipManager.get(rootIdentity, demoIdentity);
425     assertNotNull(relationship);
426     assertEquals(rootIdentity, relationship.getSender());
427     assertEquals(demoIdentity, relationship.getReceiver());
428     assertEquals(Relationship.Type.IGNORED, relationship.getStatus());
429 
430     relationship = relationshipManager.get(demoIdentity, rootIdentity);
431     assertNotNull(relationship);
432     assertEquals(rootIdentity, relationship.getSender());
433     assertEquals(demoIdentity, relationship.getReceiver());
434     assertEquals(Relationship.Type.IGNORED, relationship.getStatus());
435 
436     //
437     relationshipManager.ignore(demoIdentity, rootIdentity);
438     relationship = relationshipManager.get(demoIdentity, rootIdentity);
439     assertNotNull(relationship);
440     assertEquals(rootIdentity, relationship.getSender());
441     assertEquals(demoIdentity, relationship.getReceiver());
442     assertEquals(Relationship.Type.IGNORED, relationship.getStatus());
443 
444     relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
445     relationship = relationshipManager.get(rootIdentity, demoIdentity);
446     assertNotNull(relationship);
447     assertEquals(Relationship.Type.PENDING, relationship.getStatus());
448 
449     // Second ignore will not make any exception.
450     relationshipManager.deny(rootIdentity, demoIdentity);
451     relationship = relationshipManager.get(rootIdentity, demoIdentity);
452     assertNull(relationship);
453 
454     relationshipManager.ignore(rootIdentity, demoIdentity);
455     relationship = relationshipManager.get(rootIdentity, demoIdentity);
456     assertNotNull(relationship);
457     assertEquals(Relationship.Type.IGNORED, relationship.getStatus());
458   }
459   
460   /**
461    * Test {@link RelationshipManager#getIncomingWithListAccess(Identity)}
462    * 
463    * @throws Exception
464    * @since 1.2.0-Beta3
465    */
466   public void testGetIncomingWithListAccess() throws Exception {
467     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
468     Relationship maryToDemoRelationship = relationshipManager.inviteToConnect(maryIdentity, demoIdentity);
469     Relationship johnToDemoRelationship = relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
470     
471     ListAccess<Identity> demoIncoming = relationshipManager.getIncomingWithListAccess(demoIdentity);
472     assertNotNull("demoIncoming must not be null", demoIncoming);
473     assertEquals("demoIncoming.getSize() must return: 3", 3, demoIncoming.getSize());
474     
475     for (Identity identity : demoIncoming.load(0, 10)) {
476       assertNotNull("identity.getProfile() must not be null", identity.getProfile());
477       Identity identityLoadProfile = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, identity.getRemoteId(), true);
478       assertEquals("identity.getProfile().getFullName() must return: " + identityLoadProfile.getProfile().getFullName(),
479                    identityLoadProfile.getProfile().getFullName(), identity.getProfile().getFullName());
480     }
481     
482     ListAccess<Identity> rootIncoming = relationshipManager.getIncomingWithListAccess(rootIdentity);
483     assertNotNull("rootIncoming must not be null", rootIncoming);
484     assertEquals("rootIncoming.getSize() must return: 0", 0, rootIncoming.getSize());
485     
486     ListAccess<Identity> maryIncoming = relationshipManager.getIncomingWithListAccess(maryIdentity);
487     assertNotNull("maryIncoming must not be null", maryIncoming);
488     assertEquals("maryIncoming.getSize() must return: 0", 0, maryIncoming.getSize());
489     
490   }
491   
492   /**
493    * Test {@link RelationshipManager#getOutgoing(Identity)}
494    * 
495    * @throws Exception
496    * @since 1.2.0-Beta3
497    */
498   public void testGetOutgoing() throws Exception {
499     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
500     Relationship rootToMaryRelationship = relationshipManager.inviteToConnect(rootIdentity, maryIdentity);
501     Relationship maryToDemoRelationship = relationshipManager.inviteToConnect(maryIdentity, demoIdentity);
502     Relationship demoToJohnRelationship = relationshipManager.inviteToConnect(demoIdentity, johnIdentity);
503     
504     ListAccess<Identity> rootOutgoing = relationshipManager.getOutgoing(rootIdentity);
505     assertNotNull("rootOutgoing must not be null", rootOutgoing);
506     assertEquals("rootOutgoing.getSize() must return: 2", 2, rootOutgoing.getSize());
507     
508     for (Identity identity : rootOutgoing.load(0, 10)) {
509       Identity identityLoadProfile = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, identity.getRemoteId(), true);
510       assertNotNull("identity.getProfile() must not be nul", identity.getProfile());
511       assertNotNull("temp must not be null", identityLoadProfile);
512       assertEquals("identity.getProfile().getFullName() must return: " + identityLoadProfile.getProfile().getFullName(), 
513                    identityLoadProfile.getProfile().getFullName(), 
514                    identity.getProfile().getFullName());
515     }
516     
517     ListAccess<Identity> maryOutgoing = relationshipManager.getOutgoing(maryIdentity);
518     assertNotNull("maryOutgoing must not be null", maryOutgoing);
519     assertEquals("maryOutgoing.getSize() must return: 1", 1, maryOutgoing.getSize());
520     
521     ListAccess<Identity> demoOutgoing = relationshipManager.getOutgoing(demoIdentity);
522     assertNotNull("demoOutgoing must not be null", demoOutgoing);
523     assertEquals("demoOutgoing.getSize() must return: 1", 1, demoOutgoing.getSize());
524     
525   }
526   
527   /**
528    * Test {@link RelationshipManager#getStatus(Identity, Identity)}
529    * 
530    * @throws Exception
531    * @since 1.2.0-Beta3
532    */
533   public void testGetStatus() throws Exception {
534     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
535     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
536     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
537     
538     rootToDemoRelationship = relationshipManager.get(rootIdentity, demoIdentity);
539     assertNotNull("rootToDemoRelationship must not be null", rootToDemoRelationship);
540     assertEquals("rootToDemoRelationship.getStatus() must return: " + Relationship.Type.PENDING,
541                  Relationship.Type.PENDING, rootToDemoRelationship.getStatus());
542     assertEquals("relationshipManager.getStatus(rootIdentity, demoIdentity) must return: " + 
543                  Relationship.Type.PENDING, Relationship.Type.PENDING, 
544                  relationshipManager.getStatus(rootIdentity, demoIdentity));
545     
546     maryToRootRelationship = relationshipManager.get(maryIdentity, rootIdentity);
547     assertNotNull("maryToRootRelationship must not be null", maryToRootRelationship);
548     assertEquals("maryToRootRelationship.getStatus() must return: " + Relationship.Type.PENDING,
549                  Relationship.Type.PENDING, maryToRootRelationship.getStatus());
550     assertEquals("relationshipManager.getStatus(maryIdentity, rootIdentity) must return: " + 
551                  Relationship.Type.PENDING, Relationship.Type.PENDING,
552                  relationshipManager.getStatus(maryIdentity, rootIdentity));
553     
554     rootToJohnRelationship = relationshipManager.get(johnIdentity, rootIdentity);
555     assertNotNull("rootToJohnRelationship must not be null", rootToJohnRelationship);
556     assertEquals("rootToJohnRelationship.getStatus() must return: " + Relationship.Type.PENDING,
557                  Relationship.Type.PENDING, rootToJohnRelationship.getStatus());
558     assertEquals("relationshipManager.getStatus(rootIdentity, johnIdentity) must return: " +
559                  Relationship.Type.PENDING, Relationship.Type.PENDING,
560                  relationshipManager.getStatus(rootIdentity, johnIdentity));
561     
562   }
563   
564   /**
565    * Test {@link RelationshipManager#getAllWithListAccess(Identity)}
566    * 
567    * @throws Exception
568    * @since 1.2.0-Beta3
569    */
570   public void testGetAllWithListAccess() throws Exception {
571     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
572     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
573     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
574     
575     ListAccess<Identity> rootRelationships = relationshipManager.getAllWithListAccess(rootIdentity);
576     assertNotNull("rootRelationships must not be null", rootRelationships);
577     assertEquals("rootRelationships.getSize() must return: 3", 3, rootRelationships.getSize());
578     
579     ListAccess<Identity> demoRelationships = relationshipManager.getAllWithListAccess(demoIdentity);
580     assertNotNull("demoRelationships must not be null", demoRelationships);
581     assertEquals("demoRelationships.getSize() must return: 1", 1, demoRelationships.getSize());
582     
583     ListAccess<Identity> johnRelationships = relationshipManager.getAllWithListAccess(johnIdentity);
584     assertNotNull("johnRelationships must not be null", johnRelationships);
585     assertEquals("johnRelationships.getSize() must return: 1", 1, johnRelationships.getSize());
586     
587   }
588   
589   /**
590    * Test {@link RelationshipManager#getRelationshipById(String)}
591    * 
592    * @throws Exception
593    * @since 1.2.0-Beta3
594    */
595   public void testGetRelationshipById() throws Exception {
596     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
597     
598     rootToDemoRelationship = relationshipManager.get(rootToDemoRelationship.getId());
599     assertNotNull("rootToDemoRelationship must not be null", rootToDemoRelationship);
600     assertEquals("rootToDemoRelationship.getSender() must return: " + rootIdentity, rootIdentity, rootToDemoRelationship.getSender());
601     assertEquals("rootToDemoRelationship.getReceiver() must return: " + demoIdentity, demoIdentity, rootToDemoRelationship.getReceiver());
602     
603   }
604   
605   /**
606    * Test {@link RelationshipManager#deny(Relationship)}
607    * 
608    * @throws Exception
609    * @since 1.2.0-Beta3
610    */
611   public void testDenyWithRelationship() throws Exception {
612     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
613     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
614     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
615     
616     relationshipManager.deny(rootToDemoRelationship);
617     rootToDemoRelationship = relationshipManager.get(rootIdentity, demoIdentity);
618     assertNull("rootToDemoRelationship must be null", rootToDemoRelationship);
619     
620     relationshipManager.deny(maryToRootRelationship);
621     maryToRootRelationship = relationshipManager.get(maryIdentity, rootIdentity);
622     assertNull("maryToRootRelationship must be null", maryToRootRelationship);
623     
624     relationshipManager.deny(rootToJohnRelationship);
625     rootToJohnRelationship = relationshipManager.get(rootIdentity, johnIdentity);
626     assertNull("rootToJohnRelationship must be null", rootToJohnRelationship);
627   }
628 
629   
630   /**
631    * Test {@link RelationshipManager#getPendingRelationships(Identity)}
632    * 
633    * @throws Exception
634    * @since 1.2.0-Beta3
635    */
636   public void testGetPendingRelationships() throws Exception {
637     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
638     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
639     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
640     
641     List<Relationship> rootPendingRelationships = relationshipManager.getPendingRelationships(rootIdentity);
642     assertNotNull("rootPendingRelationships must not be null", rootPendingRelationships);
643     assertEquals("rootPendingRelationships.size() must return: 2", 2, rootPendingRelationships.size());
644     
645     List<Relationship> maryPendingRelationships = relationshipManager.getPendingRelationships(maryIdentity);
646     assertNotNull("maryPendingRelationships must not be null", maryPendingRelationships);
647     assertEquals("maryPendingRelationships.size() must return: 1", 1, maryPendingRelationships.size());
648     
649     List<Relationship> demoPendingRelationships = relationshipManager.getPendingRelationships(demoIdentity);
650     assertNotNull("demoPendingRelationships must not be null", demoPendingRelationships);
651     assertEquals("demoPendingRelationships.size() must return: 0", 0, demoPendingRelationships.size());
652     
653     List<Relationship> johnPendingRelationships = relationshipManager.getPendingRelationships(johnIdentity);
654     assertNotNull("johnPendingRelationships must not be null", johnPendingRelationships);
655     assertEquals("johnPendingRelationships.size() must return: 0", 0, johnPendingRelationships.size());
656     
657   }
658   
659   /**
660    * Test {@link RelationshipManager#getPendingRelationships(Identity, boolean)}
661    * 
662    * @throws Exception
663    * @since 1.2.0-Beta3
664    */
665   public void testGetPendingRelationshipWithSentOrReceived() throws Exception {
666     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
667     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
668     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
669     
670     List<Relationship> rootPendingRelationships = relationshipManager.getPendingRelationships(rootIdentity, true);
671     assertNotNull("rootPendingRelationships must not be null", rootPendingRelationships);
672     assertEquals("rootPendingRelationships.size() must return: 3", 3, rootPendingRelationships.size());
673     
674     List<Relationship> maryPendingRelationships = relationshipManager.getPendingRelationships(maryIdentity, true);
675     assertNotNull("maryPendingRelationships must not be null", maryPendingRelationships);
676     assertEquals("maryPendingRelationships.size() must return: 1", 1, maryPendingRelationships.size());
677     
678     List<Relationship> demoPendingRelationships = relationshipManager.getPendingRelationships(demoIdentity, true);
679     assertNotNull("demoPendingRelationships must not be null", demoPendingRelationships);
680     assertEquals("demoPendingRelationships.size() must return: 1", 1, demoPendingRelationships.size());
681     
682     List<Relationship> johnPendingRelationships = relationshipManager.getPendingRelationships(johnIdentity, true);
683     assertNotNull("johnPendingRelationships must not be null", johnPendingRelationships);
684     assertEquals("johnPendingRelationships.size() must return: 1", 1, johnPendingRelationships.size());
685     
686   }
687   
688   /**
689    * Test {@link RelationshipManager#getPendingRelationships(Identity, List, boolean)}
690    * 
691    * @throws Exception
692    * @since 1.2.0-Beta3
693    */
694   public void testGetPendingRealtionshipWithListIdentities() throws Exception {
695     List<Identity> identities = new ArrayList<Identity> ();
696     identities.add(rootIdentity);
697     identities.add(demoIdentity);
698     identities.add(johnIdentity);
699     identities.add(maryIdentity);
700     
701     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
702     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
703     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
704     
705     List<Relationship> rootPendingRelationships = relationshipManager.getPendingRelationships(rootIdentity, identities, true);
706     assertNotNull("rootPendingRelationships must not be null", rootPendingRelationships);
707     assertEquals("rootPendingRelationships.size() must return: 3", 3, rootPendingRelationships.size());
708     
709     List<Relationship> maryPendingRelationships = relationshipManager.getPendingRelationships(maryIdentity, identities, true);
710     assertNotNull("maryPendingRelationships must not be null", maryPendingRelationships);
711     assertEquals("maryPendingRelationships.size() must return: 1", 1, maryPendingRelationships.size());
712     
713     List<Relationship> demoPendingRelationships = relationshipManager.getPendingRelationships(demoIdentity, identities, true);
714     assertNotNull("demoPendingRelationships must not be null", demoPendingRelationships);
715     assertEquals("demoPendingRelationships.size() must return: 1", 1, demoPendingRelationships.size());
716     
717     List<Relationship> johnPendingRelationships = relationshipManager.getPendingRelationships(johnIdentity, identities, true);
718     assertNotNull("johnPendingRelationships must not be null", johnPendingRelationships);
719     assertEquals("johnPendingRelationships.size() must return: 1", 1, johnPendingRelationships.size());
720     
721   }
722   
723   /**
724    * Test {@link RelationshipManager#getContacts(Identity, List)}
725    * 
726    * @throws Exception
727    * @since 1.2.0-Beta3
728    */
729   public void testGetContactsWithListIdentities() throws Exception {
730     List<Identity> identities = new ArrayList<Identity> ();
731     identities.add(rootIdentity);
732     identities.add(demoIdentity);
733     identities.add(johnIdentity);
734     identities.add(maryIdentity);
735     
736     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
737     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
738     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
739     
740     relationshipManager.confirm(rootIdentity, demoIdentity);
741     relationshipManager.confirm(maryIdentity, rootIdentity);
742     relationshipManager.confirm(rootIdentity, johnIdentity);
743     
744     List<Relationship> rootContacts = relationshipManager.getContacts(rootIdentity, identities);
745     assertNotNull("rootContacts must not be null", rootContacts);
746     assertEquals("rootContacts.size() must return: 3", 3, rootContacts.size());
747     
748     List<Relationship> demoContacts = relationshipManager.getContacts(demoIdentity, identities);
749     assertNotNull("demoContacts must not be null", demoContacts);
750     assertEquals("demoContacts.size() must return: 1", 1, demoContacts.size());
751     
752     List<Relationship> maryContacts = relationshipManager.getContacts(maryIdentity, identities);
753     assertNotNull("maryContacts must not be null", maryContacts);
754     assertEquals("maryContacts.size() must return: 1", 1, maryContacts.size());
755     
756     List<Relationship> johnContacts = relationshipManager.getContacts(johnIdentity, identities);
757     assertNotNull("johnContacts must not be null", johnContacts);
758     assertEquals("johnContacts.size() must return: 1", 1, johnContacts.size());
759     
760   }
761   
762   /**
763    * Test {@link RelationshipManager#getContacts(Identity)}
764    * 
765    * @throws Exception
766    * @since 1.2.0-Beta3
767    */
768   public void testGetContacts() throws Exception {
769     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
770     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
771     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
772     
773     relationshipManager.confirm(rootIdentity, demoIdentity);
774     relationshipManager.confirm(maryIdentity, rootIdentity);
775     relationshipManager.confirm(rootIdentity, johnIdentity);
776     
777     List<Relationship> rootContacts = relationshipManager.getContacts(rootIdentity);
778     assertNotNull("rootContacts must not be null", rootContacts);
779     assertEquals("rootContacts.size() must return: 3", 3, rootContacts.size());
780     
781     List<Relationship> demoContacts = relationshipManager.getContacts(demoIdentity);
782     assertNotNull("demoContacts must not be null", demoContacts);
783     assertEquals("demoContacts.size() must return: 1", 1, demoContacts.size());
784     
785     List<Relationship> maryContacts = relationshipManager.getContacts(maryIdentity);
786     assertNotNull("maryContacts must not be null", maryContacts);
787     assertEquals("maryContacts.size() must return: 1", 1, maryContacts.size());
788     
789     List<Relationship> johnContacts = relationshipManager.getContacts(johnIdentity);
790     assertNotNull("johnContacts must not be null", johnContacts);
791     assertEquals("johnContacts.size() must return: 1", 1, johnContacts.size());
792     
793   }
794   
795   /**
796    * Test {@link RelationshipManager#getAllRelationships(Identity)}
797    * 
798    * @throws Exception
799    * @since 1.2.0-Beta3
800    */
801   public void testGetAllRelationships() throws Exception {
802     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
803     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
804     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
805     
806     List<Relationship> rootRelationships = relationshipManager.getAllRelationships(rootIdentity);
807     assertNotNull("rootRelationships must not be null", rootRelationships);
808     assertEquals("rootRelationships.size() must return: 3", 3, rootRelationships.size());
809     
810     List<Relationship> maryRelationships = relationshipManager.getAllRelationships(maryIdentity);
811     assertNotNull("maryRelationships must not be null", maryRelationships);
812     assertEquals("maryRelationships.size() must return: 1", 1, maryRelationships.size());
813     
814     List<Relationship> demoRelationships = relationshipManager.getAllRelationships(demoIdentity);
815     assertNotNull("demoRelationships must not be null", demoRelationships);
816     assertEquals("demoRelationships.size() must return: 1", 1, demoRelationships.size());
817     
818     List<Relationship> johnRelationships = relationshipManager.getAllRelationships(johnIdentity);
819     assertNotNull("johnRelationships must not be null", johnRelationships);
820     assertEquals("johnRelationships.size() must return: 1", 1, johnRelationships.size());
821     
822   }
823   
824   /**
825    * Test {@link RelationshipManager#getRelationshipsByIdentityId(String)}
826    * 
827    * @throws Exception
828    * @since 1.2.0-Beta3
829    */
830   public void testGetRelationshipsByIdentityId() throws Exception {
831     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
832     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
833     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
834     
835     List<Relationship> rootRelationships = relationshipManager.getRelationshipsByIdentityId(rootIdentity.getId());
836     assertNotNull("rootRelationships must not be null", rootRelationships);
837     assertEquals("rootRelationships.size() must return: 3", 3, rootRelationships.size());
838     
839   }
840   
841   /**
842    * Test {@link RelationshipManager#getIdentities(Identity)}
843    * 
844    * @throws Exception
845    * @since 1.2.0-Beta3
846    */
847   public void testGetIdentities() throws Exception {
848     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
849     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
850     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
851     
852     relationshipManager.confirm(rootIdentity, demoIdentity);
853     relationshipManager.confirm(maryIdentity, rootIdentity);
854     relationshipManager.confirm(rootIdentity, johnIdentity);
855     
856     List<Identity> rootConnections = relationshipManager.getIdentities(rootIdentity);
857     assertNotNull("rootConnections must not be null", rootConnections);
858     assertEquals("rootConnections.size() must return: 3", 3, rootConnections.size());
859     
860   }
861   
862   /**
863    * Test {@link RelationshipManager#create(Identity, Identity)}
864    * 
865    * @throws Exception
866    * @since 1.2.0-Beta3
867    */
868   public void testCreate() throws Exception {
869     Relationship demoToJohnRelationship = relationshipManager.create(demoIdentity, johnIdentity);
870     assertNotNull("demoToJohnRelationship must not be null", demoToJohnRelationship);
871     assertEquals("demoToJohnRelationship.getSender() must return: " + demoIdentity, demoIdentity, demoToJohnRelationship.getSender());
872     assertEquals("demoToJohnRelationship.getReceiver() must return: " + johnIdentity, johnIdentity, demoToJohnRelationship.getReceiver());
873     assertEquals("demoToJohnRelationship.getStatus() must return: " + Relationship.Type.PENDING, Relationship.Type.PENDING, demoToJohnRelationship.getStatus());
874   }
875   
876   /**
877    * Test {@link RelationshipManager#getRelationship(Identity, Identity)}
878    * 
879    * @throws Exception
880    * @since 1.2.0-Beta3
881    */
882   public void testGetRelationship() throws Exception {
883     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
884     
885     rootToDemoRelationship = relationshipManager.getRelationship(rootIdentity, demoIdentity);
886     assertNotNull("rootToDemoRelationship must not be null", rootToDemoRelationship);
887     assertEquals("rootToDemoRelationship.getStatus() must return: " + Relationship.Type.PENDING, Relationship.Type.PENDING, rootToDemoRelationship.getStatus());
888     
889     relationshipManager.confirm(rootIdentity, demoIdentity);
890     
891     rootToDemoRelationship = relationshipManager.getRelationship(rootIdentity, demoIdentity);
892     assertNotNull("rootToDemoRelationship must not be null", rootToDemoRelationship);
893     assertEquals("rootToDemoRelationship.getStatus() must return: " + Relationship.Type.CONFIRMED, Relationship.Type.CONFIRMED, rootToDemoRelationship.getStatus());
894     
895   }
896   
897   /**
898    * Test {@link RelationshipManager#findRelationships(Identity, Type)}
899    * 
900    * @throws Exception
901    * @since 1.2.0-Beta3
902    */
903   public void testFindRelationships() throws Exception {
904     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
905     Relationship maryToRootRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
906     Relationship rootToJohnRelationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
907     
908     List<Identity> rootRelationships = relationshipManager.findRelationships(rootIdentity, Relationship.Type.PENDING);
909     assertNotNull("rootRelationships must not be null", rootRelationships);
910     assertEquals("rootRelationships.size() must return: 3", 3, rootRelationships.size());
911     
912     relationshipManager.confirm(rootIdentity, demoIdentity);
913     
914     rootRelationships = relationshipManager.findRelationships(rootIdentity, Relationship.Type.CONFIRMED);
915     assertNotNull("rootRelationships must not be null", rootRelationships);
916     assertEquals("rootRelationships.size() must return: 1", 1, rootRelationships.size());
917     
918   }
919   
920   /**
921    * Test {@link RelationshipManager#getRelationshipStatus(Relationship, Identity)}
922    * 
923    * @throws Exception
924    * @since 1.2.0-Beta3
925    */
926   public void testGetRelationshipStatus() throws Exception {
927     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
928     assertEquals("relationshipManager.getRelationshipStatus(rootToDemoRelationship, rootIdentity) must return: "
929                  + Relationship.Type.PENDING, Relationship.Type.PENDING
930                  , relationshipManager.getRelationshipStatus(rootToDemoRelationship, rootIdentity));
931     
932     relationshipManager.confirm(rootIdentity, demoIdentity);
933     rootToDemoRelationship = relationshipManager.get(rootIdentity, demoIdentity);
934     assertEquals("relationshipManager.getRelationshipStatus(rootToDemoRelationship, rootIdentity) must return: "
935                  + Relationship.Type.PENDING, Relationship.Type.CONFIRMED
936                  , relationshipManager.getRelationshipStatus(rootToDemoRelationship, rootIdentity));
937     
938   }
939   
940   /**
941    * Test {@link RelationshipManager#getConnectionStatus(Identity, Identity)}
942    * 
943    * @throws Exception
944    * @since 1.2.0-Beta3
945    */
946   public void testGetConnectionStatus() throws Exception {
947     Relationship rootToDemoRelationship = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
948     
949     assertEquals("relationshipManager.getConnectionStatus(rootIdentity, demoIdentity) must return: " + 
950                  Relationship.Type.PENDING, Relationship.Type.PENDING, 
951                  relationshipManager.getConnectionStatus(rootIdentity, demoIdentity));
952     
953     relationshipManager.confirm(rootIdentity, demoIdentity);
954     assertEquals("relationshipManager.getConnectionStatus(rootIdentity, demoIdentity) must return: " + 
955                  Relationship.Type.CONFIRMED, Relationship.Type.CONFIRMED, 
956                  relationshipManager.getConnectionStatus(rootIdentity, demoIdentity));
957     
958   }
959   
960   /**
961    * Test {@link RelationshipManager#inviteToConnect(Identity, Identity) and RelationshipManager#get(String)}
962    *
963    * @throws Exception
964    */
965   public void testIntiveAndGetByRelationshipId() throws Exception {
966     Relationship invitedRelationship = relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
967     
968     Relationship foundRelationship = relationshipManager.get(invitedRelationship.getId());
969     assertNotNull("foundRelationship must not be null", foundRelationship);
970     assertNotNull("foundRelationship.getId() must not be null", foundRelationship.getId());
971     assertEquals(foundRelationship.getId(), invitedRelationship.getId());
972 
973   }
974 
975   /**
976    * Test {@link RelationshipManager#getPending(Identity)}
977    *
978    * @throws Exception
979    */
980   public void testGetPendingWithIdentity() throws Exception {
981     Relationship johnDemoRelationship = relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
982     Relationship johnMaryRelationship = relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
983     Relationship johnRootRelationship = relationshipManager.inviteToConnect(johnIdentity, rootIdentity);
984 
985     List<Relationship> foundListRelationships = relationshipManager.getPending(johnIdentity);
986     assertNotNull("foundListRelationships must not be null", foundListRelationships);
987     assertEquals(3, foundListRelationships.size());
988 
989   }
990 
991   /**
992    * Test {@link RelationshipManager#getPending(Identity) and RelationshipManager#getIncoming(Identity)}
993    *
994    * @throws Exception
995    */
996   public void testGetPendingAndIncoming() throws Exception {
997     Relationship johnDemoRelationship = relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
998     Relationship johnMaryRelationship = relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
999     Relationship johnRootRelationship = relationshipManager.inviteToConnect(johnIdentity, rootIdentity);
1000 
1001     List<Relationship> listPendingRelationship = relationshipManager.getPending(johnIdentity);
1002     assertNotNull("listRelationshipConfirm must not be null", listPendingRelationship);
1003     assertEquals(3, listPendingRelationship.size());
1004 
1005     List<Relationship> listMaryRequireValidationRelationship = relationshipManager.getIncoming(maryIdentity);
1006     assertEquals(1, listMaryRequireValidationRelationship.size());
1007 
1008   }
1009 
1010   /**
1011    * Test {@link RelationshipManager#getPending(Identity) and RelationshipManager#getIncoming(Identity, List)}
1012    *
1013    * @throws Exception
1014    */
1015   public void testGetPendingAndIncomingWithListIdentities() throws Exception {
1016     Relationship johnDemoRelationship = relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
1017     Relationship johnMaryRelationship = relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
1018     Relationship johnRootRelationship = relationshipManager.inviteToConnect(johnIdentity, rootIdentity);
1019     Relationship maryDemoRelationship = relationshipManager.inviteToConnect(maryIdentity, demoIdentity);
1020 
1021     List<Identity> listIdentities = new ArrayList<Identity>();
1022     listIdentities.add(demoIdentity);
1023     listIdentities.add(maryIdentity);
1024     listIdentities.add(johnIdentity);
1025     listIdentities.add(rootIdentity);
1026 
1027     List<Relationship> listRelationshipConfirm = relationshipManager.getPending(johnIdentity, listIdentities);
1028     assertEquals(3, listRelationshipConfirm.size());
1029 
1030     List<Relationship> listRelationshipNotConfirm = relationshipManager.getIncoming(demoIdentity, listIdentities);
1031     assertEquals(2, listRelationshipNotConfirm.size());
1032 
1033   }
1034 
1035   /**
1036    * Test {@link RelationshipManager#getConfirmed(Identity)}
1037    *
1038    * @throws Exception
1039    */
1040   public void testGetConfirmedWithIdentity() throws Exception {
1041     List<Relationship> johnContacts = relationshipManager.getConfirmed(johnIdentity);
1042     assertNotNull("johnContacts must not be null", johnContacts);
1043     assertEquals("johnContacts.size() must be 0", 0, johnContacts.size());
1044 
1045     Relationship johnDemoRelationship = relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
1046     Relationship johnMaryRelationship = relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
1047     Relationship johnRootRelationship = relationshipManager.inviteToConnect(johnIdentity, rootIdentity);
1048 
1049     relationshipManager.confirm(johnDemoRelationship);
1050     relationshipManager.confirm(johnMaryRelationship);
1051     relationshipManager.confirm(johnRootRelationship);
1052 
1053     List<Relationship> contactsList = relationshipManager.getConfirmed(johnIdentity);
1054     assertEquals(3, contactsList.size());
1055 
1056   }
1057 
1058   /**
1059    * Test {@link RelationshipManager#getConfirmed(Identity, List)}
1060    *
1061    * @throws Exception
1062    */
1063   public void testGetConfirmedWithIdentityAndListIdentity() throws Exception {
1064     Relationship johnDemoRelationship = relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
1065     Relationship johnMaryRelationship = relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
1066     Relationship johnRootRelationship = relationshipManager.inviteToConnect(johnIdentity, rootIdentity);
1067 
1068     relationshipManager.confirm(johnDemoRelationship);
1069     relationshipManager.confirm(johnMaryRelationship);
1070     relationshipManager.confirm(johnRootRelationship);
1071 
1072     List<Identity> listIdentities = new ArrayList<Identity>();
1073     listIdentities.add(demoIdentity);
1074     listIdentities.add(maryIdentity);
1075     listIdentities.add(johnIdentity);
1076     listIdentities.add(rootIdentity);
1077 
1078     List<Relationship> contactsList = relationshipManager.getConfirmed(johnIdentity, listIdentities);
1079     assertEquals(3, contactsList.size());
1080   }
1081 
1082   /**
1083    * Test {@link RelationshipManager#save(Relationship)}
1084    *
1085    * @throws Exception
1086    */
1087   public void testSave() throws Exception {
1088     Relationship testRelationship = new Relationship(johnIdentity, demoIdentity, Type.PENDING);
1089     relationshipManager.save(testRelationship);
1090     assertNotNull("testRelationship.getId() must not be null", testRelationship.getId());
1091 
1092   }
1093 
1094   /**
1095    *
1096    * @throws Exception
1097    */
1098   /*
1099   public void testGetManyRelationshipsByIdentityId() throws Exception {
1100     String providerId = OrganizationIdentityProvider.NAME;
1101 
1102     Identity sender = identityManager.getOrCreateIdentity(providerId,"john");
1103     identityManager.saveIdentity(sender);
1104     assertNotNull(sender.getId());
1105 
1106     Identity receiver = identityManager.getOrCreateIdentity(providerId,"mary");
1107     assertNotNull(receiver.getId());
1108 
1109     relationshipManager.inviteToConnect(sender, receiver);
1110 
1111     List<Relationship> senderRelationships = relationshipManager.getAllRelationships(sender);
1112     List<Relationship> receiverRelationships = relationshipManager.getAllRelationships(receiver);
1113 
1114     assertEquals(total, senderRelationships.size());
1115     assertEquals(total, receiverRelationships.size());
1116   }
1117 */
1118 
1119   /**
1120    * Test {@link RelationshipManager#inviteToConnect(Identity, Identity)}
1121    * 
1122    * @throws Exception
1123    */
1124   public void testInviteRelationship() throws Exception {
1125     Relationship relationship = relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
1126     assertNotNull(relationship.getId());
1127     assertEquals(Relationship.Type.PENDING, relationship.getStatus());
1128 
1129     List<Relationship> senderRelationships = relationshipManager.getAll(johnIdentity);
1130     List<Relationship> receiverRelationships = relationshipManager.getAll(maryIdentity);
1131 
1132     assertEquals(1, senderRelationships.size());
1133     assertEquals(1, receiverRelationships.size());
1134 
1135   }
1136 
1137   /**
1138    * Test {@link RelationshipManager#confirm(Relationship)}
1139    *
1140    * @throws Exception
1141    */
1142   public void testConfirm() throws Exception {
1143     Relationship relationship = relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
1144     relationshipManager.confirm(relationship);
1145     relationship = relationshipManager.get(johnIdentity, demoIdentity);
1146     assertNotNull(relationship.getId());
1147     assertEquals(Relationship.Type.CONFIRMED, relationship.getStatus());
1148 
1149     List<Relationship> senderRelationships = relationshipManager.getAll(johnIdentity);
1150     List<Relationship> receiverRelationships = relationshipManager.getAll(demoIdentity);
1151 
1152     assertEquals(1, senderRelationships.size());
1153     assertEquals(1, receiverRelationships.size());
1154 
1155   }
1156 
1157   /**
1158    * Test {@link RelationshipManager#delete(Relationship)}
1159    *
1160    * @throws Exception
1161    * @since 1.2.0-Beta3
1162    */
1163   public void testDelete() throws Exception {
1164     Relationship relationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
1165     relationshipManager.confirm(johnIdentity, rootIdentity);
1166     relationshipManager.delete(relationship);
1167 
1168     relationship = relationshipManager.get(rootIdentity, johnIdentity);
1169     assertNull("relationship must be null", relationship);
1170   }
1171   
1172   /**
1173    * Test {@link RelationshipManager#remove(Relationship)}
1174    *
1175    * @throws Exception
1176    */
1177   public void testRemove() throws Exception {
1178     Relationship relationship = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
1179     relationshipManager.confirm(rootIdentity, johnIdentity);
1180     relationshipManager.delete(relationship);
1181 
1182     relationship = relationshipManager.get(rootIdentity, johnIdentity);
1183     assertNull("relationship must be null", relationship);
1184   }
1185 
1186   /**
1187    * Test {@link RelationshipManager#getPending(Identity)}
1188    * 
1189    * @throws Exception
1190    */
1191   public void testGetPending() throws Exception {
1192     Relationship rootDemo = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
1193     assertNotNull("rootDemo.getId() must not be null", rootDemo.getId());
1194     Relationship rootJohn = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
1195     assertNotNull("rootJohn.getId() must not be null", rootJohn.getId());
1196     Relationship rootMary = relationshipManager.inviteToConnect(rootIdentity, maryIdentity);
1197     assertNotNull("rootMary.getId() must not be null", rootMary.getId());
1198     Relationship demoMary = relationshipManager.inviteToConnect(demoIdentity, maryIdentity);
1199     assertNotNull("demoMary.getId() must not be null", demoMary.getId());
1200     Relationship demoJohn = relationshipManager.inviteToConnect(demoIdentity, johnIdentity);
1201     assertNotNull("demoJohn.getId() must not be null", demoJohn.getId());
1202 
1203     List<Relationship> rootRelationships = relationshipManager.getPending(rootIdentity);
1204     List<Relationship> demoRelationships = relationshipManager.getPending(demoIdentity);
1205     List<Relationship> johnRelationships = relationshipManager.getPending(johnIdentity);
1206 
1207     assertEquals(3, rootRelationships.size());
1208     assertEquals(2, demoRelationships.size());
1209     assertEquals(0, johnRelationships.size());
1210 
1211   }
1212 
1213   /**
1214    * Test relationship with caching.
1215    * 
1216    * @throws Exception
1217    */
1218   public void testSavedCached() throws Exception {
1219     Relationship rootDemo = relationshipManager.get(rootIdentity, demoIdentity);
1220     assertNull("rootDemo must be null", rootDemo);
1221     Relationship rootDemo2 = relationshipManager.get(demoIdentity, rootIdentity);
1222     assertNull("rootDemo must be null", rootDemo2);
1223     Relationship.Type rootDemoStatus = relationshipManager.getStatus(demoIdentity, rootIdentity);
1224     assertNull("rootDemoStatus must be null",rootDemoStatus);
1225     rootDemo = relationshipManager.inviteToConnect(rootIdentity, demoIdentity);
1226     assertNotNull("rootDemo.getId() must not be null", rootDemo.getId());
1227     assertEquals(rootDemo.getStatus(), Relationship.Type.PENDING);
1228 
1229     Relationship rootMary = relationshipManager.get(rootIdentity, maryIdentity);
1230     Relationship.Type rootMaryStatus = relationshipManager.getStatus(maryIdentity, rootIdentity);
1231     assertNull("rootMary must be null", rootMary);
1232     assertNull("rootMaryStatus must be null", rootMaryStatus);
1233     rootMary = relationshipManager.inviteToConnect(rootIdentity, maryIdentity);
1234     assertNotNull("rootMary.getId() must not be null", rootMary.getId());
1235     assertEquals(Relationship.Type.PENDING, rootMary.getStatus());
1236 
1237     Relationship rootJohn = relationshipManager.get(rootIdentity, johnIdentity);
1238     assertNull("rootJohn must be null", rootJohn);
1239     assertNull("rootMaryStatus must be null", rootMaryStatus);
1240     rootJohn = relationshipManager.inviteToConnect(rootIdentity, johnIdentity);
1241     assertNotNull("rootJohn.getId() must not be null", rootJohn.getId());
1242     assertEquals(Relationship.Type.PENDING, rootJohn.getStatus());
1243 
1244     Relationship demoMary = relationshipManager.get(demoIdentity, maryIdentity);
1245     Relationship.Type demoMaryStatus = relationshipManager.getStatus(maryIdentity, demoIdentity);
1246     assertNull("demoMary must be null", demoMary);
1247     assertNull("demoMaryStatus must be null", demoMaryStatus);
1248     demoMary = relationshipManager.inviteToConnect(demoIdentity, maryIdentity);
1249     assertNotNull("demoMary.getId() must not be null", demoMary.getId());
1250     assertEquals(Relationship.Type.PENDING, demoMary.getStatus());
1251   }
1252   
1253 
1254   /**
1255    * Tests getting connections of one identity with list access.
1256    * 
1257    * @throws Exception
1258    */
1259   public void testGetConnections() throws Exception {
1260      Relationship johnDemoRelationship = relationshipManager.inviteToConnect(johnIdentity, demoIdentity);
1261      Relationship johnMaryRelationship = relationshipManager.inviteToConnect(johnIdentity, maryIdentity);
1262      Relationship johnRootRelationship = relationshipManager.inviteToConnect(johnIdentity, rootIdentity);
1263 
1264      relationshipManager.confirm(johnDemoRelationship);
1265      relationshipManager.confirm(johnMaryRelationship);
1266      relationshipManager.confirm(johnRootRelationship);
1267 
1268      ListAccess<Identity> contactsList = relationshipManager.getConnections(johnIdentity);
1269      assertEquals(3, contactsList.getSize());
1270   }
1271 
1272   public void testGetSuggestions() throws Exception {
1273     Relationship maryToGhostRelationship = relationshipManager.inviteToConnect(ghostIdentity, maryIdentity);
1274     Relationship ghostToJohnRelationship = relationshipManager.inviteToConnect(ghostIdentity, johnIdentity);
1275     Relationship maryToDemoRelationship = relationshipManager.inviteToConnect(demoIdentity, maryIdentity);
1276 
1277     Map<Identity, Integer> suggestions = relationshipManager.getSuggestions(ghostIdentity, -1, -1, 10); 
1278     // The relationships must be confirmed first
1279     assertTrue(suggestions.isEmpty());
1280     relationshipManager.confirm(ghostIdentity, maryIdentity);
1281     relationshipManager.confirm(ghostIdentity, johnIdentity);
1282     relationshipManager.confirm(demoIdentity, maryIdentity);
1283     suggestions = relationshipManager.getSuggestions(ghostIdentity, -1, -1, 10); 
1284     assertEquals(1, suggestions.size());
1285     Object[] objs = suggestions.entrySet().toArray();
1286     
1287     Entry<Identity, Integer> first = (Entry<Identity, Integer>) objs[0];
1288 
1289     assertEquals(1, first.getValue().intValue());
1290     assertEquals(demoIdentity.getRemoteId(), first.getKey().getRemoteId());
1291 
1292     //increase common users
1293     Relationship johnToDemoRelationship = relationshipManager.inviteToConnect(demoIdentity, johnIdentity);
1294     Relationship paulToDemoRelationship = relationshipManager.inviteToConnect(paulIdentity, maryIdentity);
1295     suggestions = relationshipManager.getSuggestions(ghostIdentity, -1, -1, 10); 
1296     assertEquals(1, suggestions.size());
1297     relationshipManager.confirm(demoIdentity, johnIdentity);
1298     relationshipManager.confirm(paulIdentity, maryIdentity);
1299 
1300     suggestions = relationshipManager.getSuggestions(ghostIdentity, -1, -1, 10); 
1301     assertEquals(2, suggestions.size());
1302     objs = suggestions.entrySet().toArray();
1303     first = (Entry<Identity, Integer>) objs[0];
1304     Entry<Identity, Integer> second = (Entry<Identity, Integer>) objs[1];
1305     
1306     assertEquals(demoIdentity.getRemoteId(), first.getKey().getRemoteId());
1307     assertEquals(paulIdentity.getRemoteId(), second.getKey().getRemoteId());
1308     assertEquals(2, first.getValue().intValue());
1309     assertEquals(demoIdentity.getRemoteId(), first.getKey().getRemoteId());
1310     assertEquals(1, second.getValue().intValue());
1311     assertEquals(paulIdentity.getRemoteId(), second.getKey().getRemoteId());
1312 
1313     relationshipManager.delete(paulToDemoRelationship);
1314     suggestions = relationshipManager.getSuggestions(ghostIdentity, -1, -1, 10); 
1315     assertEquals(1, suggestions.size());
1316 
1317   }
1318 
1319   public void testGetSuggestionsWithParams() throws Exception {
1320     Relationship maryToGhostRelationship = relationshipManager.inviteToConnect(ghostIdentity, maryIdentity);
1321     Relationship maryToDemoRelationship = relationshipManager.inviteToConnect(demoIdentity, maryIdentity);
1322     Relationship paulToMaryRelationship = relationshipManager.inviteToConnect(paulIdentity, maryIdentity);
1323     Relationship johnToMaryRelationship = relationshipManager.inviteToConnect(maryIdentity, johnIdentity);
1324     Relationship rootToMaryRelationship = relationshipManager.inviteToConnect(maryIdentity, rootIdentity);
1325 
1326     Map<Identity, Integer> suggestions = relationshipManager.getSuggestions(ghostIdentity, -1, -1, 10); 
1327     // The relationships must be confirmed first
1328     assertTrue(suggestions.isEmpty());
1329     suggestions = relationshipManager.getSuggestions(ghostIdentity, 10, 10, 10);
1330     assertTrue(suggestions.isEmpty());
1331     suggestions = relationshipManager.getSuggestions(ghostIdentity, 10, 10, 10);
1332     assertTrue(suggestions.isEmpty());
1333     relationshipManager.confirm(ghostIdentity, maryIdentity);
1334     relationshipManager.confirm(paulIdentity, maryIdentity);
1335     relationshipManager.confirm(demoIdentity, maryIdentity);
1336     relationshipManager.confirm(maryIdentity, johnIdentity);
1337     relationshipManager.confirm(maryIdentity, rootIdentity);
1338 
1339     suggestions = relationshipManager.getSuggestions(ghostIdentity, -1, -1, 10);
1340     assertFalse(suggestions.containsKey(ghostIdentity));
1341     assertEquals(4, suggestions.size());
1342     suggestions = relationshipManager.getSuggestions(ghostIdentity, -1, -1, 10);
1343     assertFalse(suggestions.containsKey(ghostIdentity));
1344     assertEquals(4, suggestions.size());
1345     suggestions = relationshipManager.getSuggestions(ghostIdentity, 2, 2, 10);
1346     assertFalse(suggestions.containsKey(ghostIdentity));
1347     // 1 or 2 depending on the connections loaded, if there is ghostIdentity, it will be one
1348     // otherwise it will be 2
1349     assertTrue(suggestions.size() > 0 && suggestions.size() <= 2);
1350     suggestions = relationshipManager.getSuggestions(ghostIdentity, 2, 3, 10);
1351     assertFalse(suggestions.containsKey(ghostIdentity));
1352     // 1 or 2 depending on the connections loaded, if there is ghostIdentity, it will be one
1353     // otherwise it will be 2
1354     assertTrue(suggestions.size() > 0 && suggestions.size() <= 2);
1355     suggestions = relationshipManager.getSuggestions(ghostIdentity, 2, 3, 10);
1356     assertFalse(suggestions.containsKey(ghostIdentity));
1357     // 1 or 2 depending on the connections loaded, if there is ghostIdentity, it will be one
1358     // otherwise it will be 2
1359     assertTrue(suggestions.size() > 0 && suggestions.size() <= 2);
1360 
1361     suggestions = relationshipManager.getSuggestions(ghostIdentity, 10, 10, 2);
1362     assertFalse(suggestions.containsKey(ghostIdentity));
1363     assertEquals(2, suggestions.size());
1364 
1365     suggestions = relationshipManager.getSuggestions(ghostIdentity, 10, 2, 2);
1366     assertFalse(suggestions.containsKey(ghostIdentity));
1367     assertEquals(2, suggestions.size());
1368 
1369   }
1370   
1371   public void testGetLastConnections() throws Exception {
1372     Relationship maryToGhostRelationship = relationshipManager.inviteToConnect(ghostIdentity, maryIdentity);
1373     relationshipManager.confirm(maryIdentity, ghostIdentity);
1374     Thread.sleep(1000);
1375     Relationship maryToDemoRelationship = relationshipManager.inviteToConnect(demoIdentity, maryIdentity);
1376     relationshipManager.confirm(maryIdentity, demoIdentity);
1377     Thread.sleep(1000);
1378     Relationship paulToMaryRelationship = relationshipManager.inviteToConnect(paulIdentity, maryIdentity);
1379     relationshipManager.confirm(maryIdentity, paulIdentity);
1380     
1381     List<Identity> identities = relationshipManager.getLastConnections(maryIdentity, 10);
1382     assertEquals(3, identities.size());
1383     assertEquals(paulIdentity.getRemoteId(), identities.get(0).getRemoteId());
1384     assertEquals(demoIdentity.getRemoteId(), identities.get(1).getRemoteId());
1385     assertEquals(ghostIdentity.getRemoteId(), identities.get(2).getRemoteId());
1386 
1387     Thread.sleep(1000);
1388     Relationship johnToMaryRelationship = relationshipManager.inviteToConnect(maryIdentity, johnIdentity);
1389     relationshipManager.confirm(johnIdentity, maryIdentity);
1390     identities = relationshipManager.getLastConnections(maryIdentity, 10);
1391     assertEquals(4, identities.size());
1392     assertEquals(johnIdentity.getRemoteId(), identities.get(0).getRemoteId());
1393     
1394   }
1395   
1396   private Profile initProfile(String userName, String firstName, String lastName, String fullName,
1397                               String position, String gender, String company) throws Exception {
1398     Identity identity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userName, true);
1399     Profile profile = identity.getProfile();
1400     profile.setProperty(Profile.FIRST_NAME, firstName);
1401     profile.setProperty(Profile.LAST_NAME, lastName);
1402     profile.setProperty(Profile.FULL_NAME, fullName);
1403     profile.setProperty(Profile.POSITION, position);
1404     profile.setProperty(Profile.GENDER, gender);
1405     Map<String, String> xp = Maps.newHashMap();
1406     List<Map<String, String>> xps = Lists.newArrayList();
1407     xp.put(Profile.EXPERIENCES_COMPANY, company);
1408     xps.add(xp);
1409     profile.setProperty(Profile.EXPERIENCES, xps);
1410     profile.setListUpdateTypes(Lists.newArrayList(Profile.UpdateType.CONTACT));
1411     identityManager.updateProfile(profile);
1412     identity.setProfile(profile);
1413     identityManager.updateIdentity(identity);
1414     return profile;
1415   }
1416 }