⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountdaomysqltest.java

📁 Chinaxp 论坛源代码
💻 JAVA
字号:
package org.redsoft.forum.dao.mysql;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;import org.redsoft.forum.fixture.MysqlFixture;import java.util.Collection;/** * Test case for AccountDAOmySql * */public class AccountDAOmySqlTest extends TestCase {private MysqlFixture mysqlFixtureIns = new MysqlFixture();private static final String USER_NAME ="ForTest";public AccountDAOmySqlTest(String name) {    super(name);}public void setUp() throws Exception {	//mysqlFixtureIns.setUp();}public void tearDown() throws Exception {	//mysqlFixtureIns.tearDown();}public void testAddAccountNormal(){    AccountDAOmySql dao = new AccountDAOmySql();    Account account = new Account(USER_NAME,"charles","charles_hhb@hotmail.com");    try {        dao.removeAccount( account.getUserName() );    } catch( final DAOException e ){        fail("Unexpected exception" + e.toString() );    }    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(){    AccountDAOmySql dao = null;    Account account = null;    try{	dao = new AccountDAOmySql();        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(){    AccountDAOmySql dao = null;    Account account = null;    try{	dao = new AccountDAOmySql();        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(){    AccountDAOmySql dao = new AccountDAOmySql();    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{		AccountDAOmySql dao = new AccountDAOmySql();        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() {    AccountDAOmySql dao = new AccountDAOmySql();    try {        Collection list = dao.findColumnWriters();        assertNotNull( "columnWriters", list );        assertTrue( "list size should not be zero", list.size() !=0 );    } catch (DAOException daoe) {        daoe.printStackTrace();        fail("Unexpected exeption:" + daoe.toString() );    }}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -