1.0 Other languages |
||||
3.2 Controller |
||||
|
org.velocityweb.controller.Controller is a pure Java class. Application that using VelocityWeb should write a sub-class of this class. There is another class named as org.velocityweb.controller.impl.SimpleController in VelocityWeb that is the sub-class of org.velocityweb.controller.Controller. The new web application should write a new class,for example, PetStoreController, make it as sub-class of either SimpleController or Controller. Normally, new controller should overwrite following functions:
Here is an example in VPetstore, PetStoreController use JNDI to lookup datasource, which is used when web application running normally: |
|||
public class PetStoreController extends SimpleController { |
||||
For unit test, we need to write a new controller which overwrite function getDataSource(). For example, we can use Apache DBCP to provide datasource: |
||||
public class TestPetStoreController extends PetStoreController { |
||||
The reason why getDataSource() is protected, is to prevent some code to call it outside DAO class. We put this Datasource object into AppContext object, it will be passed from web dispatcher to DAO. |
||||