Spring Boot + Testcontainers with remote liquidbase migrations - java

I have two Spring boot applications that don't know about Liquidbase migrations since migrations are stored in a separate repository and applied by Jenkins.
I want to introduce Testcontainers testing to test communication with DB.
The issue is that I cannot store these migrations locally in the services to avoid duplication.
Is there any way to pull migrations before TestContainer start? Maybe some workaround?

As a workaround, I decided to use JGit SDK to download migrations.
More information about JGit here:
https://www.baeldung.com/jgit

Related

how to prevent jdbc from trying to connect to a mysql database during unit testing

I'm making an application for a school project, but I'm running into the issue that when I try to run the unit tests that it tries to connect to the database while starting up the application, which isn't required for the tests (because it will be mocked), and is not available in the CI/CD pipeline.
jdbc connection error
I'm building my project in Java Maven Springboot and would like to know how I can prevent it from trying to connect to the database when running my test.
here is a link to my repository: https://gitlab.com/kwetter_jack/Kwetter_posts/-/tree/ci_cd_setup
Your test classes have #SpringBootTest annotation which will start a Spring application context - as your application uses a database the tests will also try to setup and use a database connection.
The simplest solution is to remove the annotation so the tests no longer try to connect to a database. You'll probably need to mock some more dependencies as a result as Spring is no longer creating these for you. You could also have a look at https://www.baeldung.com/spring-boot-testing for some other ideas how you could alter your tests.
Alternatively if you do want / need the application context to run you can add a application.yaml for the tests that defines and uses a in memory DB so the tests have something to connect to - see https://www.baeldung.com/spring-boot-h2-database for details how to do this.
Just change value under spring.datasource to H2 database to prevent
The application connect the real database.
Test application.yml
FYI, You no need to copy all config from original application.yml, just only some config that you need to override.
while I was investigating the spring boot H2 in-memory database (as suggested by Chris Olive and Paranaaan) I also came across the option of using a test container. after looking into this I saw that this enables the project to create a temp docker container with a MySQL image that I can use during the testing of my project, considering I was planning on using docker anyway for the integration testing of my microservices project I attempted this and it worked as I had hoped it would.
if anyone is interested in the test container solution that I used, the information can be found here:
https://www.testcontainers.org/modules/databases/mysql/

Hibernate database (maria-db) change detect

I need to understand, Is there anyway I can continuously look for change in Maria-DB table using Hibernate.
I have a spring boot application that is connected to Maria-DB. If some other application perform CURD on table, I want to catch that in spring.
If it's not possible using hibernate, suggest me alternative.
PS : This spring boot application is running is different Docker Container and Maria-DB is running is different Docker Container.
You can use Database Triggers, or better why don't you try enabling Hibernates 2nd level cache?
Solution to this specific problem is Spring Integration module as other ways not working here. I have create a sample application to demonstrate here you can find the source code
What this application does look database continuously.

CDI Flyway with multiple database vendor

Flyway provides framework which will execute migrations based on directory
/data/migration
My application supports Oracle, SQLServer or MySQL, i would like to keep scripts as /data/migration/oracle and /data/migration/sqlserver etc...
Application can be deployed either on Oracle, SQLServer or MySQL. How to inform Flyway framework to use specific database deployment migrations using spring integration?
You will pass different location for each database. You may have placeholder for that. I have it done in maven plugin ond only what is needed to be changed is
<locations>
<location>db/${database.type}</location>
</locations>

From GAE to Cloudfoundry

I'd like to know the main differences between CloudFoundry and Google App Engine for a personnal project.
I have a web application that currently runs on GAE and i'am thinking to move it to CloudFoundry for various technical reasons.
I'd like to use :
Spring MVC & Spring Security.
a full implementation of JPA instead of DataNucleus.
mavenize my project properly, i can't make the maven-gae-plugin works.
Is CloudFoundry a good alternative to GAE in my case?
What is the complexity of the migration?
Thanks
It shouldn't be too hard to migrate the app.
http://blog.springsource.org/2011/11/10/using-cloud-foundry-services-with-spring-part-4-%E2%80%93-spring-profiles/ and the whole series of articles has lot of details on how to bind your Spring app to a cloudfoundry data source.
http://blog.springsource.com/2011/09/22/rapid-cloud-foundry-deployments-with-maven/ has details about the cloudfoundry maven plugin, for deployment
To migrate your data, you may want to use the remote api http://code.google.com/appengine/docs/java/tools/remoteapi.html or bulkloader to export, then CloudFoundry Caldecott to import your data in CloudFoundry http://blog.cloudfoundry.com/post/12928974099/now-you-can-tunnel-into-any-cloud-foundry-data-service
http://start.cloudfoundry.com/frameworks/java/spring/spring.html the getting started in cloudfoundry for spring is a good place to start learning about deploying spring apps to cloudfoundry.
I hope this helps.
I can only answer the maven part: see this for a working multimodule example: https://github.com/leanengine/LeanEngine-Server
you must use it like this:
mvn gae:unpack // downloads GAE classes to your maven repo
mvn clean install package
cd lean-server-example
mvn gae:execute // starts a local server

Testing Alfresco Java services

I am looking for a method for testing Alfresco repository Java services without the need for deploying to a Tomcat server.
My idea is to start Alfresco embedded from a JUnit testclass, inject the classes I want to test into the Alfresco Spring configuration and test the classes using JUnit test methods.
The Alfresco sample application "FirstFoundationClient" is a good entry point for getting the above working but when I try to start the sample with a H2 memory database in MySQL-mode it outputs the following error:
SqlMapException: The <sqlMap> resource is missing: /alfresco/ibatis/#resource.dialect#/qname-insert-SQLMap.xml
My alfresco-global.properties configuration in the sample project:
dir.root=./alf_data
db.driver=org.h2.Driver
db.url=jdbc:h2:alf_data/h2_data/alfresco;MODE=MySQL
db.username=alfresco
db.password=alfresco
Can anyone help me with:
how to get FirstFoundationClient (from Alfresco Enterprise SDK 3.4.0) running using a H2 database
how to inject the classes under test so I can access them from the Spring application context (like standard Alfresco services are accessed in the FirstFoundationClient sample)
If you're willing to give the maven way a try, I published a little tutorial about how to use H2 with Alfresco. Here's a project where I'm leveraging that approach that you might use as a template.
NOTE: Alfresco v4.x might not be compatible with H2 - PostgreSQL mode
EDIT: the new h2-support v1.2 supports Alfresco4
EDIT: h2-support now supports up to Alfresco 4.0.2

Categories

Resources