use of com.liferay.apio.architect.request.RequestInfo in project com-liferay-apio-architect by liferay.
the class MockDocumentationWriter method write.
/**
* Writes a {@link Documentation} object.
*
* @param httpHeaders the request's HTTP headers
* @param documentationMessageMapper the {@code DocumentationMessageMapper}
* to use for writing the JSON object
*/
public static JsonObject write(HttpHeaders httpHeaders, DocumentationMessageMapper documentationMessageMapper) {
RequestInfo requestInfo = getRequestInfo(httpHeaders);
Documentation documentation = new Documentation(__ -> Optional.of(() -> "Title"), __ -> Optional.of(() -> "Description"));
DocumentationWriter documentationWriter = DocumentationWriter.create(builder -> builder.documentation(documentation).documentationMessageMapper(documentationMessageMapper).requestInfo(requestInfo).build());
return new Gson().fromJson(documentationWriter.write(), JsonObject.class);
}
use of com.liferay.apio.architect.request.RequestInfo in project com-liferay-apio-architect by liferay.
the class MockPageWriter method write.
/**
* Writes a Collection of {@link RootModel}, with the hierarchy of embedded
* models and multiple fields.
*
* @param httpHeaders the request's {@code HttpHeaders}
* @param pageMessageMapper the {@link PageMessageMapper} to use for writing
* the JSON object
*/
public static JsonObject write(HttpHeaders httpHeaders, PageMessageMapper<RootModel> pageMessageMapper) {
RequestInfo requestInfo = getRequestInfo(httpHeaders);
Collection<RootModel> items = Arrays.asList(() -> "1", () -> "2", () -> "3");
PageItems<RootModel> pageItems = new PageItems<>(items, 9);
Pagination pagination = new Pagination(3, 2);
Path path = new Path("name", "id");
List<Operation> operations = Collections.singletonList(new Operation(createForm("c", "p"), POST, "create-operation"));
Page<RootModel> page = new Page<>("root", pageItems, pagination, path, operations);
PageWriter<RootModel> pageWriter = PageWriter.create(builder -> builder.page(page).pageMessageMapper(pageMessageMapper).pathFunction(MockWriterUtil::identifierToPath).resourceNameFunction(__ -> Optional.of("models")).representorFunction(MockWriterUtil::getRepresentorOptional).requestInfo(requestInfo).singleModelFunction(MockWriterUtil::getSingleModel).build());
return new Gson().fromJson(pageWriter.write(), JsonObject.class);
}
use of com.liferay.apio.architect.request.RequestInfo in project com-liferay-apio-architect by liferay.
the class MockFormWriter method write.
/**
* Writes a {@link com.liferay.apio.architect.form.Form} object.
*
* @param httpHeaders the request's HTTP headers
* @param formMessageMapper the {@code FormMessageMapper} to use for writing
* the JSON object
*/
public static JsonObject write(HttpHeaders httpHeaders, FormMessageMapper formMessageMapper) {
RequestInfo requestInfo = getRequestInfo(httpHeaders);
FormWriter formWriter = FormWriter.create(builder -> builder.form(MockFormCreator.createForm("f", "s")).formMessageMapper(formMessageMapper).requestInfo(requestInfo).build());
return new Gson().fromJson(formWriter.write(), JsonObject.class);
}
Aggregations