Thanks Joe, that does help. Any idea how to setup a port for the
GrizzlyWebTestContainer? I'm getting:
javax.ws.rs.ProcessingException: java.net.ConnectException: Connection
refused (Connection refused)
When:
URI uri = builder.setScheme("http://")
.setHost("localhost")
.setPath("/inquiries/1/q")
.build();
Response response = resourceMock.client()
.target(uri)
.request()
.get();
Here's the setup for my test rule:
@ClassRule
public static final ResourceTestRule resourceMock =
ResourceTestRule.builder()
.addResource(new InquiryResource(mockDao, mockSearchDao,
findApiConfiguration, mockInquiryCreateSvc))
.addProvider(new AuthDynamicFeature(mockFilter))
.addProvider(RolesAllowedDynamicFeature.class)
.addProvider(new AuthValueFactoryProvider.Binder<>(HelixUser.class))
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
.build();
On Thursday, May 28, 2020 at 5:07:56 PM UTC-6, Joe Barnett wrote:
>
> Have you tried using the grizzly test container per
> https://www.dropwizard.io/en/latest/manual/testing.html#test-containers
> ? That should, I believe, get you past the injection source issue but may
> result in a null user being injected (not 100% sure on exactly what
> happens, as we have the following set up as well as the changed test
> container):
>
> To get a user injected, you'll need to register an AuthDynamicFeature as a
> provider per
> https://www.dropwizard.io/en/latest/manual/auth.html#testing-protected-resources
>
> . something along the lines of:
>
> ResourceTestRule.builder()
> .addResource(new InquiryResource(...))
> .addProvider(new AuthDynamicFeature(mockAuthFilter)) // <-- may be
> able to use the auth filter you're registering for your application
> directly, depending on how integration-y the test is
> .addProvider(RolesAllowedDynamicFeature.class)
> .addProvider(new authValueFactoryProvider.Binder<>(User.class))
> .setTestContainerFactory(new GrizzlyWebTestContainerFactory())
> .build()
>
> Hope that helps,
> -Joe
>
> On Thursday, May 28, 2020 at 2:39:04 PM UTC-7, jeremiah adams wrote:
>>
>> I am having issues using io.dropwizard.testing.junit.ResourceTestRule in
>> tandem with @Auth decorations associated with io.dropwizard.auth.Auth.
>>
>> I am using the @Auth decoration to fetch the Principal in my route
>> handlers. I am able to get our Okta roles in this manner for access
>> control. This all works fine when standing the AP and execute it as a jar.
>> However, I’m having problems when I attempt to UnitTest my route handlers.
>>
>> Logs include this information:
>>
>> ERROR [2020-05-28 15:23:11,770] org.glassfish.jersey.internal.Errors:
>> Following issues have been detected:
>>
>> WARNING: No injection source found for a parameter of type public
>> javax.ws.rs.core.Response
>> com.helixeducation.ipa.admin.resources.InquiryResource.searchInquiries(com.helixeducation.components.auth.HelixUser,com.helixeducation.components.domain.InquirySearch)
>>
>> at index 0.
>>
>> The parameter at index 0 is my Principal. Here is the method declaration:
>>
>> @POST
>>
>> @Timed
>>
>> @Path("/search")
>>
>> @Consumes(MediaType.APPLICATION_JSON)
>>
>> @PermitAll
>>
>> public Response searchInquiries(@Auth HelixUser user,
>>
>> @Valid @NotNull InquirySearch inquirySearch) {
>>
>> // check if user has an appropriate role or return 401.
>>
>> // implementation Omitted.
>>
>> }
>>
>> Here’s the declaration of my TestRule:
>>
>> @ClassRule
>>
>> public static final ResourceTestRule resourceMock =
>> ResourceTestRule.builder()
>>
>> .addResource(new InquiryResource(mockDao, mockSearchDao,
>> findApiConfiguration, mockInquiryCreateSvc))
>>
>> .build();
>>
>>
>>
>> How do I get the TestRule to inject a mocked Principal? I think if I can
>> get past that issue, I can get unblocked.
>>
>> Regards,
>>
>> - jeremiah
>>
>
--
You received this message because you are subscribed to the Google Groups
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/dropwizard-user/ebe7ec9f-30b0-4b21-b5b7-a65385fb42d1%40googlegroups.com.