Пример #1
0
 /**
  * Connects 2 identities, if toConfirm = true, they're connected. If false, in pending connection
  * type.
  *
  * @param senderIdentity the identity who sends connection request
  * @param receiverIdentity the identity who receives connnection request
  * @param beConfirmed boolean value
  */
 private void connectIdentities(
     Identity senderIdentity, Identity receiverIdentity, boolean beConfirmed) {
   relationshipManager.inviteToConnect(senderIdentity, receiverIdentity);
   if (beConfirmed) {
     relationshipManager.confirm(receiverIdentity, senderIdentity);
   }
   tearDownRelationshipList.add(relationshipManager.get(senderIdentity, receiverIdentity));
 }
Пример #2
0
  private void performRelationshipTest(String prefix) throws Exception {

    //
    String baseName = (prefix == null ? "bench.user" : prefix);
    assertClean(baseName, null);

    //
    params.put("number", "10");
    if (prefix != null) {
      params.put("prefix", prefix);
    }
    identityInjector.inject(params);

    //
    Identity user0 = identityManager.getOrCreateIdentity("organization", baseName + "0", false);
    Identity user1 = identityManager.getOrCreateIdentity("organization", baseName + "1", false);
    Identity user2 = identityManager.getOrCreateIdentity("organization", baseName + "2", false);
    Identity user3 = identityManager.getOrCreateIdentity("organization", baseName + "3", false);
    Identity user4 = identityManager.getOrCreateIdentity("organization", baseName + "4", false);
    Identity user5 = identityManager.getOrCreateIdentity("organization", baseName + "5", false);
    Identity user6 = identityManager.getOrCreateIdentity("organization", baseName + "6", false);
    Identity user7 = identityManager.getOrCreateIdentity("organization", baseName + "7", false);
    Identity user8 = identityManager.getOrCreateIdentity("organization", baseName + "8", false);
    Identity user9 = identityManager.getOrCreateIdentity("organization", baseName + "9", false);

    //
    params.put("number", "3");
    params.put("fromUser", "2");
    params.put("toUser", "8");
    if (prefix != null) {
      params.put("prefix", prefix);
    }
    relationshipInjector.inject(params);

    //
    assertEquals(0, relationshipManager.getConnections(user0).getSize());
    assertEquals(0, relationshipManager.getConnections(user1).getSize());
    assertEquals(3, relationshipManager.getConnections(user2).getSize());
    assertEquals(3, relationshipManager.getConnections(user3).getSize());
    assertEquals(3, relationshipManager.getConnections(user4).getSize());
    assertEquals(3, relationshipManager.getConnections(user5).getSize());
    assertEquals(2, relationshipManager.getConnections(user6).getSize());
    assertEquals(2, relationshipManager.getConnections(user7).getSize());
    assertEquals(2, relationshipManager.getConnections(user8).getSize());
    assertEquals(0, relationshipManager.getConnections(user9).getSize());

    //
    cleanIdentity(baseName, 10);
  }
Пример #3
0
  /** Tests {@link SecurityManager#canPostActivity(PortalContainer, Identity, Identity)}. */
  public void testCanPostActivity() {
    boolean demoPostToDemo =
        SecurityManager.canPostActivity(getContainer(), demoIdentity, demoIdentity);
    assertTrue("demoPostToDemo must be true", demoPostToDemo);
    boolean demoPostToJohn =
        SecurityManager.canPostActivity(getContainer(), demoIdentity, johnIdentity);
    assertFalse("demoPostToJohn must be false", demoPostToJohn);
    // demo is connected to mary => they can post activity to each other's activity stream
    relationshipManager.inviteToConnect(demoIdentity, maryIdentity);
    boolean demoPostToMary =
        SecurityManager.canPostActivity(getContainer(), demoIdentity, maryIdentity);
    boolean maryPostToDemo =
        SecurityManager.canPostActivity(getContainer(), maryIdentity, demoIdentity);
    assertFalse("demoPostToMary must be false", demoPostToMary);
    assertFalse("maryPostToDemo must be false", maryPostToDemo);
    relationshipManager.confirm(maryIdentity, demoIdentity);
    tearDownRelationshipList.add(relationshipManager.get(demoIdentity, maryIdentity));
    demoPostToMary = SecurityManager.canPostActivity(getContainer(), demoIdentity, maryIdentity);
    maryPostToDemo = SecurityManager.canPostActivity(getContainer(), maryIdentity, demoIdentity);
    assertTrue("demoPostToMary must be true", demoPostToMary);
    assertTrue("maryPostToDemo must be true", maryPostToDemo);
    // checks user posts to space
    createSpaces(1);
    Space createdSpace = tearDownSpaceList.get(0);
    Identity spaceIdentity =
        identityManager.getOrCreateIdentity(
            SpaceIdentityProvider.NAME, createdSpace.getPrettyName(), false);
    assertNotNull("spaceIdentity must not be null", spaceIdentity);

    // demo, mary could post activity to this space's activity stream

    boolean demoPostToSpace =
        SecurityManager.canPostActivity(getContainer(), demoIdentity, spaceIdentity);
    assertTrue("demoPostToSpace must be true", demoPostToSpace);
    boolean maryPostToSpace =
        SecurityManager.canPostActivity(getContainer(), maryIdentity, spaceIdentity);
    assertTrue("maryPostToSpace must be false", maryPostToSpace);

    // john could not
    boolean johnPostToSpace =
        SecurityManager.canPostActivity(getContainer(), johnIdentity, spaceIdentity);
    assertFalse("johnPostToSpace must be false", johnPostToSpace);
  }