Start testing with Larva

Larva is one of the test tools that comes out of the box with the framework. It’s basic use is to test single adapters. You can create sets of inputs and expected outcomes, and run them. We’ll discuss some  of its basic aspects in this article.

The Plan

 

  • See Larva in action in Ibis4Example
  • Learn to perform xslt transformations with Larva
  • See how adapters are tested via stubbing

 

You will need a working version of the framework, and a development environment to make some xml and xsl-files.

Larva in action

 

Demo video of Larva

Files

 

When you run Ibis4Example you will have two default test scenarios in your project. When you are working with another Ibis you will have to create some files and folders. StageSpecifics_LOC.properties is the place where you  turn Larva on or off, it lives in the resources folder. The managedatabase webservicelistener creates database connectivity for your test tool. We’ll look at that in the last example.

 

The folder ‘test/resources’ contains a folder for your test project. You will create scenario folders that you supply with input files and their expected results. Each scenario needs a properties file in which you describe what will happen in your test.

 

 

 

 

 

 

 

Your test properties file can contain a description that will show up during Larva execution. You will leave the generic classname as it stands but the servicename needs to be replaced by the adapter you are going to test. Ibis4Example has the HelloWorld adapter,  you will write a line “ijs.Generic.servicename = testtool-HelloWorld” then. The part ‘ijs’ is a little confusing, it is a random namespace that is meant to create a unique identiefier for your testfiles, so “abc” , “mynamespace”, etc, are just as good, as long as you prefix your adaptername with “testtool-“.

 

Basic example

 

In the HelloWorld example we’ll insert an extra pipe now. Let’s accept only a ‘hello’ message, reply that one with “Hello World”, and echo back any other message. In the step files fill in “hello”, “Hello World”, “something else”, and “something else” respectively, and adapt your properties file. Now you should be ready to run a test. This will give you a pretty good idea now about working with Larva.

 

<module>
    <adapter name="HelloWorld" active="${HelloWorld.active}">
        <receiver
            name="HelloWorld"
            className="nl.nn.adapterframework.receivers.GenericReceiver"
            >
            <listener
                name="HelloWorld"
                className="nl.nn.adapterframework.receivers.JavaListener"
            />
        </receiver>
        <pipeline firstPipe="checkifhello">
            <exits>
                <exit path="EXIT" state="success" code="200" />
                <exit path="ERROR" state="failure" code="500" />
            </exits>
            
            <pipe 
                name = "checkifhello"
                className="nl.nn.adapterframework.pipes.XmlIf"
                expressionValue = "hello">
                <forward name="then" path="HelloWorld"/>
                <forward name="else" path="ERROR"/>
            </pipe>
            
            <pipe
                name="HelloWorld"
                className="nl.nn.adapterframework.pipes.FixedResult"
                returnString="Hello World"
                >
                <forward name="success" path="EXIT"/>
            </pipe>
        </pipeline>
    </adapter>
    
</module>

Xslt transformations with Larva

Larva let’s you transform xslt’s on the fly. You can view input and output alongside eachother. Make sure to modify your properties file as in the image below.

 

For myxslt.xsl, and step01.xml you can use these two snippets :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
      <tr>
        <td><xsl:value-of select="title" /></td>
        <td><xsl:value-of select="artist" /></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

 

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <cd>
    <title>Back To Oakland</title>
    <artist>The Tower Of Power</artist>
    <country>USA</country>
    <company>RCA</company>
    <price>10.90</price>
    <year>1983</year>
  </cd>
  <cd>
    <title>The Clones Of Dr Funkenstein</title>
    <artist>Parliament</artist>
    <country>USA</country>
    <company>MGM records</company>
    <price>9.90</price>
    <year>1980</year>
  </cd>
</catalog>