Spring Boot Multi Module Integration Test - maven

+--------------------------------------+
| Parent module: com.company.project |
+----|---------------------------------+
|
+----- WebApp module: com.company.project <-- #SpringBootApplication
-
+----- Module A : com.company.project.moduleA
-
+----- Module B : com.company.project.moduleB
-
+----- Module C : com.company.project.moduleC
I have a maven structure like one above. Each module is a kind of "service" so it contains many types of components (jpa, web etc). I package the project using webapp module as the entry point.
I want to place integration tests on each service/module since they are independent and I think they "belong" there. Of course when I use #RunWith(SpringRunner.class) spring can't find components and run the tests. How should I tackle this problem?
Thanks

Related

How to setup multi-project IntelliJ workspace with Gradle?

Hello I am working on using Gradle to build a few services. I tend to have seperate repositories for each "code package" i.e. library or service.
In IntelliJ, my setup tends to be the following:
- IntelliJ Workspace
-- Service A
--- pom.xml
-- Service B
--- pom.xml
-- Library A
--- pom.xml
-- Library B
--- pom.xml
Service A & B both depend on Library A & B. This works great, within a single IntelliJ Workspace I can modify Library A and B and startup the services and all is well.
I know you can do composite builds and multi-module builds with Gradle but like I said all the 4 modules above are seperate repositories so this won't work well.
Will IntelliJ support a similar setup as above with Gradle where it recongizes that Library A & B is the library that Service A & B depend on? Or does everyone do a manual publish to Maven local for this consistently?
Thanks!
Rephrasing your question -
there are 3 separate gradle projects service1, lib1, lib2
service1 depends on lib1 and lib2
what is expected is
for local development - where source for all 3 projects locally exists - use the local code build
refer to the repository artifacts if local source does not exist
Assuming a simple folder structure like this.
app-code
- service1
- lib1
- lib2
service1 - settings.gradle
rootProject.name = 'service1'
include ':lib1'
project(':lib1').projectDir = new File('../lib1')
include ':lib2'
project(':lib2').projectDir = new File('../lib2')
service1 - build.gradle
dependencies {
implementation (project(':lib1').projectDir.exists() ? project(':lib1') : 'com.lib1:lib1:1.0.0')
implementation (project(':lib2').projectDir.exists() ? project(':lib2') : 'com.lib2:lib2:1.0.0')
}
how intellij import looks

Working with multiple module using Maven for Automation

I have a problem and i have confidence that you guys can clarify it.
I have created a java based automation project using maven project structure. I have applied the concept of Page Object Model in it. My project structure is like below.
Automation
Module1
|_____ FrameworkCore.java
|_____ FrameworkWebDriver.java
|_____ DynamicMethodCalling.java
|_____ RunSuit.csv
Module2
|_____CommonPage.java - extends Framework core
|_____Pages
| |_____ LoginPage.java
| |_____ HomePage.java
| |_____ ContactPage.java
|_____Test
|_____ Test1.java
|_____ Test2.java
--> I have created test functions in Test1 and Test2 and i am dynamically calling the methods based on the methodName.
-->In order to achieve the above i need to configure the Module1 as depenency in Module 2
("in-order to refer the webdriver defined in framework code")
AND Module 2 as dependency in Module1
(in-order to call the methods from Test1 & Test2).
This causing the circular dependency.
Is there any way to avoid this circular dependency???
Note: i have searched a lot in the internet and have not found any suitable solution for this issue
Regards,
SomeshKumar Nagarajan

Best practice for configuration in multi maven projects

given the following spring boot application layout:
app
--api
--component
--data
--xyz
libs
--lib1
--lib2
Each one is a seperate maven project where "app" contains the spring bootstrap class. Other modules are maven dependencies that are used within the application.
Each modules comes with its own profiled property file (application-dev.properies, application-qa.properties...)
What is the best way to consolidate now all property files within the application?
My proposal for consolidation:
Each module defines own profile, for example:
application-DEV-lib1.properties
application-QA-lib1.properties
application-DEV-lib2.properties
application-QA-lib2.properties
app defines profiles DEV and QA:
application-DEV.properties
spring.profiles.include=DEV-lib1,DEV-lib2
aaa=123
...
application-QA.properties
spring.profiles.include=QA-lib1,QA-lib2
aaa=456
...

Sonar Report + Multi module maven + Jacoco plugin

I am new to Sonar.
I have multi-module maven project.
please find the Project structure below
-Parent
| -Module A
|
-pom.xml (Module A)
| -Module B
|
-pom.xml (Module B)
| -Module C
| |
| -pom.xml (Module C)
|
--pom.xml (parent pom)
Note : (Module C is shared module in Module A/ Module B - means Internally module C will the part of into Module A , Module B library)
Based on the Project requirement we have these structure.
Module A - works for external users.
Module B - works for internalusers.
Module C -common b/w both the module.
I am trying to create single sonar report for both the module, but I am not able to integrate all the module junit report (Module A and Module B report)
into single report.I followed couple of example to combine the muti-module maven porject but nothing works.
similar issue1 similar issue2
github-example (reference given in sonar)
I had similiar problem with over 40 modules which were even nested. What you have to do is to create whole sonar configuration in parent pom.
<sonar.host.url>set url here (default is localhost)</sonar.host.url>
<sonar.login>user for host url (default admin)</sonar.login>
<sonar.password>password for host url (default is admin)</sonar.password>
<sonar.projectName>optional name for whole project in sonar view</sonar.projectName>
<sonar.projectDescription>optional project description for sonar view</sonar.projectDescription>
<sonar.projectBaseDir>like name says you can set project base dir, if you have parent pom as a separate module then you can type ".." to set main directory with all modules</sonar.projectBaseDir>
Set properly all modules which will be analysed separately for the whole project:
<sonar.modules>module1, module2, module3</sonar.modules>
Configure each one of them properly:
<module1.sonar.projectName>module1</module1.sonar.projectName>
<module1.sonar.projectBaseDir>module1/</module1.sonar.projectBaseDir>
<module1.sonar.sources>optionally set sources to proper directory for example src/main/java</module1.sonar.sources>
<!-- similiar for other 2 projects -->
That way all junit reports will be used per module but it will be listed in single project with modules. That way you will be able to see reports per module and per whole single project.
It's a good practise to check results after adding every single module. In case of failure simply check error in console and fix the problem.
I am able to achieve Integration test coverage using sonar with Jococo plugin.
To run the Sonar in local, i was facing the issue with SCM error in sonar.
Every time it was failing in the in sonar report creation.
For resolving the issue in local you need to disable the SCM configuration in sonar.
login in local sonar as Admin - admin/admin (default username/password)
Now under setting we have SCM tab - disable the SCM Senor and save the SCM Setting.
Now in Dashboard --> Configure widgets .Search "Integration Tests Coverage"
Now add widget into your Project Dashboard.
Follow the same configuration in your pom.xml as given in the link.
https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/combined%20ut-it/combined-ut-it-multimodule-maven-jacoco

Gradle dependency settings confusion

Consider the following project structure as a Gradle build:
backend
|- adapters
|- adapter-common
|- bar-adapter
|- bar-entrypoint
|- bar-models
\- bar-services
\- foo-adapter
|- foo-entrypoint
|- foo-models
\- foo-services
|- backend-common
|- db-conn
|- backend-entrypoint
|- build.gradle
\- settings.gradle
The dependency structure is as follows:
foo-adapter depends on foo-entrypoint and adapter-common
foo-entrypoint depends on foo-services
foo-services depends on foo-models
adapter-common depends on backend-common & db-conn
Now I have a separate project api where I need foo-adapter as a dependency. I found this Q&A which seems to be the same situation but when I tried it I get errors about how none of the other projects (adapter-common, db-conn, etc.) are found.
Am I asking too much from Gradle by telling it to just import foo-adapter and then expecting it to pull in and resolve all the dependencies itself?
Is there any way to get this to work without declaring basically the whole backend project in my api settings file?
If your foo-adapter project use some classes from other projects it cannot be added without the others. Not matters it's a jar or just uncompiled stuff. You need the others too. It's a really bad approach to depend a project on another. Better you use only interfaces and put them into a separate project. Thus your projects can be compiled independently and you need just one configuration project that combines all that stuff.

Resources