mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-05 16:19:05 +00:00
Adding test for nested query option
This commit is contained in:
parent
8bb1f0bde3
commit
367f61d63c
@ -990,7 +990,7 @@ public abstract class AbstractServices {
|
|||||||
final String entitySetName,
|
final String entitySetName,
|
||||||
final String entityId,
|
final String entityId,
|
||||||
final String format,
|
final String format,
|
||||||
final String expand,
|
String expand,
|
||||||
final String select,
|
final String select,
|
||||||
final boolean keyAsSegment) {
|
final boolean keyAsSegment) {
|
||||||
|
|
||||||
@ -1047,6 +1047,7 @@ public abstract class AbstractServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(expand)) {
|
if (StringUtils.isNotBlank(expand)) {
|
||||||
|
expand = StringUtils.substringBefore(expand, "(");
|
||||||
final List<String> links = Arrays.asList(expand.split(","));
|
final List<String> links = Arrays.asList(expand.split(","));
|
||||||
|
|
||||||
final Map<Link, Link> replace = new HashMap<Link, Link>();
|
final Map<Link, Link> replace = new HashMap<Link, Link>();
|
||||||
|
@ -30,7 +30,10 @@ 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.request.retrieve.ODataEntitySetRequest;
|
||||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
||||||
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
import org.apache.olingo.client.api.uri.v4.URIBuilder;
|
||||||
|
|
||||||
import static org.apache.olingo.fit.v4.AbstractTestITCase.client;
|
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.ODataInlineEntitySet;
|
||||||
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
|
||||||
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
|
||||||
@ -51,7 +54,22 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
|
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
|
||||||
|
|
||||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||||
req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
|
|
||||||
|
final ODataEntity customer = req.execute().getBody();
|
||||||
|
assertTrue(customer.getNavigationLink("Orders") instanceof ODataInlineEntitySet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
|
||||||
|
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||||
|
|
||||||
final ODataEntity customer = req.execute().getBody();
|
final ODataEntity customer = req.execute().getBody();
|
||||||
assertTrue(customer.getNavigationLink("Orders") instanceof ODataInlineEntitySet);
|
assertTrue(customer.getNavigationLink("Orders") instanceof ODataInlineEntitySet);
|
||||||
@ -70,7 +88,6 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
// 1. check that filtered entity set looks as expected
|
// 1. check that filtered entity set looks as expected
|
||||||
ODataEntitySetRequest<ODataEntitySet> req =
|
ODataEntitySetRequest<ODataEntitySet> req =
|
||||||
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
|
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
|
||||||
req.setFormat(ODataPubFormat.JSON);
|
|
||||||
|
|
||||||
ODataEntitySet feed = req.execute().getBody();
|
ODataEntitySet feed = req.execute().getBody();
|
||||||
assertNotNull(feed);
|
assertNotNull(feed);
|
||||||
@ -86,7 +103,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
|
|
||||||
// 3. add orderby clause to filter above
|
// 3. add orderby clause to filter above
|
||||||
req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.orderBy("PersonID desc").build());
|
req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.orderBy("PersonID desc").build());
|
||||||
req.setFormat(ODataPubFormat.JSON);
|
|
||||||
feed = req.execute().getBody();
|
feed = req.execute().getBody();
|
||||||
assertNotNull(feed);
|
assertNotNull(feed);
|
||||||
assertEquals(2, feed.getEntities().size());
|
assertEquals(2, feed.getEntities().size());
|
||||||
@ -128,9 +145,10 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
|
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
|
||||||
|
|
||||||
// 1. check that filtered entity set looks as expected
|
// 1. check that filtered entity set looks as expected
|
||||||
ODataEntitySetRequest<ODataEntitySet> req =
|
final ODataEntitySetRequest<ODataEntitySet> req =
|
||||||
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.skip(2).build());
|
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.skip(2).build());
|
||||||
ODataEntitySet feed = req.execute().getBody();
|
|
||||||
|
final ODataEntitySet feed = req.execute().getBody();
|
||||||
assertEquals(3, feed.getEntities().size());
|
assertEquals(3, feed.getEntities().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,9 +159,10 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
|
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
|
||||||
|
|
||||||
// 1. check that filtered entity set looks as expected
|
// 1. check that filtered entity set looks as expected
|
||||||
ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
|
final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
|
||||||
getEntitySetRequest(uriBuilder.top(2).build());
|
getEntitySetRequest(uriBuilder.top(2).build());
|
||||||
ODataEntitySet feed = req.execute().getBody();
|
|
||||||
|
final ODataEntitySet feed = req.execute().getBody();
|
||||||
assertEquals(2, feed.getEntities().size());
|
assertEquals(2, feed.getEntities().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +176,6 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
|
|
||||||
final ODataEntitySetRequest<ODataEntitySet> req =
|
final ODataEntitySetRequest<ODataEntitySet> req =
|
||||||
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
|
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
|
||||||
req.setFormat(ODataPubFormat.JSON);
|
|
||||||
|
|
||||||
final ODataEntitySet feed = req.execute().getBody();
|
final ODataEntitySet feed = req.execute().getBody();
|
||||||
assertNotNull(feed);
|
assertNotNull(feed);
|
||||||
@ -178,7 +196,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
|
|
||||||
final ODataEntitySetRequest<ODataEntitySet> req =
|
final ODataEntitySetRequest<ODataEntitySet> req =
|
||||||
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
|
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
|
||||||
req.setFormat(ODataPubFormat.JSON);
|
|
||||||
final ODataEntitySet feed = req.execute().getBody();
|
final ODataEntitySet feed = req.execute().getBody();
|
||||||
assertNotNull(feed);
|
assertNotNull(feed);
|
||||||
assertEquals(feed.getEntities().size(), feed.getCount());
|
assertEquals(feed.getEntities().size(), feed.getCount());
|
||||||
@ -193,7 +211,6 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
appendEntitySetSegment("Customers").appendKeySegment(1).select("PersonID,Orders").expand("Orders");
|
appendEntitySetSegment("Customers").appendKeySegment(1).select("PersonID,Orders").expand("Orders");
|
||||||
|
|
||||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||||
req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
|
|
||||||
|
|
||||||
final ODataEntity customer = req.execute().getBody();
|
final ODataEntity customer = req.execute().getBody();
|
||||||
assertEquals(1, customer.getProperties().size());
|
assertEquals(1, customer.getProperties().size());
|
||||||
@ -208,6 +225,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
expandWithSelect("Orders", "OrderID", "OrderDetails");
|
expandWithSelect("Orders", "OrderID", "OrderDetails");
|
||||||
|
|
||||||
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
|
||||||
|
|
||||||
final ODataRetrieveResponse<ODataEntity> res = req.execute();
|
final ODataRetrieveResponse<ODataEntity> res = req.execute();
|
||||||
assertEquals(200, res.getStatusCode());
|
assertEquals(200, res.getStatusCode());
|
||||||
}
|
}
|
||||||
@ -220,6 +238,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
|
|||||||
|
|
||||||
final ODataEntitySetRequest<ODataEntitySet> req =
|
final ODataEntitySetRequest<ODataEntitySet> req =
|
||||||
client.getRetrieveRequestFactory().getEntitySetRequest(builder.build());
|
client.getRetrieveRequestFactory().getEntitySetRequest(builder.build());
|
||||||
|
|
||||||
final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
|
final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
|
||||||
assertEquals(200, res.getStatusCode());
|
assertEquals(200, res.getStatusCode());
|
||||||
assertFalse(res.getBody().getEntities().isEmpty());
|
assertFalse(res.getBody().getEntities().isEmpty());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user