Tuesday, September 27, 2011

Automated Javascript Test Framework - JSTestDriver-Remote JS console - maven


There are number of factors that goes into deciding the Framework that would help automate the tests involved in testing the product again newly arriving build . As it is very important to make sure that we have all the test cases in place which can be executed against every new build and make sure that the product is stable.
1 ) Asynchronous Test
                The test framework should allow rather support Asynchronous tests .
2) Run against build tools.
                This feature will make sure that before the final release build is prepared all the test are executed and the result are in hand .
3) Browser support
                This feature will remove the manual intervention for starting the browser for executing the test (Applicable to only those projects which needs browsers to test the product ).

We now have a lot of test of test frameworks available which can perform most of the above task involved in Unit Testing the product.
1)      JSTestFDriver
2)      YUI
3)      JSUnit
And many more. This article will focus on JSTestDriver

How JSTestDriver Works?
It starts of by launching a server (Java process ) which holds the responsibility of loading the test runner code into the browser(acts as slave) . Once this happens the browser can be controlled by the server which sends across command to the browser to load the test resources . JSTestDriver has a jsTestDriver.conf' file (which can be easily configured)  which let the developer configure the files that the browser needs to load to run the tests.
Configuration File

server: http://localhost:9876

load:
  - src/*.js
  - src-test/*.js

The very first line in this conf file is URL that the browser needs to use to contact the server
Load directive tells the browser on the resources that needs to be loaded , one need to note that the resources loaded will be in the same sequence in which they are specified in the conf file.
Out here by resources it means to include the files that has the test written which are being implemented as a part of automation of tests(Unit tests).
9876 is the port on which JSTest server runs.


Configuring JSTestDriver in Maven

1)     pom.xml
Pom file needs to be configured with the jstestdriver details
  <dependencies>
        <dependency>
            <groupId>com.google.jstestdriver</groupId>
            <artifactId>maven-jstestdriver-plugin</artifactId>
            <version>1.3.2.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

<plugins>
<plugin>
          <groupId>com.google.jstestdriver</groupId>
          <artifactId>maven-jstestdriver-plugin</artifactId>
          <version>1.3.2.1</version>
          <executions>
                <execution>
                                <id>run-tests</id>
                <phase>integration-test</phase>
                                <goals>
                <goal>test</goal>
                </goals>
              <configuration>
                                                <debug>true</debug>
                <config>${project.basedir}/test/conf/jsTestDriver.conf</config>
                <browser>${browser.command}</browser>
                <port>9876</port>
                <basePath>${project.basedir}/src</basePath>
              </configuration>
            </execution>
          </executions>
 </plugin>
      </plugins>
2)     ./src/test/conf/jsTestDriver.conf
Define the server URL , resources that needs to be loaded by JSTestDriver
3)     Maven settings.xml
<profile>
           <id>jstests</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <browser.command>c:/Program Files/Mozilla Firefox/firefox.exe</browser.command>
            </properties>
</profile>
            This configuration defines the browsers that will be loaded while the JSTestDriver is started.
There is a very nice WIKI page created on JSTestDriver which would be worth taking a look at Getting Started.


Thursday, July 7, 2011

Installing Sun Java in Ubuntu

Recently I came across issue with using the Iced Tea for run my java code in Ubuntu OS and this behavior is inconsistent , even after looking at number of online posts didn’t help in figuring out the exact cause or the work around to fix it . Hence I finally decide to remove IcedTea and install Sun version of Java .
Below are the steps that one need to follow to install Sun java in Ubuntu

sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"

sudo apt-get update

sudo apt-get install sun-java6-jdk

sudo apt-get install sun-java5-plugin

Restart the system and you can verify the installation by typing java –version in terminal
Also you can check the java plugin for browser by Open FF -> Tools -> Add On ->Plugin


Before doing the above steps make sure you have uninstalled the IcedTea through Symantec manager(the package management system in Ubuntu) and to launch it one will have to navigate through System -> Administration -> Synaptic Package Manager

Saturday, July 2, 2011

Automate Active MQ Broker start/stop through maven


While writing integration test most of the time you need to start and stop Active MQ manually which most of you won’t prefer doing by this I mean get things automated . This can be easily done using maven(I have really started loving this tool ) plugin where in before you automated test start maven while start the Active MQ service . Below are the things that the developer had to do in maven
First you need to configure pom with the Maven plugin for Active MQ details
<plugin>
<groupId>org.apache.activemq.tooling</groupId>
<artifactId>maven-activemq-plugin</artifactId>
<version>5.4.0</version>
<configuration>
<configUri>xbean:file:src/main/resources/activemq.xml</configUri>
<fork>true</fork>
<systemProperties>
<property>
<name>javax.net.ssl.keyStorePassword</name>
<value>password</value>
</property>
<property>
<name>org.apache.activemq.default.directory.prefix</name>
<value>${project.build.directory}/target/</value>
</property>
</systemProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.5</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-xbean</artifactId>
<version>6.1.11</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-activemq</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</plugin>


Secondly , we will have to create activemq.xml which is the configuration file for Active MQ .
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:amq="http://activemq.apache.org/schema/core"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  http://activemq.apache.org/schema/core
  http://activemq.apache.org/schema/core/activemq-core.xsd
  ">
  <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="./data">
  <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage limit="20 mb"/>
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="1 gb" name="foo"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="100 mb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>
    <!-- The transport connectors ActiveMQ will listen to -->
    <transportConnectors>
      <transportConnector name="openwire" uri="tcp://0.0.0.0:61616" />
      <transportConnector name="stomp" uri="stomp://0.0.0.0:61613" />
    </transportConnectors>
  </broker>
</beans>

That’s it , once you are done with the above two steps you need to open up your system terminal and run
mvn clean install activemq:run -Dmaven.test.skip=true

AuthBind


Authbind is an Open source system utility which allows a program that would normally require superuser privileges to access privileged network services to run as a non-privileged user. Authbind allows the system administrator to permit specific users and groups access to bind to TCP and UDP ports below 1024

$ sudo apt-get install authbind

You can use dpkg to know more about authbind after installing it
$ dpkg -s authbind

Wednesday, January 19, 2011

Error number 1008 message while starting IBM web sphere

This WIKI page is with respect to issue of not able to start the web sphere MQ server .
The error code the I was getting was 1008 and the alert that it prompted was as below
Error number: 1008 message: attempt to reference a token that does not exist occurs when trying to start MQ
One can go into the windows system event log to find out the exact cause of the issue as it can be because of many reasons .
It can be because of permissions issue not being set for the mq services for this one can follow the steps mentioned in the below link and hopefully it should resolve the issue .
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=/com.ibm.mq.amqzag.doc/fa12250_.htm
But before going into the above link I would suggest to just try by starting the mq services manually by going into \IBM_HOME\WebSphere MQ\bin\ and execute the amqmsrvn.exe which is the MQ service process launched by way of dcom ,it normally runs under SYSTEM account .
To stop the amqsvc.exe process (other than by using the 'net stop IBM MQSeries' command), run the command "amqsvc -stop".
The MQSeries (Windows) service (amqsvc) has a few command line options to help should problems arise:
amqsvc.exe
-INSTALL : Reinstalls the registry keys to make the MQ Service defined
-UNINSTALL : Removes the MQSeries service
-SILENT : Hides error messages when install/uninstall performed
-START : Starts the service (Use Net Start "MQSeries Service" instead?)
-STOP : Stops the service (Use Net Stop "MQSeries Service" instead?)