Important online utilities for developers

There are a few online utilities which are really very helpful in day-to-day life for a developer.

  1. http://www.compileonline.com/ :
    • http://www.compileonline.com is a really nice website wherein you can test the code in more than 50 programming languages such as c, c++, java, python etc. and more than 10 web technologies like JSP, ASP .NET, HTML, JQuery etc. You just need to visit the website –> choose the desired language –> write your code piece –> Run/Compile.
  2. http://www.gskinner.com/RegExr/ :
    • Using regular expressions in the code is like a normal stuff for developers. But even a single mistake in the regular expression can cost huge money. so just to make sure we are on the right track with respect to the regular expression we can make use of this wonderful utility. You just need to visit the website –> you will see a long text box, which is there to construct your regular expression –> right below that you will find a large text area, which is meant for the data that you want to test against the regular expression.
I will keep updating this post as i find more utilities.

Perforce server configuration for local use

This post is about setting up and configuring a perforce server and use it for Software Configuration Management(SCM) in your local work network. Perforce allows you to use its facility for free for 20 users. For more information about how perforce works please go to the perforce website: http://www.perforce.com.

(This post is with respect to Windows users)
Following are the easy steps for perforce server installation/using it :

Server Configuration : 

    • Go to http://www.perforce.com
    • Under Downloads tab click Software Version Management link.
    • It will ask you for registration, if you want you can register, else you can simply skip it.
    • Select your platform – I am choosing Windows here.
    • Choose you OS whether 32 bit or 64 bit etc.
    • Here you need to download 2 exes : 1. p4d : Server 2. p4Admin : Administration Tool
    • Now you need to install the p4d first, it runs as a windows service.
    • Once you are done with the p4d installation you need to go and install the p4admin tool so that you can visualize various configuration options.
    • It will ask you to create a user first, just give your credentials and you are the super user.
    • Here you can create users, manage their credentials, manage the code repositories and many more complex tasks.
    • This is it! You are done with the perforce server configuration.

Client Configuration : 

    • For accessing this server you can either download and use p4V : Visual Client or simply use a perforce plugin in eclipse(I would recommend using a perforce plugin in the eclipse, as its really very simple and no need to use extra client software). For installing the perforce plugin you can go to eclipse marketplace and search for ‘perforce’, from the various option our interest is perforce SCM support, just check the box against it and install. Create a connection with the server url we just installed in the first section of this post and we are done!

Wicket Testing

This post is all about how to test UI components in your Wicket web application using wicket’s built-in test framework. When I say UI components it can be anything ranging from a simple text box to a very complex Panel, Form or even a full Web Page. Wicket’s test framework makes it really very easy to test all the static and dynamic behaviors of UI components.

Before starting with the actual discussion let me give brief background about what wicket is and how to create simple components using it.

Apache Wicket is a full blown Component Driven Framework. Creating a dynamic web page using wicket is a simple three step process.

  1. Create a html file with components you want.(may be using any WYSIWYG tool like dreamweaver)
  2. Provide an attribute called “wicket:id={the value you want}” to all the components for whom you want dynamic behavior.
  3. Write a Java class with exactly same name as html file and bind these wicket ids with actual wicket components.

You will get a kickstart as to how to create a simple Wicket Hello World Example.

So, normally how do we approach to test the UI in any web application. Whenever it comes to UI testing, no doubt we consider tools like Web Driver. But to test UI using Web Driver we need the entire application to be ready and running on the server. In case you find any problems you need to record them, fix them and follow the same process again. This can be painful if you have complex components on your pages.

Using wicket’s test framework, you can test the web pages while developing it. This will help discovering the UI discrepancies way to early. I am not questioning the ability of tools like Web Driver. Even they can be helpful. But point here is a java developer who is creating the web application can himself go ahead and test the UI pages in his application before handing it over to QA for testing.

There are certain guide lines which if you follow, you can be certain that it will cover almost 90 % of the test cases.

  1. All components and hence the page is rendered correctly.
  2. Visibility of all the components at the time of page loading.
  3. Availability of all the components at the time of page loading.
  4. Dynamic behavior of some of the components.
  5. Behavior of form submission.
  6. Component’s error validation and feedback messages.
  7. Miscellaneous behavior of components, mostly specific to your application.

Lets see an example to support what we saw above.

1. Create a html file containing a simple text box and a submit button.

HomePage.html

<html>
 <body>
 <form wicket:id="form">
 Name : <input type="text" wicket:id="name" />
 <input type="submit" wicket:id="submit">
 </form>
 </body>
</html>

 HomePage.java

public class HomePage extends WebPage {

private TextField<String> name;

private Button submitButton;

public HomePage(PageParameters pageParameters) {

super(pageParameters);

Form<?> form = new Form("form");

//adding a name text field

name = new TextField<String>("name", new Model());

form.add(name);

//adding a submit button

submitButton = new SubmitButton("submit") {

@Override

public void onSubmit() {

// do something

}

};

form.add(submitButton);

add(form);

}

}

Suppose your wicket application(MyWicketApplication.java) returns this HomePage. Lets follow all the guide lines mentioned above.

HomePageTest.java

public class HomePageTest {

private HomePage page;

private WicketTester wicketTester;

private FormTester formTester;

public void setup() {

wicketTester = new WicketTester(new MyWicketApplication());

formTester = wicketTester.newFormTester("form");

page = (HomePage)wicketTester.startPage(new ITestPageSource() {

@Override

public Page getTestPage() {

return new HomePage(new PageParameters());

}

});

}

//Test to see if all the components and the page renders correctly.

@Test

public void testAllComponentsAndPageRendersCorrectly() {

wicketTester.assertRenderedPage(HomePage.class);

wicketTester.assertComponent("form", Form.class);

wicketTester.assertComponent("form:name", TextField.class);

wicketTester.assertComponent("form:submit", Button.class);

}

//Test to check the visibility of the component

@Test

public void testVisibilityOfComponents() {

wicketTester.assertVisible("form");

wicketTester.assertVisible("form:name");

wicketTester.assertVisible("form:submit");

}

//Test to check if the components are enable/disable

@Test

public void testAvailabilityOfComponents() {

wicketTester.assertEnabled("form:name");

wicketTester.assertEnabled("form:submit");

}

//Test form submission

@Test

public void testFormSubmission() {

formTester.submit();

//assert whatever you have done in onSubmit() of your button

}

}

WicketTester and FormTester form the piller of wicket’s testing framework. You can find more information about these APIs here : WicketTester and FormTester.

There is lot more which I have not covered here. But this post can help you start off with wicket testing.

Follow

Get every new post delivered to your Inbox.