Hello everyone. Searched a lot and was not able t...
# pact-jvm
j
Hello everyone. Searched a lot and was not able to find a solution, so I am asking help here. I am trying to write the code for the provider side of contract in java (
au.com.dius.pact.provider:spring:4.3.16
). A have a few tests working, but when I try to test a controller that has a
Pageable
as a parameter, I get.
Copy code
1.1) Request processing failed; nested exception is java.lang.IllegalStateException: No primary or single unique constructor found for interface org.springframework.data.domain.Pageable
I am already using the
messageConverters
of the
MockMvcTarget
but I could not find an argument resolver of sorts. One solution would be to break down the pageable in the values, but I was trying to avoid that. Any ideas on how to fix this error with pageable as a parameter? (code in the first comments of the thread)
controller code
Copy code
@GetMapping("/integrations-config/search")
    public CollectionModel<?> search(@RequestParam String param1,
                                     @RequestParam String param2,
                                     Pageable pageable) {
        return  //some logic
    }
controller test
Copy code
@RunWith(SpringRestPactRunner.class)
@Provider("my-service")
@PactBroker(url = "<https://pact-brokers.tools.mydomain.com>")
@PactFilter(value = "^\\/integrations-config\\/.*", filter = InteractionFilter.ByRequestPath.class)
public class SampleControllerProviderContractTest {

    @TestTarget
    public final MockMvcTarget target = new MockMvcTarget();

    @Mock
    private IntegrationConfigService integrationConfigService;

    @Mock
    private IntegrationConfigRepository integrationConfigRepository;

    @InjectMocks
    private IntegrationConfigController integrationConfigController = new IntegrationConfigController(integrationConfigRepository);

    @Before
    public void before() {
        MockitoAnnotations.initMocks(this);
        target.setControllers(integrationConfigController);
    }

    @State("my state")
    public void stateForX() {
        //my mocks
    }
}
For anyone looking for the solution, I found it and posted here.