FunctionalTestCase in Mule - How do I load one flow before another? - java

I have a Mule application, and I'm creating some unit tests including some Mock Web Services to test certain functionality. The Mock Web Services I'm creating using a test mule flow, so I'm registering an HTTP inbound endpoint.
When I run my test, I get a failure because one of my Spring objects fails to load due to the fact that it cannot reach my mock web service(The web service is loaded dynamically, so when doing the test, it resolves to localhost, otherwise it is usually an external service). I've made sure that when I do my getConfigResources() I load my mock web service flow file before I load my spring context beans, however I still get the error.
Is there a way to make Mule/Spring load my flow file and start up my http:inbound-endpoint before my Spring beans?

You could try setting the depends-on attribute on your Spring bean to the name of the Mule flow, but I doubt it will work and I'm not convinced it's something desirable anyway.
Otherwise, the only thing I can think of is that you initialize the Spring bean factory yourself in a #Before method of your functional test case. This will give you an opportunity to pass the value of the dynamic port you're using with your mock HTTP inbound endpoint (assuming you do use a dynamic port, which is the recommended approach).

Related

Testing with Embeded stub/dummy application in SpringBoot

I'm trying to write a integration test for my SpringBoot microservice that interacts with another service inside the product ecosystem.
Since this kind of testing is consider function/integration testing (depending on what nomenclature you use) it is usually done on some development environment.
However, I wanted to test a basic interaction between my service and a STUB/dummy app which are connected with RPC (so not exactly a typical TestRestTemplate test).
I know that there is a way to embed a service while booting up the Spring Context but have never done it by myself.
Does anyone have any experience with the upper or maybe a few helpful links where I can explore.
I have used WireMock in tests to mock services external to what I want to test that communicate over HTTP.
My test class annotated with #SpringBootTest is also annotated with #ContextConfiguration. In the classes attribute #ContextConfiguration I explicitly specify the configuration classes required to set up the Spring Context for the test in question. Here I can also include additional configuration classes in which I create beans only used in the test. In test configuration classes I can also override beans for the purpose of the test, creating mock beans etc.
Note that Spring Boot 2.1 and later disables bean overriding by default. It can be enabled by setting the following property to true:
spring.main.allow-bean-definition-overriding=true
To set the property for a single test, use the #TestPropertySource annotation like this:
#TestPropertySource(properties = {
"spring.main.allow-bean-definition-overriding=true"
})

How to configure RestClientProxyFactoryBean in spring boot project

Please help. How to configure RestClientProxyFactoryBean in spring boot project
Thx
See this example: It creates a rest client service which you can call to get a rest client instance to make http calls
https://www.programcreek.com/java-api-examples/index.php?source_dir=expressui-framework-master/expressui-domain/src/main/java/com.expressui.domain/RestClientService.java
Usage of this can be seen in the Below link:
https://www.programcreek.com/java-api-examples/index.php?source_dir=expressui-framework-master/expressui-domain/src/main/java/com.expressui.domain/RestClientService.java#
And some test case to be run can be found here:
https://www.programcreek.com/java-api-examples/index.php?source_dir=expressui-framework-master/expressui-domain/src/main/java/com.expressui.domain/RestClientService.java#
Explanation:
So basically we can create different Restclients using proxyfactory bean. In the above example, a service named Geoplanetservice is being created. Rest communication happens via GeoPlanetClient service Interface which is the instantiated via our proxyfactory bean.

Force spring test configuration to load before main

I have a spring configuration class in main that creates redis client bean.
In tests I have another configuration class which creates embedded redis server bean. The problem is to force embedded redis server bean to be created before redis client one. I tried with #Order anotation without success. Importing test configuration to main one isn't an option.
When I define EmbeddedRedis as #Component then it will be created before the client but this is also not an option since EmbeddedRedis is a part of shareable test library which should not be created when not needed.
I have a workaround solution with an interface called RedisServerConfiguration which has different implementations for main and test and client depends on it so I am able to start server before the client tries to connect but this requires another abstraction and it would be nice to simplify it. Is there any spring mechanism I am not aware of that allows to force the order of bean initialization ?

Inject a bean from another application context?

Is it possible to inject a bean from a web application that deploy in another server!
I declare a scenario to myself, I have two web application that use spring framework and deploy separately in different application servers (one is TOMCAT and another one is WEBLOGIC),the first application has ServiceA and the second one has ServiceB, now I want to inject ServiceB in ServieA?
I try to do this with RMI once an another one with JMS, now I am wondering that:
Is it possible with another thing?
Is there any active project about this scenario exist?
How can share application context in spring framework, is it possible?
Thanks.
Bean is just an object in JVM. You certainly cannot use an object from one JVM in another JVM straightforward.
But you can do 2 things:
Use proxies - some objects that will have the same interface but invoke somehow to the proper server as implementation.
Use service-oriented architecture (SOA). Each server should have some limited set of beans that are responsible for their functionality. And all beans can interact with each other.
Maybe OSGI is suitable for this.
Web services, JAX-RS is the simplest. But JAX-WS provides you with the tools to automatically generate the client code.

Is it possible to use JExample and Spring integration test at the same time?

I'm testing a Spring web MVC application with heavy RESTful invocation that POST and DELETE a remote resource on demands.
When I'm trying to run integrated test, obviously I need to test POST first and then DELETE second. Unfortunately JUnit doesn't support such dependency test, and the vanilla JExample class cannot be run with Spring application context. Is there a feasible way of using both?

Categories

Resources