For the complete documentation index, see llms.txt. This page is also available as Markdown.

Assertions

After your script was executed you may want to check the produced results.

_testScript.run(context)

println("\r\n--- Test Output ----------")

int docCount = context.outputDocuments.size()
println(docCount + " Document(s) after script execution")
assert context.inputDocuments.size() == docCount

for (Document doc in context.outputDocuments) {
    String textDoc = doc.toString()
    assert textDoc != "", "Document is null"
    println("Doc[${docNo++}] ----" )
    println(textDoc)
}

As you can see you can access the output documents using context.outputDocuments.

Validate an XML output document

  /** The testfile for document 1 contains one _uniquekeys_ which is converted to:
     *  <RecordQueryRequest limit="" offsetToken="">
     *      <filter op="OR">
     *          <fieldValue>
     *              <fieldId>
     *                  VATNO
     *              </fieldId>
     *              <operator>
     *                  EQUALS
     *              </operator>
     *              <value>
     *                  V_5001
     *              </value>
     *          </fieldValue>
     *     ....
     * */
    static void _checkDoc1(Document document) {
        def ddpUniqueKeyCount = document.getProperty("DDP_UniqueKeyCount")
        assert (ddpUniqueKeyCount as Integer == 1)

        final xs = new XmlSlurper()
        String xml = document.toString()
        println( xml)
        
        def xDoc = xs.parseText(xml)
        // Get first [filter] element
        def field0 = xDoc.filter.fieldValue[0]      
        
        // Print a validate its children
        println( "OPERATION[0]:")
        println( "Field     : '${field0.fieldId}' ")
        println( "Operation : '${field0.operator}' ")
        println( "Value     : '${field0.value}' ")
        
        // @TypeChecked must be off!!! 
        assert ((xDoc.filter.fieldValue[0].fieldId) as String).equals("VATNO")
        assert !((xDoc.filter.fieldValue[0].fieldId) as String).equals("vatno")
    }

Check for Dynamic Document Properties

To get a document's dynamic properties use document.getProperties(), and, be aware, these properties start with document.dynamic.userdefined.

There are two options to read Dynamic Document Proeprties from an output document:

Last updated