Skip to content

Commit 235fe96

Browse files
committed
Expand support for http helpers for REST tests
1 parent 7c8357f commit 235fe96

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

ml-unit-test-client/build.gradle

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,49 @@ if (project.hasProperty("myBintrayUser")) {
6464
}
6565
}
6666

67-
tasks.test.dependsOn mlDeploy
67+
task createHttpCredentials(type: com.marklogic.gradle.task.MarkLogicTask) {
68+
def client = getAppConfig().newAppServicesDatabaseClient("Security")
69+
String xquery = """
70+
xquery version "1.0-ml";
71+
72+
import module namespace sec = "http://marklogic.com/xdmp/security"
73+
at "/MarkLogic/security.xqy";
74+
75+
declare option xdmp:mapping "false";
76+
77+
try {
78+
sec:remove-credential("ml-unit-test-credentials")
79+
} catch (\$e) {()};
80+
81+
xquery version "1.0-ml";
82+
83+
import module namespace sec = "http://marklogic.com/xdmp/security"
84+
at "/MarkLogic/security.xqy";
85+
86+
declare option xdmp:mapping "false";
87+
88+
sec:create-credential(
89+
"ml-unit-test-credentials",
90+
"Credentials for ML Rest Helper Calls",
91+
"${mlUsername}",
92+
"${mlPassword}",
93+
(),
94+
(),
95+
fn:false(),
96+
sec:uri-credential-target("http://localhost:${mlRestPort}/.*","digest"),
97+
xdmp:default-permissions()
98+
)
99+
""";
100+
try {
101+
String result
102+
result = client.newServerEval().xquery(xquery).evalAs(String.class);
103+
if (result != null) {
104+
println result
105+
}
106+
} finally {
107+
client.release()
108+
}
109+
}
110+
111+
mlPostDeploy.dependsOn createHttpCredentials
112+
tasks.test.dependsOn mlDeploy
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import module namespace test="http://marklogic.com/roxy/test-helper" at "/test/test-helper.xqy";
2+
3+
4+
test:assert-http-get-status("v1/search?format=xml", $test:DEFAULT_HTTP_OPTIONS,200),
5+
test:assert-http-post-status("v1/search?format=xml", $test:DEFAULT_HTTP_OPTIONS, (), 200)

0 commit comments

Comments
 (0)