use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestPartialRestResponse method testEntity.
@Test
public void testEntity() {
DataMap data = new DataMap();
RecordTemplate record = new Foo(data);
PartialRestResponse response = new PartialRestResponse.Builder().entity(record).build();
assertEquals(response.getEntity(), record);
assertTrue(response.hasData());
assertEquals(response.getDataMap(), data);
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestParameterDefaultValue method testRecord.
@Test
public void testRecord() {
final Map<String, Object> fixture;
fixture = new HashMap<String, Object>();
fixture.put("location", "LinkedIn");
Assert.assertEquals(test("{\"location\": \"LinkedIn\"}", RecordBar.class), new RecordBar(new DataMap(fixture)));
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method complexArrayArgument.
@DataProvider(name = "complexArrayArgument")
private Object[][] complexArrayArgument() {
Map<String, String> map1 = new HashMap<String, String>();
map1.put("a", "A1");
map1.put("b", "111");
Map<String, String> map2 = new HashMap<String, String>();
map2.put("a", "A2");
map2.put("b", "222");
Map<String, String> map3 = new HashMap<String, String>();
map3.put("a", "A3");
map3.put("b", "333");
DataList data = new DataList();
data.add(new DataMap(map1));
data.add(new DataMap(map2));
data.add(new DataMap(map3));
return new Object[][] { { new Parameter<MyComplexKey[]>("myComplexKeys", MyComplexKey[].class, new ArrayDataSchema(DataTemplateUtil.getSchema(MyComplexKey.class)), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {})), "myComplexKeys", "{b=111, a=A1}", data, new Object[] { new MyComplexKey[] { new MyComplexKey().setA("A1").setB(111L), new MyComplexKey().setA("A2").setB(222L), new MyComplexKey().setA("A3").setB(333L) } } } };
}
use of com.linkedin.data.DataMap 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.DataMap in project rest.li by linkedin.
the class TestRestLiResponseHandler method testFieldProjectionRecordsPALSyntax.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicData")
public void testFieldProjectionRecordsPALSyntax(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
RestResponse response;
DataMap data = new DataMap(asMap("f1", "value", "f2", new DataMap(asMap("f3", "value", "f4", "value"))));
// #1 all fields
Status status = new Status(data);
RestRequest request1 = buildRequest("/test?fields=f1,f2:(f3,f4)", acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request1, buildRoutingResult(request1, acceptTypeData.acceptHeaders), status);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
checkProjectedFields(response, new String[] { "f1", "f2", "f3" }, new String[0]);
// #2 some fields
RestRequest request2 = buildRequest("/test?fields=f1,f2:(f3)", acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request2, buildRoutingResult(request2, acceptTypeData.acceptHeaders), status);
assertTrue(status.data().containsKey("f2"));
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
checkProjectedFields(response, new String[] { "f1", "f2", "f3" }, new String[] { "f4" });
// #3 no fields
RestRequest request3 = buildRequest("/test?fields=", acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request3, buildRoutingResult(request3, acceptTypeData.acceptHeaders), status);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
checkProjectedFields(response, new String[] {}, new String[] { "f1", "f2", "f3", "f4" });
assertTrue(status.data().containsKey("f1"));
assertTrue(status.data().containsKey("f2"));
// #4 fields not in schema
RestRequest request4 = buildRequest("/test?fields=f2:(f99)", acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request4, buildRoutingResult(request4, acceptTypeData.acceptHeaders), status);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, Status.class.getName(), null, true, errorResponseHeaderName);
checkProjectedFields(response, new String[] { "f2" }, new String[] { "f1", "f3", "f99" });
assertTrue(status.data().containsKey("f2"));
}
Aggregations