mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-04 15:49:12 +00:00
More URI tests
This commit is contained in:
parent
367f61d63c
commit
a2197314fa
@ -30,9 +30,6 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRe
|
||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
|
||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||
|
||||
import static org.apache.olingo.fit.v4.AbstractTestITCase.client;
|
||||
|
||||
import org.apache.olingo.client.api.uri.QueryOption;
|
||||
import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
|
||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||
@ -61,13 +58,10 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void expandWithFilter() {
|
||||
// TODO: simplify as per OLINGO-223
|
||||
final StringBuilder expandWithFilter = new StringBuilder("Orders(").
|
||||
append('$').append(QueryOption.FILTER).append('=').
|
||||
append(getClient().getFilterFactory().gt("OrderID", 7).build()).
|
||||
append(')');
|
||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("Customers").appendKeySegment(1).expand(expandWithFilter.toString());
|
||||
appendEntitySetSegment("Customers").appendKeySegment(1).
|
||||
expandWithOptions("Orders", Collections.<QueryOption, Object>singletonMap(
|
||||
QueryOption.FILTER, getClient().getFilterFactory().gt("OrderID", 7).build()));
|
||||
|
||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||
|
||||
@ -232,7 +226,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
||||
|
||||
@Test
|
||||
public void search() {
|
||||
final URIBuilder builder = client.getURIBuilder("http://odatae2etest.azurewebsites.net/javatest/DefaultService").
|
||||
final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
|
||||
appendEntitySetSegment("People").search(client.getSearchFactory().
|
||||
or(client.getSearchFactory().literal("Bob"), client.getSearchFactory().literal("Jill")));
|
||||
|
||||
|
@ -37,6 +37,13 @@ public enum QueryOption {
|
||||
* path section of the URI, and MUST be represented inline in the data service's response.
|
||||
*/
|
||||
EXPAND,
|
||||
/**
|
||||
* Cyclic navigation properties (whose target type is identical or can be cast to its source type) can be recursively
|
||||
* expanded using the special <tt>$levels</tt> option. The value of the $levels option is either a positive integer to
|
||||
* specify the number of levels to expand, or the literal string max to specify the maximum expansion level supported
|
||||
* by that service.
|
||||
*/
|
||||
LEVELS,
|
||||
/**
|
||||
* This option specifies the media type acceptable in a response. If present, this value SHOULD take precedence over
|
||||
* value(s) specified in an Accept request header.
|
||||
|
@ -22,6 +22,7 @@ import java.util.Map;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.olingo.commons.api.edm.EdmEnumType;
|
||||
import org.apache.olingo.client.api.uri.CommonURIBuilder;
|
||||
import org.apache.olingo.client.api.uri.QueryOption;
|
||||
|
||||
public interface URIBuilder extends CommonURIBuilder<URIBuilder> {
|
||||
|
||||
@ -127,7 +128,7 @@ public interface URIBuilder extends CommonURIBuilder<URIBuilder> {
|
||||
* @return current URIBuilder instance.
|
||||
* @see org.apache.olingo.client.api.uri.QueryOption#EXPAND
|
||||
*/
|
||||
URIBuilder expandWithOptions(String expandItem, Map<String, Object> options);
|
||||
URIBuilder expandWithOptions(String expandItem, Map<QueryOption, Object> options);
|
||||
|
||||
/**
|
||||
* Properties of related entities can be specified by including the $select query option within the $expand.
|
||||
|
@ -137,8 +137,12 @@ public class URIBuilderImpl extends AbstractURIBuilder<URIBuilder> implements UR
|
||||
}
|
||||
|
||||
@Override
|
||||
public URIBuilder expandWithOptions(final String expandItem, final Map<String, Object> options) {
|
||||
return expand(expandItem + buildMultiKeySegment(options, false));
|
||||
public URIBuilder expandWithOptions(final String expandItem, final Map<QueryOption, Object> options) {
|
||||
final Map<String, Object> _options = new LinkedHashMap<String, Object>();
|
||||
for (Map.Entry<QueryOption, Object> entry : options.entrySet()) {
|
||||
_options.put("$" + entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
return expand(expandItem + buildMultiKeySegment(_options, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,16 +18,16 @@
|
||||
*/
|
||||
package org.apache.olingo.client.core.uri.v4;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.apache.olingo.client.api.uri.QueryOption;
|
||||
import org.apache.olingo.client.api.v4.ODataClient;
|
||||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||
import org.apache.olingo.client.core.AbstractTest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class URIBuilderTest extends AbstractTest {
|
||||
@ -41,13 +41,13 @@ public class URIBuilderTest extends AbstractTest {
|
||||
|
||||
@Test
|
||||
public void expandWithOptions() throws URISyntaxException {
|
||||
URI uri = getClient().getURIBuilder(SERVICE_ROOT).appendEntitySetSegment("Products").appendKeySegment(5).
|
||||
expandWithOptions("ProductDetails", new LinkedHashMap<String, Object>() {
|
||||
final URI uri = getClient().getURIBuilder(SERVICE_ROOT).appendEntitySetSegment("Products").appendKeySegment(5).
|
||||
expandWithOptions("ProductDetails", new LinkedHashMap<QueryOption, Object>() {
|
||||
private static final long serialVersionUID = 3109256773218160485L;
|
||||
|
||||
{
|
||||
put("$expand", "ProductInfo");
|
||||
put("$select", "Price");
|
||||
put(QueryOption.EXPAND, "ProductInfo");
|
||||
put(QueryOption.SELECT, "Price");
|
||||
}
|
||||
}).expand("Orders", "Customers").build();
|
||||
|
||||
@ -55,6 +55,16 @@ public class URIBuilderTest extends AbstractTest {
|
||||
addParameter("$expand", "ProductDetails($expand=ProductInfo,$select=Price),Orders,Customers").build(), uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expandWithLevels() throws URISyntaxException {
|
||||
final URI uri = getClient().getURIBuilder(SERVICE_ROOT).appendEntitySetSegment("Products").appendKeySegment(1).
|
||||
expandWithOptions("Customer", Collections.<QueryOption, Object>singletonMap(QueryOption.LEVELS, 4)).
|
||||
build();
|
||||
|
||||
assertEquals(new org.apache.http.client.utils.URIBuilder(SERVICE_ROOT + "/Products(1)").
|
||||
addParameter("$expand", "Customer($levels=4)").build(), uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void count() throws URISyntaxException {
|
||||
URI uri = getClient().getURIBuilder(SERVICE_ROOT).appendEntitySetSegment("Products").count().build();
|
||||
|
Loading…
x
Reference in New Issue
Block a user