JUnit test case for OSGI bundle - osgi-bundle

I am trying to write JUnit test case for an external OSGI bundle that I have.
I tried using Spring DM but then it gave errors while running the test cases - It was not able to start the Spring Extender bundle. Then I found out that the Spring DM is now obsolete.
I want to be able to run a junit test case for OSGI bundles via ant tasks. Any pointers will be of immense help.

It depends on what you want to do. This is immediately not clear from your question.
If you want to test your code against OSGi service, you may consider a mocking framework such as Mockito to mock your services.
If you want to test OSGi bundles developed by you against its OSGi behaviour, you may consider Pax Exam, which can start an OSGi container and run your tests on it.
Let me know if you have any other use case.

Related

Run external spring boot application as part of an integration test

Is it possible to run an external Spring boot application from an integration test? The basic idea is that I have a mock service that was developed for use in end to end testing and would like to be able to have the e2e integration test take care of starting up the service and shutting it down as part of the test.
I recommend you take a look at docker and the fabric8 maven plugin. This allows you to build container images that contain your application, start and stop instances of those containers as part of your integration test phases.

Spring Boot App - Reference external code during runtime that isn't part of the bundled WAR?

I have a Spring Boot+React application that is packaged as a bundled WAR.
This works well for most cases, but we need to be able to drop-in functionality in some cases that is not part of the bundle (such as via a JAR).
I knew OSGI exists for this case, but not sure of any usage with Spring Boot. Is there another way to do this as well?
If your use case is a kind of small plugin functionality for your spring boot app then you could start an OSGi framework inside spring boot and load bundles from a separate directory. You plugins could then offer their service via an interface that is provided by the spring boot app and an OSGi service with that interface.
You need some good OSGi knowledge for this to work.

Rollback Integration Test which uses cucumber and tests the application on embedded tomcat via maven

I am trying to set up an integration test framework for my spring project using cucumber framework and selenium for UI automation.
What I have done till now is
Use tomcat7 plugin for maven and deploy my war file to this embedded tomcat
Use the cucumber feature file to specify any test cases, be it a rest service or for the UI automation
We need to use our existing development DB for test purposes
I will hit the app url for the application running on the embedded tomcat.
What I am unable to find out is, can we rollback a transaction automatically after the test is done?
I am able to rollback transactions from cucumber/junit that were directly using my DAO as the DB connection was initiated from the same spring context.
But when the invocations are made using this model, I am unable to find any idea to rollback the transactions after the tests are done.
Can you think of achieving your integration testing in terms of Spring profile? You can create a spring profile for integration test and use it as environment variable or using annotations to specify rollback for transaction.
Take a look at following references to get an idea:
Spring integration tests with profile
https://spring.io/blog/2011/06/21/spring-3-1-m2-testing-with-configuration-classes-and-profiles

End to end test across multi Spring Boot applications

Currently in our project, we are using Spring Integration to integrate many service and some protocol related endpoints.
The project is a multi Spring Boot applications, more than one executable jars will be deployed in production.
The question is:
How to run an end to end test which needs to run cross some of these applications, I have to run the one by one manually? In before none-Spring-Boot applications, I can use Maven tomcat7 plugin to complete this work(deploy the wars into an embedded tomcat and run it in pre-integration-test phase), now how to start up all related applications before I run my test. Assume I do not use Docker/Vagrant now.
Similar question found on stackoverflow, End to end integration test for multiple spring boot applications under Maven
How to run the end2end test automatically?
In an Spring Integration test, sometime I have to mock a http endpoint, so I wrote a simple Controller in test package to archive this purpose, but I want to run it at a different port, which make it more like an outside resource. How to run different #SpringBootApplicaiton classes at varied ports at the same time in the test for this purpose?
I am using the latest Maven, Java 8, Spring Boot 1.3.1.RELEASE.
Actually, Spring Boot comes with the embedded Servlet Container support. One of them is exactly Tomcat. The default on for the org.springframework.boot:spring-boot-starter-web.
With the org.springframework.boot:spring-boot-starter-test and its #SpringApplicationConfiguration and #WebIntegrationTest you can achieve your requirements, even with the random port.
Please, refer to the Spring Boot Reference Manual for more information:
To change the port you can add environment properties to #WebIntegrationTest as colon- or equals-separated name-value pairs, e.g. #WebIntegrationTest("server.port:9000"). Additionally you can set the server.port and management.port properties to 0 in order to run your integration tests using random ports.
With that your #SpringBootApplicaiton will be deployed to that embedded Tomcat and your test can get access to the ran services/controllers.
Note: it doesn't matter if your Spring Boot application has Spring Integration facilities. The behavior is the same: embedded Servlet Container and integration tests against #Value("${local.server.port}").

CQ5 Spring integration

Is the any way to perform integration CQ5 platform with Spring framework?
I would like to use Spring IoC capabilities to make my code more clear and efficient.
UPDATE
Hello againg, seems that I found solution.
Guys here developed Slice framework that really redices amound of code and made CQ5 development easier.
You probably want to check out Eclipse Gemini Blueprint, or it's original incarnation Spring Dynamic Modules. The Blueprint project basically gives you an easy way to create Spring enabled bundles in an OSGi environment.
As shsteimer mentions, Spring distributions before 3.2.0 were OSGi bundles, so could be dropped into an OSGi environment and you could probably use them directly. Spring 3.2.0 bundles and above are now available through the SpringSource ERB. However, Blueprint gets around or helps with some of the boilerplate OSGi stuff that you would otherwise have to do.
On a past project, I was able to get Spring JDBC working inside of CQ (to support some legacy code so we didn't have to re-write it). My memory is that the spring jar files already come "OSGI-ified" and so it was just a matter of figuring out all the layers of dependency needed for JDBC to work inside of CQ, and adding all the jars to the repository in an /apps/myApp/install folder.
Long story short, I'm not sure about IoC, but you might check to see if it's already packaged as an OSGI version which you can simply use without too much hassle.

Resources