Could Spring be used as Auto Mocking Container? - spring

Looking other technologies than Java, I came accross the 'Auto Mocking Container' strategy.
An easy to use integration of Mockito and Spring (and for TestNG, since it's my preference over Junit) would be very handy
Unhopefully, I haven't found anything like it for Spring.
But is there something out there, I haven't found?

Related

Spring AOP in separate project

I've been playing around with aspects in my spring boot project using spring-boot-starter-aop. It's all working nicely and I have good test coverage with some of them leveraging whats offered in spring boot e.g. #SpringBootTest.
Since the aspects and related code would be useful across multiple different projects I wanted to extract this code into a separate "utility" project. Then import this utility project as a dependency.
As I understand stand it (from here), a spring boot project should generally not be used as a dependency. Since I'm using spring-boot-starter-aop and also leveraging spring beans etc in my tests, this is a problem...
I'm just wondering on the best way to proceed. Any advice appreciated.
Thanks

How to integrate the spring boot project generated by swagger with OSGi and deploy it in Apache karaf?

How to integrate the spring boot project generated by swagger with OSGi and deploy it in Apache karaf?
How should I write my pom.xml and how to modify the startup class. If there is something not detailed, I will add it. Thank you!
You don't. It's not strictly impossible but it would be a lot of work and struggle and you will not get any benefits out of it.
If you want SpringBoot - stick to that. You will sacrifice modularity, strong encapsulation, enforced clean architecture and bunch of other architectural thing that will matter a lot in the long run. But you will gain something that is easy to work with in the beginning and tons of code to copy/paste.
If you are playing the long game - I'd recommend to forget about SpringBoot and learn how to build modular OSGi applications. Recent version allow you to use popular technologies like JAX-RS and CDI. You can probably use one of the Swagger's JAX-RS generators and then convert the outcome to proper modular code. It may even be that there is a generator that generates OSGi JAX-RS code already.

What is meant by Spring boot follows “Opinionated Defaults Configuration” Approach?

I have just started learning spring boot . In its official page I found out this term and I did not understand that what actually it meant in Spring boot context.
Spring Boot just decides on a set of default configured beans which you can override if you want.
For example if you include the spring boot starter pom for jpa, you'll get autoconfigured for you an in memory database, a hibernate entity manager, and a simple datasource. This is an example of an opinionated (Spring's opinion that it's a good starting point) default configuration that you can override.
See https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-replacing-auto-configuration
Spring Boot, is Spring on steroids if you will. It's a great way to get started very quickly with almost the entire Spring stack. I'll try to summarize as what "Opinionated Defaults Configuration" would mean in practice from a programmer's perspective below:
Helps you to setup a fully working application(web app or otherwise) very quickly by providing you intelligent default configurations that you are most likely to be satisfied to start with.
It does so by something called "AutoConfiguration", where capabilities from the Spring ecosystem of products are "auto-magically" enabled in your application by adding certain dependencies to your classpath; adding such dependencies via maven or gradle is super easy.
Most auto-configuration respects your own configuration, and backs off silently if you have provided your own configuration via your own beans.
You would benefit most if you take the java config approach of configuring your Spring application.
Super silky integration of new capabilities in your application by developing your own auto-configuration components (via annotations!).
Tons of auto-configaration components available ranging from Databases(h2, derby etc.), servlet containers(tomact, jetty etc.) to email and websockets are available. It is easy to develop your own. The important thing is that others can use those technology enablements in their own components. Please feel free to contribute.
Helps write very clean code with all the heavy lifting taken care of you, so that you can focus more on your business logic.
Hope you have fun with Spring Boot; its absolutely among the very best of frameworks to have hit the market in the last decade or so.
It follows opinionated default configuration so it reduces the developer efforts. Spring boot always uses sensible opinions, mostly based on the class path contents. So it overrides the default configuration.

Spring Integration (not Basic Spring) support for Drools

Do we have examples or out of box support to use Spring Integration(not Basic Spring) as opposed to Camel with Drools like in link here?
What I would looking for is a way to build/set-up Decision Tables
and be able to use Spring Integration framework already existing in my application.
I have read about Spring but what I am looking for is Integration Framework support - specifically Spring-Integration as opposed to Apache Camel
Any pointers for basic set-up appreciated.
I think would be better if I move my comment to the answer to close this question:
I'd say that you should use that Drools-Camel fusion and route the result to the Spring Integration MessageChannel http://camel.apache.org/springintegration.html. Spring Integration doesn't support directly Drools and there is no plans.
The main reason - "do not reinvent the wheel".
Since Drools lives in JBOSS very well and has that Camel integration, there is no reason to find alternative solution.
Right, it's not a position of Spring Integration developer, but we just don't want to start a new holy war "Camel VS Spring Integration" :-).

Junit for application using Struts, Springs, Hibernate all

Is there any specific approach already defined or used by any one for unit testing applications using Struts, Springs, Hibernate technologies ?
What are different mocking apis we can use ?
Note: I don't want want any solution to individually unit test these technologies.
You can inject mock Spring facades into your Struts actions, and unit-test the Struts actions. You can inject mock Spring repositories/DAOs into your Spring facades and unit-test these facades. And you can use DBUnit (or another similar tool) to populate a test database before each repository test.
Choose the mocking API you like the most. There are sevaral ones: Mockito, EasyMock, JMock, etc.
If you want to test the whole app, you're not doing unit tests anymore, but integration tests. And mocking would go against your goal. If that's what you want to do, you could use Selenium or HtmlUnit to test the application.

Resources