Skip to content

Commit 7e00c3d

Browse files
committed
Merge branch 'release/1.3.0'
2 parents c2b32ec + 99753f7 commit 7e00c3d

File tree

10 files changed

+101
-15
lines changed

10 files changed

+101
-15
lines changed

docs/assertion-functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
layout: default
33
title: Assertion functions
44
nav_order: 6
5+
permalink: /docs/assertions
56
---
67

78
The list below captures the assertion functions available in the marklogic-unit-test `/test/test-helper.xqy` module.

docs/getting-started.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
layout: default
33
title: Getting started
44
nav_order: 2
5+
[comment]: "/docs" is used to preserve links to previous set of docs.
6+
permalink: /docs
57
---
68

79
This guide walks you through adding marklogic-unit-test to an existing project, followed by writing, loading, and
@@ -39,7 +41,7 @@ in your `build.gradle` file), run the following task to install marklogic-unit-t
3941

4042
./gradlew -i mlLoadModules
4143

42-
If you would like to [run your marklogic-unit-test tests](running-tests.md) via Gradle, you'll also need to include the
44+
If you would like to [run your marklogic-unit-test tests](/docs/running) via Gradle, you'll also need to include the
4345
following at the top of your `build.gradle` file:
4446

4547
```
@@ -89,7 +91,7 @@ therefore be stored in the `src/test/ml-modules/root/test/suites/(name of suite)
8991

9092
A test suite can have any name; for this example, we will use "thesaurus" as the name. Test modules can have any name
9193
as well with a few exceptions for setup and teardown modules; those exceptions are covered in the
92-
[guide for writing tests](writing-tests.md). We will use "simple-test.sjs" for this example, so we create a
94+
[guide for writing tests](/docs/writing). We will use "simple-test.sjs" for this example, so we create a
9395
file at `src/test/ml-modules/root/test/suites/thesaurus/simple-test.sjs` with the following initial content:
9496

9597
```
@@ -98,7 +100,7 @@ const lib = require("/example/lib.sjs");
98100
```
99101

100102
The first line above imports the marklogic-unit-test module containing dozens of useful
101-
[assertion functions](assertion-functions.md); every test
103+
[assertion functions](/docs/assertions); every test
102104
module will need this imported. The second line imports the library module that we wish to verify.
103105

104106
Next, add the following text to the file:
@@ -115,7 +117,7 @@ const result = lib.lookupTerm("Car");
115117
The above code will invoke the `lookupTerm` function that we wish to test with a term that we know is in the
116118
application's thesaurus. Each `assertEqual` function call - along with every other assertion function in
117119
marklogic-unit-test - will return a success or failure. The test then returns an array of these successes and failures.
118-
The different approaches for [running tests](running-tests.md) know how to collect these results and display how many
120+
The different approaches for [running tests](/docs/running) know how to collect these results and display how many
119121
tests passed and how many failed.
120122

121123
## Configuring a connection to MarkLogic
@@ -162,7 +164,7 @@ Once you execute either `mlWatch` or `mlLoadModules`, your test will be ready to
162164

163165
## Running a test
164166

165-
marklogic-unit-test provides [several ways to run tests](running-tests.md). We will look at the two primary ways to
167+
marklogic-unit-test provides [several ways to run tests](/docs/running). We will look at the two primary ways to
166168
run the test module we just wrote and loaded into our application's modules database.
167169

168170
First, tests can be run via the ml-gradle `mlUnitTest` task, as long as you have included the
@@ -216,6 +218,6 @@ This guide has covered the following topics:
216218
3. How to load a test.
217219
4. How to run a test.
218220

219-
With the above information and the references on [writing tests](writing-tests.md) and
220-
[running tests](running-tests.md), you can now start writing tests for the library modules in your application,
221+
With the above information and the references on [writing tests](/docs/writing) and
222+
[running tests](/docs/running), you can now start writing tests for the library modules in your application,
221223
ensuring that you can quickly enhance your application without breaking any existing functionality.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ marklogic-unit-test includes the following components:
1919
popular Java testing frameworks.
2020
4. A REST endpoint for integrating with testing frameworks in any language.
2121

22-
Please see the [Getting started guide](getting-started.md) to learn how to include marklogic-unit-test in your
22+
Please see the [Getting started guide](/docs) to learn how to include marklogic-unit-test in your
2323
project and to start writing and running tests.
2424

2525
If you have any questions or run into issues while using marklogic-unit-test, try one of the following:

docs/loading-test-data.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
layout: default
33
title: Loading test data
44
nav_order: 5
5+
permalink: /docs/loading
56
---
67

78
marklogic-unit-test includes a simple mechanism for loading test data specific to a test suite. This capability is
@@ -32,7 +33,7 @@ test:load-test-file("sample-doc.json", xdmp:database(), "/sample-doc.json")
3233
```
3334

3435
The above examples can also be implemented in either `suiteSetup.sjs` or `suite-setup.xqy` if desired - see the
35-
[guide on writing tests](writing-tests.md) for more information on setup and teardown modules.
36+
[guide on writing tests](/docs/writing) for more information on setup and teardown modules.
3637

3738
You can also use a teardown module to delete the data that was loaded. However, leaving data in place after a test
3839
concludes is often helpful for both manually verifying what it's in the database and for debugging test failures.

docs/running-tests.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
layout: default
33
title: Running tests
44
nav_order: 4
5+
permalink: /docs/running
56
---
67

78
Tests written using marklogic-unit-test can be run in several ways, each of which is described below.
89

910
## Using Gradle
1011

1112
The [ml-gradle plugin for Gradle](https://github.com/marklogic/ml-gradle) provides an `mlUnitTest` task for running
12-
all of your marklogic-unit-test tests. As noted in the [Getting started guide](getting-started.md), you will need to
13+
all of your marklogic-unit-test tests. As noted in the [Getting started guide](/docs), you will need to
1314
include the following block at the top of your `build.gradle` file to ensure this task can run successfully:
1415

1516
```
@@ -38,9 +39,9 @@ App Server.
3839
## Using the web application
3940

4041
Once you have deployed your application along with the marklogic-unit-test modules, as described in the
41-
[Getting started guide](getting-started.md), you will be able to access a custom endpoint via any MarkLogic HTTP
42+
[Getting started guide](/docs), you will be able to access a custom endpoint via any MarkLogic HTTP
4243
App Server associated with the modules database containing your application modules. The path of that endpoint is
43-
`/test/default.xqy`. For example, since the App Server in the [Getting started guide](getting-started.md) listens on
44+
`/test/default.xqy`. For example, since the App Server in the [Getting started guide](/docs) listens on
4445
port 8024, the endpoint would be accessible at <http://localhost:8024/test/default.xqy>.
4546

4647
The web application at this custom endpoint provides a functional, albeit antiquated-looking, interface for running

docs/writing-tests.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
layout: default
33
title: Writing tests
44
nav_order: 3
5+
permalink: /docs/writing
56
---
67

78
This guide is a reference on the different kinds of test modules, setup modules, and teardown modules you can write
@@ -11,7 +12,7 @@ in the `src/test/ml-modules/root/test/suites/thesaurus` directory in the
1112

1213
## Location of test files
1314

14-
As described in the [Getting started guide](getting-started.md), marklogic-unit-test requires the URI of each module
15+
As described in the [Getting started guide](/docs), marklogic-unit-test requires the URI of each module
1516
to begin with `/test/suites/(name of suite)/`. Thus, all test files should be located in an
1617
[ml-gradle modules directory](https://github.com/marklogic/ml-gradle/wiki/How-modules-are-loaded) under
1718
`root/test/suites/(name of suite)/`.
@@ -41,7 +42,7 @@ the test helper library to be followed by an import of the application module be
4142
const test = require("/test/test-helper.xqy");
4243
const lib = require("/example/lib.sjs");
4344

44-
The test should then return the output of one or more [assertion functions](assertion-functions.md)
45+
The test should then return the output of one or more [assertion functions](/docs/assertions)
4546
found in the `test-helper` module. This can be done via a single array:
4647

4748
```
@@ -96,7 +97,7 @@ import module namespace ex="http://example.org" at "/example/lib.xqy";
9697
```
9798

9899
The test will then call the function to be tested and use the helper library to invoke one or more
99-
[assertion functions](assertion-functions.md), returning the results of those assertions:
100+
[assertion functions](/docs/assertions), returning the results of those assertions:
100101

101102
```
102103
let $result := ex:lookup-term("Car", "elements")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
3+
const BOOM_QNAME = xs.QName("MATCH-BOOM");
4+
const BOOM_ERROR = "The values matched";
5+
6+
/**
7+
* Throw an error if the parameters match.
8+
* @param param1
9+
* @param param2
10+
* @returns
11+
*/
12+
function mightBoom(param1, param2) {
13+
// When an SJS test uses test-helper.xqy and passes a function, the parameters are wrapped as objects which may
14+
// impact how the application code has to be written or has to be tested. A future SJS version of test-helper.xqy
15+
// will avoid this issue.
16+
if (param1.toString() === param2.toString()) {
17+
fn.error(BOOM_QNAME, BOOM_ERROR);
18+
}
19+
return param1;
20+
}
21+
22+
module.exports = {
23+
BOOM_ERROR,
24+
mightBoom,
25+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
xquery version "1.0-ml";
2+
3+
module namespace ex = "http://marklogic.com/example";
4+
5+
declare option xdmp:mapping "false";
6+
7+
declare variable $BOOM_QNAME := xs:QName("MATCH-BOOM");
8+
declare variable $BOOM_ERROR := "The values matched";
9+
10+
declare function mightBoom($param1, $param2) {
11+
if ($param1 eq $param2) then
12+
fn:error($BOOM_QNAME, $BOOM_ERROR)
13+
else (
14+
xdmp:log("mightBoom; the parameters are different"),
15+
$param1
16+
)
17+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
3+
const test = require("/test/test-helper.xqy");
4+
const lib = require("/example/boom-lib.sjs");
5+
6+
const SAME_PARAM = "1";
7+
8+
let assertions = [
9+
test.assertEqual(
10+
1,
11+
lib.mightBoom(1, 2),
12+
"Different values should not blow up"
13+
),
14+
test.assertThrowsError(
15+
xdmp.function(xs.QName("mightBoom"), "/example/boom-lib.sjs"),
16+
SAME_PARAM,
17+
SAME_PARAM,
18+
lib.BOOM_ERROR
19+
),
20+
];
21+
22+
assertions;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
xquery version "1.0-ml";
2+
3+
import module namespace test = "http://marklogic.com/test" at "/test/test-helper.xqy";
4+
import module namespace lib = "http://marklogic.com/example" at "/example/boom-lib.xqy";
5+
6+
declare variable $SAME_PARAM := "1";
7+
8+
9+
(
10+
test:assert-throws-error(
11+
xdmp:function(fn:QName("http://marklogic.com/example", "mightBoom"), "/example/boom-lib.xqy"),
12+
$SAME_PARAM,
13+
$SAME_PARAM,
14+
$lib:BOOM_ERROR
15+
)
16+
)

0 commit comments

Comments
 (0)