Showing posts with label automation. Show all posts
Showing posts with label automation. Show all posts

29 October 2012

Automate JavaScript testing

I like TDD and testing automation and I'm used to consider essential a toolset providing automation for unit, integration, system tests and for code coverage analysis.

Switching from Java to JavaScript development, I tried to put together a Maven-based toolset that resembles the classic automation tools for Java: a testing framework (with a runner which I can run through mvn clean test) and a code coverage tool (which I can for example run through mvn verify, obtaining a graphical coverage report).

The result is this small example of JavaScript library, whose Maven-based automation is achieved through a number of excellent frameworks (Jasmine) and Maven plugins (Jasmine Maven Plugin, Saga JS coverage plugin).

Feel free to checkout my sample and to adjust it to your needs!

13 April 2012

How-to find a class in a JAR directory using shell scripting

The biggest problems in J2EE applications deployment  come often from classloader hierarchies and potential overlapping between server-provided and application-specific libraries. So, searching classes through collection of JARs is oftwen the main activity in order to identifiy and fix classloader issues.
This is surely a tedious and repetitive task: so, here's a shell script you can use to automate JAR collection traversing and tar command's output analysis to search a pattern, which is provided as script parameter.

Credits: Thanks to sirowain for parameter check and return code related contributions.

#!/bin/bash
# Commonly available under GPL 3 license
# Copyleft Pietro Martinelli - javapeanuts.blogspot.com
if [ -z $1 ]
then
        echo "Usage: $0 <pattern>"
        echo "tar xf's output will be tested against provided <pattern> in order\
          to select matching JARs"
        exit 1
else
        jarsFound=""
        for file in $(find . -name "*.jar"); do
                echo "Processing file ${file} ..."
                out=$(jar tf ${file} | grep ${1})
                if [ "${out}" != "" ]
                then
                        echo "  Found '${1}' in JAR file ${file}"
                        jarsFound="${jarsFound} ${file}"
                fi
        done
        echo "${jarsFound}"
        
        echo ""
        echo "Search result:"
        echo "" 
        
        if [ "${jarsFound}" != "" ]
        then
                echo "${1} found in"
                for file in ${jarsFound}
                do
                        echo "- ${file}"
                done
        else
                echo "${1} not found"
        fi
        exit 0
fi

This script is available on github.com:

12 March 2012

How to clean-up JBoss temporary directories using bash scripting

Repetitive and annoying file system tasks are the natural field of automation through shell scripting - so, here's a script  that can be used to clean up temporary directories created by JBoss Application Server.

You can provide as parameter the name of the node that you want clean up - if launched without parameters, the script cleans up temporary directories in each node under current installation.

Tested on JBoss 4.0.5.GA and JBoss 5.1.0.GA installations.

#!/bin/bash
# Commonly available under GPL 3 license
# Copyleft Pietro Martinelli - javapeanuts.blogspot.com

function cleanTmpDir {
        echo "  Cleaning ${1}/${2}"
        rm -rf "${1}/${2}"

}

function cleanNode {
        echo "Cleaning \"${1}\" jboss node"
        for tmpDir in data log tmp work
        do
                cleanTmpDir ${1} ${tmpDir}
        done
}


if [ $# -eq 0 ]
then
        for dir in $(find server -maxdepth 1 -mindepth 1 -type d)
        do
                cleanNode ${dir}
        done
else
        if [ -e "server/${1}" ]
        then
                cleanNode "server/${1}"
        else
                echo "${1} is not a subdir of server dir"
        fi
fi

Updated: this script is now available on bitbucket.org:
https://bitbucket.org/thecleancoder/javapeanuts-shell-utils/src