Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4724202
Consolidating filesystem reads
jamesagardner Jan 3, 2019
0213af9
Simplify list-from-database function and reducing arguments
jamesagardner Jan 3, 2019
2b6b46c
list() to uses a map instead of string comparison
jamesagardner Jan 4, 2019
d99cc12
list() iterates over tests once instead of twice
jamesagardner Jan 4, 2019
24c3e2f
Adding tests for suite structure and test detection
jamesagardner Jan 4, 2019
402759e
#45 Support for nested test suites
jamesagardner Jan 4, 2019
167862d
#52 Remove Roxy from all namespaces
jamesagardner Jan 4, 2019
aa14bb1
#45 Ignoring the lib directory
jamesagardner Jan 7, 2019
bed40d4
Merge pull request #54 from jamesagardner/master
jamesagardner Jan 7, 2019
1a09445
#52 Updating JS UI to use new namespace
jamesagardner Jan 7, 2019
7e44293
#52 Parameterized Tests Parse New Namespaced XML
jamesagardner Jan 7, 2019
d6bdfeb
added ability to specify permissions and collections when calling loa…
cskeefer Jan 21, 2019
fe70c4e
#52 Assert methods inside test-helper
jamesagardner Jan 22, 2019
e4f18e6
Merge pull request #56 from jamesagardner/feature-#52
jamesagardner Jan 22, 2019
7276514
Merge branch 'develop' into load-test-file-updates
jamesagardner Jan 22, 2019
e5e1e16
added ability to specify permissions and collections when calling loa…
cskeefer Jan 21, 2019
4378cb0
Organized Data Loader tests
jamesagardner Jan 23, 2019
6e3304a
Merge pull request #59 from cskeefer/load-test-file-updates
jamesagardner Jan 23, 2019
63a8697
Custom Failure Messages
jamesagardner Jan 23, 2019
98dfa5d
Custom Failure Messages in Description, not Data
jamesagardner Jan 23, 2019
f14fe57
converted all but one pesky xdmp:eval to xdmp:invoke-function and add…
cskeefer Jan 29, 2019
9bf71f7
Flattened tests down to reduce complexity and number of files/dirs
cskeefer Feb 1, 2019
c8af0b0
Merge pull request #60 from cskeefer/issue-55/remove-eval
jamesagardner Feb 1, 2019
e55af4f
Merge branch 'develop' of https://github.com/marklogic-community/mark…
jamesagardner Mar 13, 2019
9b8932e
Custom Failure Messages in Description, not Data
jamesagardner Apr 26, 2019
2c768f1
Merged marklogic-junit library into marklogic-unit-test (#66)
rjrudin Apr 26, 2019
b06a15a
Renamed Test Namespace (#68)
jamesagardner Apr 26, 2019
ad810a0
Bumping version to 1.0.beta
jamesagardner Apr 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
# Change Log

## [v1.0.0](https://github.com/marklogic-community/marklogic-unit-test/tree/v1.0.0) (2019-04-26)
[Full Changelog](https://github.com/marklogic-community/marklogic-unit-test/compare/v0.12.0...v1.0.0)

**Implemented enhancements:**

- Support Nested Test Suites [\#45](https://github.com/marklogic-community/marklogic-unit-test/issues/45)
- Add Failure Message to Assert Functions [\#51](https://github.com/marklogic-community/marklogic-unit-test/issues/51)
- Remove Roxy from Namespaces [\#52](https://github.com/marklogic-community/marklogic-unit-test/issues/52)
- Eliminate xdmp:eval\(\) [\#55](https://github.com/marklogic-community/marklogic-unit-test/issues/55)
- Allow substitutions during deployment [\#32](https://github.com/marklogic-community/marklogic-unit-test/issues/32)

**Merged pull requests:**

- Merged marklogic-junit library into marklogic-unit-test [\#66](https://github.com/marklogic-community/marklogic-unit-test/pull/66) ([rjrudin](https://github.com/rjrudin))
- Specify permissions and collections in test:load-test-file [\#59](https://github.com/marklogic-community/marklogic-unit-test/pull/59) ([cskeefer](https://github.com/cskeefer))
- Adding contributor information [\#50](https://github.com/marklogic-community/marklogic-unit-test/pull/50) ([jamesagardner](https://github.com/jamesagardner))
- Name change from ml-unit-test to marklogic-unit-test [\#43](https://github.com/marklogic-community/marklogic-unit-test/pull/43) ([dmcassel](https://github.com/dmcassel))

**Breaking Changes:**
- The namespaces were updated due to [\#52](https://github.com/marklogic-community/marklogic-unit-test/issues/52) follow these [instructions for upgrading](https://github.com/marklogic-community/marklogic-unit-test/issues/52#issuecomment-487184896).

## [v0.12.0](https://github.com/marklogic-community/marklogic-unit-test/tree/v0.12.0) (2018-09-20)
[Full Changelog](https://github.com/marklogic-community/marklogic-unit-test/compare/0.11.2...v0.12.0)


**Merged pull requests:**

- Release v0.12.0 [\#42](https://github.com/marklogic-community/marklogic-unit-test/pull/42) ([dmcassel](https://github.com/dmcassel))
- Release [\#41](https://github.com/marklogic-community/marklogic-unit-test/pull/41) ([dmcassel](https://github.com/dmcassel))
- Change to marklogic [\#40](https://github.com/marklogic-community/marklogic-unit-test/pull/40) ([dmcassel](https://github.com/dmcassel))

## [0.11.2](https://github.com/marklogic-community/marklogic-unit-test/tree/0.11.2) (2018-09-20)
[Full Changelog](https://github.com/marklogic-community/marklogic-unit-test/compare/0.11.1...0.11.2)

**Implemented enhancements:**

- assert-equal-json doesn't accept arrays [\#28](https://github.com/marklogic-community/marklogic-unit-test/issues/28)

**Fixed bugs:**

- failures in suite-setup.xqy are not reported [\#13](https://github.com/marklogic-community/marklogic-unit-test/issues/13)

**Closed issues:**

- Unit testing with ml-data-hub:2.0.4 [\#34](https://github.com/marklogic-community/marklogic-unit-test/issues/34)
- Set up github pages for docs [\#24](https://github.com/marklogic-community/marklogic-unit-test/issues/24)
- assertEqual cannot compare JS/JSON arrays [\#23](https://github.com/marklogic-community/marklogic-unit-test/issues/23)
- Add CONTRIBUTING.md [\#12](https://github.com/marklogic-community/marklogic-unit-test/issues/12)
- Add .editorconfig to help with consistent formatting [\#5](https://github.com/marklogic-community/marklogic-unit-test/issues/5)

**Merged pull requests:**

Expand Down Expand Up @@ -70,4 +105,4 @@
## [0.9.1](https://github.com/marklogic-community/marklogic-unit-test/tree/0.9.1) (2018-02-22)


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=com.marklogic
version=0.12.0
version=1.0.beta
46 changes: 46 additions & 0 deletions marklogic-junit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Easy JUnit 5 testing with MarkLogic

Want to write JUnit 5 tests that verify the behavior of endpoints in [MarkLogic](https://www.marklogic.com/),
including applications using the [Data Hub Framework](https://marklogic.github.io/marklogic-data-hub/)?
This library makes that as simple as possible by providing the following support:

1. Connect to MarkLogic with the [MarkLogic Java Client](https://developer.marklogic.com/products/java) by reusing
configuration you've already defined in your project
1. Clear your test database before a test run so it always runs in a known state
1. Easily read and make assertions on JSON and XML documents, including support for XPath-based assertions
1. Easily integrate [marklogic-unit-test](https://github.com/marklogic-community/marklogic-unit-test) tests into a JUnit test suite

Below is a simple example of a JUnit test that writes a couple documents, runs a search on them, and then reads them
back and verifies the contents of each document:

```
public class SearchTest extends AbstractSpringMarkLogicTest {

@Test
public void twoDocuments() {
getDatabaseClient().newXMLDocumentManager().write("/test/1.xml", new StringHandle("<message>Hello world</message>"));
getDatabaseClient().newJSONDocumentManager().write("/test/2.json", new StringHandle("{\"message\":\"Hello world\"}"));

QueryManager queryManager = getDatabaseClient().newQueryManager();
SearchHandle searchHandle = queryManager.search(queryManager.newStringDefinition(), new SearchHandle());
assertEquals(2, searchHandle.getTotalResults());

XmlNode xml = readXmlDocument("/test/1.xml");
xml.assertElementValue("/message", "Hello world");

JsonNode json = readJsonDocument("/test/2.json");
assertEquals("Hello world", json.get("message").asText());
}
}
```

## Getting started on an ml-gradle project

If you'd like to use marklogic-junit on a regular ml-gradle project (not a DHF project), then
start with the ml-gradle example project to see a working example with instructions on how to get started.

## Getting started on a Data Hub Framework project

If you're working on a Data Hub Framework (DHF) project and you're like to start writing JUnit tests to verify your application
features, then check out the DHF example project to see a working example with instructions on how to get started.

79 changes: 79 additions & 0 deletions marklogic-junit/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
plugins {
id "java"
id "maven-publish"
id "com.jfrog.bintray" version "1.8.0"
id "com.github.jk1.dependency-license-report" version "0.3.11"
id "net.saliman.properties" version "1.4.6"
}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

repositories {
jcenter()
}

dependencies {
compile project(":marklogic-unit-test-client")
compile "com.marklogic:ml-javaclient-util:3.11.0"
compile "jaxen:jaxen:1.1.6"
compile "org.junit.jupiter:junit-jupiter-api:5.4.1"
compile "org.junit.jupiter:junit-jupiter-params:5.4.1"
compile "org.springframework:spring-context:5.0.8.RELEASE"
compile "org.springframework:spring-test:5.0.8.RELEASE"

// Support for DHF is provided, but a client must specify their own version of the DHF library to use
compileOnly ("com.marklogic:marklogic-data-hub:4.2.2") {
exclude module: "ml-javaclient-util"
}

// Needed by Gradle 4.6+ - see https://www.petrikainulainen.net/programming/testing/junit-5-tutorial-running-unit-tests-with-gradle/
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.4.1"

// Forcing Spring to use logback instead of commons-logging
testRuntime "ch.qos.logback:logback-classic:1.1.8"
testRuntime group: "org.slf4j", name: "jcl-over-slf4j", version: "1.7.22"
testRuntime group: "org.slf4j", name: "slf4j-api", version: "1.7.22"
}

// Needed by Gradle 4.6+ - see https://www.petrikainulainen.net/programming/testing/junit-5-tutorial-running-unit-tests-with-gradle/
test {
useJUnitPlatform()
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier "sources"
from sourceSets.main.allJava
}

publishing {
publications {
mainJava(MavenPublication) {
from components.java
artifactId "marklogic-junit"
}
sourcesJava(MavenPublication) {
from components.java
artifactId "marklogic-junit"
artifact sourcesJar
}
}
}

if (project.hasProperty("myBintrayUser")) {
bintray {
user = myBintrayUser
key = myBintrayKey
publications = ["mainJava", "sourcesJava"]
pkg {
repo = "maven"
name = project.name
licenses = ["Apache-2.0"]
vcsUrl = "https://github.com/marklogic-community/" + project.name + ".git"
version {
name = project.version
released = new Date()
}
}
}
}
8 changes: 8 additions & 0 deletions marklogic-junit/examples/simple-dhf4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gradle
out
build
*.iml
gradle-local.properties
src/main
gradle.properties
.tmp
33 changes: 33 additions & 0 deletions marklogic-junit/examples/simple-dhf4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
This project shows an example of using both marklogic-junit and marklogic-unit-test within a
Data Hub Framework version 4 project.

To try this out locally, first initialize the DHF project:

./gradlew hubInit

Then add the following lines to gradle.properties:

```
mlModulePaths=src/main/ml-modules,src/test/ml-modules
mlTestDbName=data-hub-TEST
mlTestDbFilename=final-database.json
mlTestServerFilename=final-server.json
mlTestServerName=data-hub-TEST
mlTestPort=8015
mlTestUsername=someuser
mlTestPassword=someuser's password
```

You can now deploy both the normal DHF application and the test resources defined in build.gradle via:

./gradlew mlDeploy testDeploy

There are two marklogic-unit-test test modules under ./src/main/ml-modules/root/test. You can run these
via Gradle:

./gradlew test

And Gradle should report "BUILD SUCCESSFUL" as none of the tests should fail.

Or import this project into your favorite IDE and execute "RunDataHubUnitTestsTest". Each test module
will be executed as a separate JUnit test.
118 changes: 118 additions & 0 deletions marklogic-junit/examples/simple-dhf4/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
plugins {
id 'net.saliman.properties' version '1.4.6'
id 'com.marklogic.ml-data-hub' version '4.2.2'
id 'java'
}

repositories {
jcenter()
mavenLocal()
}

dependencies {
mlRestApi "com.marklogic:marklogic-unit-test-modules:0.13.develop"

testCompile "com.marklogic:marklogic-junit:0.13.develop"
testCompile "com.marklogic:marklogic-data-hub:4.2.2"

// Needed by Gradle 4.6+
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.3.0"
}

// Needed by Gradle 4.6+ - see https://www.petrikainulainen.net/programming/testing/junit-5-tutorial-running-unit-tests-with-gradle/
test {
useJUnitPlatform()
}


/**
* Tasks for setting up a test database and a test app server that mirror either your final or staging database and
* app server, and then loading hub and user modules via the test app server so that REST options are accessible to it.
* Depends on the following properties being set:
*
* - mlTestDbFilename = the name of the file to use for constructing a database - either final-database.json or staging-database.json
* - mlTestDbName = the name for the test database
* - mlTestServerFilename = the name of the file to use for constructing an app server - either final-server.json or staging-server.json
* - mlTestServerName = the name of the test app server
* - mlTestPort = the port to assign to the test app server
*/

task hubDeployTestDatabase(type: com.marklogic.gradle.task.MarkLogicTask) {
doLast {
println "Deploying a test database with name ${mlTestDbName} based on configuration file named ${mlTestDbFilename}"
new DeployHubTestDatabaseCommand(hubConfig, mlTestDbFilename, mlTestDbName).execute(mlCommandContext)
}
}

task hubDeployTestServer(type: com.marklogic.gradle.task.MarkLogicTask) {
doLast {
println "Deploying a test server with name ${mlTestServerName} and port ${mlTestPort}, connected to content database ${mlTestDbName}, based on configuration file named ${mlTestServerFilename}"
new DeployHubTestServerCommand(mlTestServerFilename, mlTestServerName, Integer.parseInt(mlTestPort), mlTestDbName).execute(mlCommandContext);
}
}

task testDeploy {
description = "Deploy a test database and a test server"
dependsOn = ["hubDeployTestDatabase", "hubDeployTestServer"]
}
hubDeployTestServer.mustRunAfter hubDeployTestDatabase

task hubUndeployTestResources(type: com.marklogic.gradle.task.MarkLogicTask) {
description = "Undeploys the test server and database that were created via testDeploy"
doLast {
mlAdminManager.invokeActionRequiringRestart({
new com.marklogic.mgmt.resource.appservers.ServerManager(mlManageClient).deleteByIdField(mlTestServerName)
return true
})
new com.marklogic.mgmt.resource.databases.DatabaseManager(mlManageClient).deleteByName(mlTestDbName)
}
}
mlUndeploy.dependsOn hubUndeployTestResources

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import com.fasterxml.jackson.databind.node.TextNode
import com.marklogic.hub.HubConfig

import java.util.regex.Pattern

class DeployHubTestDatabaseCommand extends com.marklogic.hub.deploy.commands.DeployHubDatabaseCommand {
String testDatabaseName

DeployHubTestDatabaseCommand(HubConfig config, String databaseFilename, String testDatabaseName) {
super(config, null, databaseFilename)
this.testDatabaseName = testDatabaseName
}

@Override
protected String copyFileToString(File f) {
String payload = super.copyFileToString(f)
ObjectNode node = new ObjectMapper().readTree(payload)
node.set("database-name", new TextNode(testDatabaseName))
return node.toString()
}
}

class DeployHubTestServerCommand extends com.marklogic.hub.deploy.commands.DeployHubOtherServersCommand {
String serverName
int port
String contentDatabaseName

DeployHubTestServerCommand(String serverFilenamePattern, String serverName, int port, String contentDatabaseName) {
super()
setResourceFilenamesIncludePattern(Pattern.compile(serverFilenamePattern))
this.serverName = serverName
this.port = port
this.contentDatabaseName = contentDatabaseName
}

@Override
protected String copyFileToString(File f) {
String payload = super.copyFileToString(f)
ObjectNode node = new ObjectMapper().readTree(payload)
node.set("server-name", new TextNode(serverName))
node.set("port", new TextNode(port + ""))
node.set("content-database", new TextNode(contentDatabaseName))
return node.toString()
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading