Search in sources :

Example 71 with DataMap

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);
}
Also used : RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 72 with DataMap

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)));
}
Also used : RecordBar(com.linkedin.pegasus.generator.test.RecordBar) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest)

Example 73 with DataMap

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) } } } };
}
Also used : DataList(com.linkedin.data.DataList) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) HashMap(java.util.HashMap) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) DataMap(com.linkedin.data.DataMap) DataProvider(org.testng.annotations.DataProvider)

Example 74 with DataMap

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 } };
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) AnyRecord(com.linkedin.restli.internal.server.methods.AnyRecord) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DataMap(com.linkedin.data.DataMap) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataProvider(org.testng.annotations.DataProvider)

Example 75 with DataMap

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"));
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) CreateStatus(com.linkedin.restli.common.CreateStatus) Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) PartialRestResponse(com.linkedin.restli.internal.server.response.PartialRestResponse) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

DataMap (com.linkedin.data.DataMap)471 Test (org.testng.annotations.Test)238 DataList (com.linkedin.data.DataList)130 ByteString (com.linkedin.data.ByteString)110 HashMap (java.util.HashMap)56 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)49 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)47 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)46 DataSchema (com.linkedin.data.schema.DataSchema)45 Map (java.util.Map)45 ArrayList (java.util.ArrayList)31 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)23 PathSpec (com.linkedin.data.schema.PathSpec)21 RecordTemplate (com.linkedin.data.template.RecordTemplate)21 DataProvider (org.testng.annotations.DataProvider)20 HashSet (java.util.HashSet)19 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)18 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)18 CompoundKey (com.linkedin.restli.common.CompoundKey)18 IOException (java.io.IOException)18