I have a Restful web service that I want to test. For this I use the Jersey Test Framework. In addition to the JAX-RS resources are also used websockets, which should also be tested. But when I tried to test websocket endpoint using Tyrus client I got 404 instead of the 101 code.
org.glassfish.tyrus.core.HandshakeException: Response code was not 101: 404.
In a case when I build the war file - websocket endpoint works fine and everything works as expected.
Can I test websockets with Jersey Test Framework?
Jersey 1.18
Related
I want to test an HTTP repository, and to do so I need to mock an HTTP server. I found this resource that goes over on one way to do so in Spring Boot, however, it's from 2020. I am not saying it's necessarily a bad or outdated approach, but I wanted to know if there is a more preferable or a Kotlin specific way to mock HTTP server now? Any help would be appreciated.
I would recommend using Wiremock to mock HTTP servers in your Spring Boot tests. Reasons:
well maintained and actively developed library (As of today: 5k stars on GitHub and last release April 29th 2022)
Spring boot has integration with this library (just add org.springframework.cloud:spring-cloud-contract-wiremock to your dependencies)
The team behind Spring Cloud Contract have created a library to support running WireMock using the “ambient” HTTP server. It also simplifies some aspects of configuration and eliminates some common issues that occur when running Spring Boot and WireMock together.
More info you can find here:
Spring Cloud Contract WireMock
Spring Boot Integration Tests With WireMock and JUnit 5
And here is GitHub repo with an example:
spring-boot-wiremock
I have an existing spring web application that uses spring-boot-starter-web; I have been planning to introduce reactive into this application. For a new feature that I am working, I have pulled in spring reactive web socket, configured and coded as specified in the spring doc; but unfortunately it does not work (got 404).
I tried a sample application and that works perfectly.
I used this one as my sample application.
I found that the sample application comes up on Netty, not on Tomcat. So I added spring-boot-starter-web to it, got the server to start in Tomcat and got the same 404 as I got in my application.
I also added TomcatRequestUpgradeStrategy unsuccessfully.
should I assume that spring-web and spring-webflux conflict with each other and I should go back to the regular websocket? Please advise.
Spring said that if both spring web and spring webflux present in the classpath; spring web kicks in and reactive websocket won't come up.
More details here: https://github.com/spring-projects/spring-boot/issues/23236
I have built a Springboot application which has a gRPC server as one of its dependencies. While running the integration test, I am able to use embedded Kafka, embedd MySQL etc using TestContainers, but how can I create an embedded gRPC server while running my integration test suite?
I have the .proto contract definition file. I would use Wiremock to mock the request and responses to the gRPC server, but I am unable to start the embedded gRPC server yet.
It will be really great if I could find some help here.
Come to think of it, my question can be generalized to starting a generic embedded HTTP server in Springboot integration test, using TestContainers or otherwise.
I had a similar problem with IT testing Java gRPC service integrations, as using InProcessServer is quite cumbersome and quite hard to use when you need to return different responses for different tests. Also when using it you cannot really test your Stub beans and their configuration, since you can't pass InProcessServer host as a variable.
For this purpose I've created a gRPC Java mocking tool gRPC Mock. It has two integration modules - one for spring-boot and one for JUnit5. It follows a similar DSL type of structure to HTTP mocking service WireMock for creating the stubs. You can visit the GitHub page for some examples.
We have a springboot application which is currently having gateway as Zuul 1. Our application is running in Springboot 2.0.0.M2. We are trying to upgrade our Zuul gateway to Zuul 2. We created a springboot application with Zuul 2 dependency and added webflux dependency to get Netty server. The server starts fine, but we are still unclear that how the springboot application will understand that this is a gateway and filters needs to be executed. Although we have created Routes filter, but the same is not getting invoked.
Thanks in advance,
Ron
if you go through the video "https://www.youtube.com/watch?v=9wocKqF15B8" at 18:00 from spring developers. They clearly stated that zuul2 is not going to be supported by the spring ecosystem. Also, the replacement of zuul2 (non-blocking calls) is a spring cloud gateway which is also non-blocking calls.
I have successfully integrated Spring and Jersey via Spring Boot' starter POMs, and I have a couple Jersey endpoints. Now I'd like to unit test the resources. I can't seem to get MockMvc working. I get a 404 error when attempting to GET a resource endpoint.
I know there is a Jersey test framework out there, but it appears to launch a server. I'm hoping to avoid "integration" type tests and keep this as simple as possible. Can I do this with MockMvc?
Unfortunately doesn't seem to be possible as MockMvc doesn't actually start servlet container.
You can use
RestTemplate to fire requests against server started on localhost. Here are examples from Spring Boot repo: Example 1 and Example 2.
Rest Assured library