Spring Boot Rest Client - How to test HTTP calls using @RestClientTest

  Рет қаралды 7,585

Dan Vega

Dan Vega

Күн бұрын

Пікірлер: 39
@assaduzzaman_dsi
@assaduzzaman_dsi 8 ай бұрын
Nice. Is it possible to make another video regarding how we do mock of APIs that are being protected OAuth2/OIDC and CSRF enabled?
@codemonkey
@codemonkey 4 ай бұрын
Yes. Please do this. Most endpoints need security. How to wire in these configurations is giving me fits. Please help. :)
@codemonkey
@codemonkey 4 ай бұрын
BTW, truly appreciate you taking the time to do this. :)
@andytael
@andytael 8 ай бұрын
Great information! Maybe do the same wit the JDBC Client and mocking it up?
@gallardofabian
@gallardofabian 8 ай бұрын
Nice video. Do You know a good plugin for intellij for owasp security analyzer? Maybe a series of videos with the top ten attacks
@codemonkey
@codemonkey 4 ай бұрын
When I run your tutorial WITHOUT adding any specific type of HTTP client, it still calls the actual service instead of the Mock Serivce. The test of course fails with expected 2 but had 100. Has something changed since this video was published?
@AlessiaCaraFans
@AlessiaCaraFans 5 ай бұрын
Heyyy ,pls do more videos about testing with more advanced topics , especially how to test when we have different requests at the same time for same method in a certain controller that talks to the client API , (also pls what is the name of plugin you use in intellij to autocomplete for you more than 1 line of code ) ^^ thankiiiiiiies from Morocco , you're amazing Mr Dan Vega
@JohnSmith-zs6ow
@JohnSmith-zs6ow 2 ай бұрын
Just downloaded the tutorial (with no changes) and the Test failed with 100 replies - indicating that the live server was being contacted (not the mocked server). A couple of other people seem to have had the same issue. Has there been a fix for this issue since the video was published? I commented out the JdkClientHttpRequestFactory as suggested in the video - which works - but isn't much use when your other videos recommend this substitution - meaning that I can't test the code I'm writing.
@DanVega
@DanVega 2 ай бұрын
This is a known issue you can follow here for updates github.com/spring-projects/spring-boot/issues/38832
@DanVega
@DanVega 2 ай бұрын
There is a workaround in that issue if you're interested.
@JohnSmith-zs6ow
@JohnSmith-zs6ow 2 ай бұрын
Excellent. Thank You.
@mr_raviparihar609
@mr_raviparihar609 8 ай бұрын
Much informative
@OneClickLabs
@OneClickLabs 4 ай бұрын
Could you point us to an example where the RestClient is invoking an API with HTTP method as POST method instead of GET?
@OneClickLabs
@OneClickLabs 7 ай бұрын
Very useful, thanks.
@DanVega
@DanVega 7 ай бұрын
Glad it was helpful!
@Jallallalla
@Jallallalla 5 ай бұрын
This is great. But I am stuck when I have two rest clients in my application. The documentation suggests I should use the MockServerRestClientCustomizer. This gets rid of the error messages and in the customizer I see my the mockservers for each of my clients. But I am stuck at how to get the correct server for each client. You can get a server out of the customizer with getServer(), but this takes a RestClient.Builder(??). I can get the "first" server and the "second" server out of the HashMap that the customizer provides, but the tests are too flaky. Sometimes client A is the first entry and sometimes client B is the first entry. Can you help me?
@leonardoncintra
@leonardoncintra 2 ай бұрын
How to test 404, 401 and 500 http status ?
@nickcruz4811
@nickcruz4811 8 ай бұрын
Where do you usually use the @Component? I know the @Service is for the business layers, what im quite confused with the correct usage for @Component.
@brunokingz
@brunokingz 7 ай бұрын
You can use @Component with anything you want to inject
@calintamas7576
@calintamas7576 8 ай бұрын
Mersi Dan, Cand o sa vii la Cluj?
@MustafaKanzii
@MustafaKanzii 4 ай бұрын
what is theme of dan vega ıs there any one knows it
@stevenrichman7101
@stevenrichman7101 7 ай бұрын
Hi, what IDE is used in this video?
@nico-s29
@nico-s29 6 ай бұрын
IntelliJ IDEA Ultimate
@BabaykaMoscow
@BabaykaMoscow 2 ай бұрын
Could you, please, make a video on how to setup RestClient to use proxy with and without authentication?
@marba6923
@marba6923 8 ай бұрын
Hi Dan. Nice video. I have one question. When I write tests using give/when/then sections I put the mock configuration in the 'given' section. In the 'when' section there is the execution of the tested objected only. What do you think about that?
@DanVega
@DanVega 8 ай бұрын
You are correct and I should have done the actual execution (findAll()) in the when block. Thank you for noticing and the feedback.
@codemonkey
@codemonkey 4 ай бұрын
Another approach is Arrange, Act, Assert. In this approach the given and when in the video would be part of the Arrange block. The Act block would be the call that executes the service. The asserts would then fall into the assert block, of course. :)
@erfannavab9805
@erfannavab9805 8 ай бұрын
It was so helpful. Thanks Dan
@blaaarp4u
@blaaarp4u 8 ай бұрын
why not to use "REST Assured" lib?
@ajayantony4412
@ajayantony4412 6 ай бұрын
Thank you Dan!
@AlexWen-h1r
@AlexWen-h1r 7 ай бұрын
hi Dan, i got a question, what if i have configured two rest client in a configuration file, and i want to test one of them, how should i do
@DanVega
@DanVega 7 ай бұрын
If you have 2 you should give the bean a specific name, so you can just ask for them by name @Qualifier("todoRestClient")
@nico-s29
@nico-s29 6 ай бұрын
@Dan one follow up question what would you recommend when i want to test those clients with @RestClientTest but the rest clients also use Configuration Properties so simply with rest client test i get a bean not found exception for the Config-Properties
@praneethjayawardena7883
@praneethjayawardena7883 8 ай бұрын
Great really helpful ❤
@dariuszchmiea3567
@dariuszchmiea3567 5 ай бұрын
@RestClientTest(PostClient.class) would be more usefull if you could create rest client with properties files rather than put constant url ... public PostClient(RestClient.Builder builder, RestClientProperties properties) { this.restClient = builder .baseUrl(properties.url()) .build(); } @RestClientTest(PostClient.class) @ImportAutoConfiguration(RestClientProperties.class) Does not work and produce: No qualifying bean of type 'java.lang.String' available ...
Spring по верхам: Тестирование REST-сервиса
44:32
Уголок сельского джависта
Рет қаралды 14 М.
Apple peeling hack @scottsreality
00:37
_vector_
Рет қаралды 132 МЛН
Man Mocks Wife's Exercise Routine, Faces Embarrassment at Work #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 5 МЛН
Новый уровень твоей сосиски
00:33
Кушать Хочу
Рет қаралды 4,8 МЛН
Spring Boot Rest Client Interceptors
14:00
Dan Vega
Рет қаралды 10 М.
How to call a Java REST API using JDK Http Client
22:23
Dan Vega
Рет қаралды 8 М.
Laravel vs Rails for Javascript developers
19:50
Sam Lewis
Рет қаралды 2,5 М.
Testcontainers и Spring Boot 3.1
19:47
Уголок сельского джависта
Рет қаралды 8 М.
Thoughts About Unit Testing | Prime Reacts
11:21
ThePrimeTime
Рет қаралды 225 М.
5 Common Mistakes Spring Developers Make
18:06
Dan Vega
Рет қаралды 18 М.
The Only Database Abstraction You Need | Prime Reacts
21:42
ThePrimeTime
Рет қаралды 210 М.
Apple peeling hack @scottsreality
00:37
_vector_
Рет қаралды 132 МЛН