Search in sources :

Example 71 with TestRecord

use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.

the class TestMultiplexedCallback method testSuccess.

@Test
public void testSuccess() throws Exception {
    FutureCallback<RestResponse> callback1 = new FutureCallback<RestResponse>();
    FutureCallback<RestResponse> callback2 = new FutureCallback<RestResponse>();
    ImmutableMap<Integer, Callback<RestResponse>> individualCallbacks = ImmutableMap.<Integer, Callback<RestResponse>>of(ID1, callback1, ID2, callback2);
    FutureCallback<MultiplexedResponse> aggregatedCallback = new FutureCallback<MultiplexedResponse>();
    TestRecord entity1 = fakeEntity(ID1);
    IndividualResponse ir1 = fakeIndividualResponse(entity1);
    TestRecord entity2 = fakeEntity(ID2);
    IndividualResponse ir2 = fakeIndividualResponse(entity2);
    MultiplexedResponseContent responseContent = new MultiplexedResponseContent().setResponses(new IndividualResponseMap(ImmutableMap.of(Integer.toString(ID1), ir1, Integer.toString(ID2), ir2)));
    MultiplexedCallback multiplexedCallback = new MultiplexedCallback(individualCallbacks, aggregatedCallback);
    multiplexedCallback.onSuccess(fakeRestResponse(responseContent));
    assertRestResponseEquals(callback1.get(), fakeRestResponse(entity1));
    assertRestResponseEquals(callback2.get(), fakeRestResponse(entity2));
    MultiplexedResponse multiplexedResponse = aggregatedCallback.get();
    Assert.assertEquals(multiplexedResponse.getStatus(), HttpStatus.S_200_OK.getCode());
    Assert.assertEquals(multiplexedResponse.getHeaders(), HEADERS);
}
Also used : MultiplexedResponseContent(com.linkedin.restli.common.multiplexer.MultiplexedResponseContent) RestResponse(com.linkedin.r2.message.rest.RestResponse) IndividualResponse(com.linkedin.restli.common.multiplexer.IndividualResponse) FutureCallback(com.linkedin.common.callback.FutureCallback) Callback(com.linkedin.common.callback.Callback) TestRecord(com.linkedin.restli.client.test.TestRecord) IndividualResponseMap(com.linkedin.restli.common.multiplexer.IndividualResponseMap) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Example 72 with TestRecord

use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.

the class TestClientBuilders method testBatchUpdateRequestInputIsReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testBatchUpdateRequestInputIsReadOnly() {
    BatchUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    ComplexResourceKey<TestRecord, TestRecord> id1 = buildComplexKey(1L, "KeyMessage1", 10L, "ParamMessage1");
    ComplexResourceKey<TestRecord, TestRecord> id2 = buildComplexKey(2L, "KeyMessage2", 20L, "ParamMessage2");
    TestRecord t1 = new TestRecord().setMessage("foo");
    TestRecord t2 = new TestRecord().setMessage("bar");
    BatchUpdateRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.input(id1, t1).input(id2, t2).build();
    checkKeyValueRecordCollectionIsReadOnly(id1, id2, t1, t2, TestRecord.class, (CollectionRequest<KeyValueRecord<?, TestRecord>>) request.getInputRecord());
    checkKeyValueMapIsReadOnly(id1, id2, t1, t2, TestRecord.class, request.getUpdateInputMap());
    id1.makeReadOnly();
    t2.data().makeReadOnly();
    request = builder.input(id1, t1).input(id2, t2).build();
    checkKeyValueRecordCollectionIsReadOnly(id1, id2, t1, t2, TestRecord.class, (CollectionRequest<KeyValueRecord<?, TestRecord>>) request.getInputRecord());
    checkKeyValueMapIsReadOnly(id1, id2, t1, t2, TestRecord.class, request.getUpdateInputMap());
}
Also used : KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 73 with TestRecord

use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.

the class TestRequest method testResourceProperties.

@Test
public void testResourceProperties() {
    Set<ResourceMethod> expectedSupportedMethods = new HashSet<ResourceMethod>();
    expectedSupportedMethods.add(ResourceMethod.GET);
    expectedSupportedMethods.add(ResourceMethod.BATCH_PARTIAL_UPDATE);
    ResourceSpec expectedResourceSpec = new ResourceSpecImpl(expectedSupportedMethods, null, null, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, Object>emptyMap());
    Map<String, Object> pathKeys = new HashMap<String, Object>();
    pathKeys.put("id", new ComplexResourceKey<TestRecord, TestRecord>(new TestRecord(), new TestRecord()));
    Request<TestRecord> request = new Request<TestRecord>(ResourceMethod.GET, null, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new EntityResponseDecoder<TestRecord>(TestRecord.class), expectedResourceSpec, Collections.<String, Object>emptyMap(), Collections.<String, Class<?>>emptyMap(), null, "testRecord", pathKeys, RestliRequestOptions.DEFAULT_OPTIONS, null);
    ResourceProperties expectedResourceProperties = new ResourcePropertiesImpl(expectedResourceSpec.getSupportedMethods(), expectedResourceSpec.getKeyType(), expectedResourceSpec.getComplexKeyType(), expectedResourceSpec.getValueType(), expectedResourceSpec.getKeyParts());
    Assert.assertEquals(request.getResourceProperties(), expectedResourceProperties);
}
Also used : HashMap(java.util.HashMap) ResourcePropertiesImpl(com.linkedin.restli.internal.common.ResourcePropertiesImpl) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ResourceProperties(com.linkedin.restli.common.ResourceProperties) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 74 with TestRecord

use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.

the class TestRequest method testHeadersCaseInsensitiveSet.

@Test
public void testHeadersCaseInsensitiveSet() {
    final long id = 42l;
    final ResourceSpec spec = new ResourceSpecImpl(EnumSet.allOf(ResourceMethod.class), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Long.class, null, null, TestRecord.class, Collections.<String, Class<?>>emptyMap());
    GetRequestBuilder<Long, TestRecord> builder = new GetRequestBuilder<Long, TestRecord>("abc", TestRecord.class, spec, RestliRequestOptions.DEFAULT_OPTIONS);
    Request<TestRecord> request = builder.id(id).setHeader("header", "value1").setHeader("HEADER", "value2").build();
    Assert.assertEquals(request.getHeaders().get("header"), "value2");
}
Also used : ResourceSpec(com.linkedin.restli.common.ResourceSpec) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 75 with TestRecord

use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.

the class TestRequest method testHeadersCaseInsensitiveAdd.

@Test
public void testHeadersCaseInsensitiveAdd() {
    final long id = 42l;
    final ResourceSpec spec = new ResourceSpecImpl(EnumSet.allOf(ResourceMethod.class), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Long.class, null, null, TestRecord.class, Collections.<String, Class<?>>emptyMap());
    GetRequestBuilder<Long, TestRecord> builder = new GetRequestBuilder<Long, TestRecord>("abc", TestRecord.class, spec, RestliRequestOptions.DEFAULT_OPTIONS);
    Request<TestRecord> request = builder.id(id).addHeader("header", "value1").addHeader("HEADER", "value2").build();
    Assert.assertEquals(request.getHeaders().get("HEADER"), "value1,value2");
}
Also used : ResourceSpec(com.linkedin.restli.common.ResourceSpec) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Aggregations

TestRecord (com.linkedin.restli.client.test.TestRecord)79 Test (org.testng.annotations.Test)74 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)19 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)18 ResourceMethod (com.linkedin.restli.common.ResourceMethod)16 HashMap (java.util.HashMap)16 CompoundKey (com.linkedin.restli.common.CompoundKey)15 ResourceSpec (com.linkedin.restli.common.ResourceSpec)14 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)13 DataMap (com.linkedin.data.DataMap)12 KeyValueRecord (com.linkedin.restli.common.KeyValueRecord)11 KeyValueRecordFactory (com.linkedin.restli.common.KeyValueRecordFactory)10 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)8 RecordTemplate (com.linkedin.data.template.RecordTemplate)7 CollectionRequest (com.linkedin.restli.common.CollectionRequest)7 BatchRequest (com.linkedin.restli.common.BatchRequest)6 ByteString (com.linkedin.data.ByteString)5 PathSpec (com.linkedin.data.schema.PathSpec)4 FieldDef (com.linkedin.data.template.FieldDef)4 PatchRequest (com.linkedin.restli.common.PatchRequest)3