Friday, March 12, 2010

Another NoSQL Database : FluidDB

FluidDB is another database in the NoSQL category. It is a cloud based data store and follows the Wiki style approach for data storage. By Wiki style user can create objects in the FluidDB space and modify the existing one. Yet it uses a permission model which differentiates the it from being exact Wiki like.

FluidDB provides HTTP API interface with JSON and provides the HTTP Basic Authentication. FluidDB is in the early private Alpha stage and exposed to only limited number of users. A Sandbox is available where anyone can play with the database and for more detail look one can request the private access by sending the FluidDB Team a Mail request.

FluidDB is basically divided into four parts: 1)User 2)Namespace 3)Tag 4)Object. The User is the primary entity like in any other case. User will create Namespaces, Tags or Objects. Namespace is a logical name and physical separation which primarily describes the Subject the User is interested in like Movie, Sport, Book, etc. Tags are the attributes which describe the subject further in detail like Genre, Year and Awards Tags in Movies Namespace. Tags can exist without Namespaces also like Event, Hot, New can be used irrespective of the subject. Objects are the key entities as they contains actual data. An Object can be created with a String value like http://twitter.com/dhavaln or Die Hard With Vengeance as a topic which can be expressed in detail with various Tags.

An Object can be annotated with Tags from any User or any Namespace. By attaching a Tag to an Object user can provide additional information as a Tag Value for that Object like:

Object: Die Hard With Vengeance
Tags:
  Movie=
  Movie/Genre=Action
  Movie/Year=1995

As you can see same name can be used as a Namespace and as a Tag also. Tag may not contain any value alternatively known as Marker Tags.

FluidDB provides a simple query mechanism through which Objects can be search in the FluidDB space with Tag and Tag values. The following query will return all the Objects having Movie/Year value as 1995.

/Movie/Year = 1995

/Movie/Year > 1995 will return all Objects having Movie/Year value greater than 1995. There are many other conditional approaches provided by FluidDB for searching and can be found here.

Many developers has started using the interesting FluidDB and created API libraries for various languages which can be found here. I have already started using the database with JFluidDB and finding its usefulness in many cases.

The simple HTTP and JSON based interface makes FluidDB widely acceptable in many problem domains in various languages and frameworks.

Thursday, March 4, 2010

Spring Roo with NetBeans

I am a NetBeans user and there are no reason to change the IDE for any tool as NetBeans try to accommodate most of the frameworks and tools. However most of the modern frameworks/tools has easy integration with the Eclipse, Spring Roo is latest in the list. I started evaluating Spring Roo for one of our internal small test application.

Due to the fact that Spring Roo integrated already with Spring Tool Suite (STS) they support using STS IDE for all development. After few here and there i could finally run as well as modify the Spring Roo application in NetBeans IDE.

Maven is a compulsory requirement (until the Ant/Ivy integration is available) for Spring Roo to run, so make sure Maven is configured and NetBeans is referring to the proper Maven repository.

1. Create the project from  the Roo Shell and fill the required artifacts for the basic startup.






2. Do perform:eclipse to generate the Eclipse artifacts and open the project in STS

3. Right click on the project and go to the Refactoring, select Push All option. A dialog box will show with number of files, select all the files and click on Ok. This will convert all the AspectJ code (.aj) to pure Java code. This is the point for which Spring Roo is considered to be non-intrusive and you can actually detach the Spring Roo from the application altogether.



4. Open the created application in NetBeans through Import Eclipse Project/Workspace option. Do clean and build and go for Run application. If not configured anything NetBeans will ask for the Web Server which can be selected to installed Apache Server.




Still there are many things in Spring Roo you can not do in NetBeans but for all those things, again one can go back to the command prompt or to the STS for required changes, refactor again and refresh the NetBeans project to take the new changes.

Tuesday, March 2, 2010

Easyb Revisited - A Groovy based BDD Testing Framework

easyb is a behavior driven development framework for testing. easyb accepts the Groovy syntax for better explanation of the test scenarios. The first time i encountered easyb, i could not understand the syntactical and semantical sugar but after learning Groovy now i am finding the framework pretty good and useful.

easyb provides two types of templates: one is Ruby RSpac based "it 'should...'" style and another is "given".."when".."then" style. I use the "given.." style because its very explanatory and yet simple make someone understand.

Let's take an example to understand the benefits of the easyb from a programmer and non-programmer's point.

// A utility class to be tested
public class StringList{
      public void add(String element){
           if(element == null){
                  throw new RuntimeException("Null values not allowed");
           }
           // add value
      }
}

//easyb story - given..when..then style
scenario "check StringList with null value addition", {   // scenario with a reason
     given "an empty StringList", {  // what all things available in the scenario
          strList = new StringList()
     }


     when "insert null value", {   // what all operations has to be carried out in the scenario
          insertNull = {
                strList.add(null)
          }
     }


     then "a runtime exception should be thrown", {  // what should be the result
           ensureThrows(RuntimeException){
                  insertNull()
           }
     }
}

//easyb story - it 'should..' style
description 'check StringList with null value addition'


before "initialize the StringList before each spec", {
    strList = new StringList()
}


it "should throw an exception when null value inserted", {
    ensureThrows(RuntimeException){
         strList.add(null)
    }
}

The above stories can be easily divided into two parts one who writes plain test scenarios and another who fills the valid code for testing. No additional knowledge or logic is required to write the test case. An online system can very well generate this kind of templates based on the user input.

// plain test scenario
scenario "check StringList with null value addition", {   // scenario with a reason
     given "an empty StringList", {  // what all things available in the scenario
     }

     when "insert null value", {   // what all operations has to be carried out in the scenario
     }

     then "a runtime exception should be thrown", {  // what should be the result
     }
}

The development or testing team can fill the scenario blocks later with actual code. easyb generates report with pending scenarios and executable scenarios. Pending scenarios are those in which no test code has been added so user can easily identify pending test cases from the reports.

The textual description is right available with the code and is also executable and comes in the result report. The approach helps team members to understand the test cases without much efforts or external documentation. 

The easyb comes in a .tar.gz distribution having easyb jar along with Groovy and Apache Commons CLI. So no additional Groovy dependencies are required.

...dev\tdd\easyb>java -cp .;$easyb_home\easyb-0.9.6.jar;$easyb_home\commons-cli-1.2.jar;$easyb_home\groovy-1.6.4.jar org.easyb.BehaviorRunner *.groovy

The above statement will execute all the .groovy files through easyb interpreter BehaviorRunner. There are various switches for detail result of the execution.

easyb generates the result reports in various formats like PlainText, HTML and XML, which can be integrated with any test-case reporting system.

The flexible syntax helps the business analyst and testing team to create test scenarios independent of the development team. A web-based test scenario identification system would be very helpful in generating various kinds of test cases from different users.

I use Netbeans IDE for all my development purpose. There is no plugin available for NetBeans but Eclipse and IntelliJ provides plugin for easyb. For NetBeans one can use the Ant scriptlets provided at Running easyb.

Additional refrences:

Monday, March 1, 2010

bsGrid - A simple HTML/Javascript/jQuery based data grid

bsGrid is a small javascript/jquery based data grid i have developed for data visualization. The grid is Ajax enabled and for each data operation calls a special service URL.

The grid provides basis functionalities like Sorting, Complex Searching, Paging, Column Freezing, etc. The server to client communication is in JSON so that simple POJOs can be used on the server side.


As of now the code uses Servlet for initial rendering but soon that will be converted to a jQuery Plugin for multiple platform. For other detail refer to the Google Code project site : http://code.google.com/p/bsgrid