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 BatchGetRequestBuilderTest method testSimpleBatchingFailureWithDiffParams.
@Test
public void testSimpleBatchingFailureWithDiffParams() {
BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder1 = new BatchGetRequestBuilder<Integer, TestRecord>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
batchRequestBuilder1.ids(1, 2).fields(FIELDS.id()).setParam("param1", "value1");
BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder2 = new BatchGetRequestBuilder<Integer, TestRecord>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
batchRequestBuilder2.ids(2, 3).fields(FIELDS.id(), FIELDS.message()).setParam("param1", "value1").setParam("param2", "value2");
BatchGetRequest<TestRecord> batchRequest1 = batchRequestBuilder1.build();
BatchGetRequest<TestRecord> batchRequest2 = batchRequestBuilder2.build();
try {
@SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> batchRequestsList = Arrays.asList(batchRequest1, batchRequest2);
BatchGetRequestBuilder.batch(batchRequestsList);
Assert.fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ignored) {
// Expected
}
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testBatchingWithDifferentRequestOptionsFailure.
@Test
public void testBatchingWithDifferentRequestOptionsFailure() {
BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder1 = new BatchGetRequestBuilder<Integer, TestRecord>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
batchRequestBuilder1.ids(1);
RestliRequestOptions customOptions = new RestliRequestOptionsBuilder().setProtocolVersionOption(ProtocolVersionOption.FORCE_USE_NEXT).build();
BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder2 = new BatchGetRequestBuilder<Integer, TestRecord>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Integer.class, null, null, null, Collections.<String, Object>emptyMap()), customOptions);
batchRequestBuilder2.ids(2, 3);
try {
@SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(batchRequestBuilder1.build(), batchRequestBuilder2.build());
BatchGetRequestBuilder.batch(requests, false);
Assert.fail("expected IllegalArgumentException");
} catch (IllegalArgumentException ignored) {
Assert.assertTrue(ignored.getMessage().contains("Requests must have the same RestliRequestOptions to batch!"));
}
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testBuildFailureForCompoundKeys.
@Test(expectedExceptions = UnsupportedOperationException.class)
public void testBuildFailureForCompoundKeys() {
BatchGetRequestBuilder<CompoundKey, TestRecord> builder = new BatchGetRequestBuilder<CompoundKey, TestRecord>("http://greetings", new BatchResponseDecoder<TestRecord>(TestRecord.class), _compoundResourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
builder.ids(Arrays.asList(new CompoundKey().append("abc", 5)));
builder.build();
}
Aggregations