use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method updateStatusInstantiation.
@DataProvider(name = "updateStatusInstantiation")
public Object[][] updateStatusInstantiation() {
Map<String, BatchResponseEnvelope.BatchResponseEntry> normal = new HashMap<String, BatchResponseEnvelope.BatchResponseEntry>();
UpdateStatus foo = new UpdateStatus();
// should be overwritten
foo.setStatus(500);
//should be preserved
foo.data().put("foo", "bar");
normal.put("key", new BatchResponseEnvelope.BatchResponseEntry(HttpStatus.S_200_OK, foo));
UpdateStatus normalStatus = new UpdateStatus();
normalStatus.setStatus(200);
normalStatus.data().put("foo", "bar");
Map<String, BatchResponseEnvelope.BatchResponseEntry> missing = new HashMap<String, BatchResponseEnvelope.BatchResponseEntry>();
missing.put("key", new BatchResponseEnvelope.BatchResponseEntry(HttpStatus.S_200_OK, (RecordTemplate) null));
UpdateStatus missingStatus = new UpdateStatus();
missingStatus.setStatus(200);
Map<String, BatchResponseEnvelope.BatchResponseEntry> mismatch = new HashMap<String, BatchResponseEnvelope.BatchResponseEntry>();
mismatch.put("key", new BatchResponseEnvelope.BatchResponseEntry(HttpStatus.S_200_OK, new AnyRecord(new DataMap())));
UpdateStatus mismatchedStatus = new UpdateStatus();
mismatchedStatus.setStatus(200);
RestLiResponseDataImpl batchGetNormal = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchGetNormal.setResponseEnvelope(new BatchGetResponseEnvelope(normal, batchGetNormal));
RestLiResponseDataImpl batchGetMissing = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchGetMissing.setResponseEnvelope(new BatchGetResponseEnvelope(missing, batchGetNormal));
RestLiResponseDataImpl batchGetMismatch = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchGetMismatch.setResponseEnvelope(new BatchGetResponseEnvelope(mismatch, batchGetNormal));
RestLiResponseDataImpl batchUpdateNormal = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchUpdateNormal.setResponseEnvelope(new BatchUpdateResponseEnvelope(normal, batchUpdateNormal));
RestLiResponseDataImpl batchUpdateMissing = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchUpdateMissing.setResponseEnvelope(new BatchUpdateResponseEnvelope(missing, batchUpdateMissing));
RestLiResponseDataImpl batchUpdateMismatch = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchUpdateMismatch.setResponseEnvelope(new BatchUpdateResponseEnvelope(mismatch, batchUpdateMismatch));
RestLiResponseDataImpl batchPartialUpdateNormal = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchPartialUpdateNormal.setResponseEnvelope(new BatchPartialUpdateResponseEnvelope(normal, batchPartialUpdateNormal));
RestLiResponseDataImpl batchPartialUpdateMissing = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchPartialUpdateMissing.setResponseEnvelope(new BatchPartialUpdateResponseEnvelope(missing, batchPartialUpdateMissing));
RestLiResponseDataImpl batchPartialUpdateMismatch = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchPartialUpdateMismatch.setResponseEnvelope(new BatchPartialUpdateResponseEnvelope(mismatch, batchPartialUpdateMismatch));
RestLiResponseDataImpl batchDeleteNormal = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchDeleteNormal.setResponseEnvelope(new BatchDeleteResponseEnvelope(normal, batchDeleteNormal));
RestLiResponseDataImpl batchDeleteMissing = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchDeleteMissing.setResponseEnvelope(new BatchDeleteResponseEnvelope(missing, batchDeleteMissing));
RestLiResponseDataImpl batchDeleteMismatch = new RestLiResponseDataImpl(HttpStatus.S_200_OK, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
batchDeleteMismatch.setResponseEnvelope(new BatchDeleteResponseEnvelope(mismatch, batchDeleteMismatch));
return new Object[][] { { batchGetNormal, normalStatus }, { batchGetMissing, missingStatus }, { batchGetMismatch, mismatchedStatus }, { batchUpdateNormal, normalStatus }, { batchUpdateMissing, missingStatus }, { batchUpdateMismatch, mismatchedStatus }, { batchPartialUpdateNormal, normalStatus }, { batchPartialUpdateMissing, missingStatus }, { batchPartialUpdateMismatch, mismatchedStatus }, { batchDeleteNormal, normalStatus }, { batchDeleteMissing, missingStatus }, { batchDeleteMismatch, mismatchedStatus } };
}
use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class MockBatchEntityResponseFactory method buildDataMap.
private static <K, V extends RecordTemplate> DataMap buildDataMap(Map<K, V> recordTemplates, Map<K, HttpStatus> statuses, Map<K, ErrorResponse> errorResponses, ProtocolVersion version) {
Set<K> mergedKeys = new HashSet<K>();
mergedKeys.addAll(recordTemplates.keySet());
mergedKeys.addAll(statuses.keySet());
mergedKeys.addAll(errorResponses.keySet());
DataMap batchResponseDataMap = new DataMap();
DataMap rawBatchData = new DataMap();
for (K key : mergedKeys) {
DataMap entityResponseData = new DataMap();
RecordTemplate recordTemplate = recordTemplates.get(key);
if (recordTemplate != null) {
entityResponseData.put(EntityResponse.ENTITY, recordTemplate.data());
}
HttpStatus status = statuses.get(key);
if (status != null) {
entityResponseData.put(EntityResponse.STATUS, status.getCode());
}
ErrorResponse errorResponse = errorResponses.get(key);
if (errorResponse != null) {
entityResponseData.put(EntityResponse.ERROR, errorResponse.data());
}
String stringKey = URIParamUtils.encodeKeyForBody(key, false, version);
rawBatchData.put(stringKey, entityResponseData);
}
batchResponseDataMap.put(BatchResponse.RESULTS, rawBatchData);
DataMap rawErrorData = new DataMap();
for (Map.Entry<K, ErrorResponse> errorResponse : errorResponses.entrySet()) {
rawErrorData.put(URIParamUtils.encodeKeyForBody(errorResponse.getKey(), false, version), errorResponse.getValue().data());
}
batchResponseDataMap.put(BatchResponse.ERRORS, rawErrorData);
return batchResponseDataMap;
}
use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyGetRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "complexKeyAndParam")
public void testComplexKeyGetRequestBuilder(URIDetails expectedURIDetails) throws Exception {
GetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new GetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
ComplexResourceKey<TestRecord, TestRecord> id = buildComplexKey(1L, "KeyMessage", 10L, "ParamMessage");
RecordTemplate param1 = buildComplexParam(123, "ParamMessage");
GetRequest<TestRecord> request = builder.id(id).setParam("testParam", param1).build();
Assert.assertTrue(request.isSafe());
Assert.assertTrue(request.isIdempotent());
checkBasicRequest(request, expectedURIDetails, ResourceMethod.GET, null, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyDeleteRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "complexKeyAndParam")
public void testComplexKeyDeleteRequestBuilder(URIDetails expectedURIDetails) throws Exception {
DeleteRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new DeleteRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
ComplexResourceKey<TestRecord, TestRecord> id = buildComplexKey(1L, "KeyMessage", 10L, "ParamMessage");
RecordTemplate param = buildComplexParam(123, "ParamMessage");
DeleteRequest<TestRecord> request = builder.id(id).setParam("testParam", param).build();
Assert.assertFalse(request.isSafe());
Assert.assertTrue(request.isIdempotent());
checkBasicRequest(request, expectedURIDetails, ResourceMethod.DELETE, null, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class TestClientBuilders method checkKeyValueMapIsReadOnly.
private void checkKeyValueMapIsReadOnly(ComplexResourceKey<TestRecord, TestRecord> id1, ComplexResourceKey<TestRecord, TestRecord> id2, RecordTemplate t1, RecordTemplate t2, Class<? extends RecordTemplate> valueClass, Map<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> entries) {
for (Map.Entry<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> entry : entries.entrySet()) {
ComplexResourceKey<TestRecord, TestRecord> generatedKey = entry.getKey();
if (generatedKey.equals(id1)) {
checkComplexKeyIsReadOnly(id1, generatedKey);
} else {
checkComplexKeyIsReadOnly(id2, generatedKey);
}
Assert.assertTrue(generatedKey.isReadOnly());
RecordTemplate value = entry.getValue();
if (value.equals(t1)) {
if (t1.data().isMadeReadOnly()) {
Assert.assertSame(t1, value);
} else {
Assert.assertNotSame(t1, value);
}
} else {
if (t2.data().isReadOnly()) {
Assert.assertSame(t2, value);
} else {
Assert.assertNotSame(t2, value);
}
}
Assert.assertTrue(value.data().isMadeReadOnly());
}
}
Aggregations