nosql-unit | NoSQL Unit is a JUnit extension | Database library

 by   lordofthejars Java Version: Current License: Non-SPDX

kandi X-RAY | nosql-unit Summary

kandi X-RAY | nosql-unit Summary

nosql-unit is a Java library typically used in Database, MongoDB, JPA applications. nosql-unit has no bugs, it has no vulnerabilities, it has build file available and it has low support. However nosql-unit has a Non-SPDX License. You can download it from GitHub, Maven.

Unit testing is a method by which the smallest testable part of an application is validated. Unit tests must follow the FIRST Rules; these are Fast, Isolated, Repeatable, Self-Validated and Timely. It is strange to think about a JEE application without persistence layer (typical Relational databases or new NoSQL databases) so should be interesting to write unit tests of persistence layer too. When we are writing unit tests of persistence layer we should focus on to not break two main concepts of FIRST rules, the fast and the isolated ones. Our tests will be fast if they don’t access network nor filesystem, and in case of persistence systems network and filesystem are the most used resources. In case of RDBMS ( SQL ), many Java in-memory databases exist like Apache Derby , H2 or HSQLDB . These databases, as their name suggests are embedded into your program and data are stored in memory, so your tests are still fast. The problem is with NoSQL systems, because of their heterogeneity. Some systems work using Document approach (like MongoDb ), other ones Column (like Hbase ), or Graph (like Neo4J ). For this reason the in-memory mode should be provided by the vendor, there is no a generic solution. Our tests must be isolated from themselves. It is not acceptable that one test method modifies the result of another test method. In case of persistence tests this scenario occurs when previous test method insert an entry to database and next test method execution finds the change. So before execution of each test, database should be found in a known state. Note that if your test found database in a known state, test will be repeatable, if test assertion depends on previous test execution, each execution will be unique. For homogeneous systems like RDBMS , DBUnit exists to maintain database in a known state before each execution. But there is no like DBUnit framework for heterogeneous NoSQL systems. NoSQLUnit resolves this problem by providing a JUnit extension which helps us to manage lifecycle of NoSQL systems and also take care of maintaining databases into known state.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              nosql-unit has a low active ecosystem.
              It has 374 star(s) with 121 fork(s). There are 35 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 36 open issues and 114 have been closed. On average issues are closed in 90 days. There are 13 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of nosql-unit is current.

            kandi-Quality Quality

              nosql-unit has 0 bugs and 0 code smells.

            kandi-Security Security

              nosql-unit has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              nosql-unit code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              nosql-unit has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              nosql-unit releases are not available. You will need to build from source code and install.
              Deployable package is available in Maven.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              It has 41801 lines of code, 3342 functions and 611 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed nosql-unit and discovered the below as its top functions. This is intended to give you an instant insight into nosql-unit implemented functionality, and help decide if they suit your requirements.
            • Deep equality between two objects .
            • To index options .
            • Parses the given collection of strings and returns a map of collection of properties .
            • Clears all documents .
            • Resolves the default location for the method .
            • Creates a new vault configuration from the vault configuration .
            • Validates columns families .
            • Waits until a replica set is become stable .
            • Starts the Cassandra .
            • Insert tokens into the vault .
            Get all kandi verified functions for this library.

            nosql-unit Key Features

            No Key Features are available at this moment for nosql-unit.

            nosql-unit Examples and Code Snippets

            No Code Snippets are available at this moment for nosql-unit.

            Community Discussions

            QUESTION

            Fongo - Fake Mongo : Not able to load dataset from location for unit testing of mongrepository using fongo
            Asked 2020-Aug-07 at 20:14

            I am using fongo as in memory database for testing my mongodbrepository.

            I have taken reference from http://dontpanic.42.nl/2015/02/in-memory-mongodb-for-unit-and.html for unit testing.

            To populate sample data, I have added required json file under test/resources/json-data/user/user.json but it's not loaded into fongo.

            ...

            ANSWER

            Answered 2020-Aug-06 at 19:03

            For testing I recommend this library this

            Source https://stackoverflow.com/questions/63289949

            QUESTION

            @SpringBootTest how to pre-populate embedded MongoDB?
            Asked 2020-Mar-11 at 06:44

            Doing implementation of a microservice with a few endpoints based on Spring Boot and MongoDB and trying to write integration tests using @SpringBootTest annotation capabilities.

            At the moment, I am facing an issue that I need to pre-populate an embedded MongoDB instance that instantiated only during 'test' phrase with some test data.

            And I did not find any out-of-the-box option available in Spring Boot for this purpose.

            Some people advice to use for test data pre-populating tools like mongobee or mongoprefill or nosql-unit but for me, it seems like overhead or workaround, do not want to introduce any new dependencies even in test scope.

            So could you please advice: In the current Spring Boot ecosystem, what is the right way to pre-populate MongoDB for testing purpose, when we are talking about integration (end-to-end) testing with @SpringBootTest?

            ...

            ANSWER

            Answered 2020-Mar-11 at 06:44

            There are multiple ways to pre-populate data:

            1. Use the JUnit lifecycle methods like @BeforeEach, @BeforeAll to fill in data
            2. You could disable the Spring Boot autoconfiguration for the embedded MongoDB and do it on your own and insert data after creating the connection
            3. You could somehow mirror the @Sql feature we have for testing relational databases and write something similar using the AsbtractTestExectuionListener. For this have a look at the Spring class SqlScriptsTestExecutionListener
            4. Provide a class that implements the CommandLineRunner interface and only activate this bean for your integration test profile with @Profile("integration-test")

            Source https://stackoverflow.com/questions/60627126

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install nosql-unit

            To use NoSQLUnit with MongoDb you only need to add next dependency:. ~~ {.xml} <dependency> <groupId>com.lordofthejars</groupId> <artifactId>nosqlunit-mongodb</artifactId> <version>${version.nosqlunit}</version> </dependency> ~~. Note that if you are plannig to use in-memory approach it is implemented using Fongo . Fongo is a new project that help with unit testing Java-based MongoDb Applications. [Fongo](https://github.com/fakemongo/fongo).
            In NoSQLUnit we can define a replica set architecture and starting it up, so our tests are executed against a replica set servers instead of a single server. Due the nature of replica set system, we can only create a replica set of managed servers. So let’s see how to define an architecture and starting all related servers. The main class is ReplicaSetManagedMongoDb which manages lifecycle of all servers involved in replica set. To build a ReplicaSetManagedMongoDb class, ReplicaSetBuilder builder class is provided and it will allow us to define the replica set architecture. Using it we can set the eligible servers (those that can be primary or secondary), the only secondary servers, the arbiters, the hidden ones, and configure all of them with the attributes like priority, voters, or setting tags. So let’s see an example where we are defining two eligible servers and one arbiter in a replica set called rs-test. ~~ {.java} import static com.lordofthejars.nosqlunit.mongodb.replicaset.ReplicaSetBuilder.replicaSet;. @ClassRule public static ReplicaSetManagedMongoDb replicaSetManagedMongoDb = replicaSet( "rs-test") .eligible( newManagedMongoDbLifecycle().port(27017) .dbRelativePath("rs-0").logRelativePath("log-0") .get()) .eligible( newManagedMongoDbLifecycle().port(27018) .dbRelativePath("rs-1").logRelativePath("log-1") .get()) .arbiter( newManagedMongoDbLifecycle().port(27019) .dbRelativePath("rs-2").logRelativePath("log-2") .get()) .get(); ~~. Notice that you must define different port for each server and also a different database path. Also note that ReplicaSetManagedMongoDb won’t let start executing tests until all replica set becomes stable (this can take some minutes). Then we only have to create a MongoDbRule as usually which will populate defined data into replica set servers. For this case a new configuration builder is provided that allows us to define the mongo servers location and the write concern used during seeding phase. By default Aknownledge write concern is used. ~~ {.java} import static com.lordofthejars.nosqlunit.mongodb.ReplicationMongoDbConfigurationBuilder.replicationMongoDbConfiguration;. @Rule public MongoDbRule mongoDbRule = newMongoDbRule().configure( replicationMongoDbConfiguration().databaseName("test") .seed("localhost", 27017) .seed("localhost", 27018) .configure()) .build(); ~~. Now we have configured and deployed a replica set and populated them with the dataset. But NoSQLUnit also provides an utility method to cause server failures. It is as easy as calling shutdownServer method. ~~ {.java} replicaSetManagedMongoDb.shutdownServer(27017); ~~.
            Because @ClassRule is used, we are responsible for restarting the system by calling startServer.
            System may become unstable and Mongo driver can throw many exceptions (that’s normal because of MonitorThread) and even do some test fails. If you want to wait until all servers become stable again (in real life you won’t have this possibility), you can use next call:
            In NoSQLUnit we can define a sharding architecture and starting it up, so our tests are executed against it instead of a single server. Due the nature of sharding system, we can only create sharding for managed servers. So let’s see how to define an architecture and starting all related servers. The main class is ShardedManagedMongoDb which manages lifecycle of all servers involved in sharding (shards, configs and mongos). To build a ShardedManagedMongoDb class, ShardedGroupBuilder builder class is provided and it will allow us to define each server involved in sharding. Let’s see an example on how to set up and start a system with two shards, one config server and one mongos. ~~ {.java} @ClassRule public static ShardedManagedMongoDb shardedManagedMongoDb = shardedGroup() .shard(newManagedMongoDbLifecycle().port(27018).dbRelativePath("rs-1").logRelativePath("log-1").get()) .shard(newManagedMongoDbLifecycle().port(27019).dbRelativePath("rs-2").logRelativePath("log-2").get()) .config(newManagedMongoDbLifecycle().port(27020).dbRelativePath("rs-3").logRelativePath("log-3").get()) .mongos(newManagedMongosLifecycle().configServer(27020).get()) .get(); ~~. Notice that you must define different port for each server and also a different database path. Also note that in case of mongos you must set the config server port, and is not necessary to set up the database path. And finally we only have to create a MongoDbRule as usually which will populate defined data into sharding servers. For this case we must use the same builder used for replica set but enabling sharding. Keep in mind that in this case we only have to register the mongos instances, not shards or config servers. ~~ {.java} @Rule public MongoDbRule mongoDbRule = newMongoDbRule().configure( replicationMongoDbConfiguration().databaseName("test") .enableSharding() .seed("localhost", 27017) .configure()) .build(); ~~.
            In NoSQLUnit we can define a replicated sharded cluster architecture and starting it up, so our tests are executed against it instead of a single server. Due the nature of replicated sharded cluster, we can only create sharding for managed servers. So let’s see how to define an architecture and starting all related servers. The main class is ShardedManagedMongoDb which manages lifecycle of all servers involved in sharding (shards, configs and mongos). To build a ShardedManagedMongoDb class, ShardedGroupBuilder builder class is provided and it will allow us to define each server involved in sharding, but in contrast of sharding, we need to add a replica set instead of a shard. For this reason ReplicaSetManagedMongoDb is also used. Let’s see an example on how to set up two replicated sharded cluster, with one member each replica set, (of course in production environment you would have more), one config server and one mongos. ~~ {.java} import static com.lordofthejars.nosqlunit.mongodb.shard.ShardedGroupBuilder.shardedGroup; import static com.lordofthejars.nosqlunit.mongodb.replicaset.ReplicaSetBuilder.replicaSet;. @ClassRule public static ShardedManagedMongoDb shardedManagedMongoDb = shardedGroup() .replicaSet(replicaSet("rs-test-1") .eligible( newManagedMongoDbLifecycle() .port(27007).dbRelativePath("rs-0").logRelativePath("log-0") .get() ) .get()) .replicaSet(replicaSet("rs-test-2") .eligible( newManagedMongoDbLifecycle() .port(27009).dbRelativePath("rs-0").logRelativePath("log-0") .get() ) .get()) .config(newManagedMongoDbLifecycle().port(27020).dbRelativePath("rs-3").logRelativePath("log-3").get()) .mongos(newManagedMongosLifecycle().configServer(27020).get()) .get(); ~~. Note that we are using the replicaSet method of shardedGroup to create a replica set inside a sharded, and then we use methods defined into ReplicaSetBuilder to configure the replica set. And finally we only have to create a MongoDbRule as usually which will populate defined data into servers. For replicated sharded clusters we can use the same class and dataset as sharding. ~~ {.java} @Rule public MongoDbRule mongoDbRule = newMongoDbRule().configure( replicationMongoDbConfiguration().databaseName("test") .enableSharding() .seed("localhost", 27017) .configure()) .build(); ~~. ~~ {.json} { "collection_name": { "shard-key-pattern": ["attribute_1", "attribute_2"], "data": [ {"attribute_1":"value_1","attribute_2":value_2, "attribute_3":"value_3"} ] } } ~~.
            To use NoSQLUnit with Neo4j you only need to add next dependency:. ~~ {.xml} <dependency> <groupId>com.lordofthejars</groupId> <artifactId>nosqlunit-neo4j</artifactId> <version>${version.nosqlunit}</version> </dependency> ~~.
            To use NoSQLUnit with Cassandra you only need to add next dependency:. ~~ {.xml} <dependency> <groupId>com.lordofthejars</groupId> <artifactId>nosqlunit-cassandra</artifactId> <version>${version.nosqlunit}</version> </dependency> ~~.
            To use NoSQLUnit with Redis you only need to add next dependency:. ~~ {.xml} <dependency> <groupId>com.lordofthejars</groupId> <artifactId>nosqlunit-redis</artifactId> <version>${version.nosqlunit}</version> </dependency> ~~.
            To use NoSQLUnit with HBase you only need to add next dependency:. ~~ {.xml} <dependency> <groupId>com.lordofthejars</groupId> <artifactId>nosqlunit-hbase</artifactId> <version>${version.nosqlunit}</version> </dependency> ~~.
            To use NoSQLUnit with CouchDB you only need to add next dependency:. ~~ {.xml} <dependency> <groupId>com.lordofthejars</groupId> <artifactId>nosqlunit-couchdb</artifactId> <version>${version.nosqlunit}</version> </dependency> ~~.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/lordofthejars/nosql-unit.git

          • CLI

            gh repo clone lordofthejars/nosql-unit

          • sshUrl

            git@github.com:lordofthejars/nosql-unit.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link