use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestCreateResponseBuilder method testProjectionInBuildRestLiResponseData.
@Test
public void testProjectionInBuildRestLiResponseData() throws URISyntaxException {
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockContext.isReturnEntityRequested()).andReturn(true);
EasyMock.expect(mockContext.getProjectionMask()).andReturn(maskTree);
EasyMock.expect(mockContext.getProjectionMode()).andReturn(ProjectionMode.AUTOMATIC);
EasyMock.expect(mockContext.getRawRequestContext()).andReturn(new RequestContext()).anyTimes();
EasyMock.expect(mockContext.getAlwaysProjectedFields()).andReturn(Collections.emptySet()).anyTimes();
EasyMock.replay(mockContext);
RoutingResult routingResult = new RoutingResult(mockContext, null);
Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
CreateKVResponse<Integer, Foo> values = new CreateKVResponse<>(null, value);
CreateResponseBuilder responseBuilder = new CreateResponseBuilder();
RestLiResponseData<CreateResponseEnvelope> envelope = responseBuilder.buildRestLiResponseData(new RestRequestBuilder(new URI("/foo")).build(), routingResult, values, Collections.emptyMap(), Collections.emptyList());
RecordTemplate record = envelope.getResponseEnvelope().getRecord();
Assert.assertEquals(record.data().size(), 1);
Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
Assert.assertTrue(envelope.getResponseEnvelope().isGetAfterCreate());
EasyMock.verify(mockContext);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class GeneratePatchMethodInterceptor method handleGet.
private Object handleGet(Method method) {
String propName = toCamelCase(method.getName(), 3);
assertPropertyInSchema(propName);
// And the patch would store the PathSpec of ["bar", "baz"] being set to 123.
return GeneratePatchProxyFactory.newInstance(method.getReturnType(), _patchTree, new PathSpec(_pathSpec.getPathComponents(), propName));
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class GeneratePatchMethodInterceptor method handleRemove.
private Object handleRemove(String methodName) {
String propName = toCamelCase(methodName, 6);
assertPropertyInSchema(propName);
_patchTree.addOperation(new PathSpec(_pathSpec.getPathComponents(), propName), PatchOpFactory.REMOVE_FIELD_OP);
return null;
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestScatterGather method testRequest.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void testRequest(BatchRequest<?> request, Set<String> expectedParams, Set<PathSpec> expectedFields, Map<Long, Greeting> expectedInput, Set<Set<String>> requestIdSets, Set<Long> requestIds) {
Assert.assertEquals(request.getQueryParamsObjects().keySet(), expectedParams);
if (expectedFields != null) {
Set<PathSpec> actualFields = request.getFields();
Assert.assertTrue(expectedFields.equals(actualFields));
}
Set<String> uriIds = request.getObjectIds().stream().map(Object::toString).collect(Collectors.toSet());
if (expectedInput != null) {
RecordTemplate inputRecordTemplate;
if (request instanceof BatchUpdateRequest) {
ResourceProperties resourceProperties = request.getResourceProperties();
CollectionRequest inputRecord = (CollectionRequest) request.getInputRecord();
inputRecordTemplate = CollectionRequestUtil.convertToBatchRequest(inputRecord, resourceProperties.getKeyType(), resourceProperties.getComplexKeyType(), resourceProperties.getKeyParts(), resourceProperties.getValueType());
} else {
inputRecordTemplate = request.getInputRecord();
}
checkInput(inputRecordTemplate.data().getDataMap(com.linkedin.restli.common.BatchRequest.ENTITIES), expectedInput, uriIds);
}
Set<String> theseIds = request.getObjectIds().stream().map(Object::toString).collect(Collectors.toSet());
Assert.assertEquals(uriIds, theseIds);
// no duplicate requests
Assert.assertFalse(requestIdSets.contains(theseIds));
for (String id : theseIds) {
// no duplicate ids
Assert.assertFalse(requestIds.contains(Long.parseLong(id)));
requestIds.add(Long.parseLong(id));
}
requestIdSets.add(theseIds);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestScatterGather method testBuildSGGetRequests.
private static void testBuildSGGetRequests(int numEndpoints, ScatterGatherBuilder<Greeting> sg, Long[] ids) throws ServiceUnavailableException {
Collection<ScatterGatherBuilder.RequestInfo<Greeting>> requests = buildScatterGatherGetRequests(sg, ids);
Assert.assertEquals(requests.size(), numEndpoints);
Set<Set<String>> requestIdSets = new HashSet<>();
Set<Long> requestIds = new HashSet<>();
for (ScatterGatherBuilder.RequestInfo<Greeting> requestInfo : requests) {
// URI will be something like "greetings/?ids=21&ids=4&ids=53&ids=60&ids=66&ids=88&ids=93&foo=bar"
BatchRequest<BatchResponse<Greeting>> request = requestInfo.getBatchRequest();
Set<String> expectedParams = new HashSet<>();
expectedParams.add(RestConstants.QUERY_BATCH_IDS_PARAM);
expectedParams.add("foo");
expectedParams.add(RestConstants.FIELDS_PARAM);
Set<PathSpec> expectedFields = Collections.singleton(new PathSpec("message"));
testRequest(request, expectedParams, expectedFields, null, requestIdSets, requestIds);
}
Assert.assertTrue(requestIds.containsAll(Arrays.asList(ids)));
Assert.assertEquals(requestIds.size(), ids.length);
}
Aggregations