use of com.liferay.apio.architect.uri.Path in project com-liferay-apio-architect by liferay.
the class PageTest method testHasNextReturnsFalseWhenIsLast.
@Test
public void testHasNextReturnsFalseWhenIsLast() {
Pagination pagination = new Pagination(1, 10);
_path = new Path("name", "id");
Page<String> page = new Page<>("", _pageItems, pagination, _path, emptyList());
assertThat(page.hasNext(), is(false));
}
use of com.liferay.apio.architect.uri.Path 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.uri.Path in project com-liferay-apio-architect by liferay.
the class FieldsWriterTest method testWriteEmbeddedRelatedModelsWithEmbeddedPredicate.
@SuppressWarnings("unchecked")
@Test
public void testWriteEmbeddedRelatedModelsWithEmbeddedPredicate() {
List<String> linkedRelatedModelURLs = new ArrayList<>();
List<String> embeddedRelatedModelURLs = new ArrayList<>();
List<FunctionalList<String>> firstEmbeddedPathElementsList = new ArrayList<>();
List<FunctionalList<String>> secondEmbeddedPathElementsList = new ArrayList<>();
List<FunctionalList<String>> thirdEmbeddedPathElementsList = new ArrayList<>();
List<SingleModel> singleModels = new ArrayList<>();
Function<SingleModel<?>, Optional<Path>> pathFunction = Mockito.mock(Function.class);
Mockito.when(_requestInfo.getEmbedded()).thenReturn("first.embedded2"::equals);
Mockito.when(pathFunction.apply(Mockito.any())).thenReturn(Optional.of(new Path("name1", "id1")), Optional.of(new Path("name2", "id2")), Optional.of(new Path("name3", "id3")), Optional.of(new Path("name4", "id4")));
_fieldsWriter.writeRelatedModels(pathFunction, (singleModel, embeddedPathElements) -> {
singleModels.add(singleModel);
firstEmbeddedPathElementsList.add(embeddedPathElements);
}, (url, embeddedPathElements) -> {
linkedRelatedModelURLs.add(url);
secondEmbeddedPathElementsList.add(embeddedPathElements);
}, (url, embeddedPathElements) -> {
embeddedRelatedModelURLs.add(url);
thirdEmbeddedPathElementsList.add(embeddedPathElements);
});
assertThat(singleModels, hasSize(equalTo(1)));
SingleModel singleModel = singleModels.get(0);
assertThat(singleModel.getModel(), is(instanceOf(FirstEmbeddedModel.class)));
assertThat(linkedRelatedModelURLs, hasSize(equalTo(3)));
assertThat(linkedRelatedModelURLs, contains("www.liferay.com/p/name1/id1", "www.liferay.com/p/name3/id3", "www.liferay.com/p/name4/id4"));
assertThat(embeddedRelatedModelURLs, hasSize(equalTo(1)));
assertThat(embeddedRelatedModelURLs, contains("www.liferay.com/p/name2/id2"));
assertThat(firstEmbeddedPathElementsList, hasSize(equalTo(1)));
assertThat(firstEmbeddedPathElementsList, contains(aFunctionalListThat(contains("first", "embedded2"))));
assertThat(secondEmbeddedPathElementsList, hasSize(equalTo(3)));
assertThat(secondEmbeddedPathElementsList, contains(aFunctionalListThat(contains("first", "embedded1")), aFunctionalListThat(contains("first", "linked1")), aFunctionalListThat(contains("first", "linked2"))));
assertThat(thirdEmbeddedPathElementsList, hasSize(equalTo(1)));
assertThat(thirdEmbeddedPathElementsList, contains(aFunctionalListThat(contains("first", "embedded2"))));
}
use of com.liferay.apio.architect.uri.Path 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