use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBatchGetKVInputIsReadOnly.
@Test
@SuppressWarnings("unchecked")
public void testBatchGetKVInputIsReadOnly() {
BatchGetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchGetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
TestRecord testRecord1 = new TestRecord();
TestRecord testRecord2 = new TestRecord();
ComplexResourceKey<TestRecord, TestRecord> key = new ComplexResourceKey<TestRecord, TestRecord>(testRecord1, testRecord2);
BatchGetKVRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.ids(key).buildKV();
ComplexResourceKey<TestRecord, TestRecord> requestKey = (ComplexResourceKey<TestRecord, TestRecord>) request.getObjectIds().iterator().next();
Assert.assertNotSame(requestKey, key);
Assert.assertTrue(requestKey.isReadOnly());
key.makeReadOnly();
request = builder.buildKV();
requestKey = (ComplexResourceKey<TestRecord, TestRecord>) request.getObjectIds().iterator().next();
Assert.assertSame(requestKey, key);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestRequest method testHeadersCaseInsensitiveGet.
@Test
public void testHeadersCaseInsensitiveGet() {
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", "value").build();
Assert.assertEquals(request.getHeaders().get("HEADER"), "value");
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class ParSeqRestClientTest method mockClient.
/**
* @return a mock ParSeqRestClient that returns a TestRecord with the given id.
*/
private ParSeqRestClient mockClient(final long id, final int httpCode, final ProtocolVersion protocolVersion) {
final TestRecord record = new TestRecord().setId(id);
byte[] mapBytes;
try {
mapBytes = new JacksonDataCodec().mapToBytes(record.data());
} catch (final IOException e) {
throw new RuntimeException(e);
}
final Map<String, String> headers = new HashMap<>();
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
return new ParSeqRestClient(new RestClient(new MockClient(httpCode, headers, mapBytes), "http://localhost"), RequestConfigProvider.build(new ParSeqRestliClientConfigBuilder().build(), () -> Optional.empty()));
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testActionRequestInputIsReadOnly.
@Test
@SuppressWarnings("unchecked")
public void testActionRequestInputIsReadOnly() {
FieldDef<TestRecord> pParam = new FieldDef<TestRecord>("p", TestRecord.class, DataTemplateUtil.getSchema(TestRecord.class));
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<String, DynamicRecordMetadata>();
DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>singleton(pParam));
requestMetadataMap.put("action", requestMetadata);
DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<String, DynamicRecordMetadata>();
responseMetadataMap.put("action", responseMetadata);
ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
ActionRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new ActionRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
TestRecord testRecord1 = new TestRecord();
TestRecord testRecord2 = new TestRecord();
ComplexResourceKey<TestRecord, TestRecord> key = new ComplexResourceKey<TestRecord, TestRecord>(testRecord1, testRecord2);
ActionRequest<TestRecord> request = builder.name("action").setParam(pParam, testRecord1).id(key).build();
DynamicRecordTemplate inputParams = (DynamicRecordTemplate) request.getInputRecord();
Assert.assertNotSame(inputParams.getValue(pParam).data(), testRecord1.data());
Assert.assertTrue(inputParams.data().isReadOnly());
Assert.assertTrue(inputParams.getValue(pParam).data().isMadeReadOnly());
Assert.assertNotSame(request.getId(), key);
Assert.assertTrue(((ComplexResourceKey<TestRecord, TestRecord>) request.getId()).isReadOnly());
testRecord1.data().makeReadOnly();
testRecord2.data().makeReadOnly();
request = builder.build();
inputParams = (DynamicRecordTemplate) request.getInputRecord();
Assert.assertSame(inputParams.getValue(pParam).data(), testRecord1.data());
Assert.assertTrue(inputParams.data().isReadOnly());
Assert.assertSame(request.getId(), key);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testPartialUpdateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "singleEntity")
public void testPartialUpdateRequestBuilder(URIDetails expectedURIDetails) throws Exception {
PartialUpdateRequestBuilder<Long, TestRecord> builder = new PartialUpdateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
TestRecord t1 = new TestRecord();
TestRecord t2 = new TestRecord(t1.data().copy());
t2.setId(1L);
t2.setMessage("Foo Bar Baz");
PatchRequest<TestRecord> patch = PatchGenerator.diff(t1, t2);
PartialUpdateRequest<TestRecord> request = builder.id(1L).input(patch).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
checkBasicRequest(request, expectedURIDetails, ResourceMethod.PARTIAL_UPDATE, patch, Collections.<String, String>emptyMap(), _streamingDataSources);
}
Aggregations