# Assertions

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

```groovy
_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

```groovy
  /** 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`.&#x20;

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

```groovy
_testScript.run(context)
_checkDoc0( context.outputDocuments[0])
...

static void _checkDoc0(Document document) {
    // OPTION A
    def props = document.getProperties()
    def ddpUniqueKeyCount0 = props.get("document.dynamic.userdefined.DDP_UniqueKeyCount")
    
    // OPTION B
    def ddpUniqueKeyCount1 = document.getProperty("DDP_UniqueKeyCount")
    
    // Asert they are the same
    assert( ddpUniqueKeyCount0 == ddpUniqueKeyCount1)
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boomi.markusschmidt.pro/boomi-scriptease/test-contexts/assertions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
