junit test cases not executing when spring boot application migrated from 2.1.5 to 2.4 - spring-boot

I had an application running in spring-boot 2.1.5, migrated that to version 2.4.0. None of my tests are executing now.
When I hit mvn clean test it always says 0 tests executed.
I noticed that spring boot 2.4.0 comes bundled with junit.jupiter library. My 2.1.5 tests are using junit:junit:4.4 dependency.
How to retain my old test cases without migrating to junit.jupiter?

This is covered in the release notes for Spring Boot 2.4:
If you do not want to migrate your tests to JUnit 5 and wish to continue using JUnit 4, add a dependency on the Vintage Engine, as shown in the following example for Maven:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
If you are using Gradle, the equivalent configuration is shown in the following example:
testImplementation("org.junit.vintage:junit-vintage-engine") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}

Related

Method does not exist: org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)

I am creating Hibernate Search 6 application with Spring Boot 2.3.4
I am facing this error while I try to build my application -
Description:
An attempt was made to call a method that does not exist. The attempt was made from the
following location:
org.hibernate.search.backend.elasticsearch.client.impl.ElasticsearchClientImpl.setPerRequestSocketTimeout(ElasticsearchClientImpl.java:198)
The following method did not exist:
org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)Lorg/elasticsearch/client/RequestOptions$Builder;
The method's class, org.elasticsearch.client.RequestOptions$Builder, is available from the following locations:
jar:file:/C:/Users/pranali.rasal/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar!/org/elasticsearch/client/RequestOptions$Builder.class
The class hierarchy was loaded from the following locations:
org.elasticsearch.client.RequestOptions.Builder:
file:/C:/Users/pranali.rasal/.m2/repository/org/elasticsearch/client/elasticsearch-rest-client/7.6.2/elasticsearch-rest-client-7.6.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.RequestOptions$Builder
Following are the dependencies that i have added -
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-mapper-orm</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
<version>6.1.5.Final</version>
</dependency>
Let me know if I missing something.
This is all explained here: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#gettingstarted-framework-spring-boot-dependency-versions
Basically, Spring Boot is managing your dependencies, and it's forcing an older version of the Elasticsearch client. You need to force it back to the version Hibernate Search expects (a newer version, 7.16.x).
And just to clarify, this has nothing to do with the Elasticsearch server version that I've seen mentioned in other answers. This is strictly about your client.
This is probably due to incompatible version of the elasticsearch dependency. From https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#getting-started-compatibility it seems you need 7.10 or 7.16 but you have 7.6 dependency. Also check server version to be sure.
hibernate-search-backend-elasticsearch
is internally dependent on elasticsearch-rest-client-7.6.2.jar
And the method
org.elasticsearch.client.RequestOptions$Builder.setRequestConfig(Lorg/apache/http/client/config/RequestConfig;)Lorg/elasticsearch/client/RequestOptions$Builder;
it is trying to find is in later versions of low level client.
Temporary solution will be to exclude 7.6.2 and include latest version of elasticsearch-rest-client-7.6.2.jar -
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
<exclusions>
<exclusion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
</exclusion>
</exclusions>
</dependency>
and including,
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>7.10.0</version>
</dependency>
Since this is a temporary, I am not sure if this is reliable.
Please let me know in case there is a better solution.

Compatibility (as Spring boot Maven dependencies) between Elasticsearch 7.17, spring data elasticsearch and elasticsearch-rest-high-level-client

I have an Spring Boot + Elasticsearch application that had the now deprecated High Level Rest Client. I am trying to migrate the existing queries/methods to the new Java API Client but want to keep the HLRC for a bit (in case I break anything).
I seem to be running into a dependency problem that I'm not getting. I am currently getting the error java.lang.NoClassDefFoundError: org/elasticsearch/xcontent/ToXContentObject which I assume is due to compatibility issues. These are my current (relevent) dependencies:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.17.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>4.3.4</version>
</dependency>
The Elasticsearch is on 7.17 . As for the maven dependencies... I don't really know what versions to use so that it can run the old HLRC still while I test out newer code? (So I set the versions to the newest possible ones)
Edit infos:
current spring boot version is 2.2.8
before manually setting the version, org.elasticsearch.client was on 6.8.x
is my approach dumb and I should just scrap all the HLRC in favor of implementing/testing Java API Client?
Any pointers/fixes appreciated!
If I remember correctly it was in version 7.15 or 7.16 that Elasticsearch had a breaking change moving the xcontent classes to a different package. You cannot use Spring Data Elasticsearch 4.3.x with Elasticsearch 7.17

Adding spring-cloud-starter-sleuth dependency to a Spring-Boot App some of the Rest Doc test failing

I have a Spring-Boot 2.1.4 application with n-RestDoc tests for Flux controller.
Environment:
Spring-Boot 2.1.4
Junit 5.4.0
spring-restdocs-webtestclient
spring-webflux
If I add the spring-clout-starter-sleuth dependendcy to the app, some of the doc test fails in maven build.
Important on different environment different test classes fails with:
java.lang.IllegalStateException: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext#6516dd09 has been closed already ....
If run the failling test with maven -Dtest=OptDocTest than the test will not fail, also if a set (not all) test where specified.
Dependendcy
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>2.1.1.RELEASE</version>
<exclusions> <!-- exclude old spring versions -->
<exclusion>
<artifactId>*</artifactId>
<groupId> org.springframework.security</groupId>
</exclusion>
<exclusion>
<artifactId>spring-aop</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
All test looks simular
#ExtendWith({ RestDocumentationExtension.class, SpringExtension.class })
#AutoConfigureRestDocs("target/generated-snippets")
#SpringBootTest(//webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = { ArchimedesApplication.class })
class OptControllerDocTest {
#MockBean
private SrkConnector srkTConnector;
#Autowired
private ApplicationContext context;
private WebTestClient webTestClient;
#BeforeEach
void beforeEach(RestDocumentationContextProvider restDocumentation) {
this.webTestClient = WebTestClient.bindToApplicationContext(context)
.configureClient()
.filter(documentationConfiguration(restDocumentation))
.build();
}
#Test
void documentationTest() throws IOException {
this.webTestClient.post()
.uri("/opt")
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromObject(testRequest))
.exchange()
.expectStatus() // here the error occur
.isOk()
.expectBody() ...
}
All IT Test with a running Boot Application works correct.
I have no idea what goes wrong and why the AnnotationConfigReactiveWebServerApplicationContext is closed.
On a windows box the rest doc test for controller with a flux content fails on a linux box for controller with mono content.
It is solved if I fall back to spring-cloud-starter-sleuth in version 2.1.0.RELEASE and remove all exclusions.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
If I use version 2.1.1.RELEASE the error occur.
This has been raised as a bug in the sleuth github issue list github.com/spring-cloud/spring-cloud-sleuth/issues/1450
If you, as me, have had this situation in regard to junit tests, then I solved it by removing all annotations #DirtiesContext in every junit test class I had in my project.
Same issue I also met. I solved the issue by downgrade Sleuth to 2.0.3.RELEASE(2.1.0 also not work with me). Mine Spring Boot version is 2.0.5.RELEASE.
If 2.0.3 still not work for you, try more downgrade version from mvn repo

Perfomance Test and API test are not working together in same framework

#ptrthomas - I am able to perform API test and performance test separate in karate. But when I try to merge both in same framework, either of them stopped working.
Reason that I can see here - karate-core is sub dependency of both karate-junit4 and karate-apache. But both of them install different version of karate-core. Hence either have to exclude one of them. But wherever you exclude it, it will stop working. If you exclude it from karate-junit4 then API test will not work, if you exclude it from karate-apache or gatling, performance will not work.
Is there any common version for dependencies for both performance and API test (which run through junit) or any github location where someone might have integrated both in one project?
Below are the version that I am using -
UTF-8 1.8 3.6.0 0.9.0.RC3 2.2.4
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit4</artifactId>
<version>0.2.7</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-core</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>${karate.version}</version>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-gatling</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
Can someone please help here?
Just use this sample project: https://github.com/ptrthomas/karate-gatling-demo
This has the right dependencies set as a simple, stand-alone project and many teams have used and validated it.
If you are still facing issues, please follow the instructions here: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Ratpack 1.5.4 hystrix dependency cannot be resolved

I cannot compile my project that uses Ratpack 1.5.4 because there is a missing dependency to Hystrix 1.5.13 which cannot be resolved.
http://search.maven.org/#search%7Cga%7C1%7Cg%3A"com.netflix.hystrix"%20AND%20v%3A"1.5.13"
What is wrong here?
You can try excluding com.netflix:hystrix-core:1.5.13 from io.ratpack:ratpack-hystrix:1.5.4 and then you can add com.netflix:hystrix-core:1.5.12 directly to your pom.xml file, something like that:
<dependencies>
<dependency>
<groupId>io.ratpack</groupId>
<artifactId>ratpack-core</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>io.ratpack</groupId>
<artifactId>ratpack-hystrix</artifactId>
<version>1.5.4</version>
<exclusions>
<exclusion>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.12</version>
</dependency>
</dependencies>
I've tested this simple Maven Ratpack "Hello, World!" app https://github.com/wololock/ratpack-maven-example
It compiles in Travis without any issue - https://travis-ci.org/wololock/ratpack-maven-example (I have com.netflix:hystrix-core:1.5.13 in my local .m2 repository, so I wanted to use something with a clean local Maven repository like Travis CI)
I don't know if version 1.5.13 got rolled back or something like that. It can be found in MvnRepository.com https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-core/1.5.13 however it says that 1.5.12 is newer, even though it got released 2 months earlier.

Resources