Adding test for nested query option

This commit is contained in:
Francesco Chicchiriccò 2014-05-08 15:07:43 +02:00
parent 8bb1f0bde3
commit 367f61d63c
2 changed files with 31 additions and 11 deletions

View File

@ -990,7 +990,7 @@ public abstract class AbstractServices {
final String entitySetName,
final String entityId,
final String format,
final String expand,
String expand,
final String select,
final boolean keyAsSegment) {
@ -1047,6 +1047,7 @@ public abstract class AbstractServices {
}
if (StringUtils.isNotBlank(expand)) {
expand = StringUtils.substringBefore(expand, "(");
final List<String> links = Arrays.asList(expand.split(","));
final Map<Link, Link> replace = new HashMap<Link, Link>();

View File

@ -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.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;
import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
@ -51,7 +54,22 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
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();
assertTrue(customer.getNavigationLink("Orders") instanceof ODataInlineEntitySet);
@ -70,7 +88,6 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
// 1. check that filtered entity set looks as expected
ODataEntitySetRequest<ODataEntitySet> req =
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
req.setFormat(ODataPubFormat.JSON);
ODataEntitySet feed = req.execute().getBody();
assertNotNull(feed);
@ -86,7 +103,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
// 3. add orderby clause to filter above
req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.orderBy("PersonID desc").build());
req.setFormat(ODataPubFormat.JSON);
feed = req.execute().getBody();
assertNotNull(feed);
assertEquals(2, feed.getEntities().size());
@ -128,9 +145,10 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
// 1. check that filtered entity set looks as expected
ODataEntitySetRequest<ODataEntitySet> req =
final ODataEntitySetRequest<ODataEntitySet> req =
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.skip(2).build());
ODataEntitySet feed = req.execute().getBody();
final ODataEntitySet feed = req.execute().getBody();
assertEquals(3, feed.getEntities().size());
}
@ -141,9 +159,10 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
// 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());
ODataEntitySet feed = req.execute().getBody();
final ODataEntitySet feed = req.execute().getBody();
assertEquals(2, feed.getEntities().size());
}
@ -157,7 +176,6 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
final ODataEntitySetRequest<ODataEntitySet> req =
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
req.setFormat(ODataPubFormat.JSON);
final ODataEntitySet feed = req.execute().getBody();
assertNotNull(feed);
@ -178,7 +196,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
final ODataEntitySetRequest<ODataEntitySet> req =
client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
req.setFormat(ODataPubFormat.JSON);
final ODataEntitySet feed = req.execute().getBody();
assertNotNull(feed);
assertEquals(feed.getEntities().size(), feed.getCount());
@ -193,7 +211,6 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
appendEntitySetSegment("Customers").appendKeySegment(1).select("PersonID,Orders").expand("Orders");
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
final ODataEntity customer = req.execute().getBody();
assertEquals(1, customer.getProperties().size());
@ -208,6 +225,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
expandWithSelect("Orders", "OrderID", "OrderDetails");
final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
final ODataRetrieveResponse<ODataEntity> res = req.execute();
assertEquals(200, res.getStatusCode());
}
@ -220,6 +238,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
final ODataEntitySetRequest<ODataEntitySet> req =
client.getRetrieveRequestFactory().getEntitySetRequest(builder.build());
final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
assertEquals(200, res.getStatusCode());
assertFalse(res.getBody().getEntities().isEmpty());