Skip to content

Commit dc33c77

Browse files
committed
Updating example projects
Removed jcenter wherever possible. Swapped marklogic-junit out for marklogic-junit5.
1 parent 77eef45 commit dc33c77

File tree

48 files changed

+702
-485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+702
-485
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ Then pick a project under ./examples, and replace the "plugins" block with the f
3737
buildscript {
3838
repositories {
3939
mavenLocal()
40-
jcenter()
40+
mavenCentral()
4141
}
4242
dependencies {
4343
classpath "com.marklogic:ml-gradle:(the version number you chose)"
4444
}
4545
}
4646
apply plugin: "com.marklogic.ml-gradle"
4747

48-
The above unfortunately has to be done because while the "plugins" DSL in Gradle is very concise and automatically
49-
includes jcenter() as a repository, it can't be used for finding plugins in your local Maven repository. So we have to
48+
The above unfortunately has to be done because while the "plugins" DSL in Gradle is very concise,
49+
it can't be used for finding plugins in your local Maven repository. So we have to
5050
replace it with the much more verbose syntax. Of course, after you're done testing with this, change the Gradle file
5151
back to just use the plugins DSL.
5252

examples/alert-project/build.gradle

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
plugins {
22
id "java"
33
id "eclipse"
4-
id "com.marklogic.ml-gradle" version "3.6.0"
4+
id "com.marklogic.ml-gradle" version "4.2.1"
5+
}
6+
7+
repositories {
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
testImplementation "com.marklogic:marklogic-junit5:1.1.0"
13+
}
14+
15+
test {
16+
useJUnitPlatform()
517
}
618

719
/**
@@ -13,11 +25,3 @@ plugins {
1325
ext {
1426
mlAppDeployer.commands.add(new com.marklogic.appdeployer.command.cpf.DeployDefaultPipelinesCommand())
1527
}
16-
17-
repositories {
18-
jcenter()
19-
}
20-
21-
dependencies {
22-
testCompile "com.marklogic:ml-junit:3.0.0"
23-
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mlHost=localhost
22
mlAppName=alert-example
3-
mlRestPort=8077
3+
mlRestPort=8017
4+
mlTestRestPort=8018
45
mlUsername=admin
56
mlPassword=admin
67
mlContentForestsPerHost=1
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
package test;
22

3-
import org.junit.Test;
4-
import org.springframework.test.context.ContextConfiguration;
5-
63
import com.marklogic.client.document.XMLDocumentManager;
74
import com.marklogic.client.io.DocumentMetadataHandle;
85
import com.marklogic.client.io.Format;
96
import com.marklogic.client.io.StringHandle;
10-
import com.marklogic.junit.spring.AbstractSpringTest;
7+
import com.marklogic.junit5.spring.AbstractSpringMarkLogicTest;
8+
import org.junit.jupiter.api.Test;
119

12-
@ContextConfiguration(classes = { TestConfig.class })
13-
public class AlertTest extends AbstractSpringTest {
10+
public class AlertTest extends AbstractSpringMarkLogicTest {
1411

15-
@Override
16-
public void deleteDocumentsBeforeTestRuns() {
17-
// We don't want to do this, as it will blow away our alert configuration
18-
}
12+
@Override
13+
public void deleteDocumentsBeforeTestRuns() {
14+
// Not doing this so that our alert config isn't deleted
15+
}
1916

20-
@Test
21-
public void test() {
22-
// URI of the document we'll insert
23-
final String uri = System.currentTimeMillis() + ".xml";
17+
@Test
18+
void test() {
19+
// URI of the document we'll insert
20+
final String uri = System.currentTimeMillis() + ".xml";
2421

25-
// Insert a document into the collection that we have the alerting pipeline attached to
26-
XMLDocumentManager mgr = getClient().newXMLDocumentManager();
27-
DocumentMetadataHandle metadata = new DocumentMetadataHandle();
28-
metadata.withCollections("sample");
29-
mgr.write(uri, metadata, new StringHandle(
30-
"<test>This has the word hello in it, so it should trigger our alert action</test>")
31-
.withFormat(Format.XML));
22+
// Insert a document into the collection that we have the alerting pipeline attached to
23+
XMLDocumentManager mgr = getDatabaseClient().newXMLDocumentManager();
24+
DocumentMetadataHandle metadata = new DocumentMetadataHandle();
25+
metadata.withCollections("sample");
26+
mgr.write(uri, metadata, new StringHandle(
27+
"<test>This has the word hello in it, so it should trigger our alert action</test>")
28+
.withFormat(Format.XML));
3229

33-
// Check ErrorLog.txt to verify that my-alert.xqy logged an entry
34-
}
30+
// Check ErrorLog.txt to verify that my-alert.xqy logged an entry
31+
}
3532
}

examples/alert-project/src/test/java/test/TestConfig.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

examples/corb2-project/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
buildscript {
1414
repositories {
15-
jcenter()
15+
mavenCentral()
1616
}
1717
dependencies {
1818
//Needed for CorbTask to dynamically generate properties from CORB Options class
@@ -25,7 +25,7 @@ plugins {
2525
}
2626

2727
repositories {
28-
jcenter()
28+
mavenCentral()
2929
}
3030

3131
configurations {

examples/cpf-project/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This project shows an example of configuring CPF with a simple pipeline and doma
33
To try this out, you need the following installed:
44

55
1. MarkLogic 8.0-3 or higher
6-
1. Java 1.7
6+
1. Java 1.8
77

88
Deploying this application requires Gradle, but you don't need Gradle installed, as long as you have Java 1.7 installed.
99

@@ -20,7 +20,7 @@ and with the modules under src/main/ml-modules. The test task will then run the
2020
The above commands assume that you're deploying to a MarkLogic instance on your localhost. If you need to point to a different host,
2121
just do (you can run mlDepoy and test together):
2222

23-
1. ./gradlew -PmlHost=some-other-host mlDeploy test
23+
./gradlew -PmlHost=some-other-host mlDeploy test
2424

2525
You can also run the test in Eclipse by running "./gradlew eclipse", and then importing this project into Eclipse.
2626

@@ -30,4 +30,4 @@ To tinker with the CPF config:
3030
1. If you change a module under src/main/ml-modules, run "./gradlew mlLoadModules" to load the new/modified module.
3131
You can also run "./gradlew mlWatch" to continuously load new/modified modules.
3232

33-
33+

examples/cpf-project/build.gradle

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
plugins {
2-
id "java"
3-
id "eclipse"
4-
id "com.marklogic.ml-gradle" version "3.6.0"
2+
id "java"
3+
id "eclipse"
4+
id "com.marklogic.ml-gradle" version "4.2.1"
55
}
66

77
repositories {
8-
jcenter()
8+
mavenCentral()
9+
mavenLocal()
910
}
1011

1112
dependencies {
12-
testCompile "com.marklogic:ml-junit:3.0.0"
13-
testCompile "com.jayway.restassured:rest-assured:2.4.1"
13+
testImplementation "com.marklogic:marklogic-junit5:1.1.0"
14+
}
15+
16+
test {
17+
useJUnitPlatform()
1418
}

examples/cpf-project/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ mlAppName=cpf-example
33
mlRestPort=8050
44
mlUsername=admin
55
mlPassword=admin
6+
mlTestRestPort=8051
Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,58 @@
11
package sample;
22

3-
import javax.xml.namespace.QName;
4-
5-
import org.junit.Test;
6-
import org.springframework.test.context.ContextConfiguration;
7-
import org.springframework.test.context.TestExecutionListeners;
8-
93
import com.marklogic.client.document.XMLDocumentManager;
104
import com.marklogic.client.io.DocumentMetadataHandle;
115
import com.marklogic.client.io.DocumentMetadataHandle.DocumentProperties;
126
import com.marklogic.client.io.Format;
137
import com.marklogic.client.io.StringHandle;
14-
import com.marklogic.junit.spring.AbstractSpringTest;
15-
import com.marklogic.junit.spring.ModulesLoaderTestExecutionListener;
16-
import com.marklogic.junit.spring.ModulesPath;
17-
18-
@ContextConfiguration(classes = { TestConfig.class })
19-
@TestExecutionListeners(value = { ModulesLoaderTestExecutionListener.class })
20-
@ModulesPath(baseDir = "src/main/ml-modules")
21-
public class CpfTest extends AbstractSpringTest {
22-
23-
@Test
24-
public void test() {
25-
// URI of the document we'll insert
26-
final String uri = "/cpf-example/test.xml";
8+
import com.marklogic.junit5.spring.AbstractSpringMarkLogicTest;
9+
import org.junit.jupiter.api.Test;
2710

28-
// Insert a document into the collection that we have a CPF pipeline attached to
29-
XMLDocumentManager mgr = getClient().newXMLDocumentManager();
30-
DocumentMetadataHandle metadata = new DocumentMetadataHandle();
31-
metadata.withCollections("cpf-test");
32-
mgr.write(uri, metadata, new StringHandle("<test/>").withFormat(Format.XML));
33-
34-
// Wait for the task server to finish processing requests
35-
waitForTaskServerRequestsToFinish();
36-
37-
// Verify that a property was set on our test document by the CPF action
38-
DocumentProperties props = mgr.readMetadata(uri, new DocumentMetadataHandle()).getProperties();
39-
assertEquals("The sample-prop property should have been set by the CPF action", "Hello from the CPF action",
40-
props.get(new QName("http://marklogic.com/sample", "sample-prop")));
41-
}
42-
43-
/**
44-
* TODO Move this into ml-junit for reuse.
45-
*/
46-
private void waitForTaskServerRequestsToFinish() {
47-
String xquery = "declare namespace ss = 'http://marklogic.com/xdmp/status/server'; ";
48-
xquery += "xdmp:server-status(xdmp:hosts(), xdmp:server('TaskServer'))/ss:request-statuses/ss:request-status";
49-
50-
final int MAX_TRIES = 100;
51-
final int SLEEP_TIME = 500;
11+
import javax.xml.namespace.QName;
5212

53-
logger.info("Waiting for task server requests to finish...");
54-
for (int i = 0; i < MAX_TRIES; i++) {
55-
String result = getXccTemplate().executeAdhocQuery(xquery);
56-
if (result == null || result.trim().length() == 0) {
57-
break;
58-
}
59-
try {
60-
Thread.sleep(SLEEP_TIME);
61-
} catch (Exception e) {
62-
throw new RuntimeException("Unexpected error from sleeping while waiting for task server to finish", e);
63-
}
64-
}
65-
logger.info("Task server no longer has any outstanding requests");
66-
}
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
15+
public class CpfTest extends AbstractSpringMarkLogicTest {
16+
17+
@Test
18+
public void test() {
19+
// URI of the document we'll insert
20+
final String uri = "/cpf-example/test.xml";
21+
22+
// Insert a document into the collection that we have a CPF pipeline attached to
23+
XMLDocumentManager mgr = getDatabaseClient().newXMLDocumentManager();
24+
DocumentMetadataHandle metadata = new DocumentMetadataHandle();
25+
metadata.withCollections("cpf-test");
26+
mgr.write(uri, metadata, new StringHandle("<test/>").withFormat(Format.XML));
27+
28+
// Wait for the task server to finish processing requests
29+
waitForTaskServerRequestsToFinish();
30+
31+
// Verify that a property was set on our test document by the CPF action
32+
DocumentProperties props = mgr.readMetadata(uri, new DocumentMetadataHandle()).getProperties();
33+
assertEquals("Hello from the CPF action", props.get(new QName("http://marklogic.com/sample", "sample-prop")),
34+
"The sample-prop property should have been set by the CPF action");
35+
}
36+
37+
private void waitForTaskServerRequestsToFinish() {
38+
String xquery = "declare namespace ss = 'http://marklogic.com/xdmp/status/server'; ";
39+
xquery += "xdmp:server-status(xdmp:hosts(), xdmp:server('TaskServer'))/ss:request-statuses/ss:request-status";
40+
41+
final int MAX_TRIES = 100;
42+
final int SLEEP_TIME = 500;
43+
44+
logger.info("Waiting for task server requests to finish...");
45+
for (int i = 0; i < MAX_TRIES; i++) {
46+
String result = getDatabaseClient().newServerEval().xquery(xquery).evalAs(String.class);
47+
if (result == null || result.trim().length() == 0) {
48+
break;
49+
}
50+
try {
51+
Thread.sleep(SLEEP_TIME);
52+
} catch (Exception e) {
53+
throw new RuntimeException("Unexpected error from sleeping while waiting for task server to finish", e);
54+
}
55+
}
56+
logger.info("Task server no longer has any outstanding requests");
57+
}
6758
}

0 commit comments

Comments
 (0)