Monday, October 31, 2011

FitNessize your JEE dev with minuteproject

This article shows you how-to setup FitNesse in your development environment when dealing with Relation Database CRUD operations. MinuteProject 4 FitNesse generates entire set of FitNesse wiki pages and associated java fixtures allowing you to reset the database as well as performing intuitively CRUD operations on top of tables and Select on top of views.
To illustrate this MinuteProject track, the Database used comes from the Lazuly showcase.
The sources can be found under lazuly-fitnesse.
This page will show you:
  • FitNesse + Minuteproject operating mechanism in Agile development
  • How-to Generate CRUD fixture
  • Integrate then in your own scenario to gain QA

Install FitNesse and Generate A Custom CRUD wiki for you model
  • Use Java 6
  • Install Lazuly DB (sql script here)
Download FitNesse
Execute java -jar fitnesse.jar
On a browser go to http://localhost to view the FitNesse wiki
Generate a FitNesse wiki for your model
  • Download MinuteProject
  • Generate using the following minuteproject configuration script: mp-config-LAZULY-FITNESSE.xml
  • Set this script in /mywork/config and run generate-model.(cmd/sh) mp-config-LAZULY-FITNESSE.xml
The mp-config-LAZULY-FITNESSE.xml configuration file
<!DOCTYPE root>
   <target-convention type="enable-updatable-code-feature" />
  <model name="conference" version="1.0" package-root="">
         <business-package default="conference">
             <condition type="package" startsWith="STAT" result="statistics"></condition>
             <condition type="package" startsWith="COUNTRY" result="admin"></condition>
             <condition type="package" startsWith="ROLE" result="admin"></condition>        
            default-primary-key-names="ID" >
   <target refname="FitNesse" 
   <target refname="LIB" 

What is generated
Wiki Fixtures for CRUD operations

Wiki source to be copied in your FitNesse Root Directory

FitNesse CRUD Wiki generated for you model.
Pick-up the snippet you need to:
  • SetUp you DB model
  • Perform sanity check 
    • after X UCs in a scenario, are my data correctly stored?
Lazuly FitNesse subwiki for select operations

Details of Select wiki fixtures for view 'stat_mb_by_role'

Lazuly FitNesse subwiki for insert update delete operations

Details of Insert, Update, Delete wiki fixtures for table 'address'

Associated Java Fixture 

Assemble for your need
Build Java Fixture Project
Compile the code in an IDE
  • add src-generated to your source directories
  • add MP 4 FitNesse depencies libraries
    • For the moment they are provided in MP package under /target/fitnesse/ and /target/fitnesse/dep
  • Lazuly-fitnesse is shipped with an eclipse project that compiles the code to /bin
  • The compilation directory is to be reference by the FitNesse wiki path directives.
SetUp FitNesse Lazuly Wiki
Althought MinuteProject provides CRUD wiki ready to use, the purpose of this section is to setup a custom wiki that will be used for your UC.
  • Create your FitNesse Application Wiki HomePage
    • Edit main page add a section called 'FitNesseLazulyScenario'
      • Add snippet [[Lazuly][FitNesse.LazulyScenario]]
  • Click on Lazuly ? or go to http://localhost/FitNesse.LazulyScenario
  • Compose a simple structure
    • Simple structure proposal
      • HomePage section (define the path to use)
      • Setup section (Used to reset DB)
      • Data Definition section (Used to define common variables referenced in scenario)
      • Populate section (Used to initialize DB with data)
      • Couple of UC section
Write a sample scenario
This scenario will populate couple of tables of the Lazuly DB and check if the result expected in the views is correct.
HomePage section
  • different pages (SetUp, VariableDefinition, UC sections) 
  • classpath

Setup section 
  • Reset Database
    • Reference Reset script executed by Scriptella (etl.xml)
      • Adapt the variable resetfilepathvar to point to your file path.
    • etl.xml references 3 sql script
      • reset_db.sql that proposed a Delete statement per table
        • It can be altered since the delete order might not be correct
        • In this case please add -- MP-MANAGED-STOP-GENERATING to prevent your modification to be lost for consecutive generation
      • insert_reference_data.sql
        • Add the data you wish
      • commit.sql that just perform a commit
  • Connection parameter to point to the database that include
    • DB URL
    • JDBC driver
    • Username
    • Password
  • All this code is generate in /ConferenceFitnesseWikiSetup/content.txt. It can also be copied from http://localhost/ConferenceFitnesseWikiSetup
Variable Definition section
Use Fitnesse directive !define to add relevant variable name for your scenario
Those variables will be later refered in your UCs

Populate section 
The SetUp page is automatically included at the beginning of your scenario.
But you have to reference the Variable Definition section. For that use the FitNesse directive !include (!include VariableDefinition)

Pick-up CRUD snippet from MP generated FitNesse Wiki to create you own customed DB initialization.
Insert reference data Country, Role
Insert business data: Address, Conference, ConferenceMember


UC Check section
Pick-up CRUD snippet from MP generated FitNesse Wiki to create you own customed DB initialization.
In this case, I simply check that the data are stored correctly.
There is a view that gather BI information and I use it to validate the correctness of the information.

This example shows that you can have use very easily CRUD fitnesse fixture (Zero LOC of development are required) customized for your data model.
To sum-up, here are the main points:
  • Reset DB
  • Initialize DB
  • Perform sanity check
  • Set-up FitNesse for your hadoc UCs for JEE data centric application

MinuteProject Spin-offs
At this point on you can guarante that the data retrieved from the view are correct.
That means that you have QA on your model.
If the views have a field containing unique values then you can benefit of MinuteProject spin-off i.e. use other track to generate out-of-the-box:
  • Web2.0 application in Openxava on top of views. See on this blog the following article 
  • REST application.
  • Web service application.
For Real UCs
Here the UCs demonstrated concern only CRUD operations on top of DB entities.
2 next articles in prepartion will show how to integrate with:
  • JPA2 ORM backend
  • Spring/JPA/Hibernate backend
Additional information
MinuteProject 4 FitNesse

Friday, October 14, 2011

MinuteProject goes SOA

Minuteproject "traditional" activity is to generate artifacts based on a Relation Database (RDBMS).
Meanwhile RDBMS is not the only type of standard structured information that is available on the market.
WSDL and WADL format describes a standard way to integrate systems with open technologies.
WSDL is widely used for webservice with SOAP messages integration promoted by the OASIS standards.
WADL is the representation of the REST contract offered by an application.

Minuteproject is integrating the metro API to parse wsdl and get a WsdlModel to generate artifacts upon.

The integration with metro is fairly simple

package metro;



public class SimpleWSDLModel {

public static void main(String[] args) {
ErrorReceiverFilter receiver = new ErrorReceiverFilter();
WsimportOptions options = new WsimportOptions();
options.addWSDL(new File(args[0]));
WSDLModeler wsdlModeler = new WSDLModeler(options, receiver);
Model wsdlModel = wsdlModeler.buildModel();

When giving a wsdl location file-system or URL, then Metro provides a wsdlModel that contains all the wsdl structure in memory and xml schema elements converted into their jaxb correspondance.
This eases the integration into minuteproject since the elements (jaxb classes, service, port, binding) are ready to be set into templates.
The goal for minuteproject is not to re-do the JAX-WS part of Metro available by wsimport command but to add a set of new tracks and artifacts to reduce the development effort.

Some tracks could be:
  • SOA FitNesse track: providing a FitNesse wiki with fixture (slim) to test the webservice implementation (without deployment)
  • Screens: JSF, vaadin for webservice client
  • WebService implementation
  • ...
This functionality will be available in the next release 0.7.
The SOA tracks will be added one at time.