I made a change in the blogger configuration to ease the later work when blogging. It is possible that older entries are not correctly formatted.

Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts

Saturday, 2 June 2012

Spring Testing

This entry contains necessary information about Testing with Spring. One of the most interesting feature of the Spring Framework is the use of lightweight containers which simplify the testing of an application, whether the usual J2EE container can be more cumbersome to test.

Since there are so many aspects in Spring, I should first present a given overview of the different topics.

Dao Testing

Spring provides different mechanism to simplify testing. In particular there is a class to perform Dao testing by including the transactional aspects. You can easily load your daos using a xml file to initialize the configurations of the database and daos.

NOTE to myself: I hsould give here a code example.

Controller Testing

Here again Spring controller are quite easy to test. They require very little overhead. And the dependency injection provide a very simple setup.

Thursday, 14 January 2010

ROO - a spring and Maven based rapid development framework

I just discovered ROO. I tried it. But I had some problems running it under fedora with java 1.6 and maven 2.0.8. It seems that it need maven 2.0.9. The idea behind roo is to have a command line based system to develop. It is somewhat similar to Ruby on Rails. You issue commands and create and edit the entities that way. I give here an example of script:
project --topLevelPackage org.myexample persistence setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT database properties list database properties set --key database.url --value jdbc:hsqldb:${user.home}/tmp/datasources/my-example database properties list
This first part of the script creates a project pom.xml (for maven) and sets the necessary properties for working with hibernate using an in memory database.
entity --class ~.domain.MyExample field string code --notNull --sizeMin 32 --sizeMax 32 field string firstName --sizeMax 65 field string lastName --sizeMax 65 field string email --sizeMax 65 field number age --type java.lang.Integer field date confirmed --type java.util.Date
This second party from the script creates an entity: MyExample. It also creates a number of fields: code, firstName, lastName, email. The next part of the script takes care of creating controllers and tests. The line:
controller scaffold ~.web.MyExampleController
creates a controller for CRUD operations. It also performs the tests to make sure it works correctly. Finally, it sets up the logging framework as well as the security framework.
test integration controller scaffold ~.web.MyExampleController selenium test --controller ~.web.MyExampleController perform test // (OPTION: quit, mvn tomcat:run, localhost:8080/myexample, mvn selenium:selenese) logging setup --level DEBUG --package WEB security setup
The next section creates a new controller class called: org.myexample.web.My2ndExampleController. It lists the finders and adds the finder to the class.
controller class --class ~.web.My2ndExampleController finder list --class ~.domain.MyExample --filter code,equ finder add --finderName findMyExamplesByCodeEquals perform eclipse
At the end the perform eclipse sets the system for using the system under eclipse.

Friday, 11 January 2008

Spring Aspect Oriented Programming

The Spring framework has many features for aspect orientation. I do not define here the usual concepts of aspect oriented programming: join points, cut points, advice, weaving... A few important aspects:
  • the weaving process of the Spring framework is performed at runtime.
  • the Spring framework uses proxies to implement the aspect orientation. These proxies come in two flavors, either a JDK dynamic Proxy (?) or a CGLIB proxy (see the web site of CGLIB for this).
  • no field point cut (use aspectJ for this)
  • the spring AOP does not implement the complete AOP, but mainly the most important aspects of AOP needed for the Inversion of Control approach of the spring framework for enterprise applications

Wednesday, 12 December 2007

Spring framework

The following explanation comes mainly from an article from: the ServerSide

Since Spring is a framework which is gathering speed and value in the software industry, I also had to take a look at this framework.

The spring framework is based on the use of a method close to the design pattern: dependency injection (a flavor of another pattern called inversion of control). The basic idea is that there is a light-weight container which helps the programmer managing the life cycle of the objects ( from creation to destruction). It is similar to the idea of bean container, but also work with POJOs (Plain Old Data Objects). This has two advantages:

  • it is a lightweight container which can be used on top of application servers like Web Sphere, JBoss,...
  • the configuration of the object can be done easily through configuration files (some can be in XML, but simple property files are also possible)
Supplementary to the Inversion of control features, the spring framework provides a number of supplementary help tools. For example: using the JDBCTemplate class on a data source, it is easy to query and store the results of the query in a list.

JDBC, Hibernate and Transactions

There is many possibilities to use JDBC with DAO object with the spring framework. It allows the possibility to use configuration to use JTA transaction or direct call using direct JDBC calls or calls to Hibernate.

Aspect Orientation

Using the Spring AOP features you can specify:

  • Interception: some code can be called before or after method calls for any interface or class.
  • Introduction: it is possible to use advices to modify the class or implementation of classes and objects ( the called code when getting to a point cut, i.e when a crosscutting feature must be implemented
  • Static and dynamic pointcuts: the static pointcuts define what happens when a join point is reached; it is possible to consider parameters of method for the pointcut definition. Through separation from pointcuts and interceptors, the interceptors can be reused in different applications.
Moreover, Spring integrates with AspectJ, so it is possible to use aspectJ code with Spring.

Again using the AOP from spring, it is possible to implement transaction management with Rollback with or without JTA.

MVC

Spring contains a powerful and highly configurable MVC framework which integrates well with struts, JSP, velocity...

EJB

Spring framework can be useful for implementing EJBs as well as on the client side of the EJBs

Testing

Testing is very important for enterprise applications, Spring allows many aspects of testings in particular unit testing through the use of the inversion of control design pattern.

This is very succint especially toward the end but I will complete it later.