-
Notifications
You must be signed in to change notification settings - Fork 13
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
Usage with ResourceTestRule #30
Comments
Looks like doing: @ClassRule
public static final ResourceTestRule resources = ResourceTestRule.builder()
.addResource(new UserResource(store))
.addProvider(new Pac4JValueFactoryProvider.Binder()).build(); fixes the above error, but now outputs:
I have |
@ClassRule
public static final ResourceTestRule resources = ResourceTestRule.builder()
.addResource(new UserResource(store))
.addProvider(new JaxRsConfigProvider(new Config()))
.addProvider(new JaxRsContextFactoryProvider())
.addProvider(new Pac4JValueFactoryProvider.Binder()).build(); is looking more promising:
|
There is no easy solution to this question, because you could want to mock the CommonProfile for your test… This is what I do for example: https://gitlab.com/linagora/petals-cockpit/blob/master/backend/src/test/java/org/ow2/petals/cockpit/server/resources/AbstractCockpitResourceTest.java#L136 with https://gitlab.com/linagora/petals-cockpit/blob/master/backend/src/test/java/org/ow2/petals/cockpit/server/mocks/MockProfileParamValueFactoryProvider.java That's not great at all ^^ I will try to make something easier to use at least :) |
That sounds great @victornoel. I was also fumbling around with Grizzle test as well but wasn't having much luck. Thanks for the help. |
np, let's keep this open until we have a cleaner solution to easily use ResourceTestRule :) |
@jplock I've committed some changes in jax-rs-pac4j to make this easier to use. Basically you can now pass some mock profile and profile manager to the The rest of the providers should be the same as those used in the dropwizard bundle. Don't hesitate to tell me if you think we need more than that :) |
This seemed to be the minimum amount of code for my test to pass. Grizzly definitely seems to be required. Thanks for the help! private static Config getConfig() {
final Authenticator<UsernamePasswordCredentials> auth = new SimpleTestUsernamePasswordAuthenticator();
final DirectBasicAuthClient basicAuth = new DirectBasicAuthClient(auth);
final Clients clients = new Clients(basicAuth);
final JaxRsConfig config = new JaxRsConfig();
config.setClients(clients);
return config;
}
@ClassRule
public static final ResourceTestRule resources = ResourceTestRule.builder()
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
.addResource(new UserResource(store))
.addProvider(new JaxRsConfigProvider(getConfig()))
.addProvider(new Pac4JValueFactoryProvider.Binder(new CommonProfile()))
.build(); |
Yes, that's seem similar to what I have ! And yes, you are right, it won't work without grizzly I think! I don't remember what was the explanation, but I think it is acceptable to use grizzly :) |
Hi Victor. In the above example, I saw that you injected CommonProfile to your resource by addProvider. |
@lucianonet that's how I do it: https://gitlab.com/linagora/petals-cockpit/blob/f9f7f44235a9c84f4dc0c45ac9e2be6d2619bba8/backend/src/test/java/org/ow2/petals/cockpit/server/rules/CockpitResourceRule.java Basically I have a class member of my test class that contain the profile I want, and then the |
Are there any examples of using Dropwizard's ResourceTestRule with this module?
I'm getting a:
error when trying to test my resource.
The text was updated successfully, but these errors were encountered: