facebook

Test datasource application using JUNIT.

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #305207 Reply

    muddu_shafi
    Member

    I have a JUnit class which imports my DAO class.
    In one of my JUNIT testcase. I want to call a method from DAO class, that connects to database. i.e I want to test a connection to database.

    
    /* DAO class connection that is used to connect to database by reading datasource files stored in JBOSS applicatin server */
    private Connection connectToDatabase(String name) throws DaoException, SQLException{
            Context ctx = null;
            DataSource ds = null;
            try{
                ctx = new InitialContext();
                ds = (DataSource) ctx.lookup("java:" + name + "-ds");
            }catch(Exception e){
                throw new ErpProxyDaoException("Thrown NamingException -- ", e);
            }
    
            return ds.getConnection();
    }

    I’ve connected to Jboss4.3 server using MyEclipse, and ran the server using default configruation. The server started with out any hitch.

    But when I try to run Junit test it displays me a error as such

    org.atcc.erpproxy.services.dao.ErpProxyDaoException: org.atcc.erpproxy.services.dao.ErpProxyDaoException: Thrown NamingException -- 
        at org.atcc.erpproxy.services.dao.progress.ErpProxyProgressDAO.persistSalesOrder(ErpProxyProgressDAO.java:2828)
        at org.atcc.erpproxy.services.dao.ErpProxyProgressDAOJunitTest.testPersistSalesOrderSalesOrderGood(ErpProxyProgressDAOJunitTest.java:447)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at junit.framework.TestSuite.runTest(TestSuite.java:208)
        at junit.framework.TestSuite.run(TestSuite.java:203)
        at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: org.atcc.erpproxy.services.dao.ErpProxyDaoException: Thrown NamingException -- 
        at [b]org.atcc.erpproxy.services.dao.progress.ErpProxyProgressDAO.connectToDatabase(ErpProxyProgressDAO.java:233)
        at org.atcc.erpproxy.services.dao.progress.ErpProxyProgressDAO.getQadWebDbConnection(ErpProxyProgressDAO.java:201)[/b]
        at org.atcc.erpproxy.services.dao.progress.ErpProxyProgressDAO.persistSalesOrder(ErpProxyProgressDAO.java:2801)
        ... 19 more
    Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at org.atcc.erpproxy.services.dao.progress.ErpProxyProgressDAO.connectToDatabase(ErpProxyProgressDAO.java:231)
        ... 21 more
    

    1) Can anyone explain me what am I doing wrong here?
    2) Is the JUnit/MyEclipse looking at the Jboss sever to read the datasource files? If not, how should I make them look at those files?

    3) Can any one give me a (link to ) tutorialthat explains how to test database application using Myclipse, JUNit and Jboss?
    Please any help is appreciated.

Viewing 1 post (of 1 total)
Reply To: Test datasource application using JUNIT.

You must be logged in to post in the forum log in