Search in sources :

Example 1 with Path

use of com.liferay.apio.architect.uri.Path in project com-liferay-apio-architect by liferay.

the class PageTest method testHasPreviousReturnsFalseWhenIsFirst.

@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void testHasPreviousReturnsFalseWhenIsFirst() {
    Pagination pagination = new Pagination(1, 1);
    _path = new Path("name", "id");
    Page<String> page = new Page<>("", _pageItems, pagination, _path, emptyList());
    assertThat(page.hasPrevious(), is(false));
}
Also used : Path(com.liferay.apio.architect.uri.Path) Test(org.junit.Test)

Example 2 with Path

use of com.liferay.apio.architect.uri.Path in project com-liferay-apio-architect by liferay.

the class PathLongIdentifierMapperTest method testMapReturnsLongIfValidPathId.

@Test
public void testMapReturnsLongIfValidPathId() {
    Long identifier = _pathIdentifierMapper.map(new Path("name", "42"));
    assertThat(identifier, is(42L));
}
Also used : Path(com.liferay.apio.architect.uri.Path) Test(org.junit.Test)

Example 3 with Path

use of com.liferay.apio.architect.uri.Path in project com-liferay-apio-architect by liferay.

the class PathStringIdentifierMapperTest method testMapReturnsPath.

@Test
public void testMapReturnsPath() {
    Path path = _pathIdentifierMapper.map("name", "id");
    assertThat(path.getName(), is("name"));
    assertThat(path.getId(), is("id"));
}
Also used : Path(com.liferay.apio.architect.uri.Path) Test(org.junit.Test)

Example 4 with Path

use of com.liferay.apio.architect.uri.Path in project com-liferay-apio-architect by liferay.

the class PathStringIdentifierMapperTest method testMapReturnsString.

@Test
public void testMapReturnsString() {
    String identifier = _pathIdentifierMapper.map(new Path("name", "id"));
    assertThat(identifier, is("id"));
}
Also used : Path(com.liferay.apio.architect.uri.Path) Test(org.junit.Test)

Example 5 with Path

use of com.liferay.apio.architect.uri.Path in project com-liferay-apio-architect by liferay.

the class MockWriterUtil method identifierToPath.

/**
 * Returns a mock {@link Path} from an identifier. The identifier must be a
 * {@link String}, otherwise {@code Optional#empty()} is returned.
 *
 * @param  identifier the identifier
 * @return the mock {@code Path} from the identifier, if the identifier is a
 *         {@code String}; {@code Optional#empty()} otherwise
 */
public static Optional<Path> identifierToPath(String resourceName, Object identifier) {
    if (!(identifier instanceof String)) {
        return Optional.empty();
    }
    String string = (String) identifier;
    Function<String, Optional<Path>> function = name -> Optional.of(new Path(name, string));
    if ("root".equals(resourceName)) {
        return function.apply("model");
    }
    if ("first".equals(resourceName)) {
        return function.apply("first-inner-model");
    }
    if ("second".equals(resourceName)) {
        return function.apply("second-inner-model");
    }
    return function.apply("third-inner-model");
}
Also used : MockRepresentorCreator.createFirstEmbeddedModelRepresentor(com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createFirstEmbeddedModelRepresentor) Arrays(java.util.Arrays) MockRepresentorCreator.createRootModelRepresentor(com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createRootModelRepresentor) RequestInfo(com.liferay.apio.architect.request.RequestInfo) MockRepresentorCreator.createThirdEmbeddedModelRepresentor(com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createThirdEmbeddedModelRepresentor) Path(com.liferay.apio.architect.uri.Path) Function(java.util.function.Function) MockRepresentorCreator.createSecondEmbeddedModelRepresentor(com.liferay.apio.architect.test.util.representor.MockRepresentorCreator.createSecondEmbeddedModelRepresentor) Operation(com.liferay.apio.architect.operation.Operation) Representor(com.liferay.apio.architect.representor.Representor) SecondEmbeddedId(com.liferay.apio.architect.test.util.identifier.SecondEmbeddedId) Identifier(com.liferay.apio.architect.identifier.Identifier) SecondEmbeddedModel(com.liferay.apio.architect.test.util.model.SecondEmbeddedModel) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) Locale(java.util.Locale) DELETE(com.liferay.apio.architect.operation.Method.DELETE) Optional(java.util.Optional) SingleModel(com.liferay.apio.architect.single.model.SingleModel) FirstEmbeddedId(com.liferay.apio.architect.test.util.identifier.FirstEmbeddedId) FirstEmbeddedModel(com.liferay.apio.architect.test.util.model.FirstEmbeddedModel) Collections(java.util.Collections) ThirdEmbeddedId(com.liferay.apio.architect.test.util.identifier.ThirdEmbeddedId) ThirdEmbeddedModel(com.liferay.apio.architect.test.util.model.ThirdEmbeddedModel) Path(com.liferay.apio.architect.uri.Path) Optional(java.util.Optional)

Aggregations

Path (com.liferay.apio.architect.uri.Path)14 Test (org.junit.Test)9 Optional (java.util.Optional)6 Operation (com.liferay.apio.architect.operation.Operation)5 SingleModel (com.liferay.apio.architect.single.model.SingleModel)5 Page (com.liferay.apio.architect.pagination.Page)4 Collections (java.util.Collections)4 List (java.util.List)4 POST (com.liferay.apio.architect.operation.Method.POST)3 Representor (com.liferay.apio.architect.representor.Representor)3 RequestInfo (com.liferay.apio.architect.request.RequestInfo)3 JsonObject (com.google.gson.JsonObject)2 Body (com.liferay.apio.architect.form.Body)2 Identifier (com.liferay.apio.architect.identifier.Identifier)2 FunctionalList (com.liferay.apio.architect.list.FunctionalList)2 PageMessageMapper (com.liferay.apio.architect.message.json.PageMessageMapper)2 DELETE (com.liferay.apio.architect.operation.Method.DELETE)2 PageItems (com.liferay.apio.architect.pagination.PageItems)2 Pagination (com.liferay.apio.architect.pagination.Pagination)2 Function (java.util.function.Function)2