Coder Social home page Coder Social logo

ekino / jcv-db Goto Github PK

View Code? Open in Web Editor NEW
6.0 20.0 1.0 404 KB

JSON Content Validator for Database (JCV-DB) allow you to compare database contents against a JSON with JCV validators.

License: MIT License

Kotlin 83.21% Shell 0.16% Java 16.63%
java json testing assertions assertj cassandra kotlin mysql mssql mongodb postgresql assertj-assertions jcv

jcv-db's Introduction

JCV-DB

JSON Content Validator for Database (JCV-DB) allow you to compare database contents against a JSON with JCV validators.

Build Status GitHub (pre-)release Maven Central GitHub license

Table of contents

Summary

JCV-DB provides assertions to validate database content against a json file. The goal is for now to support SQL and NoSQL databases : PostgreSQL, MySQL, MSSQL, Cassandra and mongoDB. JCV validators are also supported making tests light and exhaustive.

Quick Start

Assertj-db

A JCV-DB module that supports Assertj-db. Only PostgreSQL, MySQL, MSSQL server are supported in this module.

Example

import static com.ekino.oss.jcv.db.assertj.DbComparatorAssertJ.assertThatTable

@Test
fun testContentTable() {
    assertThatTable(assertDb.table("table_name"))
    .isValidAgainst("""[
        {
            "id": "e3881fb1-b3dd-4701-b08c-f5d17389edfa",
            "number_field": 1,
            "boolean_field: true,
            "string_field": "Hello"
        }
    ]""".trimIndent())
}

Dependencies

Maven

<dependencies>
  ...
  <dependency>
    <groupId>org.skyscreamer</groupId>
    <artifactId>jsonassert</artifactId>
    <version>1.5.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.assertj</groupId>
    <artifactId>assertj-db</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.ekino.oss.jcv</groupId>
    <artifactId>jcv-core</artifactId>
    <version>1.4.1</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.ekino.oss.jcv-db</groupId>
    <artifactId>jcv-db-assertj-db</artifactId>
    <version>0.0.5</version>
    <scope>test</scope>
  </dependency>
  ...
</dependencies>

Gradle

dependencies {
    ...
    testImplementation 'org.skyscreamer:jsonassert:1.5.0'
    testImplementation 'org.assertj:assertj-db:1.2.0'
    testImplementation 'com.ekino.oss.jcv:jcv-core:1.4.1'
    testImplementation 'com.ekino.oss.jcv-db:jcv-db-assertj-db:0.0.3'
    ...
}

Jdbc module

A JCV-DB module that allow you to execute sql requests. Only PostgreSQL, MySQL, MSSQL server are supported in this module.

Example

import static com.ekino.oss.jcv.db.jdbc.DbComparatorJDBC.assertThatQuery

@Test
fun testContentTable() {
    assertThatQuery("select * from table_name")
    .isValidAgainst("""[
        {
            "id": "e3881fb1-b3dd-4701-b08c-f5d17389edfa",
            "number_field": 1,
            "boolean_field: true,
            "string_field": "Hello"
        }
    ]""".trimIndent())
}

Dependencies

Maven

<dependencies>
  ...
  <dependency>
    <groupId>org.skyscreamer</groupId>
    <artifactId>jsonassert</artifactId>
    <version>1.5.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.assertj</groupId>
    <artifactId>assertj-db</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.ekino.oss.jcv</groupId>
    <artifactId>jcv-core</artifactId>
    <version>1.4.1</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.ekino.oss.jcv-db</groupId>
    <artifactId>jcv-db-jdbc</artifactId>
    <version>0.0.5</version>
    <scope>test</scope>
  </dependency>
  ...
</dependencies>

Gradle

dependencies {
    ...
    testImplementation 'org.skyscreamer:jsonassert:1.5.0'
    testImplementation 'org.assertj:assertj-db:1.2.0'
    testImplementation 'com.ekino.oss.jcv:jcv-core:1.4.1'
    testImplementation 'com.ekino.oss.jcv-db:jcv-db-jdbc:0.0.3'
    ...
}

Cassandra module

A JCV-DB module that allow you to execute cql requests and criteria builder in cassandra database

Example

import static com.ekino.oss.jcv.db.cassandra.DbComparatorCassandra.assertThatQuery

@Test
fun testContentTable() {
    assertThatQuery("select * from table_name")
    .isValidAgainst("""[
        {
            "id": "e3881fb1-b3dd-4701-b08c-f5d17389edfa",
            "number_field": 1,
            "boolean_field: true,
            "string_field": "Hello"
        }
    ]""".trimIndent())
}

Dependencies

Maven

<dependencies>
  ...
  <dependency>
    <groupId>org.skyscreamer</groupId>
    <artifactId>jsonassert</artifactId>
    <version>1.5.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.assertj</groupId>
    <artifactId>assertj-db</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.ekino.oss.jcv</groupId>
    <artifactId>jcv-core</artifactId>
    <version>1.4.1</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.ekino.oss.jcv-db</groupId>
    <artifactId>jcv-db-cassandra</artifactId>
    <version>0.0.5</version>
    <scope>test</scope>
  </dependency>
  ...
</dependencies>

Gradle

dependencies {
    ...
    testImplementation 'org.skyscreamer:jsonassert:1.5.0'
    testImplementation 'org.assertj:assertj-db:1.2.0'
    testImplementation 'com.ekino.oss.jcv:jcv-core:1.4.1'
    testImplementation 'com.ekino.oss.jcv-db:jcv-db-cassandra:0.0.3'
    ...
}

Mongo database module

A JCV-DB module that allow you to mongo database content against a json file.

Example

import static com.ekino.oss.jcv.db.mongo.DbComparatorMongo.assertThatCollection

@Test
fun testContentTable() {
    assertThatQuery(database.getCollection("testCollection").find(eq("name", "test-mongo-db"))
    .isValidAgainst("""[
        {
            "id": "e3881fb1-b3dd-4701-b08c-f5d17389edfa",
            "number_field": 1,
            "boolean_field: true,
            "string_field": "Hello"
        }
    ]""".trimIndent())
}

Dependencies

Maven

<dependencies>
  ...
  <dependency>
    <groupId>org.skyscreamer</groupId>
    <artifactId>jsonassert</artifactId>
    <version>1.5.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.assertj</groupId>
    <artifactId>assertj-db</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.ekino.oss.jcv</groupId>
    <artifactId>jcv-core</artifactId>
    <version>1.4.1</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.ekino.oss.jcv-db</groupId>
    <artifactId>jcv-db-mongo</artifactId>
    <version>0.0.5</version>
    <scope>test</scope>
  </dependency>
  ...
</dependencies>

Gradle

dependencies {
    ...
    testImplementation 'org.skyscreamer:jsonassert:1.5.0'
    testImplementation 'org.assertj:assertj-db:1.2.0'
    testImplementation 'com.ekino.oss.jcv:jcv-core:1.4.1'
    testImplementation 'com.ekino.oss.jcv-db:jcv-db-mongo:0.0.1'
    ...
}

jcv-db's People

Contributors

celcius112 avatar clemstoquart avatar dependabot[bot] avatar mraolen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

laurent45

jcv-db's Issues

Reinstate github release creation

The previous script used a old version of the github release script. See this link for the new CLI.

Old code

      - name: Create Github release
        run: |
          set -x
          assets=()
          for asset in ${JCV_DB_CORE_ASSETS_FOLDER}; do
            assets+=("-a" "$asset")
          done
          for asset in ${JCV_DB_ASSERTJ_DB_ASSETS_FOLDER}; do
            assets+=("-a" "$asset")
          done
          for asset in ${JCV_DB_CASSANDRA_ASSETS_FOLDER}; do
            assets+=("-a" "$asset")
          done
          for asset in ${JCV_DB_JDBC_ASSETS_FOLDER}; do
            assets+=("-a" "$asset")
          done
          for asset in ${JCV_DB_MONGO_ASSETS_FOLDER}; do
            assets+=("-a" "$asset")
          done
          hub release create --draft "${assets[@]}" -m "Release of ${{ github.ref }}" "${{ github.ref }}"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          JCV_DB_CORE_ASSETS_FOLDER: "${{ github.workspace }}/jcv-db-core/build/libs/*"
          JCV_DB_ASSERTJ_DB_ASSETS_FOLDER: "${{ github.workspace }}/jcv-db-assertj-db/build/libs/*"
          JCV_DB_CASSANDRA_ASSETS_FOLDER: "${{ github.workspace }}/jcv-db-cassandra/build/libs/*"
          JCV_DB_JDBC_ASSETS_FOLDER: "${{ github.workspace }}/jcv-db-jdbc/build/libs/*"
          JCV_DB_MONGO_ASSETS_FOLDER: "${{ github.workspace }}/jcv-db-mongo/build/libs/*"

Support single json object in validation

Hello, it would be cool that queries returning a single result could be validated with a json object like that:

    dBComparatorBuilder
        .build("select * from person")
        .isValidAgainst("""
          {
            "id": "{#uuid#}",
            "name": "test",
          }
        """

Remove dependencies on org.json

There are multiple occurrences of org.json.JSONObject on the class path :
image
and
image

It should be possible to remove the direct dependencies on org.json:json.

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.