1. dw::test::internal::Ansi

1.1. Functions

1.1.1. cyan

cyan(txt: String): String

1.1.2. deletePreviousLine

deletePreviousLine(): String

1.1.3. faint

faint(txt: String): String

1.1.4. green

green(txt: String): String

1.1.5. red

red(txt: String): String

1.1.6. superGreen

superGreen(txt: String): String

1.1.7. superRed

superRed(txt: String): String

1.1.8. superWhite

superWhite(txt: String): String

1.1.9. white

white(txt: String): String

1.1.10. yellow

yellow(txt: String): String

1.2. Variables

1.2.1. SANE

2. dw::test::internal::coverage::CoverageReports

2.1. Functions

2.1.1. fileCoverage

fileCoverage(f: File): Number

2.1.2. getAllBranches

getAllBranches(f: File): Array<Object>

2.1.3. totalCoverage

totalCoverage(files: Array<File>): Number

2.2. Types

2.2.1. CovLine

Definition
1
{ location: Object, branches: Array<Object>, covered: Boolean }

2.2.2. File

Definition
1
{ path: String, nameIdentifier: Object, lines: Array<CovLine> }

3. dw::test::internal::coverage::HtmlCoverage

3.1. Variables

3.1.1. files: Array<File>

3.1.2. formatter

4. dw::test::internal::coverage::Sonar

5. dw::test::internal::DWITUtils

5.1. Functions

5.1.1. createTestCase

createTestCase(scenario: String, testUrl: { content: String, url: String }, context: { _?: Any }, expected: Any, expectedPath: String, mimeType: String): () -> TestResult

5.1.2. createTestCases

createTestCases(mappingDir: String, resourceProvider: TestResourceProvider): Array<() -> TestResult>

Creates a Single Test Case from the

Parameters
Name Description

mappingDir

The mapping directory path

testUrlProvider

Factory function that returns the url of the mapping file to be executed

5.1.3. createTestSuite

createTestSuite(directory: String, resourceProvider: TestResourceProvider): Array<() -> TestResult>

Creates all the tests suites from a given directory.

Parameters
Name Description

directory

The directory where to search all the test cases

5.1.4. evalPathTest

evalPathTest(testUrl: { content: String, url: String }, context: { _?: Any }, expected: Any, expectedPath: String, mimeType: String): TestResult

5.2. Types

5.2.1. TestResourceProvider

Definition
1
(mappingDir: String, testCase: String) -> { content: String, url: String }

6. dw::test::internal::Functions

6.1. Functions

6.1.1. buildContext

buildContext(dir: String)

Helper function to generate input context to run mappings. By default, it will check for the existence of reader properties files for a given input within the same directory, and attempt to pass them to the read function within the reader properties object.

Parameters
Name Description

dir

Directory where files will be traversed and transformed into inputs for the desired mapping execution

6.1.2. hasReaderProperties

hasReaderProperties(p: Path): Boolean

Helper function to assert whether a properties file containing reader parameters exists within the same directory for a given input file

Parameters
Name Type Description

p

Path

Path to the input file

6.1.3. interceptor

interceptor<T>(before: () -> Any, value: () -> T, after: (T) -> Any): T

Helper method to execute something before and after

Parameters
Name Description

before

The method to be executed before

value

The function to be executed

after

The function to be executed after

6.1.4. propertiesFileOf

propertiesFileOf(p: Path): Path

Helper function to assemble the path to a properties file corresponding to an input based on implicit naming conventions.

Parameters
Name Type Description

p

Path

Path to the input file.

7. dw::test::internal::reporter::Default

8. dw::test::internal::reporter::HtmlAggregator

8.1. Functions

8.1.1. testResultDetail

testResultDetail(testSuite: TestResult)

9. dw::test::internal::reporter::JUnit

9.1. Functions

9.1.1. processTestResult

processTestResult(testResult)

Transforms the test result in a junit compatible test result report

10. dw::test::internal::reporter::Reports

10.1. Functions

10.1.1. totalErrors

totalErrors(testsuite: TestResult)

10.1.2. totalFail

totalFail(testsuite: TestResult)

10.1.3. totalOk

totalOk(testsuite: TestResult)

10.1.4. totalSkip

totalSkip(testsuite: TestResult)

10.1.5. totalTests

totalTests(testsuite: TestResult)

10.1.6. totalWithCriteria

totalWithCriteria(testSuite: TestResult, criteria: (TEST_STATUS) -> Boolean): Number

10.1.7. totalWithStatus

totalWithStatus(testsuite: TestResult, statusId: String)

10.2. Types

10.2.1. AggregatorInput

Definition
1
{ showCoverageReport: Boolean, testsResult: TestsResult }

10.2.2. TestsResult

Definition
1
Array<{ name: String, testResult: TestResult }>

11. dw::test::internal::reporter::Sonar

11.1. Functions

11.1.1. processTestResult

processTestResult(testResult: TestsResult): SonarResult

Transforms the test result in a junit compatible test result report

11.2. Types

11.2.1. FileType

Definition
1
{| file @(path: String)*: TestCasesType |}

11.2.2. SonarResult

Definition
1
{| testExecutions @(version: 1): FileType |}

11.2.3. TestCasesType

Definition
1
{| testCase @(name: String, duration: Number)*?: { skipped @(message?: String)?: String | Null, error @(message?: String)?: String | Null, failure @(message?: String)?: String | Null } |}

12. dw::test::internal::reporter::Summary

13. dw::test::Tests

This module contains all functions required to create a DataWeave test

13.1. Example

Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%dw 2.0
import * from dw::test::Tests
---
 "Matcher api" describedBy [
     "It should support nested matching" in  do {
         var payload = {}
         ---
         payload must [
             beObject(),
             $.foo must [
                 beNull()
             ]
         ]
     },
     "It should support simple matching" in do {
         var payload = {}
         ---
         payload must beObject()
     },

     "It should support multiple root cases" in do {
         var payload = {}
         var flowVar = {a: 123}
         ---
         [
             payload must beObject(),
             flowVar must [
                 beObject(),
                 $.a must equalTo(123)
             ]
         ]
     },
     "It should support using custom assertions" in  do {
         var payload = []
         ---
         payload must sizeOf($) > 2
     }
 ]

13.2. Functions

13.2.1. describedBy

describedBy(suite: String, testsToRun: Array<() -> TestResult>): TestResult

Defines a new test suite with the list of test cases.

Example
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
%dw 2.0
import * from dw::test::Tests
 ---

 "Matcher api" describedBy [
     "It should support nested matching" in  do {
         var payload = {}
         ---
         payload must [
             beObject(),
             $.foo must [
                 beNull()
             ]
         ]
     },
]

13.2.2. evalPath

evalPath(dwlFilePath: String, context: { _?: Any }, mimeType: String): Any

Runs a specific mapping with the given context and mimetype.

Parameters
Name Description

dwlFilePath

Path inside the classpath where the runnable dataweave file is present.

context

Object which contains different input values (each input name would be the key of the object).

mimeType

The expected output mimetype.

Example
Source
1
2
3
4
5
6
7
8
9
10
%dw 2.0
import * from dw::test::Tests
import * from dw::test::Asserts
---
"Test MyMapping" describedBy [
    "Assert SimpleScenario" in do {
        evalPath("MyMapping.dwl", inputsFrom("MyMapping/SimpleScenario"), "application/json" ) must
                  equalTo(outputFrom("MyMapping/SimpleScenario"))
    }
 ]
evalPath(testUrl: { content: String, url: String }, context: { _?: Any }, mimeType: String): Any

13.2.3. in

in(testName: String, testCases: () -> MatcherResult): TestResult

Defines a new test case inside a test suite with a single assertion.

Example
Source
1
2
3
"It should support nested matching" in  do {
   "foo" must beString()
}
in(testName: String, callback: Array<() -> MatcherResult>): TestResult

Defines a new test case with multiple assertions

Example
Source
1
2
3
4
5
6
7
8
9
10
11
12
 "It should support multiple root cases" in do {
     var payload = {}
     var flowVar = {a: 123}
     ---
    [
        payload must beObject(),
        flowVar must [
             beObject(),
             $.a must equalTo(123)
          ]
      ]
 }
in(testName: String, callback: Array<() -> MatcherResult>, skipAll: Boolean): TestResult

13.2.4. inputsFrom

inputsFrom(dir: String): { _?: Any }

Builds an object with all the inputs to be used as context for a specific mapping.

Parameters
Name Description

dir

Directory where to look for the inputs folder and build the context from.

13.2.5. outputFrom

outputFrom(dir: String)

Returns the result of reading the expected output

Parameters
Name Description

dir

Directory where to look for the out file to make assertions on your mapping test.

13.3. Variables

13.3.1. ERROR_STATUS

13.3.2. FAIL_STATUS

13.3.3. OK_STATUS

13.3.4. SKIP_STATUS

13.4. Types

13.4.1. TEST_STATUS

Data Type that describes the result of a Test Execution

Definition
1
"ERROR" | "OK" | "FAIL" | "SKIP"

13.4.2. TestResult

Definition
1
{ name: String, time: Number, status: TEST_STATUS, tests?: Array<TestResult>, errorMessage?: String, location?: Location }