Skip to content

Commit

Permalink
Merge pull request #113 from mmnaseri/release-v1.1.3#112
Browse files Browse the repository at this point in the history
Release v1.1.3#112
  • Loading branch information
mmnaseri authored Jun 15, 2016
2 parents 59794a8 + 273012f commit a9e642b
Show file tree
Hide file tree
Showing 40 changed files with 913 additions and 182 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties

# Eclipse IDE stuff
.settings/
.classpath
.project

# Maven Target
target

# Mac OS X junk
.DS_Store
.DS_Store
27 changes: 14 additions & 13 deletions spring-data-mock-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
96 changes: 58 additions & 38 deletions spring-data-mock-sample-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
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;
}

}
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;
}

}
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> {
}
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);

}
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);

}
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();
}

}
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;
}

}
Loading

0 comments on commit a9e642b

Please sign in to comment.