Search in sources :

Example 6 with RequestInfo

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);
}
Also used : Documentation(com.liferay.apio.architect.documentation.Documentation) DocumentationWriter(com.liferay.apio.architect.writer.DocumentationWriter) Gson(com.google.gson.Gson) RequestInfo(com.liferay.apio.architect.request.RequestInfo) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo)

Example 7 with RequestInfo

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);
}
Also used : Path(com.liferay.apio.architect.uri.Path) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) MockFormCreator.createForm(com.liferay.apio.architect.test.util.form.MockFormCreator.createForm) RequestInfo(com.liferay.apio.architect.request.RequestInfo) Collection(java.util.Collection) PageItems(com.liferay.apio.architect.pagination.PageItems) Path(com.liferay.apio.architect.uri.Path) Operation(com.liferay.apio.architect.operation.Operation) PageMessageMapper(com.liferay.apio.architect.message.json.PageMessageMapper) List(java.util.List) PageWriter(com.liferay.apio.architect.writer.PageWriter) HttpHeaders(javax.ws.rs.core.HttpHeaders) Pagination(com.liferay.apio.architect.pagination.Pagination) Gson(com.google.gson.Gson) RootModel(com.liferay.apio.architect.test.util.model.RootModel) Page(com.liferay.apio.architect.pagination.Page) POST(com.liferay.apio.architect.operation.Method.POST) Optional(java.util.Optional) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo) Collections(java.util.Collections) RootModel(com.liferay.apio.architect.test.util.model.RootModel) Gson(com.google.gson.Gson) Page(com.liferay.apio.architect.pagination.Page) Operation(com.liferay.apio.architect.operation.Operation) RequestInfo(com.liferay.apio.architect.request.RequestInfo) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo) Pagination(com.liferay.apio.architect.pagination.Pagination) PageItems(com.liferay.apio.architect.pagination.PageItems)

Example 8 with RequestInfo

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);
}
Also used : Gson(com.google.gson.Gson) RequestInfo(com.liferay.apio.architect.request.RequestInfo) MockWriterUtil.getRequestInfo(com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo) FormWriter(com.liferay.apio.architect.writer.FormWriter)

Aggregations

RequestInfo (com.liferay.apio.architect.request.RequestInfo)8 Optional (java.util.Optional)6 HttpHeaders (javax.ws.rs.core.HttpHeaders)6 Collections (java.util.Collections)5 Gson (com.google.gson.Gson)4 Language (com.liferay.apio.architect.language.Language)4 Embedded (com.liferay.apio.architect.response.control.Embedded)4 Fields (com.liferay.apio.architect.response.control.Fields)4 MockWriterUtil.getRequestInfo (com.liferay.apio.architect.test.util.writer.MockWriterUtil.getRequestInfo)4 ServerURL (com.liferay.apio.architect.url.ServerURL)4 ProviderManager (com.liferay.apio.architect.wiring.osgi.manager.ProviderManager)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 PrintWriter (java.io.PrintWriter)4 Annotation (java.lang.annotation.Annotation)4 Type (java.lang.reflect.Type)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Locale (java.util.Locale)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4