use of com.liferay.apio.architect.operation.Operation 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.Operation in project com-liferay-apio-architect by liferay.
the class PageTest method setUp.
@Before
public void setUp() {
_pageItems = new PageItems<>(Collections.singleton("apio"), 10);
Pagination pagination = new Pagination(1, 4);
_path = new Path("name", "id");
_operations = Collections.singletonList(new Operation(POST, "operation"));
_page = new Page<>("name", _pageItems, pagination, _path, _operations);
}
use of com.liferay.apio.architect.operation.Operation in project com-liferay-apio-architect by liferay.
the class ItemRoutesTest method _testItemRoutes.
private void _testItemRoutes(ItemRoutes<String, Long> itemRoutes) throws Exception {
Optional<ItemRoutes<String, Long>> optional = Optional.of(itemRoutes);
Map map = optional.flatMap(ItemRoutes::getFormOptional).map(form -> {
assertThat(form.id, is("u/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(ItemRoutes::getItemFunctionOptional).get().apply(null).apply(42L).getUnchecked();
assertThat(singleModel.getResourceName(), is("name"));
assertThat(singleModel.getModel(), is("Apio"));
optional.flatMap(ItemRoutes::getDeleteConsumerOptional).get().apply(null).accept(42L);
SingleModel<String> updatedSingleModel = optional.flatMap(ItemRoutes::getUpdateItemFunctionOptional).get().apply(null).apply(42L).apply(_body).getUnchecked();
assertThat(updatedSingleModel.getResourceName(), is("name"));
assertThat(updatedSingleModel.getModel(), is("Updated"));
List<Operation> operations = updatedSingleModel.getOperations();
assertThat(operations, hasSize(2));
Operation firstOperation = operations.get(0);
assertThat(firstOperation.getFormOptional(), is(emptyOptional()));
assertThat(firstOperation.method, is(DELETE));
assertThat(firstOperation.name, is("name/delete"));
Operation secondOperation = operations.get(1);
assertThat(secondOperation.getFormOptional(), is(optionalWithValue()));
assertThat(secondOperation.method, is(PUT));
assertThat(secondOperation.name, is("name/update"));
}
use of com.liferay.apio.architect.operation.Operation 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