@Test
  public void testCreateGroupMembership() {
    Account account = new Account();
    account.setGivenName("Anthony");
    account.setSurname("Wolski");
    account.setEmail("*****@*****.**");
    account.setPassword("password");
    account.setUsername("awolski");
    accountService.createAccount(account);

    Group group = new Group();
    group.setName("Test Group");
    accountService.createGroup(group);

    GroupMembership groupMembership = new GroupMembership(account, group);
    accountService.createGroupMembership(groupMembership);

    List<Account> groupAccounts = accountService.getGroupAccounts(group.getId());
    assertEquals(1, groupAccounts.size());

    List<Group> accountGroups = accountService.getAccountGroups(account.getId());
    assertEquals(1, accountGroups.size());

    List<GroupMembership> groupGroupMemberships =
        accountService.getGroupGroupMemberships(group.getId());
    assertEquals(1, groupGroupMemberships.size());

    List<GroupMembership> accountGroupMemberships =
        accountService.getAccountGroupMemberships(account.getId());
    assertEquals(1, accountGroupMemberships.size());
  }
  @Test
  public void testCRUDAccount() {
    // Create
    Account account = new Account();
    account.setGivenName("Anthony");
    account.setSurname("Wolski");
    account.setEmail("*****@*****.**");
    account.setPassword("password");
    account.setUsername("awolski");
    accountService.createAccount(account);
    assertEquals(new Long(0), account.getVersion());

    // Read
    Account found = accountService.getAccount(account.getId());
    assertEquals("Anthony", found.getGivenName());
    assertEquals("Wolski", found.getSurname());
    assertEquals("*****@*****.**", found.getEmail());
    assertEquals("password", found.getPassword());
    assertEquals("awolski", found.getUsername());
    assertEquals(new Long(0), account.getVersion());

    // Update
    account.setMiddleName("Keith");
    accountService.saveAccount(account);
    account = accountService.getAccount(account.getId());
    assertEquals(new Long(1), account.getVersion());

    // Delete
    String accountId = account.getId();
    accountService.deleteAccountById(accountId);
    account = accountService.getAccount(accountId);
    assertNull(account);
  }
예제 #3
0
  /** Creates an account object with detailed data. */
  public static Account createDetails(
      String uid,
      String givenName,
      String surname,
      String org,
      String physicalDeliveryOfficeName,
      String postalAddress,
      String postalCode,
      String postOfficeBox,
      String registeredAddress,
      String title) {

    Account a = new AccountImpl();

    a.setUid(uid);

    a.setGivenName(givenName);
    a.setSurname(surname);
    a.setCommonName(formatCommonName(givenName, surname));

    a.setOrg(org);

    a.setPhysicalDeliveryOfficeName(physicalDeliveryOfficeName);
    a.setPostalAddress(postalAddress);
    a.setPostalCode(postalCode);
    a.setPostOfficeBox(postOfficeBox);

    a.setRegisteredAddress(registeredAddress);
    a.setTitle(title);

    return a;
  }
예제 #4
0
  /**
   * Brief data
   *
   * @param uid
   * @param password
   * @param firstName
   * @param surname
   * @param email
   * @param phone
   * @param org
   * @param description
   * @return
   */
  public static Account createBrief(
      String uid,
      String password,
      String firstName,
      String surname,
      String email,
      String phone,
      String org,
      String title,
      String description) {

    Account account = new AccountImpl();

    account.setUid(uid);
    account.setPassword(password);

    account.setGivenName(firstName);
    account.setSurname(surname);

    account.setCommonName(formatCommonName(firstName, surname));

    account.setEmail(email);
    account.setPhone(phone);
    account.setOrg(org);
    account.setTitle(title);
    account.setDescription(description);

    return account;
  }
예제 #5
0
 /**
  * Creates an account object from another one, given as argument.
  *
  * @param o other account to copy
  */
 public static Account create(Account o) {
   Account a = new AccountImpl();
   a.setUid(o.getUid());
   a.setCommonName(o.getCommonName());
   a.setSurname(o.getSurname());
   a.setOrg(o.getOrg());
   a.setEmail(o.getEmail());
   a.setPhone(o.getPhone());
   a.setDescription(o.getDescription());
   // passwords / new passwords fields voluntarily omitted:
   // the password update process should not go through this.
   a.setGivenName(o.getGivenName());
   a.setTitle(o.getTitle());
   a.setPostalAddress(o.getPostalAddress());
   a.setPostalCode(o.getPostalCode());
   a.setRegisteredAddress(o.getRegisteredAddress());
   a.setPostOfficeBox(o.getPostOfficeBox());
   a.setPhysicalDeliveryOfficeName(o.getPhysicalDeliveryOfficeName());
   a.setStreet(o.getStreet());
   a.setLocality(o.getLocality());
   a.setFacsimile(o.getFacsimile());
   a.setMobile(o.getMobile());
   a.setRoomNumber(o.getRoomNumber());
   a.setStateOrProvince(o.getStateOrProvince());
   a.setOrganizationalUnit(o.getOrganizationalUnit());
   a.setHomePostalAddress(o.getHomePostalAddress());
   return a;
 }
예제 #6
0
  /**
   * Creates an account object with all data.
   *
   * @param uid
   * @param cn full name
   * @param surname surname
   * @param givenName first name
   * @param email
   * @param org
   * @param title
   * @param phone
   * @param description
   * @param postalAddress
   * @param postalCode
   * @param registeredAddress
   * @param postOfficeBox
   * @param physicalDeliveryOfficeName
   * @param locality
   * @param street
   * @param facsimile
   * @param organizationalUnit
   * @param mobile
   * @param roomNumber
   * @return {@link Account}
   */
  public static Account createFull(
      String uid,
      String cn,
      String surname,
      String givenName,
      String email,
      String org,
      String title,
      String phone,
      String description,
      String postalAddress,
      String postalCode,
      String registeredAddress,
      String postOfficeBox,
      String physicalDeliveryOfficeName,
      String street,
      String locality,
      String facsimile,
      String organizationalUnit,
      String homePostalAddress,
      String mobile,
      String roomNumber,
      String stateOrProvince) {

    Account a = new AccountImpl();

    a.setUid(uid);
    a.setCommonName(cn);
    a.setGivenName(givenName);
    a.setSurname(surname);
    a.setEmail(email);

    a.setOrg(org);
    a.setTitle(title);

    a.setPhone(phone);
    a.setDescription(description);

    a.setStreet(street);
    a.setLocality(locality);

    a.setPostalAddress(postalAddress);
    a.setPostalCode(postalCode);
    a.setRegisteredAddress(registeredAddress);
    a.setPostOfficeBox(postOfficeBox);
    a.setPhysicalDeliveryOfficeName(physicalDeliveryOfficeName);

    a.setFacsimile(facsimile);
    a.setOrganizationalUnit(organizationalUnit);

    a.setHomePostalAddress(homePostalAddress);
    a.setMobile(mobile);
    a.setRoomNumber(roomNumber);
    a.setStateOrProvince(stateOrProvince);

    return a;
  }