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
Overview




Install FitNesse and Generate A Custom CRUD wiki for you model
Prerequisites
  • Use Java 6
  • Install Lazuly DB (sql script here)
Installation
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>
<generator-config>
 <configuration>
  <conventions>
   <target-convention type="enable-updatable-code-feature" />
  </conventions> 
  <model name="conference" version="1.0" package-root="net.sf.mp.demo">
   <data-model>
    <dataSource>
     <driverClassName>org.gjt.mm.mysql.Driver</driverClassName>
     <url>jdbc:mysql://127.0.0.1:3306/conference</url>
     <username>root</username>
     <password>mysql</password>
    </dataSource>
   </data-model>
   <business-model>
         <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>        
         </business-package>   
    <enrichment>
     <conventions>
         <view-primary-key-convention 
            type="apply-default-primary-key-otherwise-first-one" 
            default-primary-key-names="ID" >
         </view-primary-key-convention>
     </conventions>
    </enrichment>
   </business-model>
  </model>
  <targets> 
   <target refname="FitNesse" 
      name="default" 
      fileName="mp-template-config-fitnesse.xml" 
      outputdir-root="D:/DEV/LAZULY/lazuly-fitnesse"
      templatedir-root="../../template/framework/fitnesse">
   </target> 
   <target refname="LIB" 
      fileName="mp-template-config-bsla-LIB-features.xml" 
      templatedir-root="../../template/framework/bsla">
   </target>
  </targets>  

 </configuration>
</generator-config>
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
Defines 
  • 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.


















Conclusion
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

2 comments:

  1. Hello ,

    Im currently working as ETL Tester were i used to Test the [Data Validation] Data between Source vs Target

    I would like to how can i achieve with this tool ?

    Thanks ,
    Srini

    ReplyDelete
    Replies
    1. Hello Srini,

      The example above shows you how to use minuteproject 4 fitnesse to get:
      - fitnesse CRUD fixtures
      - fitnesse wiki pages

      This pages illustrate how to use those fixture to perform a sample test with 2 aspects
      - setting all the data to test
      - retrieving the data (here based on views)
      The second steps validate that the implementation of the view is correct and acts also as a sanity check.

      In real project for the second step can replaced by a fixture on top of your Use case or the system (application ETL tool).
      This fixture has to be developed by yourself: it is a class (JAVA/.NET) that transmits data from Fitnesse wiki to your fixture which calls the API of your system (in your case your ETL tool)

      Regards,

      Florian

      Delete