views:

106

answers:

1

I've been struggling with this for past couple of days. I am trying to test a DAO outside the container but while running the test case I am getting the error:

Error creating bean with name 'SqlMapClient' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/iplanet/ias/admin/common/ASException

I'm using NB to run the tests. people have been saying that I need the above class to be in the run time class path of the test case. However, I am absolutely unable to find where actually that jar is...?? I've included all that jars that are on my containers classpath + jars in my projects lib folder to the runtime classpath of the Unit test. Still I get the same error.

Also googling for this JAR didnt work either.

Maybe someone out there knows where to get this freakin jar from. And hopefully that fixed my problems.

+2  A: 

This doesn't directly answer your question but I have two advices. First, now that I know that you are using Spring, I'd suggest to stop using your own ServiceLocator to lookup the JNDI datasource as you mentioned in a previous question. Instead, you should use Spring facilities for that and then inject the datasource into yours beans. To get a JDNI datasource, use Spring's JndiObjectFactoryBean, something like that:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:/comp/env/jdbc/myDS</value>
    </property>
</bean>

Then, when running outside the container (typically when running tests), my advice would be to not use a JNDI datasource. Instead, you should use Spring facilities to provide a datasource to your DAOs in another way (e.g. using a DriverManagerDataSource, you don't need a real connection pool when running tests). This would allow you to run your tests without having to start iPlanet which makes sense for testing (and you don't want to test iPlanet's connection pool, you want to test your DAOs).

So, create an applicationContext-test.xml to be used during testing with another configuration for the data access. Below, a sample configuration for the DriverManagerDataSource:

<bean id="dataSource"
         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="..."/>
    <property name="url" value="..."/>
    <property name="username" value="..."/>
    <property name="password" value="..."/>
</bean>

This is really the recommended approach (check the chapter Data access using JDBC for more details on the different options).

PS: I have no idea from where com/iplanet/ias/admin/common/ASException comes from but it is obviously one of iPlanet itself. If you really want to find out, search in all jars of your iPlanet install, especially the one referenced in its startup script. But I think that' you'll face JNDI issues after that, be warned.

Pascal Thivent
when working outside the container I did stop using the JNDI name. instead I use what you suggested. As mentioned in this question: stackoverflow.com/questions/1716636/… The xml snippet you gave above wont be enough. I will still need SqlMapClientFactoryBean (because my DAO uses getSqlMapClientTemplate().queryForXXX(). If I don't have SqlMapClientFactoryBean then I get an error saying 'No sqlMapClient Found'. And the error comes when instantiating THAT bean. I did not explicitly install iplanet. I think i'll install it now to actually find the damn thing.
Omnipresent
Of course you need `SqlMapClientFactoryBean`, I was just covering the datasource part. I'm gonna check the other question because something is confusing me, I don't get how a iPlanet exception can be thrown if you're not doing anything with iPlanet...
Pascal Thivent
exactly!! and Im trying to do everything outside the container. whatever iplanet is..it has to be related to the appserver..but appserver is not even in the picture here. Please let me know if you want me to post something else (code wise). I'll accept your answer here. we can move to the other question. thanks
Omnipresent