I have a RepositoryRestController
that exposes resources for some persistent entities.
I have a method on my controller that takes a PersistentEnt
I ended up doing a slightly hacky solution here:
PersistentEntityResourceAssembler
from the controller method.@Autowired RepositoryEntityLinks
to the controller, on which I call linkToSingleResource
to create the links as needed.I added an @MockBean RepositoryEntityLinks
to my test class, and configured the mocking to return something sensible:
given(repositoryEntityLinks.linkToSingleResource(any(Identifiable.class)))
.willAnswer(invocation -> {
final Identifiable identifiable = (Identifiable) invocation.getArguments()[0];
return new Link("/data/entity/" + identifiable.getId().toString());
});
It's far from ideal - I'd love to know if there's a way of getting just enough of the data layer up that I can depend on PersistentEntityResourceAssembler
.
I ended up for now with:
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
The downsite of it is that the test would start the full Spring application context (but without the server).