# Test Contexts

In a *Test Method* you create and provide all the necessary information that is needed in the script. The *Test Method* creates the [`ScriptContext`](/boomi-scriptease/knowlede-base/script-contexts.md) (see [Concepts](/boomi-scriptease/general.md)) and passes it to the script.

```groovy
def context = new ProcessScriptContext(
        inputDocuments: [
                Document.fromText('''
                { 
                        "firstname" : "Walter", 
                        "lastname" : "Schmidt" 
                }''')
        ],
        dynProcPros: [ 
                DPP_Prop01: "2024",        
        ])
_testScript.run(context)
```

### The Script Context Properties

The `ScriptContext` has the following properties:

```groovy
public List<ProcessExecutionProperties> processCallChain;
public Map dynProcPros;
public Map procPros;
public final Map executionProperties;
  
// additional, ProcessScriptContext, only, properties
public List<Document> inputDocuments;
public final List<Document> outputDocuments;
```

See in the following chapter how to set and pass a content to a Process Script.

### Documents and Dynamic Document Properties

{% hint style="info" %}
**IMPORTANT**

In this section you will learn how to **initialize properties in a Test class** to use them in a script. If you want to know how to access (read/write) properties in a Boomi Script, read here: [How to use Properties in a Boomi Script](https://community.boomi.com/s/article/properties-using-groovy)
{% endhint %}

<details>

<summary>Add input Documents from code (inline)</summary>

Use the `Document.`**`fromText`**`()` factory method to add any number of documents to the `ProcessScriptContext.inputDocuments` list.

```groovy
ProcessScriptContext context = new ProcessScriptContext( inputDocuments: 
[
  Document.fromText('{ "firstname" : "Walter", "lastname" : "Schmidt" }'),
  Document.fromText( JsonOutput.toJson( [ firstname : "John", lastname : "Doe" ])),
  Document.fromText('''
  { 
    "firstname" : "Walter Jr.", 
    "lastname" : "Miller" 
  }'''), // Groovy multi-line text support
  
])
_testScript.run(context)
```

</details>

<details>

<summary>Add input Documents from file</summary>

Use a `TestFilesHelper _testFiles` instance to support access to files in a specified sub-directory.

<img src="/files/ollvdM4RjfagepKJQRre" alt="" data-size="original">

Use the `Document.`**`fromFile`**`()` factory method to add any number of documents to the `ProcessScriptContext.inputDocuments` list.

<pre class="language-groovy"><code class="lang-groovy">final TestFilesHelper _testFiles = new TestFilesHelper( "testData", _sourceUri)

<strong>ProcessScriptContext context = new ProcessScriptContext(
</strong>  inputDocuments: [
    Document.fromFile( _testFiles.get( "doc01.json")),
    Document.fromFile( _testFiles.get( "doc01.json"))
  ])
_testScript.run(context)
</code></pre>

</details>

<details>

<summary>Mixed input documents</summary>

You can mix `fromText` and `fromFile` as you want. The input documents do not care where they are coming from.

```groovy
ProcessScriptContext context = new ProcessScriptContext(
  inputDocuments: [
    Document.fromFile( _testFiles.get( "doc01.json")),
    Document.fromText( '{ "firstname" : "Walter", "lastname" : "Schmidt" }')
  ])
```

</details>

<details>

<summary>Add input Documents with Dynamic Document Properties</summary>

Use the `Document.fromText()` factory method to add any number of documents to the `ProcessScriptContext.inputDocuments` list. Dynamic Dcoument Properties are represented as [Groovy Map](https://www.tutorialspoint.com/groovy/groovy_maps.htm), which is a `key : value` list.

```groovy
// Add three documents with DDP_Prop1 and DDP_Prop02 each
ProcessScriptContext context = new ProcessScriptContext(
	inputDocuments: 
	[
		Document.fromText('Doc Content01', 
		[
			DDP_Prop01: "Doc1_Value1", 
			DDP_Prop02: "Doc1_P2"
		]),
		Document.fromText('Doc Content02', 
		[
			DDP_Prop01: "Doc2_Value1", 
			DDP_Prop02: "Doc2_P2"
		]),
		Document.fromText('Doc Content03', 
		[
			DPP_Prop01: "Doc3_Value1", 
			DPP_Prop02: "Doc3_P2"
		])
	])
_testScript.run(context)
```

</details>

### Dynamic Process Properties

<details>

<summary>Standard</summary>

```groovy
ProcessScriptContext context = new ProcessScriptContext(
  inputDocuments: [ ... ],
  dynProcPros: [
	DPP_DynProcProp01 : 1,
	DPP_DynProcProp02 : "Value01"
  ]
)
_testScript.run(context)
```

</details>

<details>

<summary>Explicit assignment to the script context</summary>

```groovy
ProcessScriptContext context = new ProcessScriptContext()

context.dynProcPros.DPP_ProcPropString = "My Process Property"
context.dynProcPros.DPP_IntValue = 0

context.inputDocuments = [ Document.fromText('abc') ]

_testScript.run(context)
```

</details>

### Process Properties

Process Properties need a little bit more effort. You need to provide

* the Process Property <mark style="color:blue;">Component Id</mark> (`b91d87a4-7e8b-4a98-8ea8-a85e32bb5677`) and
* the Process Property <mark style="color:orange;">Value Key</mark> (`fcc4749d-5135-4eaa-a9cf-1b2ddc1ad12`)

<figure><img src="/files/JixNzu9p2dbIAzRhpO7w" alt=""><figcaption><p>Process Property Ids</p></figcaption></figure>

**Process Property Ids are system independent.** This means, these IDs won't change even if you copy or export process properties to a different account. The Ids remain the same!

<details>

<summary>Standard Initialization</summary>

```groovy
final String ppMessageContext = "b91d87a4-7e8b-4a98-8ea8-a85e32bb5677"
final String ppKeyServiceIncident = "fcc4749d-5135-4eaa-a9cf-1b2ddc1ad12"
final String ppKeySenderAddress = "anotherGuid"

// Wrap keys in parenthesis 
// so that the variables (Ids) are taken and not the text as a string

ProcessScriptContext context = new ProcessScriptContext(
	inputDocuments: [Document.fromText("abc")],
	procPros: 
	[
		(ppMessageContext): [
				(ppKeyServiceIncident): "Incident_01",
				(ppKeySenderAddress)  : "mailto@google.com"
		]
	])

_testScript.run(context)
```

</details>


---

# 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.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.
