Creating Java Command Line Applications using jLine

Most common way of writing a command line application in java is to use BufferedReader to read user input. But if you want more features like tab completion, you have to write code to handle it from the scratch in BufferedReader method.

There is a nice library called jLine http://jline.sourceforge.net/ which can be used to write nice CLI apps without much effort. It has out of the box support for;

  • Command History 
  • Tab completion 
  • Line editing 
  • Custom Key Bindings 
  • Character masking
I've written simple sample application on how to use jLine. You can check that out in github https://github.com/sandarenu/sample-apps/tree/master/java-cli-app
 

Another Tech Genius Passed Away...













Dennis Ritche, co-author of C programming language and one of the creators of Unix operating system has passed away last week. His inventions changed the way how we do things in the computer industry.
Thank You Dennis....

It is really sad to see that two of the great minds in technology world passed away in a month...
 

Remembering Steve Jobs

Steve Jobs, one of the greatest visionaries of our time has passed away on Wednesday(5th Oct 2011). He was 56.

At 2005 Stanford address quated on his own mortality, saying:
“Remembering that I’ll be dead soon is the most important tool I’ve ever encountered to help me make the big choices in life. Because almost everything — all external expectations, all pride, all fear of embarrassment or failure - these things just fall away in the face of death, leaving only what is truly important.

 

How to Use Multiple GIT Accounts

Yesterday at HMS we moved some of our projects to GIT from SVN repository. So in order to access that office GIT repository I had to create a new ssh key using my office email address. I already had a ssh key which I used to access my GitHub account. So once I created new key I was unable to access GitHub since in normal configuration ssh can only have one public key.
But I wanted to find a way which I can use both office GIT server login and my GitHub login. After doing some searching on google I found a solution to that. For that we'll have to create ssh config file. So I created following config file at my .ssh folder
vi ~/.ssh/config

# hms-git
Host hms-git
  HostName git.myoffice.com
  User git
  IdentityFile /home/sandarenu/.ssh/id_rsa

# github
Host github.com
  HostName github.com
  User git
  IdentityFile /home/sandarenu/.ssh/id_rsa_github


Once this config file is saved I could clone office git projects using
  git clone git@hms-git:myproject

To clone GitHub project I could use
  git clone git@github.com:sandarenu/task_tracker.git



 

Using SoapUI for Web Service Testing

SoapUI is a great tool which can be used to test web services. In this post I'll show you how to set up SoapUI project for WS testing.

Create new project from File ->New SoapUI Project, and in "New Project Dialog" give name and the location of the WSDL file.


You can find the sample wsdl file I used for testing in github https://github.com/sandarenu/soapui-test.

Web Service Mocking

Service mocking is required when you are writing a web service clients and either you don't have the web service implemented or you don't have the access to the real service. Here's how to do that using SoapUI.

Create Mock of the web service by right clicking on the project and selecting 'Generate MockService'.

Once mock service is created you can mock the operations by clicking on the small icon in the service mock dialog.




Double click on the operation you just mocked and you'll get a dialog to configure mock responses.
You can configure any number of mock responses and then select how those response to be dispatched when our mock service receives WS request. There are many dispatching strategies available such as "Script", "Sequence", "Query Match", etc...

When you do some integration testing you need your mock service to respond based on different parameters of the requests you send. In such cases you can either use "Script" or "Query Match" dispatch mechanism.

Web Service Testing
We can use SoapUI to create test cases to test a Web Service we developed. To create a test suite right click on the project and select "New TestSuite" from the context menu. Then right click on the test suite we just created and select "New TestCase".



Once we have created the test case we can add test steps to it. Lets add a test step to test time for time zone 'lk'. Right click on the test steps dialog and select "Test Request" and create the request you want to test.
Once test request is created we can add assertion step to it. Click the "Assertions" button at the bottom of the test request editor.


Right click on the assertion editor and add "xPath Match"

 Put //Time as "xQuery Expression" and put value you are expecting as "Expected Result"

Now you can test this request using the Mock WS you created before. Start the mock service by clicking on the small green arrow found in the top of the "TimeServiceMock". Then open the test case you created above by double clicking it. Then run the test case again by clicking small green arrow in the to of the dialog box.


If every thing went well you'll be able get success result for your test case.

This is just the start. You can then add more test cases and assertions and improve your test suite. SoapUI site has good documentation on how to do functional testing. http://www.soapui.org/Getting-Started/functional-testing.html
You can refer that and get more information.

You can also find the SoapUI project for this example at https://github.com/sandarenu/soapui-test. Download it and open it using "File -> Import Project"

Happy Testing.....
 

Solving 'symbol lookup error' in new Eclipse 3.7 Indigo in Fedora

When I downloaded and run the latest eclipse 3.7 Indigo release, it crashed with a strange error.

symbol lookup error: /usr/lib/libwebkit-1.0.so.2: undefined symbol: soup_content_decoder_get_type

After some searching in the web I found out that it is due that I'm having an older version of libsoup library. I had libsoup-2.28.1-1.fc12.i686 in my fedora 12.
Issue was solved by updating that library using yum.
yum update libsoup

 

Hibernate HQL Select Query Based on Item in a One-to-Many Relationship

Few days back I had a situation where I have to fetch some data based on a value of an item stored in one-to-many relationship. I my project I had two classes like below. I had to fetch all the Oders that has particular item.

class Order {
    private List<Item> items;
    //more code ...
}

class Item {
    private String itemId;
    private String name;
    //more code ...
}

With native SQL it was not that difficult, but since I've used Hibernate I wanted to find a way to do it in HQL. After some searching in Google I found out how to do it.

select o from Order o left join o.items its where its.itemId = :itemId
 

Different views for your blog

Recently Blogger started providing different views for the blogs created in it. They are very cute way to view our blogs in different angles. Following is snapshot view of my blog.
 

After Long Time.......

Its being long time since my last post......
Hopping to do some posts more frequently in coming months. So keep your fingers crossed :)
 

Tribune to Heros

Tribune to Heros
We will never forget the sacrifices you made to protect our country....

Subscribe


Get Google Toolbar Button

Enter your email address:

Delivered by FeedBurner

Blog Archive