mmnaseri / spring-data-mock

Mock facility for Spring Data repositories
MIT License
135 stars 44 forks source link

Doesn't work with Spring Boot 2.0 #163

Closed binakot closed 4 years ago

binakot commented 5 years ago

I migrated from spring boot 1.5.6.RELEASE to 2.0.5.RELEASE. And every tests with redis-repository stoped to working with error:

java.lang.IllegalStateException: Could not find property `id` on `class my.app.service.domain.model.Entity`

I just remove library and start to use @MockBean for my repository and it works as well.

binakot commented 5 years ago

I guess the reason in new method findById contract. Now it returns Optional<>.

Encountered an error while resolving operation metadata: public abstract java.util.Optional org.springframework.data.repository.CrudRepository.findById(java.lang.Object)
paulvi commented 5 years ago

There should have been update of Spring Data version used in Spring Boot 1.5 to 2.0

binakot commented 4 years ago

I did a fork and made few changes to add init impl to support spring boot 2.0+ https://github.com/waliot/spring-data-mock/tree/spring-boot-2

The main points of migration to spring boot 2.0: 1) https://docs.spring.io/spring-data/commons/docs/1.10.2.RELEASE/api/org/springframework/data/repository/CrudRepository.html VS https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/CrudRepository.html - Now it returns Optinal of value; half of methods were renamed. 2) https://docs.spring.io/spring-data/jpa/docs/1.10.2.RELEASE/api/org/springframework/data/jpa/repository/JpaRepository.html VS https://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/JpaRepository.html - Methods were renamed. 3) https://docs.spring.io/spring-data/commons/docs/1.12.2.RELEASE/api/org/springframework/data/domain/Example.html VS https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Example.html - Now it's interface, not a class. 4) https://docs.spring.io/spring-data/data-commons/docs/1.12.2.RELEASE/api/org/springframework/data/domain/Auditable.html VS https://docs.spring.io/spring-data/data-commons/docs/current/api/org/springframework/data/domain/Auditable.html - JodaTime isn't using anymore, now Java 8 DateTime API with Instant class; now it returns Optinal of value.

mmnaseri commented 4 years ago

Hi @binakot!

Thanks a lot for the interest and following this through. Unfortunately, I have been so distant from Spring lately that I haven't been able to keep up with all their changes and anytime I wanted to make modifications to this code, it seemed like a large undertaking.

If you have a code that is tested and is working with 2.0+, I'd be more than happy to merge it in. Merging in to master will automatically release the code to mvncentral as well, so, it would constitute a release.

Let me know what works for you and we can set something up :)

binakot commented 4 years ago

Hello, @mmnaseri !

It's awesome! First of all thanks for the great library and thanks for response here.

Currently my team is migrating from Java 8 / Spring Boot 1.0+ to Java 11 / Spring Boot 2.0+. All tests of your library are successful in my fork for spring boot 2.0+. We already import its build in one of our services on java, and it works like a charm.

Anyway I want to test it for few more services to be sure in my changes. When I will be sure enough and create PR to your master :octocat: ☕️

mmnaseri commented 4 years ago

That sounds great. Actually, if you don't mind, make the PR to my development branch. I will then create a release-vX branch and merge it into master, which will kick off the release over Maven central.

binakot commented 4 years ago

That sounds great. Actually, if you don't mind, make the PR to my development branch. I will then create a release-vX branch and merge it into master, which will kick off the release over Maven central.

Sure. Actually I did my changes from your development branch, because it's more actual. Then I do PR asap ☕

binakot commented 4 years ago

@mmnaseri Hello. The PR is ready :)

mmnaseri commented 4 years ago

Thanks! I reviewed the code :)

binakot commented 4 years ago

@mmnaseri Hello!

All right! What's next?

mmnaseri commented 4 years ago

Just to give an update, I've not forgotten about this. The Travis build is failing, which means we never get to the post-build stage to actually push this upstream. I am playing with the Travis CI configuration to get it to a green build.

mmnaseri commented 4 years ago

Actually, only openjdk8 on xenial passes. I am going to investigate why. Having it only support 8+ is fine, since this will be a major release, but I can't have it pass on 8 and fail on 9.

binakot commented 4 years ago

Hmm, it's interesting.

Btw it's my environment:

$ uname -a               
Darwin iMac-Ivan.local 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64

$ java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

$ mvn --version
Apache Maven 3.6.1

And it's result of building:

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.mmnaseri.utils.sample:spring-data-mock-sample-jpa:jar:1.0
[WARNING] 'dependencies.dependency.systemPath' for com.mmnaseri.utils:spring-data-mock:jar should not point at files within the project directory, ${project.basedir}/../spring-data-mock/target/spring-data-mock-1.1.4.jar will be unresolvable by dependent projects @ line 83, column 25
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] Spring Data Mock                                                   [jar]
[INFO] Spring Data Mock: Samples (JPA)                                    [jar]
[INFO] Spring Data Mock: Build Aggregator                                 [pom]
[INFO] 
[INFO] ----------------< com.mmnaseri.utils:spring-data-mock >-----------------
[INFO] Building Spring Data Mock 1.1.4                                    [1/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ spring-data-mock ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ spring-data-mock ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 257 source files to /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/target/classes
[INFO] /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/repository/DefaultQueryByExampleExecutor.java: Some input files use unchecked or unsafe operations.
[INFO] /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/repository/DefaultQueryByExampleExecutor.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ spring-data-mock ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ spring-data-mock ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 229 source files to /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/target/test-classes
[INFO] /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/src/test/java/com/mmnaseri/utils/spring/data/repository/DefaultQueryDslPredicateExecutorTest.java: Some input files use unchecked or unsafe operations.
[INFO] /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/src/test/java/com/mmnaseri/utils/spring/data/repository/DefaultQueryDslPredicateExecutorTest.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ spring-data-mock ---
[INFO] Surefire report directory: /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@366e2eef
Tests run: 1075, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.918 sec

Results :

Tests run: 1075, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ spring-data-mock ---
[INFO] Building jar: /Users/binakot/Projects/github/spring-data-mock/spring-data-mock/target/spring-data-mock-1.1.4.jar
[INFO] 
[INFO] -------< com.mmnaseri.utils.sample:spring-data-mock-sample-jpa >--------
[INFO] Building Spring Data Mock: Samples (JPA) 1.0                       [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ spring-data-mock-sample-jpa ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/binakot/Projects/github/spring-data-mock/spring-data-mock-sample-jpa/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ spring-data-mock-sample-jpa ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ spring-data-mock-sample-jpa ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/binakot/Projects/github/spring-data-mock/spring-data-mock-sample-jpa/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ spring-data-mock-sample-jpa ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ spring-data-mock-sample-jpa ---
[INFO] Surefire report directory: /Users/binakot/Projects/github/spring-data-mock/spring-data-mock-sample-jpa/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@1c2c22f3
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Tests run: 26, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.952 sec

Results :

Tests run: 26, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ spring-data-mock-sample-jpa ---
[INFO] 
[INFO] -------------< com.mmnaseri.utils:spring-data-mock-build >--------------
[INFO] Building Spring Data Mock: Build Aggregator 1.1.0                  [3/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Spring Data Mock 1.1.4 ............................. SUCCESS [ 14.495 s]
[INFO] Spring Data Mock: Samples (JPA) 1.0 ................ SUCCESS [  1.289 s]
[INFO] Spring Data Mock: Build Aggregator 1.1.0 ........... SUCCESS [  0.001 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  16.014 s
[INFO] Finished at: 2020-04-25T22:00:02+03:00
[INFO] ------------------------------------------------------------------------

I will try to build it on my linux machine...

binakot commented 4 years ago

This is my second machine:

$ uname -a
Linux muratov-linux-pc 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux

$ java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)

$ mvn --version
Apache Maven 3.6.0

And build's output:

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.mmnaseri.utils.sample:spring-data-mock-sample-jpa:jar:1.0
[WARNING] 'dependencies.dependency.systemPath' for com.mmnaseri.utils:spring-data-mock:jar should not point at files within the project directory, ${project.basedir}/../spring-data-mock/target/spring-data-mock-1.1.4.jar will be unresolvable by dependent projects @ line 83, column 25
[WARNING] 'dependencies.dependency.systemPath' for com.mmnaseri.utils:spring-data-mock:jar refers to a non-existing file /home/muratov/repos/github/spring-data-mock/spring-data-mock-sample-jpa/../spring-data-mock/target/spring-data-mock-1.1.4.jar @ line 83, column 25
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Spring Data Mock                                                   [jar]
[INFO] Spring Data Mock: Samples (JPA)                                    [jar]
[INFO] Spring Data Mock: Build Aggregator                                 [pom]
[INFO]
[INFO] ----------------< com.mmnaseri.utils:spring-data-mock >-----------------
[INFO] Building Spring Data Mock 1.1.4                                    [1/3]
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for io.pivotal.gemfire:geode-core:jar:9.8.7 is missing, no dependency information available
[WARNING] The POM for io.pivotal.gemfire:geode-cq:jar:9.8.7 is missing, no dependency information available
[WARNING] The POM for io.pivotal.gemfire:geode-lucene:jar:9.8.7 is missing, no dependency information available
[WARNING] The POM for io.pivotal.gemfire:geode-wan:jar:9.8.7 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Spring Data Mock 1.1.4 ............................. FAILURE [  0.275 s]
[INFO] Spring Data Mock: Samples (JPA) 1.0 ................ SKIPPED
[INFO] Spring Data Mock: Build Aggregator 1.1.0 ........... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.382 s
[INFO] Finished at: 2020-04-25T22:15:05+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project spring-data-mock: Could not resolve dependencies for project com.mmnaseri.utils:spring-data-mock:jar:1.1.4: The following artifacts could not be resolved: io.pivotal.gemfire:geode-core:jar:9.8.7, io.pivotal.gemfire:geode-cq:jar:9.8.7, io.pivotal.gemfire:geode-lucene:jar:9.8.7, io.pivotal.gemfire:geode-wan:jar:9.8.7: Failure to find io.pivotal.gemfire:geode-core:jar:9.8.7 in http://dist.gemstone.com/maven/release was cached in the local repository, resolution will not be reattempted until the update interval of gemfire-repository has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Now I see. The problem is in io.pivotal.gemfire:geode-core:jar:9.8.7 dependency. It looks like now it's commercial dependency https://gemfire.docs.pivotal.io/910/gemfire/getting_started/installation/obtain_gemfire_maven.html

mmnaseri commented 4 years ago

Yeah. I have deployed 2.0.0 to central, so we should be able to use it. But I had to make modifications to the build mechanism that I need to push upstream.

mmnaseri commented 4 years ago

There were several problems:

  1. In the audit-related tests, we needed to truncate the instant to milliseconds for tests to pass on all target JDKs,
  2. maven-javadoc-plugin has a known issue with JDK 11,
  3. The PGP tool used to sign the build has changed now it reads from stdin, so, it was stuck during the auto-release process waiting for user input in a non-TTY environment,
  4. As you pointed out, the repositories for testng and gemfire need to be removed.
mmnaseri commented 4 years ago

Thank you to @binakot who helped clean up this issue and took care of the incompatibilities. I will be closing this now, and track the progress of automating the release once more in a separate issue.

binakot commented 4 years ago

Yeah. I have deployed 2.0.0 to central, so we should be able to use it. But I had to make modifications to the build mechanism that I need to push upstream.

Just import 2.0.0 to one of our services on java 11, spring boot 2.2.6.RELEASE. And it works like a charm 🍸 Many thanks 😄