Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot Testing Facilities #218

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

pfrank13
Copy link

@pfrank13 pfrank13 commented Feb 14, 2017

I created issue #217 that goes over this in more detail. I'd like to point out a few things about the pull request:

  1. Upgrades Spring's version and adds a Spring Boot version that matches, this was needed because the latest Spring Boot requires changes in AnnotationUtils that is present in the version it was meant to use (go figure =))
  2. I couldn't suss out what was going on in AbstractCassandraUnitTestExecutionListener.alternativePath() and because of the requirements of that method I just ignored it, it seems like a convention of data loading that isn't documented nor even used by the project AFAIK
  3. I really wanted to break up EmbeddedCassandraServerHelper into a series of factories or the like as it's a static helper that is definitely order dependent in terms of how it needs to be used. For the Spring Boot related work that ordered is expressed in the Java Config EmbeddedCassandraAutoConfiguration, clearly that won't be able to work outside of a spring context, I wanted to refactor but I was trying to limit change, in terms of smell how I'm using that class is definitely strange but it was mostly to maintain behaviors from the existing testing mechanisms present in CassandraUnit.
  4. I changed the default value for the configuration file to use the random port configuration as the annotation is meant to be used with a Spring Boot Application in situ, e.g. this won't even work if there isn't a @SpringBootApplication being bootstrapped, this is just the way the Spring Boot Test mechanisms work. This doesn't preclude someone from using their own configuration file either, the Session and Cluster being used by Spring Data Cassandra isn't even port aware because of how it's being bootstrapped.

@jsevellec
Copy link
Owner

Really thanks for your the contribution, I'll have a look asap

Peter Frank and others added 9 commits March 14, 2017 14:36
Now I've created a Spring Boot annotation that uses standard Spring Boot Test facilities for bootstrapping a springboot test.  This still requires using the cassandra-unit-spring annotations but that was to POC this, the plan is to remove that requirement and have that functionality be rolled up into the @EmbeddedCassandraTest annotation
Trying to get Spring Data to bootstrap in Spring Data Cassandra properly via AutoConfiguration related boot classes
The test proving out that the Cluster and Session generated works with Spring Data Cassandra on a random port.
Now the configurations that are needed to remove the @EmbeddedCassandra and @CassandraDataSet are available as ConfigurationProperties for the EmbeddedCassandraAutoConfiguration class.  The implementation of piping that into Cassandra Daemon, Session and Cluster creation are still not in place.
So technically at this point things work, although the implementation is heavily reliant on side effects that are present in both the AutoConfiguration and static helper class
The closes Spring Boot test annoations for comparison is @DataJpaTest so to match that convention most closely I've changed what I previously called EmbeddedCassandraTest to DataCassandraTest.  The expectations closesly map as well which is an embedded datastore is spun up and properly bootstraps Spring Data Cassandra
I needed to exclude Spring Boot's Logging facilities as it was bootstrapping both log4j and logback and logback wasn't found as I had only included log4j
@asarkar
Copy link

asarkar commented May 1, 2021

You might be interested in my library cassandra-unit-spring that makes testing with Spring Boot/Spring Data a no-brainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants