@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);
  }
예제 #2
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;
 }
  public void updateProfile(String key, Account pAccount)
      throws SQLException, ConnectionException, MissingDataException, NullAccountException,
          ProfileException, PasswordException, EmailException {
    try (Connection connect = DBConnection.getConnection()) {
      pAccount = testAccount(pAccount);

      String sql =
          "UPDATE account"
              + "set name = '"
              + Utility.Replace(testProfileData(pAccount.getName()))
              + "', surname = '"
              + Utility.Replace(testProfileData(pAccount.getSurname()))
              + "', password = '******', secondaryEmail = '"
              + testEmail(pAccount.getSecondaryEmail())
              + "WHERE email = '"
              + key
              + "'";

      String sql2 = "UPDATE " + pAccount.getTypeAccount();

      if (pAccount instanceof PhdStudent) {
        sql2 +=
            " set telephone = '"
                + testProfileData(((PhdStudent) pAccount).getTelephone())
                + "', link =  '"
                + testProfileData(((PhdStudent) pAccount).getLink())
                + "', deparment = '"
                + testProfileData(((PhdStudent) pAccount).getDepartment())
                + "', researchInterest = '"
                + testProfileData(((PhdStudent) pAccount).getResearchInterest())
                + "' WHERE fkAccount = '"
                + testProfileData(((PhdStudent) pAccount).getSecondaryEmail());
      }

      if (pAccount instanceof Professor) {
        sql2 +=
            " set link = '"
                + ((Professor) pAccount).getLink()
                + "', set department = '"
                + ((Professor) pAccount).getDepartment()
                + "' WHERE fkAccount = '"
                + ((Professor) pAccount).getSecondaryEmail()
                + "'";
      }

      if (pAccount.getTypeAccount().equals("basic")) // aggiorna solo info base
      Utility.executeOperation(connect, sql);
      else {
        Utility.executeOperation(connect, sql);
        Utility.executeOperation(connect, sql2);
      }

      connect.commit();
    }
  }
예제 #4
0
  @Test
  public void getAccountTest() throws IOException, VscaleException {
    Result<Account> query = this.api.account();

    Account account = query.get();

    assertNotNull(account.getActivationDate());
    assertNotNull(account.getCountry());
    assertNotNull(account.getId());
    assertNotNull(account.getEmail());
    assertNotNull(account.getFaceId());
    assertNotNull(account.getState());
    assertNotNull(account.getLocale());
    assertNotNull(account.getMobile());
    assertNotNull(account.getName());
    assertNotNull(account.getSurname());
  }