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

Поделиться
HTML-код
  • Опубликовано: 8 июн 2024
  • In this tutorial you will learn how to test Rest Client calls in Spring Boot using the @RestClientTest annotation.
    🔗Resources & Links mentioned in this video:
    GitHub Repository: github.com/danvega/rest-clien...
    👋🏻Connect with me:
    Website: www.danvega.dev
    Twitter: / therealdanvega
    Github: github.com/danvega
    LinkedIn: / danvega
    Newsletter: www.danvega.dev/newsletter
    SUBSCRIBE TO MY CHANNEL: bit.ly/2re4GH0 ❤️
  • НаукаНаука

Комментарии • 34

  • @assaduzzaman_dsi
    @assaduzzaman_dsi 4 месяца назад +11

    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 Месяц назад

      Yes. Please do this. Most endpoints need security. How to wire in these configurations is giving me fits. Please help. :)

  • @codemonkey
    @codemonkey Месяц назад

    BTW, truly appreciate you taking the time to do this. :)

  • @erfannavab9805
    @erfannavab9805 4 месяца назад +1

    It was so helpful. Thanks Dan

  • @ajayantony4412
    @ajayantony4412 3 месяца назад

    Thank you Dan!

  • @mr_raviparihar609
    @mr_raviparihar609 4 месяца назад

    Much informative

  • @OneClickLabs
    @OneClickLabs 4 месяца назад

    Very useful, thanks.

    • @DanVega
      @DanVega  4 месяца назад

      Glad it was helpful!

  • @andytael
    @andytael 4 месяца назад +1

    Great information! Maybe do the same wit the JDBC Client and mocking it up?

  • @peshutanpavri1599
    @peshutanpavri1599 3 месяца назад

    This is great, thank you so much for this. When we are doing the Integration test and we are using @SpringBootTest, we just use the regular rest client to test my own controllers ?

  • @AlessiaCaraFans
    @AlessiaCaraFans Месяц назад

    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

  • @gallardofabian
    @gallardofabian 4 месяца назад +1

    Nice video. Do You know a good plugin for intellij for owasp security analyzer? Maybe a series of videos with the top ten attacks

  • @marba6923
    @marba6923 4 месяца назад +2

    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  4 месяца назад +1

      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 Месяц назад

      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. :)

  • @praneethjayawardena7883
    @praneethjayawardena7883 4 месяца назад +1

    Great really helpful ❤

  • @calintamas7576
    @calintamas7576 4 месяца назад

    Mersi Dan,
    Cand o sa vii la Cluj?

  • @OneClickLabs
    @OneClickLabs Месяц назад

    Could you point us to an example where the RestClient is invoking an API with HTTP method as POST method instead of GET?

  • @nickcruz4811
    @nickcruz4811 4 месяца назад

    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 4 месяца назад

      You can use @Component with anything you want to inject

  • @Jallallalla
    @Jallallalla Месяц назад

    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?

  • @codemonkey
    @codemonkey Месяц назад

    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?

  • @user-uq4sq6sq6z
    @user-uq4sq6sq6z 4 месяца назад

    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  4 месяца назад

      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 3 месяца назад

      @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

  • @stevenrichman7101
    @stevenrichman7101 3 месяца назад

    Hi, what IDE is used in this video?

    • @nico-s29
      @nico-s29 3 месяца назад +1

      IntelliJ IDEA Ultimate

  • @blaaarp4u
    @blaaarp4u 4 месяца назад

    why not to use "REST Assured" lib?

  • @MustafaKanzii
    @MustafaKanzii 28 дней назад

    what is theme of dan vega ıs there any one knows it

  • @dariuszchmiea3567
    @dariuszchmiea3567 2 месяца назад

    @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 ...