Unit tests voor ibis (Larva testtool)
Dutch version

,

Improve your IAF skills!




1. Het concept

Om een unit test te kunnen uitvoeren is het van belang dat alle calls van en naar externe systemen worden “gestubt”. Deze stubs worden gedefinieerd in de testtool directory van de ibis.

testool-overview

Figuur 1

Voor elke gestubde sender in de ibis wordt in de testool een listener gedefinieerd

2. Stubbing

Om de stubbing aan te zetten wordt in de config StageSpecifics_LOC.properties de property stub4testtool.configuration=true gezet. Met behulp van een xslt op de configuratie, alle externe senders en listeners worden vervangen door javalisteners en senders met naam: “testtool – $naam”

This XSLT adjusts the IBIS configuration as follows:

- disable all receiver elements, except those with childs JdbcQueryListener, DirectoryListener, JavaListener, WebServiceListener and RestListener

- add a default receiver (name="testtool-[adapter name]") with a child JavaListener (serviceName="testtool-[adapter name]") to each adapter (and copy all attributes (except transactionAttribute), errorStorage and messageLog from disabled receiver when present)

- disable all listener elements which have a parent pipe

- stub all sender elements, which have a parent pipe, by an IbisJavaSender (serviceName="testtool-[pipe name]"), except the ResultSet2FileSender, DirectQuerySender, FixedQuerySender, XmlQuerySender, DelaySender, EchoSender, IbisLocalSender, LogSender, ParallelSenders, SenderSeries, SenderWrapper, XsltSender, CommandSender, FixedResultSender and FileSender

- disable all elements sapSystems

- disable all elements jmsRealm which have an attribute queueConnectionFactoryName (if combined with the attribute datasourceName a new jmsRealm for this datasourceName is created)

- add the attribute returnFixedDate with value true to all pipe elements PutSystemDateInSession

- replace the value '{now,...,...}' of the attribute pattern in all param elements with the value '{fixeddate,...,...}'

- add the attribute useFixedValues with value true to all pipe, inputWrapper and outputWrapper elements SoapWrapperPipe

- stub the pipe element FtpFileRetrieverPipe by a pipe element GenericMessageSendingPipe (and copy the attributes name, storeResultInSessionKey, getInputFromSessionKey and getInputFromFixedValue) with a child Ibis4JavaSender (serviceName="testtool-[pipe name]")

- add the attribute timeOutOnResult with value '[timeout]' and attribute exceptionOnResult with value '[error]' to all pipe elements GenericMessageSendingPipe and ForEachChildElementPipe

- add, if not available, the parameter destination with value 'P2P.Infrastructure.Ibis4TestTool.Stub.Request' to all pipe and inputWrapper elements SoapWrapperPipe with attribute direction=wrap

- add, if not available, the parameter destination with value 'P2P.Infrastructure.Ibis4TestTool.Stub.Response' to all outputWrapper elements SoapWrapperPipe with attribute direction=wrap

Je kan de betreffende xslt ook aanpassen en op nemen in je project (javasource/xml/xsl/stub4testtool.xsl) dit geeft de mogelijkheid om de selectie van de te stubben adapters aan te passen.

 

3. Basic scenario

Een testool scenario bestaat uit een aantal delen

Typische directory structuur:

(JavaSource/)Testtool
AdapterNaam
  01
    adapter-input.xml
    stub1-input.xml
   
stub1.output.xml
   
adapter-output.xml
  02
   
adapter-input.xml
   
stub1-input.xml
   
stub1.output.xml
   
adapter-output.xml
  common.properties
 
scenario01.properties
 
scenario02.properties

common.properties
adapter.AdapterName.className=nl.nn.adapterframework.senders.IbisJavaSender 
adapter.AdapterName.serviceName=testtool-AdapterName 
stub.ExternalCallName.className=nl.nn.adapterframework.receivers.JavaListener 
stub.ExternalCallName.serviceName=testtool-Name sender Pipe 
ignoreContentBetweenKeys1.key1=<ConversationId> 
ignoreContentBetweenKeys1.key2=</ConversationId> 
ignoreContentBetweenKeys2.key1=<MessageId> 
ignoreContentBetweenKeys2.key2=</MessageId> 
ignoreContentBetweenKeys3.key1=<Timestamp> 
ignoreContentBetweenKeys3.key2=</Timestamp>
scenario0X.properties
scenario.description = Scenario01
include = common.properties
scenario.fulldescription = Scenario01 success AdapterName

step1.adapter. AdapterName .write = 0X/adapter-input.xml
step2.stub. ExternalCallName.read = 0X/stub1-input.xml
step3.stub. ExternalCallName.write = 0X/stub1-output.xml
step4.adapter. AdapterName.read = 0X/adapter-output.xml

4. Create files en directories

ANT script

Dir + file

Scenario or common.properties

 

dir.init.className     = nl.nn.adapterframework.testtool.FileSender

dir.init.filename          = 01/dir-init.xml

dir.init.runAnt              = true

 

scenario.properties

step1.dir.init.write   = 01/dummy.txt

 

Dir-init.xml

<project default=”copy.files”>

<target name=”copy.files”>

<copy file=”in.zip” tofile=”D:/temp/ibis4voorbeeld/fxf/flow/in/in.zip” overwrite=”true” />

</target>

</project>

In.zip wordt uit scenario directory naar d:temp etc gekopieerd

 

File

Scenario or common.properties

file.txt.className=nl.nn.adapterframework.testtool.FileSender

file.txt.filename=d:/temp/ibis4testiaf/file.txt

file.txt.overwrite=true

file.txt.checkDelete=false

 

scenarioX.properties

step1.dir.init.write = scenario01/dummy.txt

 

5. Database

Met behulp van standaard managedatabase adapter in ibis

Scenario or common.properties

 

manage.db.className=nl.nn.adapterframework.senders.IbisJavaSender

manage.db.serviceName=testtool-ManageDatabase

 

scenario.properties

step1.manage.db.write                                                                                       = scenario_05/update.xml

step2.manage.db.read                                                                                         = scenario_05/read.xml

 

update.xml

<manageDatabaseREQ>

<update>

<tableName>TRANSLATIONMULTILINGUAL</tableName>

<columns>

<column><name>LANGUAGECD</name><value>NN</value></column>

</columns>

<where>GROUPTYPE=72 and SOURCETEXTVALUE=’ERR8002′</where>

</update>

</manageDatabaseREQ>

 

read.xml

<manageDatabaseRLY>

<completionInformation>

<returnCode>OK</returnCode>

</completionInformation>

<results count=”1″>

<result item=”1″>

<result>

<rowsupdated>1</rowsupdated>

</result>

</result>

</results>

</manageDatabaseRLY>

 

Je kan uiteraard een create/delete/update uitvoeren

 

6. Fout scenarios

“convertExceptionToMessage” maakt van je exceptie een xml bericht wat je kan valideren

 

common.properties

adapter.AdapterName.className=nl.nn.adapterframework.senders.IbisJavaSender

adapter.AdapterName.serviceName=testtool-AdapterName

adapter.AdapterName.convertExceptionToMessage=true

 

stub.ExternalCallName.className=nl.nn.adapterframework.receivers.JavaListener

stub.ExternalCallName.serviceName=testtool-Name sender Pipe

 

7. Diversen

Er zijn diverse properties beschikbaar zie setters en getters testool classes

http://maven.ibissource.org/iaf/apidocs/nl/nn/adapterframework/testtool/package-summary.html

 

Voorbeelden

JmsListener

adapter.AdapterName.queue=jms/queue (jndi)

adapter.AdapterName.jmsRealm=qcf

adapter.AdapterName.persistent=true

adapter.AdapterName.SOURCE=I4TESTGR

 

FileSender

adapter.AdapterName.filename=d:/temp/BATCHFF1

adapter.AdapterName.checkDelete=false

adapter.AdapterName.overwrite=true