The Spring LDAP framework is a great library to assist in working with LDAP servers through a more manageable API. It provides the niceties that the DataSource interface does for JDBC along with support similar to the Spring JDBC framework. One area that has been lacking though is testing. With JDBC based code it is easy enough to use HSQLDB to provide an in-memory database to test against. With LDAP based code there hasn't been a good solution, until the Apache Directory project came along.
Apache Directory is a 100% Java LDAP implementation and includes support for in-memory LDAP instances for unit testing. Using this support plus a few helper classes to bridge the gap to Spring LDAP providing unit tests for LDAP related code is easy.
First add the necessary dependencies. If you are using Maven your project needs to depend on the following for testing:
Second, add AbstractDirContextTest.java and SingleContextSource.java to your project.
Finally extend AbstractDirContextTest for your LDAP code test class.
Your test class needs to provide a partition name, which is the root of the DN for the server to test against, and a Resource array of ldiff files to load into the LDAP server. For the test above the ldiff file looke like:
Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts
Monday, July 14, 2008
Wednesday, March 26, 2008
Java SQLException Chaining
In JDK 1.4 chained Throwables were added and made logging and tracing exceptions much easier. Being able to create a new exception and specify the causing exception in a standard way, tied to JVM printing out the stack chain, was a big boost to tracking down problems in an application.
There are still some exceptions that do not use this standard chaining mechanism and one of the most frustraiting cases in SQLException. It provides a getNextException() method which returns the next SQLException related to the failed operation. The problem here is without special handling code these nextExceptions just get lost in log messages.
A general solution to this problem is to add an Aspect that either logs the results of getNextException or adds them to the exception chain.
This aspect class can be used via Spring's AOP support with the following context configuration:
There are still some exceptions that do not use this standard chaining mechanism and one of the most frustraiting cases in SQLException. It provides a getNextException() method which returns the next SQLException related to the failed operation. The problem here is without special handling code these nextExceptions just get lost in log messages.
A general solution to this problem is to add an Aspect that either logs the results of getNextException or adds them to the exception chain.
This aspect class can be used via Spring's AOP support with the following context configuration:
Wednesday, December 12, 2007
Spring 2.5 Module Contents
The 2.5 release of the Spring Framework re-organized many packages and classes in the specific module JARs. Moving from Spring 2.0 to 2.5 introduces some pain in figuring out what moved where and I couldn't find anything detailing which packages reside in which module JARs. So after a few lines of shell-fu I produced the following to help with the upgrades:
spring-jms.jar
spring-core.jar
spring-web.jar
spring-aop.jar
spring-webmvc-portlet.jar
spring-tx.jar
spring-beans.jar
spring-webmvc-struts.jar
spring-context-support.jar
spring-context.jar
spring-orm.jar
spring-webmvc.jar
spring-test.jar
spring-jdbc.jar
spring-jms.jar
META-INF/
org/
org/springframework/
org/springframework/jms/
org/springframework/jms/config/
org/springframework/jms/connection/
org/springframework/jms/core/
org/springframework/jms/core/support/
org/springframework/jms/listener/
org/springframework/jms/listener/adapter/
org/springframework/jms/listener/endpoint/
org/springframework/jms/listener/serversession/
org/springframework/jms/remoting/
org/springframework/jms/support/
org/springframework/jms/support/converter/
org/springframework/jms/support/destination/
spring-core.jar
META-INF/
org/
org/springframework/
org/springframework/asm/
org/springframework/asm/commons/
org/springframework/asm/signature/
org/springframework/core/
org/springframework/core/annotation/
org/springframework/core/enums/
org/springframework/core/io/
org/springframework/core/io/support/
org/springframework/core/style/
org/springframework/core/task/
org/springframework/core/task/support/
org/springframework/core/type/
org/springframework/core/type/classreading/
org/springframework/core/type/filter/
org/springframework/metadata/
org/springframework/metadata/commons/
org/springframework/util/
org/springframework/util/comparator/
org/springframework/util/xml/
spring-web.jar
META-INF/
org/
org/springframework/
org/springframework/remoting/
org/springframework/remoting/caucho/
org/springframework/remoting/httpinvoker/
org/springframework/remoting/jaxrpc/
org/springframework/remoting/jaxrpc/support/
org/springframework/remoting/jaxws/
org/springframework/web/
org/springframework/web/bind/
org/springframework/web/bind/annotation/
org/springframework/web/bind/support/
org/springframework/web/context/
org/springframework/web/context/request/
org/springframework/web/context/support/
org/springframework/web/filter/
org/springframework/web/jsf/
org/springframework/web/jsf/el/
org/springframework/web/multipart/
org/springframework/web/multipart/commons/
org/springframework/web/multipart/support/
org/springframework/web/util/
spring-aop.jar
META-INF/
org/
org/springframework/
org/springframework/aop/
org/springframework/aop/aspectj/
org/springframework/aop/aspectj/annotation/
org/springframework/aop/aspectj/autoproxy/
org/springframework/aop/config/
org/springframework/aop/framework/
org/springframework/aop/framework/adapter/
org/springframework/aop/framework/autoproxy/
org/springframework/aop/framework/autoproxy/target/
org/springframework/aop/interceptor/
org/springframework/aop/scope/
org/springframework/aop/support/
org/springframework/aop/support/annotation/
org/springframework/aop/target/
org/springframework/aop/target/dynamic/
spring-webmvc-portlet.jar
META-INF/
org/
org/springframework/
org/springframework/web/
org/springframework/web/portlet/
org/springframework/web/portlet/bind/
org/springframework/web/portlet/context/
org/springframework/web/portlet/handler/
org/springframework/web/portlet/multipart/
org/springframework/web/portlet/mvc/
org/springframework/web/portlet/mvc/annotation/
org/springframework/web/portlet/util/
spring-tx.jar
META-INF/
org/
org/springframework/
org/springframework/dao/
org/springframework/dao/annotation/
org/springframework/dao/support/
org/springframework/jca/
org/springframework/jca/cci/
org/springframework/jca/cci/connection/
org/springframework/jca/cci/core/
org/springframework/jca/cci/core/support/
org/springframework/jca/cci/object/
org/springframework/jca/context/
org/springframework/jca/endpoint/
org/springframework/jca/support/
org/springframework/jca/work/
org/springframework/transaction/
org/springframework/transaction/annotation/
org/springframework/transaction/config/
org/springframework/transaction/interceptor/
org/springframework/transaction/jta/
org/springframework/transaction/support/
spring-beans.jar
META-INF/
org/
org/springframework/
org/springframework/beans/
org/springframework/beans/annotation/
org/springframework/beans/factory/
org/springframework/beans/factory/access/
org/springframework/beans/factory/annotation/
org/springframework/beans/factory/config/
org/springframework/beans/factory/generic/
org/springframework/beans/factory/parsing/
org/springframework/beans/factory/serviceloader/
org/springframework/beans/factory/support/
org/springframework/beans/factory/wiring/
org/springframework/beans/factory/xml/
org/springframework/beans/propertyeditors/
org/springframework/beans/support/
spring-webmvc-struts.jar
META-INF/
org/
org/springframework/
org/springframework/web/
org/springframework/web/servlet/
org/springframework/web/servlet/view/
org/springframework/web/servlet/view/tiles/
org/springframework/web/struts/
spring-context-support.jar
META-INF/
org/
org/springframework/
org/springframework/cache/
org/springframework/cache/ehcache/
org/springframework/mail/
org/springframework/mail/javamail/
org/springframework/scheduling/
org/springframework/scheduling/commonj/
org/springframework/scheduling/quartz/
org/springframework/ui/
org/springframework/ui/freemarker/
org/springframework/ui/jasperreports/
org/springframework/ui/velocity/
spring-context.jar
META-INF/
org/
org/springframework/
org/springframework/context/
org/springframework/context/access/
org/springframework/context/annotation/
org/springframework/context/config/
org/springframework/context/event/
org/springframework/context/i18n/
org/springframework/context/support/
org/springframework/context/weaving/
org/springframework/ejb/
org/springframework/ejb/access/
org/springframework/ejb/config/
org/springframework/ejb/support/
org/springframework/instrument/
org/springframework/instrument/classloading/
org/springframework/instrument/classloading/glassfish/
org/springframework/instrument/classloading/oc4j/
org/springframework/instrument/classloading/weblogic/
org/springframework/jmx/
org/springframework/jmx/access/
org/springframework/jmx/export/
org/springframework/jmx/export/annotation/
org/springframework/jmx/export/assembler/
org/springframework/jmx/export/metadata/
org/springframework/jmx/export/naming/
org/springframework/jmx/export/notification/
org/springframework/jmx/support/
org/springframework/jndi/
org/springframework/jndi/support/
org/springframework/remoting/
org/springframework/remoting/rmi/
org/springframework/remoting/soap/
org/springframework/remoting/support/
org/springframework/scheduling/
org/springframework/scheduling/backportconcurrent/
org/springframework/scheduling/concurrent/
org/springframework/scheduling/support/
org/springframework/scheduling/timer/
org/springframework/scripting/
org/springframework/scripting/bsh/
org/springframework/scripting/config/
org/springframework/scripting/groovy/
org/springframework/scripting/jruby/
org/springframework/scripting/support/
org/springframework/stereotype/
org/springframework/ui/
org/springframework/ui/context/
org/springframework/ui/context/support/
org/springframework/validation/
spring-orm.jar
META-INF/
org/
org/springframework/
org/springframework/orm/
org/springframework/orm/hibernate3/
org/springframework/orm/hibernate3/annotation/
org/springframework/orm/hibernate3/support/
org/springframework/orm/ibatis/
org/springframework/orm/ibatis/support/
org/springframework/orm/jdo/
org/springframework/orm/jdo/support/
org/springframework/orm/jpa/
org/springframework/orm/jpa/persistenceunit/
org/springframework/orm/jpa/support/
org/springframework/orm/jpa/vendor/
org/springframework/orm/toplink/
org/springframework/orm/toplink/support/
spring-webmvc.jar
META-INF/
org/
org/springframework/
org/springframework/web/
org/springframework/web/servlet/
org/springframework/web/servlet/handler/
org/springframework/web/servlet/handler/metadata/
org/springframework/web/servlet/i18n/
org/springframework/web/servlet/mvc/
org/springframework/web/servlet/mvc/annotation/
org/springframework/web/servlet/mvc/multiaction/
org/springframework/web/servlet/mvc/support/
org/springframework/web/servlet/mvc/throwaway/
org/springframework/web/servlet/support/
org/springframework/web/servlet/tags/
org/springframework/web/servlet/tags/form/
org/springframework/web/servlet/theme/
org/springframework/web/servlet/view/
org/springframework/web/servlet/view/document/
org/springframework/web/servlet/view/freemarker/
org/springframework/web/servlet/view/jasperreports/
org/springframework/web/servlet/view/tiles2/
org/springframework/web/servlet/view/velocity/
org/springframework/web/servlet/view/xslt/
spring-test.jar
META-INF/
org/
org/springframework/
org/springframework/mock/
org/springframework/mock/jndi/
org/springframework/mock/web/
org/springframework/mock/web/portlet/
org/springframework/test/
org/springframework/test/annotation/
org/springframework/test/context/
org/springframework/test/context/junit38/
org/springframework/test/context/junit4/
org/springframework/test/context/support/
org/springframework/test/context/testng/
org/springframework/test/context/transaction/
org/springframework/test/jdbc/
org/springframework/test/jpa/
org/springframework/test/util/
org/springframework/test/web/
spring-jdbc.jar
META-INF/
org/
org/springframework/
org/springframework/jdbc/
org/springframework/jdbc/core/
org/springframework/jdbc/core/metadata/
org/springframework/jdbc/core/namedparam/
org/springframework/jdbc/core/simple/
org/springframework/jdbc/core/support/
org/springframework/jdbc/datasource/
org/springframework/jdbc/datasource/lookup/
org/springframework/jdbc/object/
org/springframework/jdbc/support/
org/springframework/jdbc/support/incrementer/
org/springframework/jdbc/support/lob/
org/springframework/jdbc/support/nativejdbc/
org/springframework/jdbc/support/rowset/
Subscribe to:
Posts (Atom)