Skip to content

Commit

Permalink
Merge pull request #88 from mmnaseri/release-v1.1.2#87
Browse files Browse the repository at this point in the history
Release v1.1.2#87
  • Loading branch information
mmnaseri authored Jun 13, 2016
2 parents cad27b2 + 033c9b1 commit 59794a8
Show file tree
Hide file tree
Showing 18 changed files with 462 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ script:
- cd spring-data-mock
- mvn test -B
after_success:
- cd spring-data-mock-parent
- cd spring-data-mock-build
- mvn -P coverage clean cobertura:cobertura coveralls:report
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 8)" == "x8" ) ]] && sudo apt-get install gnupg2'
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 8)" == "x8" ) ]] && bash ../deployment/deploy.sh eb1a6f34f056 ../deployment/key.asc.enc ../deployment/settings.xml'
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ There you can get more information on how to download the framework, as well as
incorporate it in your project to have hassle-free data store mocking capabilities added to
your shiny applications.

## History

- 1.1 Add QueryDSL and findByExample support

see [site changelog](https://mmnaseri.github.io/spring-data-mock/site/#/changelog)


FAQ
-------------

Expand Down
5 changes: 3 additions & 2 deletions spring-data-mock-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<groupId>com.mmnaseri.utils</groupId>
<artifactId>spring-data-mock-build</artifactId>
<version>1.1.1</version>
<version>1.1.0</version>
<name>Spring Data Mock: Build Aggregator</name>
<description>This is the build module that will aggregate all reactors for the spring-data-mock project</description>
<url>https://mmnaseri.github.io/spring-data-mock</url>
Expand Down Expand Up @@ -73,7 +73,8 @@

<modules>
<module>../spring-data-mock/</module>
</modules>
<module>../spring-data-mock-sample-jpa</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
90 changes: 90 additions & 0 deletions spring-data-mock-sample-jpa/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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.mmnaseri.utils.sample</groupId>
<artifactId>spring-data-mock-sample-jpa</artifactId>
<version>1.0</version>
<name>Spring Data Mock: Samples (JPA)</name>
<description>This module tries to demonstrate how Spring Data Mock could be used to test an application that
is using Spring Data JPA.</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${target-jdk.version}</source>
<target>${target-jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura-maven-plugin.version}</version>
<configuration>
<format>xml</format>
<maxmem>256m</maxmem>
<!-- aggregated reports for multi-module projects -->
<aggregate>true</aggregate>
<check/>
<outputDirectory>target/reports</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${spring-data-commons.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${spring-data-jpa.version}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>${persistence-api.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>${hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.mmnaseri.utils</groupId>
<artifactId>spring-data-mock</artifactId>
<version>${spring-data-mock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
<spring-data-commons.version>1.12.1.RELEASE</spring-data-commons.version>
<spring-data-jpa.version>1.10.1.RELEASE</spring-data-jpa.version>
<persistence-api.version>1.0.2</persistence-api.version>
<spring-data-mock.version>1.1.2</spring-data-mock.version>
<testng.version>6.9.6</testng.version>
<hamcrest.version>1.3</hamcrest.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<target-jdk.version>1.7</target-jdk.version>
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.mmnaseri.utils.samples.spring.data.jpa.model;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;

/**
* @author Mohammad Milad Naseri ([email protected])
* @since 1.0 (6/12/16, 1:50 PM)
*/
@Entity
public class Customer {

@Id
private Long id;
@Temporal(TemporalType.DATE)
private Date birthday;
private String firstName;
private String lastName;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Date getBirthday() {
return birthday;
}

public void setBirthday(Date birthday) {
this.birthday = birthday;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mmnaseri.utils.samples.spring.data.jpa.repository;

import com.mmnaseri.utils.samples.spring.data.jpa.model.Customer;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Date;
import java.util.List;

/**
* @author Mohammad Milad Naseri ([email protected])
* @since 1.0 (6/12/16, 1:53 PM)
*/
public interface CustomerRepository extends JpaRepository<Customer, Long> {

List<Customer> findByBirthdayBetween(Date from, Date to);

List<Customer> findByExample(Example<Customer> probe);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mmnaseri.utils.samples.spring.data.jpa.service;

import com.mmnaseri.utils.samples.spring.data.jpa.model.Customer;

import java.util.Date;
import java.util.List;

/**
* @author Mohammad Milad Naseri ([email protected])
* @since 1.0 (6/12/16, 1:51 PM)
*/
public interface CustomerService {

long register(String firstName, String lastName, Date birthday);

Customer findCustomer(long id);

List<Customer> findCustomersByBirthday(Date from, Date to);

List<Customer> findCustomersByName(String firstName, String lastName);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.mmnaseri.utils.samples.spring.data.jpa.service.impl;

import com.mmnaseri.utils.samples.spring.data.jpa.model.Customer;
import com.mmnaseri.utils.samples.spring.data.jpa.repository.CustomerRepository;
import com.mmnaseri.utils.samples.spring.data.jpa.service.CustomerService;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;

import java.util.Date;
import java.util.List;

import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase;

/**
* @author Mohammad Milad Naseri ([email protected])
* @since 1.0 (6/12/16, 1:55 PM)
*/
public class DefaultCustomerService implements CustomerService {

private final CustomerRepository repository;

public DefaultCustomerService(CustomerRepository repository) {
this.repository = repository;
}

public long register(String firstName, String lastName, Date birthday) {
final Customer customer = new Customer();
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setBirthday(birthday);
return repository.save(customer).getId();
}

public Customer findCustomer(long id) {
return repository.findOne(id);
}

public List<Customer> findCustomersByBirthday(Date from, Date to) {
return repository.findByBirthdayBetween(from, to);
}

public List<Customer> findCustomersByName(String firstName, String lastName) {
final Customer probe = new Customer();
probe.setFirstName(firstName);
probe.setLastName(lastName);
final ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("firstName", ignoreCase())
.withMatcher("lastName", ignoreCase());
final Example<Customer> example = Example.of(probe, matcher);
return repository.findByExample(example);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mmnaseri.utils.samples.spring.data.jpa.repository;

import com.mmnaseri.utils.samples.spring.data.jpa.model.Customer;
import com.mmnaseri.utils.spring.data.domain.RepositoryAware;
import org.springframework.data.domain.Example;

import java.util.List;

/**
* @author Mohammad Milad Naseri ([email protected])
* @since 1.0 (6/12/16, 5:30 PM)
*/
public class CustomerRepositoryExampleSupport implements RepositoryAware<CustomerRepository> {

private CustomerRepository repository;

public List<Customer> findByExample(Example<Customer> example) {
return repository.findAll(example);
}

@Override
public void setRepository(CustomerRepository repository) {
this.repository = repository;
}

}
Loading

0 comments on commit 59794a8

Please sign in to comment.