2

I have added a new querydsl controller method in my spring (not spring boot) application.

@GetMapping("/watcher")
@ResponseBody
public List<Watcher> getWatchers(final Predicate predicate) {
  return repo.findAll(predicate);
}

I have also added the following annotation in my WebMvcConfigurer implementation:

@EnableSpringDataWebSupport

The application works with this new endpoint as intented. I would now like to add a Spring IT test to test this new feature.

This is the test:

@Test
public void test() {
  mvc.perform(get("/watcher"));
}

The test class contains the following annotations:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringITConfig.class)
@WebAppConfiguration

Other tests are present in the same class, and perform() works for those, but it's the first time I'm adding a test to a querydsl controller.

The test fails with No primary or default constructor found for interface com.querydsl.core.types.Predicate.

I tried adding the annotation @EnableSpringDataWebSupport to my test, but it doesn't change anything.

What am I missing ?

Thanks

Gaga3
  • 21
  • 1
  • Have you checked this post https://stackoverflow.com/questions/50679551/junit-no-primary-or-default-constructor-found-for-interface-com-querydsl-core-t ?? – Seba López Aug 26 '20 at 10:27
  • Yes, it says to add the annotation `EnableSpringDataWebSupport` to the test as well, which I did as mentioned in my question, but it doesn't change the outcome – Gaga3 Aug 26 '20 at 10:36

1 Answers1

0

Try removing your @ContextConfiguration and replace it with @SpringApplicationConfiguration(classes = YOUR_MAIN_APP_CLASS) to bootstrap all the needed querydsl repositories, and also the correct jackson mapper for your predicate class.

Alex Ciocan
  • 2,272
  • 14
  • 20