Adding headers when using MockMvcTarget
See original GitHub issueWhen using SpringRestPactRunner
and MockMvcTarget
the @TargetRequestFilter
is never being invoked so I am not able to add headers. Is there another way? It looks like @TargetRequestFilter
only works when using HttpTarget
@RunWith(SpringRestPactRunner.class)
@Provider("provider-name")
@PactBroker
public class PactVerificationTest {
@Mock
private MockedService mockedService;
@InjectMocks
private MyController controller = new MyController(mockedService);
@TestTarget
public final MockMvcTarget target = new MockMvcTarget();
@Before
public void before() {
//initialize your mocks using your mocking framework
MockitoAnnotations.initMocks(this);
//configure the MockMvcTarget with your controller and controller advice
target.setControllers(controller);
target.setPrintRequestResponse(true);
}
// This block is never invoked
@TargetRequestFilter
public void requestFilter(HttpRequest request) {
request.addHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE);
}
@State({"person"})
public void verify() throws DownstreamServiceException {
target.setRunTimes(1);
// ... mockito mocks
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Adding headers when using MockMvcTarget · Issue #1339
I am getting below error while passing headers in @TargetRequestFilter public void requestFilter(MockHttpServletRequestBuilder request) ...
Read more >Developers - Adding headers when using MockMvcTarget -
I am getting below error while passing headers in @TargetRequestFilter public void requestFilter(MockHttpServletRequestBuilder request) {
Read more >How to add a header to a MockMvc request, depending on ...
How to post-process the request builder to automatically apply .header("Authorization", "Bearer foo") if the test is decorated with @WithJwt ?
Read more >Changelog | Pact Docs
da6efdec9 - GH-1632 invent default auth header with additional tests ... add support for request filters with MockMvcTarget #983 (Ronald ...
Read more >Add a Header to a Jersey SSE Client Request
In this tutorial, we'll see an easy way to send headers in Server-Sent Event (SSE) client requests using the Jersey Client API.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Version 4.0.5 has been released with this change
I’ve added support for request filters, but the parameter will be an instance of
MockHttpServletRequestBuilder
notHttpRequest