Arvind's Arena

I want to know God's thoughts… the rest are details. Albert Einstein

An integration testing framework for Java EE

leave a comment »

I am part of a team that is handling the migration of old code base to JEE6. The existing Architecture is monolith and complex one, the components are very tightly coupled because of which the project teams generally have great difficulty in managing and writing Test Cases. Unit tests alone aren’t sufficient to guarantee a component’s behavior. Though every project for long term success and maintainability would need a well defined, comprehensive Test Bed but it was not easy to find a Remote, Embedded and Managed container to test the components.

  Arquillian is an Integration Testing Framework for JEE6, it allows the developer to execute tests within the container, deployed alongside the code or by speaking with the container, acting as a client to the packaged code. Arquillian ensures the developer is not locked into a proprietary environment by making the model a pluggable one. With Arquillian we can actually test managed beans provided through dependency injection.

Well, it does sound very interesting doesn’t it? Sadly the documentation is not good enough. I have had terrible experiences in the past when I was working in JBPM.Things haven’t changed over the years as far as the documentation is concerned. Let me try to knit all the missing pieces which I had to hunt in various forums.

I always prefer to use Netbeans from the days of Maven 1.0. Once Maven(2 or 3 ) Web Project is created, the below dependencies are needed.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>org.jcc</groupId>
 <artifactId>ArqullianEJBDemo</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>jar</packaging>
 <name>Arqullian EJB Test Demo</name>
 <url>http://maven.apache.org</url>
 <properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <arquillian.version>1.0.0.CR5</arquillian.version>
 <shrinkwrap.version>1.0.0-beta-5</shrinkwrap.version>
 <shrinkwrap_descriptor.version>1.1.0-beta-1</shrinkwrap_descriptor.version>
 </properties>
 <pluginRepositories>
 <pluginRepository>
 <id>jboss-public-repository-group</id>
 <name>JBoss Public Repository Group</name>
 <url>http://repository.jboss.org/nexus/content/groups/public/</url>
 <layout>default</layout>
 </pluginRepository>
 </pluginRepositories>

 <build>
 <plugins>
 <plugin>
 <artifactId>maven-compiler-plugin</artifactId>
 <configuration>
 <source>1.6</source>
 <target>1.6</target>
 </configuration>
 </plugin>
 </plugins>
 </build>

 <dependencies>
 <dependency>
 <groupId>javax.ejb</groupId>
 <artifactId>ejb-api</artifactId>
 <version>3.0</version>
 <optional>false</optional>
 </dependency>
 <dependency>
 <groupId>javax.enterprise</groupId>
 <artifactId>cdi-api</artifactId>
 <version>1.0-SP1</version>
 <optional>false</optional>
 </dependency>
 <dependency>
 <groupId>org.jboss.arquillian.junit</groupId>
 <artifactId>arquillian-junit-container</artifactId>
 <version>${arquillian.version}</version>
 <scope>test</scope>
 <optional>false</optional>
 </dependency>
 <dependency>
 <groupId>org.jboss.shrinkwrap.descriptors</groupId>
 <artifactId>shrinkwrap-descriptors-api</artifactId>
 <version>${shrinkwrap_descriptor.version}</version>
 <scope>test</scope>
 <optional>false</optional>
 </dependency>
 <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>4.8.1</version>
 <scope>test</scope>
 <optional>false</optional>
 </dependency>
 </dependencies>

 <profiles>
 <profile>
 <id>jbossas-remote-6</id>
 <dependencies>
 <dependency>
 <groupId>org.jboss.arquillian.container</groupId>
 <artifactId>arquillian-jbossas-remote-6</artifactId>
 <version>1.0.0.CR2</version>
 <scope>test</scope>
 </dependency>
 <dependency>
 <groupId>org.jboss.jbossas</groupId>
 <artifactId>jboss-as-client</artifactId>
 <version>6.0.0.Final</version>
 <type>pom</type>
 </dependency>
 </dependencies>
 </profile>
 </profiles>

 <repositories>
 <!-- other repos here -->
 <repository>
 <id>jboss-public-repository-group</id>
 <name>JBoss Public Repository Group</name>
 <url>http://repository.jboss.org/nexus/content/groups/public/</url>
 <layout>default</layout>
 </repository>
 <repository>
 <releases>
 <enabled>true</enabled>
 </releases>
 <snapshots>
 <enabled>false</enabled>
 </snapshots>
 <id>jboss-central</id>
 <name>JBoss Central</name>
 <url>https://repository.jboss.org/nexus/content/repositories/central/</url>
 <layout>default</layout>
 </repository>
 <repository>
 <releases>
 <enabled>true</enabled>
 </releases>
 <snapshots>
 <enabled>false</enabled>
 </snapshots>
 <id>jboss-deprecated</id>
 <name>JBoss Deprecated</name>
 <url>https://repository.jboss.org/nexus/content/repositories/deprecated/</url>
 <layout>default</layout>
 </repository>
 <repository>
 <releases>
 <enabled>true</enabled>
 </releases>
 <snapshots>
 <enabled>false</enabled>
 </snapshots>
 <id>jboss-public</id>
 <name>JBoss Public</name>
 <url>https://repository.jboss.org/nexus/content/repositories/public-jboss/</url>
 <layout>default</layout>
 </repository>

 </repositories>

</project>

The official documentation   uses Arqullian version 1.0.0.CR1 (also another doc uses 1.0.0Alpha5),  and there is no detail on shrinkwrap version and its dependencies.
I used the same TemperatureConverter Java Code and annotated it as a Stateless Session Bean.


@Stateless
public class TemperatureConverterBean implements TemperatureConverter {
	@Resource
	EJBContext ctx;

	public double convertToCelsius(double f) {
		return ((f - 32) * 5 / 9);
	}

	public double convertToFarenheit(double c) {
		return ((c * 9 / 5) + 32);
	}

}

Arquillian works with both JUnit and TestNG versions, in my demo I used JUnit4. When the Arquillian test runner processes a test class, the first thing it does is retrieve the definition of the Java archive from the @Deployment method, appends the test class to the archive and packages the archive using ShrinkWrap.

import javax.ejb.EJB;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class TemperatureConverterTest {

	@Deployment
	public static JavaArchive createTestArchive() {
		return ShrinkWrap.create(JavaArchive.class, "test.jar").addClasses(TemperatureConverter.class, TemperatureConverterBean.class);
	}

	@EJB
	private TemperatureConverter converter;

	@Test
	public void testConvertToCelsius() {
		Assert.assertEquals(converter.convertToCelsius(212d), 100d, 0.9);
	}

}

Before executing, we need to define connection parameters for JBoss AS6,the documentation says that we need to use jndi.properties

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://127.0.0.1:1099

but it didnt work for me, I added Arquillian.xml in src/test/resources

<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.com/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://jboss.org/schema/arquillian
    http://jboss.org/schema/arquillian/arquillian-1.0.xsd">

   <container qualifier="jbossas-remote-6" default="true">
	 <configuration>
	 	<property name="providerUrl">jnp://127.0.0.1:1099</property>
	 </configuration>
	 <protocol type="Servlet 3.0">
	 	<property name="host">127.0.0.1</property>
	 	<property name="port">8080</property>
	 </protocol>
 </container>
 

   
    
</arquillian>

To run your code from command line, just use
mvn test -Pjbossas-remote-6

for netbeans select the jbossas-remote-6 profile in the main toolbar.

But once the setup was ready, testing EJB, CDI from  the command line or netbeans is very easy.

Advertisements

Written by Arvind A

December 7, 2011 at 6:04 pm

Posted in Rendezvous with Technology

Tagged with , , ,

Devoxx Day 1 – 14th Nov 2011

with one comment

  It was a fantastic day at Devoxx on Day 1. First up, I attended  Cross-platform RIAs and Mobile Applications connected to a Java back-end by Michael Chaize. Well it was a Partner Slot for Adobe and since Andriod and EE6 were running in parallel, this hall (which is a BIG movie Threater) was sparsely crowded. Michael with his French assent started with how Adobe wants to make life easy for Enterprise Folks in writing an App once and porting it in different Mobile Platforms and also  the same into Desktop. He spoke about the Products that are being lined up for release like Adobe Edge (designing using CSS3 and HTML5), CSS shaders and when asked about how they are contributing to w3c and HTML5 the answer was that they have just acquired PhoneGap and TypeKit ! The last one hour was all about Flex Builder 6 and Flex 5.The key features that could be noted are Action Script Native Extn, AIR captive runtime, Multi threading(gaming), native JSON Support ad Cryptographic functions and most eye catching one was the Automatic Scaling (layouts) for different DI’s for all mobiles. Michael wrote a Twitter client on the fly and also showed some of his ipad apps like CloudCore.

The lunch wasn’t filling at all, though I must say that here in devoxx they have something for Vegetarians :). Post lunch I attended Android Awesomeness by Chet HaaseRomain Guy and Philip Milne. This is FULL house and because I was late, I had to sit on the stairs for the next 3 hours. It was fantastic ! The session started with the demo of the new OS followed by the dev tool kit, the new Grid API.

Then I attended I attended two sessions catagorized in Tools in Action, a 45 minute session on Vaadin to create HTML5-enabled web apps in pure Scalaby Henri Muurimaa and  Forge new Ground in Rapid Enterprise Java Development   by  Lincoln Baxter and Dan Allen. Must say I really want to try my hands on Forge right away. It seems like Spring Roo in many ways.

Dinner was in an Indian Hotel !!! 🙂 Well, thats its for Day1.

Written by Arvind A

November 15, 2011 at 7:29 am

Posted in devoxx

Devoxx 2011

leave a comment »


Arrived Antwerp, Belgium yesterday to attend the 5 day Dev0xx University and Conference.  The wait has ended 🙂 , this year its all about Android and HTML5!!! I just hope that the internet connectivity is good , that would help me to post some entries live from the Arena !!!

Talking about Antwerp, its a very beautiful place :). Diamond shops everywhere 🙂 lots of Albatross flying around and the best part is everyone speaks english out here!!! Quite a few number of grocery shops here are run by Sardars, speaking to them I got to know that they have been here for the past 25 years!

The hotel where I am put up is just Amazing. Fantastic service and the railway station, Tram way is all close by.

I am sure its going to be a great week ahead. Excitement is Adrenalizing !!!

Written by Arvind A

November 14, 2011 at 5:32 am

Posted in devoxx

Tagged with

Re-Engineered to think !

leave a comment »

Lets face it, all of us try to be honest, off course as long we can afford honesty. As I type, I am already regretting the way I am beginning this article. You would have already got a feeling that what ever you are going to read further is not going me an honest opinion! I know that creating a bad opinion on the article right at the beginning itself is like screwing up your project design, later the more you try to fix it the worse it turns out to be!  We procrastinate, as we wait for a perfect moment. Let me not procrastinate to share the thoughts thats running in my mind right now.

I didn’t get carried away when my loved ones (yeh my big gang of lovable friends) kept saying your motto of being perfect has turned into an obsession because it never did , I could never till date point out at some little creation of mine  that seemed perfect and most importantly  I was always talking about healthy perfectionism. We are not alone when we do things, be it home or work place. At home we have our never changing team OUR FAMILY and off course we would never ever want that to change and a different kind of family at work place. At work place when we  think about perfectionism its not just about getting things done correctly and how we do it ! Simple things like making  no fuss over solving problems, everyone trying to become and Active  listener and most importantly in a team   make others feel valued, respected and appreciated even when their contribution is a zero hoping that they would realize soon and they bring out the best in them.

Krithika keeps telling me that I am too good in giving Free Gyan and Yyaan(knowledge in Hindi), I am not to sure of the latter but still would stop it here.

Between I am planning to start a new Technical blog so that I can keep these two separate. For the past couple of weeks, I have been working on a lot of stuffs which I found very interesting like writing widgets for Vaadin, trying out Comet a  model that enables Web servers to send data to the client without having to request for it, was trying out GWT based Facebook App which was really cool!

Coming week I will post all the photos that you have been asking for !

Written by Arvind A

May 9, 2010 at 6:50 pm

Posted in Thoughts

Drizzle After A Drought

with one comment

drought
After a long drought, when it starts to drizzle.Even the thought of  the deafening thunder gives everyone a sense of relief, the leaves await the rains to lash and for once every living creature wants to forget the misery and wants to move on to live a life it always yearned for! What if it was just a drizzle ? A teaser for the worst to come ?

But we don’t wait for things to happen, do we ? We let ourselves take the road that we ourselves aren’t sure of  but how many times do we come back on track ?
I’m not a scientist, a theologist, or even a doctor. Happiness is the goal everyone and all wish to live a happy life. But what does happy life mean? Its an unattainable utopia and anyone who comes up with a formula of happy life like GODMEN themselves know its not true.

Wondering why on a Sunday evening I am up with such a thought?  Stop thinking and go watch the Unscripted Soap Opera IPL3.


Written by Arvind A

March 21, 2010 at 6:04 pm

Posted in Thoughts

Evolution

with one comment

Today my day started in Asiana , marking the end of our three week training with Stefano. I was taken back when teams shared sharing their views about the training and the Trainer. They were all humble and spoke very openly , going on to say  We did not know GRASP(General Responsibility Assignment Software Patterns), but we are happy we know that now. They are ready to change and I guess this marks the start of a new Revolution. The reason being ,this was a workshop where Stefano sat with their project and at every point like a Mentor politely kept asking them WHAT IF . This turned everything around, to what was very Autocratic  things started to become more Democratic 🙂 What I am trying to say here is that everyone started working together , teams started becoming more self organizing and responsible. Of course like every other place we do find some lousy people trying to fit in but lets leave it at that :).

I had to come back to office but went to Navalur(my college is there) and I was telling Raja how things have changed in these three years. Now there are two sky scrapers near Navalur Bus stand !!!!! When I first joined college back in 2002 , there were just two buildings that were quite famous INFY and TCS. Now the two have got lost among the many others sprouting up everyday.

Once back Raja was at his best, Velrajan and Raja both of them are now working with Liferay’s Deployment in Weblogic Cluster. They are through with eh-clustered-cache tests and also tested our custom portlets. You see in the picture here, these guys had many rounds of discussion and yes they are at the right place , just next to the white board , isn’t it more meaningful to be next to a place thats BLANK and let your ideas flow ?

Between I had some quick releases to make and on Monday I would like to do some load / stress tests on the Artifact that I released. Had a very fruitful discussion across different teams today, we all have one common problem. Very Rich User Interface without making things complicated. Will share about it sometime tomorrow. Now its time for me to go back and start with my Book !

Written by Arvind A

March 19, 2010 at 4:21 pm

Most Likely to Change the World

leave a comment »

Just got my hands on MS Application Architecture Patterns and Practices thanks to my Guru! Seeing the Contents itself one gets a feeling Woah ! With this I am most likely to change the world. Naa … Be the change you want to be….

Had a great 2 week workshop with Stefano from KTech. I am searching for Adjectives to describe Stefano but I am sure I would fall short of words. From Object Oriented Principles to Design Patters , from taking a dig at our framework and Project Structure to taking a dig at JAVA itself ! No guesses why he would take a dig at what the entire crowd seems to be so proud about, yes he loves Python and he was instrumental in bringing Python, Django in Banca Sella. I am not over exaggerating but my colleague who used to swear by Oracle has installed Python in his laptop. You should have seen his expression when he executed his first command, never seen him like this for years even when he fine tuned a PL/SQL query that was running for 5 hours to just 15 minutes!!!!

I did get a lot to learn from this MAN, at times feel like just following what he says without questioning him because not only does he bring with him years of experience but when he says something its not without facts. I am truly lucky to have met him , spoken to him.

Thanks a tonne Sir

Written by Arvind A

March 18, 2010 at 4:57 pm