https://github.com/ekino/jcv-db
JSON Content Validator for Database (JCV-DB) allow you to compare database contents against a JSON with JCV validators.
https://github.com/ekino/jcv-db
assertions assertj assertj-assertions cassandra java jcv json kotlin mongodb mssql mysql postgresql testing
Last synced: 28 days ago
JSON representation
JSON Content Validator for Database (JCV-DB) allow you to compare database contents against a JSON with JCV validators.
- Host: GitHub
- URL: https://github.com/ekino/jcv-db
- Owner: ekino
- License: mit
- Created: 2019-10-23T12:28:07.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-11T20:48:52.000Z (6 months ago)
- Last Synced: 2025-03-24T06:11:30.688Z (about 1 month ago)
- Topics: assertions, assertj, assertj-assertions, cassandra, java, jcv, json, kotlin, mongodb, mssql, mysql, postgresql, testing
- Language: Kotlin
- Homepage:
- Size: 456 KB
- Stars: 6
- Watchers: 20
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# JCV-DB
JSON Content Validator for Database (JCV-DB) allow you to compare database contents against a JSON with [JCV](https://github.com/ekino/jcv) validators.
[](https://travis-ci.org/ekino/jcv-db)
[](https://github.com/ekino/jcv-db/releases)
[](https://search.maven.org/search?q=g:com.ekino.oss.jcv-db)
[](https://github.com/ekino/jcv/blob/master/LICENSE.md)## Table of contents
* [Summary](#summary)
* [Prerequisites](#prerequisites)
* [Quick start](#quick-start)
* [Assertj-db module](#assertj-db)
* [JDBC module](#jdbc-module)
* [Cassandra module](#cassandra-module)
* [Mongo database module](#mongo-database-module)## 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](https://github.com/ekino/jcv) validators are also supported making tests light and exhaustive.## Prerequisites
If you want to test this project locally we must have the following software install:
- Java 11 (if launching without using Gradle)
- Docker
- Docker composeSome tests require that the database container is running. To start the containers, run the following command in the project root:
````bash
docker compose up -d
````## Quick Start
### Assertj-db
A JCV-DB module that supports [Assertj-db](https://github.com/joel-costigliola/assertj-db). Only PostgreSQL, MySQL, MSSQL server are supported in this module.
#### Example
````kotlin
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
```xml
...
org.skyscreamer
jsonassert
1.5.0
test
org.assertj
assertj-db
1.2.0
test
com.ekino.oss.jcv
jcv-core
1.4.1
test
com.ekino.oss.jcv-db
jcv-db-assertj-db
0.0.5
test
...```
Gradle
```groovy
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 moduleA JCV-DB module that allow you to execute sql requests. Only PostgreSQL, MySQL, MSSQL server are supported in this module.
#### Example
````kotlin
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
```xml
...
org.skyscreamer
jsonassert
1.5.0
test
org.assertj
assertj-db
1.2.0
test
com.ekino.oss.jcv
jcv-core
1.4.1
test
com.ekino.oss.jcv-db
jcv-db-jdbc
0.0.5
test
...```
Gradle
```groovy
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
````kotlin
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
```xml
...
org.skyscreamer
jsonassert
1.5.0
test
org.assertj
assertj-db
1.2.0
test
com.ekino.oss.jcv
jcv-core
1.4.1
test
com.ekino.oss.jcv-db
jcv-db-cassandra
0.0.5
test
...```
Gradle
```groovy
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
````kotlin
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
```xml
...
org.skyscreamer
jsonassert
1.5.0
test
org.assertj
assertj-db
1.2.0
test
com.ekino.oss.jcv
jcv-core
1.4.1
test
com.ekino.oss.jcv-db
jcv-db-mongo
0.0.5
test
...```
Gradle
```groovy
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'
...
}
```