Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that RouterFunction beans in the context cannot be used with @WebFluxTest #10683

Closed
wilkinsona opened this issue Oct 18, 2017 · 9 comments
Labels
type: documentation A documentation update
Milestone

Comments

@wilkinsona
Copy link
Member

No description provided.

@wilkinsona wilkinsona added this to the 2.0.0.RC1 milestone Oct 18, 2017
@snicoll
Copy link
Member

snicoll commented Nov 10, 2017

@wilkinsona those are usually defined within a @Configuration class so I am wondering how we would detect that.

@wilkinsona
Copy link
Member Author

wilkinsona commented Nov 11, 2017

And now that you've asked, I'm wondering too. Without support in the Framework for filtering the beans produced by a configuration class that's similar to the filtering offered for component scanning, I can't think how we can do it.

@snicoll
Copy link
Member

snicoll commented Nov 12, 2017

It's worse than that even. The router is linked to one or more handlers. I think a good match in that world would be to split routers per area and the slice is the router.

But even if you have that you need to add the handler beans. And those are regular components with methods in them. So we would have to scan the injection point upfront to add them. Sounds quite complicated.

@snicoll snicoll removed this from the 2.0.0.M7 milestone Nov 14, 2017
@snicoll
Copy link
Member

snicoll commented Nov 14, 2017

@wilkinsona removing from the 2.0 bucket as I don't see a way to implement this at the moment. Worth considering in par with the "programmatic/explicit configuration"

@kizux
Copy link

kizux commented Jan 27, 2018

Hello there !
Any news about this point ? I am not using controller but new functional endpoints. Will be really awesome to use WebFluxTest.
Thank you !

@wilkinsona
Copy link
Member Author

No news at this time (this issue would have been updated if there was). As things stand, we don't think it's possible to do what we'd like, certainly not without some changes in Spring Framework and maybe not at all.

@kizux
Copy link

kizux commented Feb 3, 2018

If it can help people who are using functional endpoints as I do. I so finally test them by this way :

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {RouteConfiguration.class, UserHandler.class})
@WebFluxTest
public class UserHandlerTest
{
    @Autowired
    private ApplicationContext context;
    @MockBean(name="userService")
    private UserService userService;
    private WebTestClient testClient;

    @Before
    public void setUp()
    {
        testClient = WebTestClient.bindToApplicationContext(context).build();
    }

    ...

The WebFluxTest annotation keep avoid to load other things than RestController and I customize the ContextConfiguration to load my functional endpoints.

@philwebb philwebb added theme: testing Issues related to testing and removed priority: normal labels Mar 21, 2018
@philwebb philwebb changed the title Include RouterFunction beans in the context when using @WebFluxTest Document RouterFunction beans in the context cannot be used with @WebFluxTest Mar 21, 2018
@philwebb philwebb added type: documentation A documentation update and removed theme: testing Issues related to testing labels Mar 21, 2018
@philwebb philwebb added this to the 2.0.x milestone Mar 21, 2018
@philwebb philwebb removed the type: enhancement A general enhancement label Mar 21, 2018
@wilkinsona wilkinsona changed the title Document RouterFunction beans in the context cannot be used with @WebFluxTest Document that RouterFunction beans in the context cannot be used with @WebFluxTest Mar 22, 2018
@mbhave mbhave modified the milestones: 2.0.x, 2.0.1 Mar 27, 2018
@mbhave mbhave closed this as completed in db7d477 Mar 27, 2018
@mythicallage
Copy link

mythicallage commented Feb 28, 2024

Hello there!

I tried the below and It works for me.

@WebFluxTest(controllers = {RouteConfiguration.class, UserHandler.class})
public class UserHandlerTest {
   @Autowired
   private WebTestClient testClient;

   @MockBean(name="userService")
   private UserService userService;
...
}

@NadChel
Copy link

NadChel commented Mar 15, 2024

Hello there!

I tried the below and It works for me.

@WebFluxTest(controllers = {RouteConfiguration.class, UserHandler.class})
public class UserHandlerTest {
   @Autowired
   private WebTestClient testClient;

   @MockBean(name="userService")
   private UserService userService;
...
}

I confirm. My Boot is at 3.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

7 participants