package enterprise.web.tookit.account.test;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import enterprise.web.tookit.account.Account;
import enterprise.web.tookit.account.AccountException;
import enterprise.web.tookit.account.CreateAccountEJBRemote;
public class CreateAccountTest {
static CreateAccountEJBRemote createAccount;
public static void main(String[] args) {
// criarContaRegis();
// loginContaRegis();
atualizarConta();
}
public static void loginContaRegis() {
try {
InitialContext context = new InitialContext();
Object ref = context.lookup("CreateAccount");
createAccount = (CreateAccountEJBRemote) ref;
Account account = new Account();
account.setUsername("Regis Rocha");
account.setPassword("webToolkit");
System.out.println(createAccount.login(account));
} catch (Exception e) {
e.printStackTrace();
}
}
private static void criarContaRegis() {
try {
InitialContext context = new InitialContext();
Object ref = context.lookup("CreateAccount");
createAccount = (CreateAccountEJBRemote) ref;
Account account = new Account();
account.setUsername("Regis Rocha");
account.setFirstname("Regis");
Calendar date = new GregorianCalendar();
date.set(1989, 00, 03);
account.setBirthday(date);
account.setEmail("RegisRocha3@gmail.com");
account.setGender("M");
account.setLastname("Rocha");
account.setMobilephone("982895805");
account.setPassword("webtoolkit");
createAccount.createAccout(account);
} catch (NamingException e) {
e.printStackTrace();
} catch (AccountException e) {
e.printStackTrace();
}
}
public static void atualizarConta() {
try {
InitialContext context = new InitialContext();
Object ref = context.lookup("CreateAccount");
createAccount = (CreateAccountEJBRemote) ref;
Account accountToSearch = new Account();
accountToSearch.setUsername("Regis Rocha");
accountToSearch.setPassword("webtoolkit");
Calendar birthday = Calendar.getInstance();
birthday.set(1989, 00, 03);
final Account accountPersisted = createAccount.login(accountToSearch);
accountPersisted.setBirthday(birthday);
createAccount.updateAccount(accountPersisted);
} catch (Exception e) {
e.printStackTrace();
}
}
}