[OLINGO-365] Adding checks for enhanced composable invoker

This commit is contained in:
Francesco Chicchiriccò 2014-08-04 13:09:47 +02:00
parent a13a0d865f
commit 34f0825604
2 changed files with 68 additions and 21 deletions

View File

@ -112,19 +112,6 @@ public class V4Services extends AbstractServices {
super(ODataServiceVersion.V40, metadata);
}
@POST
@Path("/GetAllProducts()/Discount")
public Response discount() {
try {
final String basePath = "Products" + File.separatorChar + "feed";
final InputStream feed = FSManager.instance(version).readFile(basePath, Accept.JSON_FULLMETA);
return xml.createResponse(null, feed, Commons.getETag(basePath, version), Accept.JSON_FULLMETA);
} catch (Exception e) {
return xml.createFaultResponse(Accept.JSON_FULLMETA.toString(version), e);
}
}
@GET
@Path("/redirect/{name}({id})")
public Response conformanceRedirect(
@ -386,7 +373,7 @@ public class V4Services extends AbstractServices {
return StringUtils.isBlank(filter) && StringUtils.isBlank(search)
? NumberUtils.isNumber(type)
? super.getEntityInternal(
uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null)
uriInfo.getRequestUri().toASCIIString(), accept, "People", type, format, null, null)
: super.getEntitySet(accept, "People", type)
: super.getEntitySet(uriInfo, accept, "People", top, skip, format, count, filter, orderby, skiptoken);
}
@ -767,7 +754,7 @@ public class V4Services extends AbstractServices {
return utils.getValue().createResponse(
FSManager.instance(version).readFile(Constants.get(version, ConstantKey.REF)
+ File.separatorChar + filename, utils.getKey()),
+ File.separatorChar + filename, utils.getKey()),
null,
utils.getKey());
} catch (Exception e) {
@ -807,7 +794,7 @@ public class V4Services extends AbstractServices {
final Response response =
getEntityInternal(uriInfo.getRequestUri().toASCIIString(),
accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY);
accept, entitySetName, entityId, accept, StringUtils.EMPTY, StringUtils.EMPTY);
return response.getStatus() >= 400
? super.postNewEntity(uriInfo, accept, contentType, prefer, entitySetName, changes)
: super.patchEntity(uriInfo, accept, contentType, prefer, ifMatch, entitySetName, entityId, changes);
@ -1033,7 +1020,7 @@ public class V4Services extends AbstractServices {
// 1. Fetch the contained entity to be removed
final InputStream entry = FSManager.instance(version).
readFile(containedPath(entityId, containedEntitySetName).
append('(').append(containedEntityId).append(')').toString(), Accept.ATOM);
append('(').append(containedEntityId).append(')').toString(), Accept.ATOM);
final ResWrap<Entity> container = atomDeserializer.toEntity(entry);
// 2. Remove the contained entity
@ -1160,6 +1147,37 @@ public class V4Services extends AbstractServices {
uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "1", format, null, null);
}
@GET
@Path("/GetPerson2({param:.*})/Emails")
public Response functionGetPerson2Emails(
@Context final UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
return getPath(accept, "Customers", "1", "Emails", format);
}
@GET
@Path("/GetPerson2({param:.*})/HomeAddress")
public Response functionGetPerson2HomeAddress(
@Context final UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
return getPath(accept, "Customers", "1", "HomeAddress", format);
}
@GET
@Path("/GetPerson2({param:.*})/Parent")
public Response functionGetPerson2Parent(
@Context final UriInfo uriInfo,
@HeaderParam("Accept") @DefaultValue(StringUtils.EMPTY) final String accept,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format) {
return getEntityInternal(
uriInfo.getRequestUri().toASCIIString(), accept, "Customers", "2", format, null, null);
}
@GET
@Path("/GetPerson({param:.*})")
public Response functionGetPerson(
@ -1283,6 +1301,19 @@ public class V4Services extends AbstractServices {
}
}
@POST
@Path("/GetAllProducts()/Discount")
public Response actionBoundDiscount() {
try {
final String basePath = "Products" + File.separatorChar + "feed";
final InputStream feed = FSManager.instance(version).readFile(basePath, Accept.JSON_FULLMETA);
return xml.createResponse(null, feed, Commons.getETag(basePath, version), Accept.JSON_FULLMETA);
} catch (Exception e) {
return xml.createFaultResponse(Accept.JSON_FULLMETA.toString(version), e);
}
}
@POST
@Path("/ResetBossAddress()")
public Response actionResetBossAddress(
@ -1307,7 +1338,7 @@ public class V4Services extends AbstractServices {
final ResWrap<Property> result = new ResWrap<Property>(
URI.create(Constants.get(version, ConstantKey.ODATA_METADATA_PREFIX)
+ "Microsoft.Test.OData.Services.ODataWCFService.Address"),
+ "Microsoft.Test.OData.Services.ODataWCFService.Address"),
null,
entity.getProperty("address"));

View File

@ -550,10 +550,26 @@ public class APIBasicDesignTestITCase extends AbstractTestITCase {
expand("ProductDetail").
orderBy("Name").skip(3).top(5).execute();
// Complex/Entity
final PersonComposableInvoker invoker2 = container.operations().getPerson2("London");
// Complex/Entity (available only select and expand: after query option composition is not available anymore)
invoker2.select("Name"). // after the first query option no composition is possible
expand("Order").execute();
// a. whole entity
final Person person = invoker2.select("Name").expand("Order").execute();
assertNotNull(person);
assertEquals(1, person.getPersonID(), 0);
// b. primitive collection property
final PrimitiveCollection<String> emails = invoker2.getEmails().execute();
assertNotNull(emails);
assertFalse(emails.isEmpty());
// c. complex property
final Address homeAddress = invoker2.getHomeAddress().load();
assertNotNull(homeAddress);
// d. navigation property
final Person parent = invoker2.getParent().load();
assertNotNull(parent);
assertEquals(2, parent.getPersonID(), 0);
}
}