Created
January 21, 2017 21:33
-
-
Save arthurportas/0bf35bbe9ee758a132f97a666de1f1c7 to your computer and use it in GitHub Desktop.
Sample test with Spring-data-mongo repository and NoSqlUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.arthurportas.unit.repository; | |
import com.arthurportas.mongodb.example.repository.UserRepository; | |
import com.lordofthejars.nosqlunit.annotation.UsingDataSet; | |
import com.lordofthejars.nosqlunit.core.LoadStrategyEnum; | |
import com.lordofthejars.nosqlunit.mongodb.MongoDbRule; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import static com.lordofthejars.nosqlunit.mongodb.MongoDbRule.MongoDbRuleBuilder.newMongoDbRule; | |
import static org.assertj.core.api.Java6Assertions.assertThat; | |
/** | |
* Created by arthurportas on 21/01/2017. | |
*/ | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringBootTest | |
public class UserRepositoryTest { | |
private static Logger LOGGER = LoggerFactory.getLogger(UserRepositoryTest.class); | |
@Rule | |
public MongoDbRule mongoDbRule = newMongoDbRule().defaultSpringMongoDb("demo-test"); | |
/** | |
* nosql-unit requirement | |
*/ | |
@Autowired | |
private ApplicationContext applicationContext; | |
@Autowired | |
private UserRepository userRepository; | |
@Test | |
@UsingDataSet(locations = {"/five-users.json"}, loadStrategy = LoadStrategyEnum.CLEAN_INSERT) | |
public void testCountAllUsers() { | |
LOGGER.info("testCountAllUsers"); | |
long total = this.userRepository.findAll().size(); | |
assertThat(total).isEqualTo(5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment