use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method dataProvider.
@DataProvider(name = "testData")
public Object[][] dataProvider() {
CompoundKey c1 = new CompoundKey().append("a", "a1").append("b", 1);
CompoundKey c2 = new CompoundKey().append("a", "a2").append("b", 2);
CompoundKey c3 = new CompoundKey().append("a", "a3").append("b", 3);
Map<CompoundKey, UpdateResponse> results = new HashMap<>();
results.put(c1, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
results.put(c2, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
RestLiServiceException restLiServiceException = new RestLiServiceException(HttpStatus.S_404_NOT_FOUND);
Map<CompoundKey, RestLiServiceException> errors = Collections.singletonMap(c3, restLiServiceException);
BatchUpdateResult<CompoundKey, Foo> batchUpdateResult = new BatchUpdateResult<>(results, errors);
Map<CompoundKey, UpdateResponse> keyOverlapResults = new HashMap<>();
keyOverlapResults.put(c1, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
keyOverlapResults.put(c2, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
keyOverlapResults.put(c3, new UpdateResponse(HttpStatus.S_404_NOT_FOUND));
BatchUpdateResult<CompoundKey, Foo> keyOverlapBatchUpdateResult = new BatchUpdateResult<>(keyOverlapResults, errors);
UpdateStatus updateStatus = new UpdateStatus().setStatus(202);
ErrorResponse errorResponse = new ErrorResponse().setStatus(404);
Map<String, UpdateStatus> expectedProtocol1Results = new HashMap<>();
expectedProtocol1Results.put("a=a1&b=1", updateStatus);
expectedProtocol1Results.put("a=a2&b=2", updateStatus);
Map<String, ErrorResponse> expectedProtocol1Errors = new HashMap<>();
expectedProtocol1Errors.put("a=a3&b=3", errorResponse);
Map<String, UpdateStatus> expectedProtocol2Results = new HashMap<>();
expectedProtocol2Results.put("(a:a1,b:1)", updateStatus);
expectedProtocol2Results.put("(a:a2,b:2)", updateStatus);
Map<String, ErrorResponse> expectedProtocol2Errors = new HashMap<>();
expectedProtocol2Errors.put("(a:a3,b:3)", errorResponse);
Map<String, UpdateStatus> expectedAltKeyResults = new HashMap<>();
expectedAltKeyResults.put("aa1xb1", updateStatus);
expectedAltKeyResults.put("aa2xb2", updateStatus);
Map<String, ErrorResponse> expectedAltKeyErrors = new HashMap<>();
expectedAltKeyErrors.put("aa3xb3", errorResponse);
Map<String, AlternativeKey<?, ?>> alternativeKeyMap = new HashMap<>();
alternativeKeyMap.put("alt", new AlternativeKey<>(new TestKeyCoercer(), String.class, new StringDataSchema()));
List<Object[]> data = new ArrayList<>();
for (ResourceMethod resourceMethod : BUILDERS.keySet()) {
data.add(new Object[] { batchUpdateResult, null, null, expectedProtocol1Results, expectedProtocol1Errors, AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), resourceMethod });
data.add(new Object[] { batchUpdateResult, null, null, expectedProtocol2Results, expectedProtocol2Errors, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), resourceMethod });
data.add(new Object[] { batchUpdateResult, "alt", alternativeKeyMap, expectedAltKeyResults, expectedAltKeyErrors, AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), resourceMethod });
data.add(new Object[] { batchUpdateResult, "alt", alternativeKeyMap, expectedAltKeyResults, expectedAltKeyErrors, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), resourceMethod });
data.add(new Object[] { keyOverlapBatchUpdateResult, null, null, expectedProtocol2Results, expectedProtocol2Errors, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), resourceMethod });
}
return data.toArray(new Object[data.size()][]);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method unsupportedNullKeyMapData.
@DataProvider(name = "unsupportedNullKeyMapData")
public Object[][] unsupportedNullKeyMapData() {
final CompoundKey c1 = new CompoundKey().append("a", "a1").append("b", 1);
final Map<CompoundKey, UpdateResponse> results = new ConcurrentHashMap<>();
results.put(c1, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
final BatchUpdateResult<CompoundKey, Foo> batchUpdateResult = new BatchUpdateResult<>(results, new ConcurrentHashMap<>());
final UpdateStatus updateStatus = new UpdateStatus().setStatus(202);
final Map<String, UpdateStatus> expectedProtocol1Results = new HashMap<>();
expectedProtocol1Results.put("a=a1&b=1", updateStatus);
final Map<String, UpdateStatus> expectedProtocol2Results = new HashMap<>();
expectedProtocol2Results.put("(a:a1,b:1)", updateStatus);
return new Object[][] { { batchUpdateResult, AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), expectedProtocol1Results }, { batchUpdateResult, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), expectedProtocol2Results } };
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method update.
public ExampleRequestResponse update() {
checkSupports(ResourceMethod.UPDATE);
UpdateRequestBuilder<Object, RecordTemplatePlaceholder> update = new UpdateRequestBuilder<>(_uriTemplate, RecordTemplatePlaceholder.class, _resourceSpec, _requestOptions);
if (_resourceSpec.getKeyType() != null) {
update.id(generateKey());
}
update.input(generateEntity());
addParams(update, ResourceMethod.UPDATE);
addPathKeys(update);
UpdateRequest<RecordTemplatePlaceholder> request = update.build();
return buildRequestResponse(request, new UpdateResponse(HttpStatus.S_200_OK), buildResourceMethodDescriptorForRestMethod(request));
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method partialUpdate.
public ExampleRequestResponse partialUpdate() {
checkSupports(ResourceMethod.PARTIAL_UPDATE);
PartialUpdateRequestBuilder<Object, RecordTemplatePlaceholder> update = new PartialUpdateRequestBuilder<>(_uriTemplate, RecordTemplatePlaceholder.class, _resourceSpec, _requestOptions);
if (_resourceSpec.getKeyType() != null) {
update.id(generateKey());
}
update.input(PatchGenerator.<RecordTemplatePlaceholder>diffEmpty(generateEntity()));
addParams(update, ResourceMethod.PARTIAL_UPDATE);
addPathKeys(update);
PartialUpdateRequest<RecordTemplatePlaceholder> request = update.build();
return buildRequestResponse(request, new UpdateResponse(HttpStatus.S_200_OK), buildResourceMethodDescriptorForRestMethod(request));
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class TestAlbumEntryResource method makeData.
private void makeData() {
_entries = new AlbumEntry[] { new AlbumEntry().setAddTime(1), new AlbumEntry().setAddTime(2), new AlbumEntry().setAddTime(3), new AlbumEntry().setAddTime(4), new AlbumEntry().setAddTime(5) };
_keys = new CompoundKey[] { new CompoundKey().append("photoId", 1L).append("albumId", 1L), new CompoundKey().append("photoId", 2L).append("albumId", 1L), new CompoundKey().append("photoId", 3L).append("albumId", 1L), new CompoundKey().append("photoId", 1L).append("albumId", 2L), new CompoundKey().append("photoId", 4L).append("albumId", 2L) };
for (int i = 0; i < _entries.length; i++) {
final UpdateResponse uResp = _entryRes.update(_keys[i], _entries[i]);
Assert.assertEquals(uResp.getStatus(), HttpStatus.S_204_NO_CONTENT);
}
}
Aggregations