I'm using spring-data-rest on top of spring-data-jpa.
I'm writing integration tests to test my SDR API using MockMvc and an in-memory testing database.
Until now, I concentrated on the GETs, but now I'm looking at creating tests for the POST, PUT and PATCH requests and it looks like I'll have to write my own JSON generator (perhaps based on GSON) in order to get stuff like URLs for related entities e.g.
public class ForecastEntity {
@RestResource
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "UNITID", referencedColumnName = "ID")
private UnitEntity unit;
}
and in my tests I would build up an entity with parent / children:
ForecastEntity forecast = new ForecastEntity();
forecast.setTitle("test-forecast");
forecast.setUnit(new UnitEntity("test-unit"));
should generate JSON like this:
{
"title" : "test-forecast",
"unit" : "http://localhost/units/test-unit"
}
Is there functionality in SDR that I can use to produce JSON from manually initialized entities in tests?