use of com.yahoo.elide.swagger.property.Datum in project elide by yahoo.
the class SwaggerBuilderTest method verifyDatum.
/**
* Verifies that the given property is of type 'Datum' containing a reference to the given model.
* @param property The property to check
* @param refTypeName The model name
* @param included Whether or not the datum should have an 'included' section.
*/
private void verifyDatum(Property property, String refTypeName, boolean included) {
assertTrue((property instanceof Datum));
RefProperty ref = (RefProperty) ((Datum) property).getProperties().get("data");
assertEquals("#/definitions/" + refTypeName, ref.get$ref());
if (included) {
assertNotNull(((Datum) property).getProperties().get("included"));
}
}
use of com.yahoo.elide.swagger.property.Datum in project elide by yahoo.
the class SwaggerBuilderTest method verifyDatum.
/**
* Verifies that the given model is of type 'Datum' containing a reference to the given model name.
* @param model The model to check
* @param refTypeName The model name to check
*/
private void verifyDatum(Model model, String refTypeName) {
assertTrue((model instanceof com.yahoo.elide.swagger.model.Datum));
RefProperty ref = (RefProperty) model.getProperties().get("data");
assertEquals("#/definitions/" + refTypeName, ref.get$ref());
}
use of com.yahoo.elide.swagger.property.Datum in project elide by yahoo.
the class SwaggerBuilderTest method testOperationRequestBodies.
@Test
public void testOperationRequestBodies() throws Exception {
/* These take a datum pointing to a resource */
Operation[] resourceOps = { swagger.getPaths().get("/book").getPost(), swagger.getPaths().get("/book/{bookId}").getPatch() };
for (Operation op : resourceOps) {
BodyParameter bodyParam = (BodyParameter) op.getParameters().stream().filter((param) -> param.getIn().equals("body")).findFirst().get();
assertNotNull(bodyParam);
verifyDatum(bodyParam.getSchema(), "book");
}
/* These don't take any params */
Operation[] noParamOps = { swagger.getPaths().get("/book").getGet(), swagger.getPaths().get("/book/{bookId}").getDelete(), swagger.getPaths().get("/book/{bookId}").getGet() };
for (Operation op : noParamOps) {
Optional<Parameter> bodyParam = op.getParameters().stream().filter((param) -> param.getIn().equals("body")).findFirst();
assertFalse(bodyParam.isPresent());
}
/* These take a 'data' of relationships */
Operation[] relationshipOps = { swagger.getPaths().get("/book/{bookId}/relationships/authors").getPatch(), swagger.getPaths().get("/book/{bookId}/relationships/authors").getDelete(), swagger.getPaths().get("/book/{bookId}/relationships/authors").getPost() };
for (Operation op : relationshipOps) {
BodyParameter bodyParam = (BodyParameter) op.getParameters().stream().filter((param) -> param.getIn().equals("body")).findFirst().get();
assertNotNull(bodyParam);
verifyDataRelationship(bodyParam.getSchema(), "author");
}
}
Aggregations