Skip to content

Commit 38c5edb

Browse files
committed
#360 Can now configure connection in mlUnitTest
1 parent 1283da6 commit 38c5edb

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

examples/unit-test-project/README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
This project shows an example of using the ml-unit-test framework to run server-side tests within MarkLogic.
22

3+
## Enabling ml-unit-test in an ml-gradle project
4+
35
Using ml-unit-test requires two additions to the build.gradle file, as described below.
46

57
First, ml-gradle includes an "mlUnitTest" task, which depends on the ml-unit-test-client JAR file. ml-gradle does not
@@ -25,8 +27,10 @@ is a feature of ml-gradle for depending on packages of MarkLogic modules):
2527
mlRestApi "com.marklogic:ml-unit-test-modules:0.11.1"
2628
}
2729

28-
With those additions in place, the "mlUnitTest" task can be run. This task will use the value of mlTestRestPort to
29-
determine which MarkLogic app server to connect to.
30+
## Running unit tests
31+
32+
With the above additions in place, the "mlUnitTest" task can be run. This task will use the value of mlTestRestPort to
33+
determine which MarkLogic app server to connect to - see below for how to customize this.
3034

3135
First, deploy the application:
3236

@@ -56,3 +60,28 @@ You can also access the ml-unit-test REST endpoints directly:
5660
And you can run the original UI test runner by going to:
5761

5862
- http://localhost:8135/test/default.xqy
63+
64+
## Configuring which server mlUnitTest connects to
65+
66+
Prior to ml-gradle 3.8.1, the mlUnitTest task will connect to mlTestRestPort if it's set, else mlRestPort.
67+
68+
Starting in release 3.8.1, you can configure which REST API server mlUnitTest will connect to. The mlUnitTest task now
69+
exposes a property of type [DatabaseClientConfig](https://github.com/marklogic-community/ml-javaclient-util/blob/master/src/main/java/com/marklogic/client/ext/DatabaseClientConfig.java).
70+
You can configure the properties of this object, and mlUnitTest will use it for creating a connection to MarkLogic.
71+
72+
Below is an example - note that you need to configure every property necessary for the type of connection you want, as
73+
none of the properties of the DatabaseClientConfig have any default value:
74+
75+
mlUnitTest.databaseClientConfig.host = mlHost
76+
mlUnitTest.databaseClientConfig.port = 8880 // probably a port that differs from mlRestPort and mlTestRestPort
77+
mlUnitTest.databaseClientConfig.username = mlUsername
78+
mlUnitTest.databaseClientConfig.password = mlPassword
79+
// Other properties that can be set
80+
// mlUnitTest.databaseClientConfig.securityContextType
81+
// mlUnitTest.databaseClientConfig.database
82+
// mlUnitTest.databaseClientConfig.sslContext
83+
// mlUnitTest.databaseClientConfig.sslHostnameVerifier
84+
// mlUnitTest.databaseClientConfig.certFile
85+
// mlUnitTest.databaseClientConfig.certPassword
86+
// mlUnitTest.databaseClientConfig.externalName
87+
// mlUnitTest.databaseClientConfig.trustManager

src/main/groovy/com/marklogic/gradle/task/test/UnitTestTask.groovy

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.marklogic.gradle.task.test
22

3+
import com.marklogic.client.ext.DatabaseClientConfig
34
import com.marklogic.gradle.task.MarkLogicTask
45
import com.marklogic.test.unit.DefaultJUnitTestReporter
56
import com.marklogic.test.unit.JUnitTestSuite
@@ -13,6 +14,8 @@ import org.gradle.api.tasks.TaskAction
1314
*/
1415
class UnitTestTask extends MarkLogicTask {
1516

17+
DatabaseClientConfig databaseClientConfig = new DatabaseClientConfig()
18+
1619
@TaskAction
1720
void runUnitTests() {
1821
try {
@@ -21,8 +24,21 @@ class UnitTestTask extends MarkLogicTask {
2124
def message = "This task requires the com.marklogic:marklogic-unit-test-client library to be a buildscript dependency"
2225
throw new GradleException(message)
2326
}
27+
2428
def appConfig = getAppConfig()
25-
def client = appConfig.getTestRestPort() != null ? appConfig.newTestDatabaseClient() : appConfig.newDatabaseClient()
29+
30+
def client
31+
if (databaseClientConfig.getPort() != null && databaseClientConfig.getPort() > 0) {
32+
println "Constructing DatabaseClient based on settings in the databaseClientConfig task property"
33+
client = appConfig.configuredDatabaseClientFactory.newDatabaseClient(databaseClientConfig)
34+
} else if (appConfig.getTestRestPort() != null) {
35+
println "Constructing DatabaseClient that will connect to port: " + appConfig.getTestRestPort()
36+
client = appConfig.newTestDatabaseClient()
37+
} else {
38+
println "Constructing DatabaseClient that will connect to port: " + appConfig.getRestPort()
39+
client = appConfig.newDatabaseClient()
40+
}
41+
2642
try {
2743
def testManager = new TestManager(client)
2844

0 commit comments

Comments
 (0)