-
-
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 #113 from mmnaseri/release-v1.1.3#112
Release v1.1.3#112
- Loading branch information
Showing
40 changed files
with
913 additions
and
182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,11 +27,12 @@ | |
<groupId>com.mmnaseri.utils</groupId> | ||
<artifactId>spring-data-mock-build</artifactId> | ||
<version>1.1.0</version> | ||
<packaging>pom</packaging> | ||
|
||
<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> | ||
<packaging>pom</packaging> | ||
|
||
<inceptionYear>2015</inceptionYear> | ||
<licenses> | ||
<license> | ||
<name>MIT</name> | ||
|
@@ -51,12 +52,23 @@ | |
</developer> | ||
</developers> | ||
|
||
<modules> | ||
<module>../spring-data-mock/</module> | ||
<module>../spring-data-mock-sample-jpa</module> | ||
</modules> | ||
|
||
<scm> | ||
<connection>scm:git:[email protected]:mmnaseri/spring-data-mock.git</connection> | ||
<developerConnection>scm:git:[email protected]:mmnaseri/spring-data-mock.git</developerConnection> | ||
<url>[email protected]:mmnaseri/spring-data-mock.git</url> | ||
</scm> | ||
|
||
<properties> | ||
<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> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
|
@@ -71,15 +83,4 @@ | |
</plugins> | ||
</build> | ||
|
||
<modules> | ||
<module>../spring-data-mock/</module> | ||
<module>../spring-data-mock-sample-jpa</module> | ||
</modules> | ||
|
||
<properties> | ||
<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> | ||
</properties> | ||
|
||
</project> |
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 |
---|---|---|
|
@@ -7,36 +7,42 @@ | |
<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> | ||
<inceptionYear>2016</inceptionYear> | ||
<licenses> | ||
<license> | ||
<name>MIT</name> | ||
<url>http://mit-license.org</url> | ||
</license> | ||
</licenses> | ||
|
||
<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> | ||
<developers> | ||
<developer> | ||
<name>Milad Naseri</name> | ||
<email>[email protected]</email> | ||
<url>http://www.mmnaseri.com</url> | ||
<roles> | ||
<role>designer</role> | ||
<role>developer</role> | ||
</roles> | ||
</developer> | ||
</developers> | ||
|
||
<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.3</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> | ||
|
||
<dependencies> | ||
<dependency> | ||
|
@@ -74,17 +80,31 @@ | |
</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> | ||
<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> | ||
|
||
</project> |
42 changes: 42 additions & 0 deletions
42
...mock-sample-jpa/src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/model/Plane.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,42 @@ | ||
package com.mmnaseri.utils.samples.spring.data.jpa.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
/** | ||
* @author Milad Naseri ([email protected]) | ||
* @since 1.0 (6/14/16, 11:34 PM) | ||
*/ | ||
@Entity | ||
public class Plane extends SerialAwareEntity { | ||
|
||
@Id | ||
private Long id; | ||
private String model; | ||
private int capacity; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getModel() { | ||
return model; | ||
} | ||
|
||
public void setModel(String model) { | ||
this.model = model; | ||
} | ||
|
||
public int getCapacity() { | ||
return capacity; | ||
} | ||
|
||
public void setCapacity(int capacity) { | ||
this.capacity = capacity; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...jpa/src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/model/SerialAwareEntity.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.model; | ||
|
||
import javax.persistence.MappedSuperclass; | ||
|
||
/** | ||
* @author Milad Naseri ([email protected]) | ||
* @since 1.0 (6/14/16, 11:36 PM) | ||
*/ | ||
@MappedSuperclass | ||
public class SerialAwareEntity { | ||
|
||
private String serial; | ||
|
||
public String getSerial() { | ||
return serial; | ||
} | ||
|
||
public void setSerial(String serial) { | ||
this.serial = serial; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
.../src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/repository/PlaneRepository.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,11 @@ | ||
package com.mmnaseri.utils.samples.spring.data.jpa.repository; | ||
|
||
import com.mmnaseri.utils.samples.spring.data.jpa.model.Plane; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** | ||
* @author Milad Naseri ([email protected]) | ||
* @since 1.0 (6/14/16, 11:34 PM) | ||
*/ | ||
public interface PlaneRepository extends JpaRepository<Plane, Long>, SerialAwareEntityRepository<Plane> { | ||
} |
13 changes: 13 additions & 0 deletions
13
...va/com/mmnaseri/utils/samples/spring/data/jpa/repository/SerialAwareEntityRepository.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,13 @@ | ||
package com.mmnaseri.utils.samples.spring.data.jpa.repository; | ||
|
||
import com.mmnaseri.utils.samples.spring.data.jpa.model.SerialAwareEntity; | ||
|
||
/** | ||
* @author Milad Naseri ([email protected]) | ||
* @since 1.0 (6/14/16, 11:37 PM) | ||
*/ | ||
public interface SerialAwareEntityRepository<E extends SerialAwareEntity> { | ||
|
||
E lookupBySerial(String serial); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...le-jpa/src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/service/PlaneService.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,15 @@ | ||
package com.mmnaseri.utils.samples.spring.data.jpa.service; | ||
|
||
/** | ||
* @author Milad Naseri ([email protected]) | ||
* @since 1.0 (6/14/16, 11:39 PM) | ||
*/ | ||
public interface PlaneService { | ||
|
||
Long create(String model, String serial); | ||
|
||
String lookup(Long id); | ||
|
||
String lookup(String serial); | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...ain/java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultPlaneService.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,46 @@ | ||
package com.mmnaseri.utils.samples.spring.data.jpa.service.impl; | ||
|
||
import com.mmnaseri.utils.samples.spring.data.jpa.model.Plane; | ||
import com.mmnaseri.utils.samples.spring.data.jpa.repository.PlaneRepository; | ||
import com.mmnaseri.utils.samples.spring.data.jpa.service.PlaneService; | ||
|
||
/** | ||
* @author Milad Naseri ([email protected]) | ||
* @since 1.0 (6/14/16, 11:39 PM) | ||
*/ | ||
public class DefaultPlaneService implements PlaneService { | ||
|
||
private final PlaneRepository repository; | ||
|
||
public DefaultPlaneService(PlaneRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
@Override | ||
public Long create(String model, String serial) { | ||
final Plane plane = new Plane(); | ||
plane.setModel(model); | ||
plane.setCapacity(100); | ||
plane.setSerial(serial); | ||
return repository.save(plane).getId(); | ||
} | ||
|
||
@Override | ||
public String lookup(Long id) { | ||
final Plane plane = repository.findOne(id); | ||
if (plane == null) { | ||
return null; | ||
} | ||
return plane.getModel(); | ||
} | ||
|
||
@Override | ||
public String lookup(String serial) { | ||
final Plane plane = repository.lookupBySerial(serial); | ||
if (plane == null) { | ||
return null; | ||
} | ||
return plane.getModel(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...mmnaseri/utils/samples/spring/data/jpa/repository/SerialAwareEntityRepositorySupport.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,39 @@ | ||
package com.mmnaseri.utils.samples.spring.data.jpa.repository; | ||
|
||
import com.mmnaseri.utils.samples.spring.data.jpa.model.SerialAwareEntity; | ||
import com.mmnaseri.utils.spring.data.domain.RepositoryAware; | ||
import com.mmnaseri.utils.spring.data.error.DataOperationExecutionException; | ||
import org.springframework.data.domain.Example; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Milad Naseri ([email protected]) | ||
* @since 1.0 (6/14/16, 11:45 PM) | ||
*/ | ||
public class SerialAwareEntityRepositorySupport implements SerialAwareEntityRepository, RepositoryAware<JpaRepository> { | ||
|
||
private JpaRepository repository; | ||
|
||
@Override | ||
public SerialAwareEntity lookupBySerial(String serial) { | ||
final SerialAwareEntity probe = new SerialAwareEntity(); | ||
probe.setSerial(serial); | ||
final Example<?> example = Example.of(probe); | ||
final List found = repository.findAll(example); | ||
if (found.isEmpty()) { | ||
return null; | ||
} | ||
if (found.size() > 1) { | ||
throw new DataOperationExecutionException("Expected only one instance to be found", null); | ||
} | ||
return (SerialAwareEntity) found.get(0); | ||
} | ||
|
||
@Override | ||
public void setRepository(JpaRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
} |
Oops, something went wrong.