use of com.liferay.apio.architect.operation.Method.POST in project com-liferay-apio-architect by liferay.
the class CollectionRoutesTest method _testCollectionRoutes.
private void _testCollectionRoutes(CollectionRoutes<String> collectionRoutes) {
Optional<CollectionRoutes<String>> optional = Optional.of(collectionRoutes);
Map map = optional.flatMap(CollectionRoutes::getFormOptional).map(form -> {
assertThat(form.id, is("c/name"));
return (Map) form.get(_body);
}).get();
Optional<String> valueOptional = _body.getValueOptional("key");
assertThat(map.get("key"), is(valueOptional.get()));
SingleModel<String> singleModel = optional.flatMap(CollectionRoutes::getCreateItemFunctionOptional).get().apply(null).apply(_body).getUnchecked();
assertThat(singleModel.getResourceName(), is("name"));
assertThat(singleModel.getModel(), is("Apio"));
Page<String> page = optional.flatMap(CollectionRoutes::getGetPageFunctionOptional).get().apply(null).getUnchecked();
assertThat(page.getItems(), hasSize(1));
assertThat(page.getItems(), hasItem("Apio"));
assertThat(page.getTotalCount(), is(1));
List<Operation> operations = page.getOperations();
assertThat(operations, hasSize(1));
Operation operation = operations.get(0);
assertThat(operation.getFormOptional(), is(optionalWithValue()));
assertThat(operation.method, is(POST));
assertThat(operation.name, is("name/create"));
}
use of com.liferay.apio.architect.operation.Method.POST in project com-liferay-apio-architect by liferay.
the class NestedCollectionRoutesTest method _testNestedCollectionRoutes.
private void _testNestedCollectionRoutes(NestedCollectionRoutes<String, Long> nestedCollectionRoutes) {
Optional<NestedCollectionRoutes<String, Long>> optional = Optional.of(nestedCollectionRoutes);
Map map = optional.flatMap(NestedCollectionRoutes::getFormOptional).map(form -> {
assertThat(form.id, is("c/name/nested"));
return (Map) form.get(_body);
}).get();
Optional<String> valueOptional = _body.getValueOptional("key");
assertThat(map.get("key"), is(valueOptional.get()));
SingleModel<String> singleModel = optional.flatMap(NestedCollectionRoutes::getNestedCreateItemFunctionOptional).get().apply(null).apply(42L).apply(_body).getUnchecked();
assertThat(singleModel.getResourceName(), is("nested"));
assertThat(singleModel.getModel(), is("Apio"));
Path path = new Path("name", "42");
Page<String> page = optional.flatMap(NestedCollectionRoutes::getNestedGetPageFunctionOptional).get().apply(null).apply(path).apply(42L).getUnchecked();
assertThat(page.getItems(), hasSize(1));
assertThat(page.getItems(), hasItem("Apio"));
assertThat(page.getPathOptional(), optionalWithValue(equalTo(path)));
assertThat(page.getTotalCount(), is(1));
List<Operation> operations = page.getOperations();
assertThat(operations, hasSize(1));
Operation secondOperation = operations.get(0);
assertThat(secondOperation.getFormOptional(), is(optionalWithValue()));
assertThat(secondOperation.method, is(POST));
assertThat(secondOperation.name, is("name/nested/create"));
}
use of com.liferay.apio.architect.operation.Method.POST 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);
}
Aggregations