📄 accountdaojdotest.java
字号:
/* * Copyright 2003 by Redsoft Factory Inc., * Apt 738, 68 Corporate Drive, Toronto, Ontario, Canada * All rights reserved. * * This software is the confidential and proprietary information * of Redsoft Factory Inc. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with Redsoft Factory. */package org.redsoft.forum.dao.jdo;import java.util.Collection;import junit.framework.TestCase;import org.redsoft.forum.dao.Account;import org.redsoft.forum.exception.AccountAlreadyExistException;import org.redsoft.forum.exception.AccountNotFoundException;import org.redsoft.forum.exception.DAOException;/** * Test cases for AccountDAOJDO * * @author Charles Huang * Date: 22-Feb-2004 * $Id: AccountDAOJDOTest.java,v 1.3 2004/04/10 19:57:01 cinc Exp $ */public class AccountDAOJDOTest extends TestCase { private static final String USER_NAME = "ForTest"; public void testAddAccountNormal() { AccountDAOJDO dao = (AccountDAOJDO) new LiberatorDAOFactory().getAccountDAO(); Account account = new Account(USER_NAME, "charles", "charles_hhb@hotmail.com"); try { dao.addAccount(account); Account account_new = dao.findByUserName(account.getUserName()); assertEquals("Expecting charles", account.getUserName(), account_new.getUserName()); assertEquals("Expecting charles", account.getPassword(), account_new.getPassword()); assertEquals("Expecting charles@hotmail.com", account.getEmail(), account_new.getEmail()); assertEquals("Expecting false", account.isColumnWriter(), account_new.isColumnWriter()); dao.removeAccount(account.getUserName()); } catch (final Exception e) { e.printStackTrace(); fail("Unexpected exception::" + e.toString()); } } public void testAddAccountAlreadyExist() { AccountDAOJDO dao = null; Account account = null; try { dao = (AccountDAOJDO) new LiberatorDAOFactory().getAccountDAO(); account = new Account(USER_NAME, "charles", "charles_hhb@hotmail.com"); dao.addAccount(account); Account account_new = dao.findByUserName(account.getUserName()); assertEquals("Expecting " + USER_NAME, account.getUserName(), account_new.getUserName()); assertEquals("Expecting charles", account.getPassword(), account_new.getPassword()); assertEquals("Expecting charles@hotmail.com", account.getEmail(), account_new.getEmail()); dao.addAccount(account); fail("AccountAlreadyExistException expected"); } catch (final DAOException e) { e.printStackTrace(); fail("Unexpected exception::" + e.toString()); } catch (final AccountNotFoundException notFound) { notFound.printStackTrace(); fail("Unexpected exception: " + notFound.toString()); } catch (final AccountAlreadyExistException ex) { // Pass try { dao.removeAccount(account.getUserName()); } catch (final DAOException daoException) { daoException.printStackTrace(); fail("Unexpected exception "); } } } public void testUpdateAccountAlreadyExist() { AccountDAOJDO dao = null; Account account = null; try { dao = (AccountDAOJDO) new LiberatorDAOFactory().getAccountDAO(); account = new Account(USER_NAME, "charles", "charles_hhb@hotmail.com"); dao.addAccount(account); account.setPassword("newpwd"); account.setEmail("newemail"); account.setColumnWriter(true); dao.updateAccount(account); Account account_new = dao.findByUserName(USER_NAME); assertEquals("Expecting " + USER_NAME, account.getUserName(), account_new.getUserName()); assertEquals("Expecting charles", account.getPassword(), account_new.getPassword()); assertEquals("Expecting charles@hotmail.com", account.getEmail(), account_new.getEmail()); assertEquals("Expecting true", account.isColumnWriter(), account_new.isColumnWriter()); } catch (final DAOException e) { e.printStackTrace(); fail("Unexpected exception:" + e.toString()); } catch (final AccountNotFoundException notFound) { notFound.printStackTrace(); fail("Unexpected exception: " + notFound.toString()); } catch (final AccountAlreadyExistException ex) { // Pass try { dao.removeAccount(account.getUserName()); } catch (final DAOException daoException) { daoException.printStackTrace(); fail("Unexpected exception "); } } } public void testRemoveAccount() { AccountDAOJDO dao = (AccountDAOJDO) new LiberatorDAOFactory().getAccountDAO(); Account account = new Account(USER_NAME, "charles", "charles_hhb@hotmail.com"); try { dao.addAccount(account); } catch (final AccountAlreadyExistException ex) { //pass } catch (DAOException e) { fail("Unexpected exception" + e.toString()); } try { dao.removeAccount(account.getUserName()); dao.findByUserName(account.getUserName()); fail("Expecting AccountNotFoundException"); } catch (final AccountNotFoundException notFound) { // Pass } catch (DAOException e) { fail("Unexpected exception" + e.toString()); } } public void testFindByUserNameNotFound() { try { AccountDAOJDO dao = (AccountDAOJDO) new LiberatorDAOFactory().getAccountDAO(); dao.findByUserName("NotExist"); // fail fail("Expecting excpeiton"); } catch (final AccountNotFoundException e) { //Pass } catch (final DAOException daoException) { daoException.printStackTrace(); fail("Unexpected exeption:" + daoException.toString()); } } public void testFindColumnWriter() { AccountDAOJDO dao = (AccountDAOJDO) new LiberatorDAOFactory().getAccountDAO(); try { Account account = new Account(USER_NAME, "charles", "charles_hhb@hotmail.com"); account.setColumnWriter( true ); dao.addAccount(account); Collection list = dao.findColumnWriters(); assertNotNull("columnWriters", list); assertTrue("list size should not be zero", list.size() != 0); dao.removeAccount(account.getUserName()); } catch (DAOException daoe) { daoe.printStackTrace(); fail("Unexpected exeption:" + daoe.toString()); }catch( final Exception e ){ e.printStackTrace(); fail("Unexpected exeption:" + e.toString()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -