From: Cruz, E. J. <e....@ra...> - 2003-12-11 20:44:41
|
Hi, First I apologize for sending this to this list but the user list keeps bouncing the message. I have an interface described below. interface AccountBusiness { public UserTo authenticateUser(AccountTo account); } interface AccountDao { public AccountBusiness getAccount(account); } I have a method that uses this interface below: public UserTo authenticateUser(AccountTo account) { AccountBusiness accountBusiness = null; accountBusiness = getAccount(account); /** Some more stuff to perform authentication */ } private AccountBusiness getAccount(accounTo account) { AccountBusiness accountBusiness = null; try { defaultDaoManager.startTransaction(); /** This is the line that causes the error */ accountBusiness = accountDao.getAccount(account); defaultDaoManager.commitTransaction(); } catch (DaoException de) { try { defaultDaoManager.rollbackTransaction(); } catch (DaoException de2) { log.error(de.getMessage(), de); throw new ResourceException(de); } return accountBusiness; } I am trying to test this method using Mock Objects. I have the following code to test this: public class AccountAppServiceTest extends TestCase { private AccountAppService accountAppService = null; private AccountTo account = null; private DaoManager defaultDaoManager = null; private Mock accountDao = null; protected void setUp() throws Exception { super.setUp(); defaultDaoManager = new DaoManagerMock(); accountDao = new Mock(AccountDAO.class); accountAppService = new AccountAppService (defaultDaoManager, (AccountDAO)accountDao.proxy()); account = new AccountTo(); account.setUsername("ecruz"); account.setPassword("testing"); account.setStatus("Active"); account.setBadPasswordCounter(2); account.setDatePasswordChanged(new Date()); account.setFirstLogin(true); } public void testAuthenticateUser() { //Setup Mock returnMock = new Mock(AccountBusiness.class); UserTo expectedUser = new UserTo(account.getUsername()); List expectedRoles = new ArrayList(); expectedRoles.add("test"); expectedRoles.add("test1"); AccountBusiness returnVal = (AccountBusiness)returnMock.proxy(); /** Here I tell it to expect the call to the accountDao getAccount method and to return the AccountBusiness Mock proxy but I receive the error below.*/ accountDao.expectAndReturn("getAccount", C.eq(account), (AccountBusiness)returnMock.proxy()); returnMock.expectAndReturn("authenticateUser", C.eq(account), expectedUser); accountDao.expectAndReturn("getAccountRoles", C.eq(account), expectedRoles); UserTo actualUser = null; //Run try { actualUser = accountAppService.authenticateUser(account); } catch (Exception e) { e.printStackTrace(); this.fail("Unexpected Exception reported " + e.toString()); } //Validate this.assertEquals("Unexpected UserName: ", expectedUser.getUserName(), actualUser.getUserName()); this.assertEquals("Unexpected Roles: ", expectedRoles, actualUser.getRoles()); accountDao.verify(); returnMock.verify(); } protected void tearDown() throws Exception { // Set everything to null } } I receive this error when the accountDao.getAccount(account) method is called above in the private getAccount method of the AccountAppService. I use the same type of return value in the expect in another test case and I do not get any errors. Any Suggestions on what this may be? [junit] ------------- Standard Error ----------------- [junit] java.lang.ClassCastException [junit] at $Proxy0.getAccount(Unknown Source) [junit] at gov.wos.domain.account.AccountAppService.getAccount(Unknown Source) [junit] at gov.wos.domain.account.AccountAppService.authenticateUser(Unknown Source) [junit] at gov.wos.domain.account.AccountAppServiceTest.testAuthenticateUser(Unknown Source) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) [junit] at java.lang.reflect.Method.invoke(Method.java:324) [junit] at junit.framework.TestCase.runTest(TestCase.java:154) [junit] at junit.framework.TestCase.runBare(TestCase.java:127) [junit] at junit.framework.TestResult$1.protect(TestResult.java:106) [junit] at junit.framework.TestResult.runProtected(TestResult.java:124) [junit] at junit.framework.TestResult.run(TestResult.java:109) [junit] at junit.framework.TestCase.run(TestCase.java:118) [junit] at junit.framework.TestSuite.runTest(TestSuite.java:208) [junit] at junit.framework.TestSuite.run(TestSuite.java:203) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRu nner.java:325) [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestR unner.java:524) [junit] ------------- ---------------- --------------- [junit] Testcase: testAuthenticateUser(gov.wos.domain.account.AccountAppServiceTest): FAILED [junit] Unexpected Exception reported java.lang.ClassCastException [junit] junit.framework.AssertionFailedError: Unexpected Exception reported java.lang.ClassCastException [junit] at gov.wos.domain.account.AccountAppServiceTest.testAuthenticateUser(Unknown Source) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) Jamie Cruz Software Engineering e....@ra... (301)688-1430 ------_=_NextPart_000_01C3C025.C3736B30 Content-Type: application/octet-stream; name="Cruz, Edward J..vcf" Content-Disposition: attachment; filename="Cruz, Edward J..vcf" BEGIN:VCARD VERSION:2.1 N:Cruz;Edward FN:Cruz, Edward J. ADR;WORK:;Ops3 LABEL;WORK:Ops3 KEY;X509;ENCODING=BASE64: MIIEMzCCA5ygAwIBAgIDAnL2MA0GCSqGSIb3DQEBBQUAMGQxCzAJBgNVBAYTAlVTMRgwFgYD VQQKEw9VLlMuIEdvdmVybm1lbnQxDDAKBgNVBAsTA0RvRDEMMAoGA1UECxMDUEtJMR8wHQYD VQQDExZET0QgQ0xBU1MgMyBFTUFJTCBDQS0zMB4XDTAyMDMyMjIxMzAyN1oXDTA1MDMyMjIx MzAyN1oweDELMAkGA1UEBhMCVVMxGDAWBgNVBAoTD1UuUy4gR292ZXJubWVudDEMMAoGA1UE CxMDRG9EMQwwCgYDVQQLEwNQS0kxEDAOBgNVBAsTB05TQS9DU1MxITAfBgNVBAMTGENydXou RWR3YXJkLkouMDUxNDEwMTI2MjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA9MUBKNyq 6pcDEkrbH+sv05Roqv7PG6uL+atAiRgpUlqRuzuj8wPFBJLGGH4e+70Z9blnzGY/4vn6EXkw f7jB/MLHtEHrLgDQ200/U6rQdzylekHX3EDDdDLKHGfNvs7i8jV1IgllKEpegdEFB1KxDiVV zAT42fYkCBcvSpJ9UjkCAwEAAaOCAd0wggHZMA4GA1UdDwEB/wQEAwIFIDAfBgNVHSMEGDA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