Skip to content

Instantly share code, notes, and snippets.

View lhauspie's full-sized avatar

Logan HAUSPIE lhauspie

View GitHub Profile
@lhauspie
lhauspie / ProductRepositoryUnitTest.java
Created August 22, 2017 22:26
Deuxieme tentative de test unitaire de la couche Repository
@SpringBootTest
@RunWith(SpringRunner.class)
public class ProductRepositoryUnitTest {
@MockBean
private MongoConverter mongoConverter;
[...]
@Test
public void searchProductTest() {
@lhauspie
lhauspie / ProductRepositoryUnitTest.log
Created August 22, 2017 21:59
Trace de log de la premiere tentative de test unitaire de la couche Repository
Caused by: java.lang.NullPointerException
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.<init>(MongoRepositoryFactory.java:73)
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.getFactoryInstance(MongoRepositoryFactoryBean.java:104)
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.createRepositoryFactory(MongoRepositoryFactoryBean.java:88)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:248)
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:117)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 93 more
@lhauspie
lhauspie / ProductRepositoryUnitTest.java
Created August 22, 2017 21:54
Premiere tentative de test unitaire de la couche Repository
@SpringBootTest
@RunWith(SpringRunner.class)
public class ProductRepositoryUnitTest {
@Autowired
private ProductRepository productRepo;
@MockBean
private MongoTemplate mongoTemplate;
@Test
@lhauspie
lhauspie / ProductCustomRepository.java
Created August 22, 2017 21:20
Interface Spring Data Custom Repository contenant les fonctionnalités custom sur les produits
public interface ProductCustomRepository {
Collection<Product> search(SearchQuery query);
}
@lhauspie
lhauspie / ProductRepository.java
Created August 22, 2017 21:18
Interface Spring Data Repository contenant les fonctionnalités de CRUD sur les produits
public interface ProductRepository extends MongoRepository<Product, String>, ProductCustomRepository {
Product findForUpdateById(String id);
}
@lhauspie
lhauspie / ProductRepositoryImpl.java
Last active August 22, 2017 21:17
implémentation des fonctionnalités custom sur les produits
public class ProductRepositoryImpl implements ProductCustomRepository {
public static final String CODE = "code";
public static final String LABEL = "label";
public static final String DESCRIPTION = "description";
public static final String PRICE = "price";
@Autowired
private MongoTemplate mongoTemplate;
@lhauspie
lhauspie / pom.xml
Created August 22, 2017 20:20
pom.xml file of a Spring Boot application with MongoDB
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.lhauspie</groupId>
<artifactId>mongodb-junit-demo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>