Skip to content

Commit 185af08

Browse files
committed
Merge pull request #48 from mmnaseri/release-v1.0.3
Release v1.0.3
2 parents e2da430 + 77ad7be commit 185af08

File tree

470 files changed

+747
-220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

470 files changed

+747
-220
lines changed

.travis.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
language: java
22
jdk:
3-
- oraclejdk8
43
- oraclejdk7
4+
- oraclejdk8
5+
script:
6+
- cd spring-data-mock
7+
- mvn test -B
58
after_success:
9+
- cd spring-data-mock-parent
610
- mvn -P coverage clean cobertura:cobertura coveralls:report
711
- '[[ $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'
8-
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 8)" == "x8" ) ]] && bash deploy.sh eb1a6f34f056 key.asc.enc settings.xml'
12+
- '[[ $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'
13+
# SUDO should be set to `false` except when deploying to OSSRH to trigger container infrastructure
914
sudo: true
1015
env:
1116
global:

deploy.sh deployment/deploy.sh

File renamed without changes.

key.asc.enc deployment/key.asc.enc

File renamed without changes.
File renamed without changes.

spring-data-mock-build/pom.xml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2016 Milad Naseri
4+
~
5+
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this
6+
~ software and associated documentation files (the "Software"), to deal in the Software
7+
~ without restriction, including without limitation the rights to use, copy, modify, merge,
8+
~ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9+
~ to whom the Software is furnished to do so, subject to the following conditions:
10+
~
11+
~ The above copyright notice and this permission notice shall be included in all copies or
12+
~ substantial portions of the Software.
13+
~
14+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
~ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16+
~ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17+
~ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18+
~ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
~ SOFTWARE.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<groupId>com.mmnaseri.utils</groupId>
28+
<artifactId>spring-data-mock-build</artifactId>
29+
<version>1.0.2</version>
30+
<name>Spring Data Mock: Build Aggregator</name>
31+
<description>This is the build module that will aggregate all reactors for the spring-data-mock project</description>
32+
<url>https://mmnaseri.github.io/spring-data-mock</url>
33+
<packaging>pom</packaging>
34+
35+
<licenses>
36+
<license>
37+
<name>MIT</name>
38+
<url>http://mit-license.org</url>
39+
</license>
40+
</licenses>
41+
42+
<developers>
43+
<developer>
44+
<name>Milad Naseri</name>
45+
<email>[email protected]</email>
46+
<url>http://www.mmnaseri.com</url>
47+
<roles>
48+
<role>designer</role>
49+
<role>developer</role>
50+
</roles>
51+
</developer>
52+
</developers>
53+
54+
<scm>
55+
<connection>scm:git:[email protected]:mmnaseri/spring-data-mock.git</connection>
56+
<developerConnection>scm:git:[email protected]:mmnaseri/spring-data-mock.git</developerConnection>
57+
<url>[email protected]:mmnaseri/spring-data-mock.git</url>
58+
</scm>
59+
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-compiler-plugin</artifactId>
65+
<version>${maven-compiler-plugin.version}</version>
66+
<configuration>
67+
<source>${target-jdk.version}</source>
68+
<target>${target-jdk.version}</target>
69+
</configuration>
70+
</plugin>
71+
</plugins>
72+
</build>
73+
74+
<modules>
75+
<module>../spring-data-mock/</module>
76+
</modules>
77+
78+
<properties>
79+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
80+
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
81+
<target-jdk.version>1.7</target-jdk.version>
82+
</properties>
83+
84+
</project>

pom.xml spring-data-mock/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<groupId>com.mmnaseri.utils</groupId>
2828
<artifactId>spring-data-mock</artifactId>
29-
<version>1.0.2</version>
29+
<version>1.0.3</version>
3030
<name>Spring Data Mock</name>
3131
<description>A framework for mocking Spring Data repositories</description>
3232
<url>https://mmnaseri.github.io/spring-data-mock</url>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mmnaseri.utils.spring.data.domain;
2+
3+
/**
4+
* Represents an operator that was picked because of a parse operation
5+
*
6+
* @author Mohammad Milad Naseri ([email protected])
7+
* @since 1.0 (4/17/16, 12:36 PM)
8+
*/
9+
public interface MatchedOperator extends Operator {
10+
11+
/**
12+
* @return the suffix that was matched when looking up this operator
13+
*/
14+
String getMatchedToken();
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.mmnaseri.utils.spring.data.domain.impl;
2+
3+
import com.mmnaseri.utils.spring.data.domain.Operator;
4+
import com.mmnaseri.utils.spring.data.domain.OperatorContext;
5+
import com.mmnaseri.utils.spring.data.domain.impl.matchers.*;
6+
import com.mmnaseri.utils.spring.data.error.DuplicateOperatorException;
7+
import org.apache.commons.logging.Log;
8+
import org.apache.commons.logging.LogFactory;
9+
10+
import java.util.Arrays;
11+
import java.util.Set;
12+
import java.util.concurrent.CopyOnWriteArraySet;
13+
14+
/**
15+
* This class is used to store the operators used in the name of a query method. Operators are matched by
16+
* the "suffixes" eagerly (meaning that "EqualTo" will precede over "To").
17+
*
18+
* @author Milad Naseri ([email protected])
19+
* @since 1.0 (9/29/15)
20+
*/
21+
public class DefaultOperatorContext implements OperatorContext {
22+
23+
private static final Log log = LogFactory.getLog(DefaultOperatorContext.class);
24+
private final Set<Operator> operators;
25+
26+
public DefaultOperatorContext() {
27+
this(true);
28+
}
29+
30+
public DefaultOperatorContext(boolean registerDefaults) {
31+
operators = new CopyOnWriteArraySet<>();
32+
if (registerDefaults) {
33+
log.info("Registering all the default operators");
34+
operators.add(new ImmutableOperator("AFTER", 1, new IsGreaterThanMatcher(), "After", "IsAfter"));
35+
operators.add(new ImmutableOperator("BEFORE", 1, new IsLessThanMatcher(), "Before", "IsBefore"));
36+
operators.add(new ImmutableOperator("CONTAINING", 1, new ContainingMatcher(), "Containing", "IsContaining", "Contains"));
37+
operators.add(new ImmutableOperator("BETWEEN", 2, new IsBetweenMatcher(), "Between", "IsBetween"));
38+
operators.add(new ImmutableOperator("NOT_BETWEEN", 2, new IsNotBetweenMatcher(), "NotBetween", "IsNotBetween"));
39+
operators.add(new ImmutableOperator("ENDING_WITH", 1, new EndingWithMatcher(), "EndingWith", "IsEndingWith", "EndsWith"));
40+
operators.add(new ImmutableOperator("FALSE", 0, new IsFalseMatcher(), "False", "IsFalse"));
41+
operators.add(new ImmutableOperator("GREATER_THAN", 1, new IsGreaterThanMatcher(), "GreaterThan", "IsGreaterThan"));
42+
operators.add(new ImmutableOperator("GREATER_THAN_EQUALS", 1, new IsGreaterThanOrEqualToMatcher(), "GreaterThanEqual", "IsGreaterThanEqual"));
43+
operators.add(new ImmutableOperator("IN", 1, new IsInMatcher(), "In", "IsIn"));
44+
operators.add(new ImmutableOperator("IS", 1, new IsEqualToMatcher(), "Is", "EqualTo", "IsEqualTo", "Equals"));
45+
operators.add(new ImmutableOperator("NOT_NULL", 0, new IsNotNullMatcher(), "NotNull", "IsNotNull"));
46+
operators.add(new ImmutableOperator("NULL", 0, new IsNullMatcher(), "Null", "IsNull"));
47+
operators.add(new ImmutableOperator("LESS_THAN", 1, new IsLessThanMatcher(), "LessThan", "IsLessThan"));
48+
operators.add(new ImmutableOperator("LESS_THAN_EQUAL", 1, new IsLessThanOrEqualToMatcher(), "LessThanEqual", "IsLessThanEqual"));
49+
operators.add(new ImmutableOperator("LIKE", 1, new IsLikeMatcher(), "Like", "IsLike"));
50+
operators.add(new ImmutableOperator("NEAR", 1, null, "Near", "IsNear"));
51+
operators.add(new ImmutableOperator("NOT", 1, new IsNotMatcher(), "IsNot", "Not", "IsNotEqualTo", "DoesNotEqual"));
52+
operators.add(new ImmutableOperator("NOT_IN", 1, new IsNotInMatcher(), "NotIn", "IsNotIn"));
53+
operators.add(new ImmutableOperator("NOT_LIKE", 1, new IsNotLikeMatcher(), "NotLike", "IsNotLike"));
54+
operators.add(new ImmutableOperator("REGEX", 1, new RegexMatcher(), "Regex", "MatchesRegex", "Matches"));
55+
operators.add(new ImmutableOperator("STARTING_WITH", 1, new StartingWithMatcher(), "StartingWith", "IsStartingWith", "StartsWith"));
56+
operators.add(new ImmutableOperator("TRUE", 0, new IsTrueMatcher(), "True", "IsTrue"));
57+
}
58+
}
59+
60+
@Override
61+
public void register(Operator operator) {
62+
log.info("Registering operator " + operator.getName() + " which will respond to suffixes " + Arrays.toString(operator.getTokens()));
63+
for (Operator item : operators) {
64+
for (String token : item.getTokens()) {
65+
for (String newToken : operator.getTokens()) {
66+
if (newToken.equals(token)) {
67+
throw new DuplicateOperatorException(item, token);
68+
}
69+
}
70+
}
71+
}
72+
operators.add(operator);
73+
}
74+
75+
@Override
76+
public Operator getBySuffix(String suffix) {
77+
for (Operator operator : operators) {
78+
for (String token : operator.getTokens()) {
79+
if (token.equals(suffix)) {
80+
return operator;
81+
}
82+
}
83+
}
84+
return null;
85+
}
86+
87+
}

src/main/java/com/mmnaseri/utils/spring/data/domain/impl/DefaultRepositoryMetadataResolver.java spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/domain/impl/DefaultRepositoryMetadataResolver.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.mmnaseri.utils.spring.data.domain.impl;
22

33
import com.mmnaseri.utils.spring.data.domain.RepositoryMetadata;
4+
import org.apache.commons.logging.Log;
5+
import org.apache.commons.logging.LogFactory;
46
import org.springframework.data.repository.RepositoryDefinition;
57

68
/**
@@ -18,14 +20,17 @@
1820
*/
1921
public class DefaultRepositoryMetadataResolver extends AbstractRepositoryMetadataResolver {
2022

23+
private static final Log log = LogFactory.getLog(DefaultRepositoryMetadataResolver.class);
2124
private final AssignableRepositoryMetadataResolver assignableRepositoryMetadataResolver = new AssignableRepositoryMetadataResolver();
2225
private final AnnotationRepositoryMetadataResolver annotationRepositoryMetadataResolver = new AnnotationRepositoryMetadataResolver();
2326

2427
@Override
2528
protected RepositoryMetadata resolveFromInterface(Class<?> repositoryInterface) {
2629
if (repositoryInterface.isAnnotationPresent(RepositoryDefinition.class)) {
30+
log.info("Since the repository interface was annotated with @RepositoryDefinition we will try to resolve the metadata using the provided annotation");
2731
return annotationRepositoryMetadataResolver.resolve(repositoryInterface);
2832
}
33+
log.info("Since no annotation was found on the repository, we will try to read the metadata from the generic type parameters derived from the Repository interface");
2934
return assignableRepositoryMetadataResolver.resolve(repositoryInterface);
3035
}
3136

src/main/java/com/mmnaseri/utils/spring/data/domain/impl/DescribedDataStoreOperation.java spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/domain/impl/DescribedDataStoreOperation.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.mmnaseri.utils.spring.data.query.QueryDescriptor;
88
import com.mmnaseri.utils.spring.data.store.DataStore;
99
import com.mmnaseri.utils.spring.data.store.DataStoreOperation;
10+
import org.apache.commons.logging.Log;
11+
import org.apache.commons.logging.LogFactory;
1012

1113
import java.io.Serializable;
1214
import java.util.List;
@@ -19,7 +21,8 @@
1921
* @since 1.0 (9/29/15)
2022
*/
2123
public class DescribedDataStoreOperation<K extends Serializable, E> implements DataStoreOperation<Object, K, E> {
22-
24+
25+
private static final Log log = LogFactory.getLog(DescribedDataStoreOperation.class);
2326
private final SelectDataStoreOperation<K, E> selectOperation;
2427
private final DataFunctionRegistry functionRegistry;
2528

@@ -30,11 +33,14 @@ public DescribedDataStoreOperation(SelectDataStoreOperation<K, E> selectOperatio
3033

3134
@Override
3235
public Object execute(DataStore<K, E> store, RepositoryConfiguration configuration, Invocation invocation) {
36+
log.info("Trying to select the data from the data store");
3337
final List<E> selection = selectOperation.execute(store, configuration, invocation);
3438
final QueryDescriptor descriptor = selectOperation.getDescriptor();
3539
if (descriptor.getFunction() == null) {
40+
log.info("No function was specified for the current selection");
3641
return selection;
3742
}
43+
log.info("Executing function " + descriptor.getFunction() + " on the selected items");
3844
final DataFunction<?> function = functionRegistry.getFunction(descriptor.getFunction());
3945
return function.apply(store, descriptor, configuration, selection);
4046
}

src/main/java/com/mmnaseri/utils/spring/data/domain/impl/ImmutableInvocation.java spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/domain/impl/ImmutableInvocation.java

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mmnaseri.utils.spring.data.domain.Invocation;
44

55
import java.lang.reflect.Method;
6+
import java.util.Arrays;
67

78
/**
89
* This is an immutable invocation.
@@ -29,4 +30,10 @@ public Method getMethod() {
2930
public Object[] getArguments() {
3031
return arguments;
3132
}
33+
34+
@Override
35+
public String toString() {
36+
return method + ", " + Arrays.toString(arguments);
37+
}
38+
3239
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.mmnaseri.utils.spring.data.domain.impl;
2+
3+
import com.mmnaseri.utils.spring.data.domain.MatchedOperator;
4+
import com.mmnaseri.utils.spring.data.domain.Matcher;
5+
import com.mmnaseri.utils.spring.data.domain.Operator;
6+
7+
/**
8+
* @author Mohammad Milad Naseri ([email protected])
9+
* @since 1.0 (4/17/16, 12:37 PM)
10+
*/
11+
@SuppressWarnings("WeakerAccess")
12+
public class ImmutableMatchedOperator implements MatchedOperator {
13+
14+
private final Operator original;
15+
private final String matchedToken;
16+
17+
public ImmutableMatchedOperator(Operator original, String matchedToken) {
18+
this.original = original;
19+
this.matchedToken = matchedToken;
20+
}
21+
22+
@Override
23+
public String getName() {
24+
return original.getName();
25+
}
26+
27+
@Override
28+
public int getOperands() {
29+
return original.getOperands();
30+
}
31+
32+
@Override
33+
public Matcher getMatcher() {
34+
return original.getMatcher();
35+
}
36+
37+
@Override
38+
public String[] getTokens() {
39+
return original.getTokens();
40+
}
41+
42+
@Override
43+
public String getMatchedToken() {
44+
return matchedToken;
45+
}
46+
47+
}

src/main/java/com/mmnaseri/utils/spring/data/domain/impl/MethodInvocationDataStoreOperation.java spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/domain/impl/MethodInvocationDataStoreOperation.java

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.mmnaseri.utils.spring.data.proxy.RepositoryConfiguration;
66
import com.mmnaseri.utils.spring.data.store.DataStore;
77
import com.mmnaseri.utils.spring.data.store.DataStoreOperation;
8+
import org.apache.commons.logging.Log;
9+
import org.apache.commons.logging.LogFactory;
810

911
import java.io.Serializable;
1012
import java.lang.reflect.InvocationTargetException;
@@ -19,6 +21,7 @@
1921
*/
2022
public class MethodInvocationDataStoreOperation<K extends Serializable, E> implements DataStoreOperation<Object, K, E> {
2123

24+
private static final Log log = LogFactory.getLog(MethodInvocationDataStoreOperation.class);
2225
private final Object instance;
2326
private final Method method;
2427

@@ -31,6 +34,7 @@ public MethodInvocationDataStoreOperation(Object instance, Method method) {
3134
public Object execute(DataStore<K, E> store, RepositoryConfiguration configuration, Invocation invocation) {
3235
final Object result;
3336
try {
37+
log.info("Invoking method " + method + " to handle invocation " + invocation);
3438
result = method.invoke(instance, invocation.getArguments());
3539
} catch (IllegalAccessException e) {
3640
throw new DataOperationExecutionException("Failed to access target method: " + method, e);

0 commit comments

Comments
 (0)