-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from mmnaseri/release-v1.1.2#87
Release v1.1.2#87
- Loading branch information
Showing
18 changed files
with
462 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
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> |
55 changes: 55 additions & 0 deletions
55
...k-sample-jpa/src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/model/Customer.java
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
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; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...c/main/java/com/mmnaseri/utils/samples/spring/data/jpa/repository/CustomerRepository.java
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
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); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...jpa/src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/service/CustomerService.java
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
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); | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
.../java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultCustomerService.java
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
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); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...m/mmnaseri/utils/samples/spring/data/jpa/repository/CustomerRepositoryExampleSupport.java
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
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; | ||
} | ||
|
||
} |
Oops, something went wrong.