Git Product home page Git Product logo

marklogic-junit's Introduction

This is now part of marklogic-unit-test

The releases from this project are still available, but please use the releases from marklogic-unit-test instead.

Easy JUnit 5 testing with MarkLogic

Want to write JUnit 5 tests that verify the behavior of endpoints in MarkLogic, including applications using the Data Hub Framework? This library makes that as simple as possible by providing the following support:

  1. Connect to MarkLogic with the MarkLogic Java Client by reusing configuration you've already defined in your project
  2. Clear your test database before a test run so it always runs in a known state
  3. Easily read and make assertions on JSON and XML documents, including support for XPath-based assertions
  4. Easily integrate marklogic-unit-test tests into a JUnit test suite
  5. And for Data Hub Framework users - run harmonize flows against your staging database and easily verify results in a test database that mirrors your final database

Here's a simple example of a JUnit test that runs a harmonize flow and then makes assertions on some of the documents that were generated:

@Test
public void verifyMyHarmonizeFlow() {
  runHarmonizeFlow("MyEntity", "My Harmonize Flow");
  
  assertCollectionSize("Expecting 100 new entities as a result of running the harmonize flow", "my-entities", 100);
  
  // Read and verify the contents of a JSON document using standard Jackson and JUnit APIs
  JsonNode json = readJsonDocument("/entity/1.json");
  assertEquals("SomeValue", json.get("someProperty").asText());
  
  // Or read and verify the contents of an XML document using XPath and JUnit      
  XmlNode xml = readXmlDocument("/entity/2.xml");
  xml.assertElementValue("/my:document/my:element", "some value");
  xml.assertElementCount("Should have gotten two of these", "/my:document/other:element", 2);
  
  // Can easily make assertions on permissions
  readDocumentPermissions("/entity/1.json")
    .assertReadPermissionExists("rest-reader")
    .assertUpdatePermissionExists("rest-writer");
  
  // And on properties too
  readDocumentProperties("/entity/1.json").assertElementExists("/prop:properties/prop:last-modified[. != '']");
}

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 sample 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 harmonize flows and other application features, then check out the DHF sample project to see a working example with instructions on how to get started.

marklogic-junit's People

Contributors

rjrudin avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

derms

marklogic-junit's Issues

Add tests for marklogic-junit itself

The example projects help with this, but would be better to run a set of tests that use marklogic-junit to test itself, presumably using 8000 and the Documents database

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.