PromiseStatusCollectionResource.class,
PromiseRepliesCollectionResource.class,
PromiseLocationResource.class,
PromiseDiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/promisestatuses");
ResourceModel repliesResourceModel = statusResourceModel.getSubResource("promisereplies");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("promiselocation");
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/promisediscovereditems");
ResourceMethodDescriptor methodDescriptor;
PromiseStatusCollectionResource statusResource;
PromiseRepliesCollectionResource repliesResource;
PromiseLocationResource locationResource;
PromiseDiscoveredItemsResource discoveredItemsResource;
// #1
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.CREATE);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.create((Status)EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
checkInvocation(statusResource,
methodDescriptor,
"POST",
version,
"/promisestatuses",
"{}");
// #1.1: different endpoint
methodDescriptor = repliesResourceModel.findMethod(ResourceMethod.CREATE);
repliesResource = getMockResource(PromiseRepliesCollectionResource.class);
EasyMock.expect(repliesResource.create((Status)EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
checkInvocation(repliesResource,
methodDescriptor,
"POST",
version,
"/promisestatuses/1/replies",
"{}",
buildPathKeys("statusID", 1L));
// #1.2: invalid entity
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.CREATE);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.create((Status)EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
try
{
checkInvocation(statusResource,
methodDescriptor,
"POST",
version,
"/promisestatuses",
"{");
fail("Expected exception");
}
catch (RoutingException e)
{
// expected
EasyMock.reset(statusResource);
}
// #2: Collection Partial Update
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
PatchTree p = new PatchTree();
p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(42)));
PatchRequest<Status> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
EasyMock.expect(statusResource.update(eq(1L), eq(expected))).andReturn(Promises.<UpdateResponse>value(null)).once();
checkInvocation(statusResource,
methodDescriptor,
"POST",
version,
"/promisestatuses/1",
"{\"patch\":{\"$set\":{\"foo\":42}}}",
buildPathKeys("statusID", 1L));
// #3: Simple Resource Partial Update
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
locationResource = getMockResource(PromiseLocationResource.class);
p = new PatchTree();
p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(51)));
PatchRequest<Location> expectedLocation = PatchRequest.createFromPatchDocument(p.getDataMap());
EasyMock.expect(locationResource.update(eq(expectedLocation))).andReturn(Promises.<UpdateResponse>value(null)).once();
checkInvocation(locationResource,
methodDescriptor,
"POST",
version,
"/promisestatuses/1/promiselocation",
"{\"patch\":{\"$set\":{\"foo\":51}}}",
buildPathKeys("statusID", 1L));
// #4 Complex key resource create
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.CREATE);
discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
EasyMock.expect(
discoveredItemsResource.create(
(DiscoveredItem)EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
checkInvocation(discoveredItemsResource,
methodDescriptor,
"POST",
version,
"/promisediscovereditems",
"{}");
// #5 Complex key resource partial update
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
p = new PatchTree();
p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(43)));
PatchRequest<DiscoveredItem> expectedDiscoveredItem =
PatchRequest.createFromPatchDocument(p.getDataMap());