예제 #1
0
  private void checkGroupValidity(Guid groupId, Guid bobId, Guid janeId) throws NotFoundException {
    ReadOnlySession session = support.currentSessionRO();

    TestGroupDMO groupDMO = session.find(TestGroupDMO.class, groupId);
    assertNotNull(groupDMO);
    assertEquals(groupId, groupDMO.getKey());

    boolean seenBob = false;
    boolean seenJane = false;

    assertEquals(2, groupDMO.getMembers().size());

    for (TestGroupMemberDMO groupMemberDMO : groupDMO.getMembers()) {
      TestUserDMO memberDMO = groupMemberDMO.getMember();
      if (memberDMO.getKey().equals(bobId)) {
        seenBob = true;
        assertEquals("Bob", memberDMO.getName());
      }
      if (memberDMO.getKey().equals(janeId)) {
        seenJane = true;
        assertEquals("Jane", memberDMO.getName());
      }
    }

    assertTrue(seenBob && seenJane);
  }
예제 #2
0
  // Test looking up objects by String resource ID
  public void testStringResourceId() throws NotFoundException {
    EntityManager em;

    TestViewpoint viewpoint = new TestViewpoint(Guid.createNew());

    /////////////////////////////////////////////////
    // Setup

    em = support.beginSessionRW(viewpoint);

    TestUser bob = new TestUser("Bob");
    em.persist(bob);

    TestGroup group = new TestGroup("BobOnly");
    Guid groupId = group.getGuid();
    em.persist(group);

    TestGroupMember groupMember;

    groupMember = new TestGroupMember(group, bob);
    em.persist(groupMember);
    group.getMembers().add(groupMember);

    em.getTransaction().commit();

    /////////////////////////////////////////////////

    em = support.beginSessionRO(viewpoint);

    ReadOnlySession session = support.currentSessionRO();

    // Test for a GUID key
    TestGroupDMO groupDMO = session.find(TestGroupDMO.class, groupId);
    assertEquals(groupDMO, session.find(groupDMO.getResourceId()));

    // Test for a custom key
    TestGroupMemberDMO groupMemberDMO = groupDMO.getMembers().get(0);
    assertEquals(groupMemberDMO, session.find(groupMemberDMO.getResourceId()));

    em.getTransaction().commit();
  }