use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testCompoundKeyBatchingWithoutTypedKeys.
@Test
public void testCompoundKeyBatchingWithoutTypedKeys() {
GetRequestBuilder<CompoundKey, TestRecord> requestBuilder2 = new GetRequestBuilder<CompoundKey, TestRecord>("/", TestRecord.class, _compoundResourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
CompoundKey key = new CompoundKey().append("abc", 1).append("def", 2);
requestBuilder2.id(key);
GetRequest<TestRecord> request2 = requestBuilder2.build();
try {
BatchGetRequestBuilder.batch(request2);
Assert.fail("Compound Keys should not be supported by the non-KV batch operation.");
} catch (UnsupportedOperationException exc) {
}
Map<String, Object> queryParams = new HashMap<String, Object>();
queryParams.put("ids", Arrays.asList((Object) key));
BatchGetRequest<TestRecord> request4 = new BatchGetRequest<TestRecord>(Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new BatchResponseDecoder<TestRecord>(TestRecord.class), queryParams, Collections.<String, Class<?>>emptyMap(), _compoundResourceSpec, "/", Collections.<String, Object>emptyMap(), RestliRequestOptions.DEFAULT_OPTIONS);
try {
@SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(request4);
BatchGetRequestBuilder.batch(requests);
Assert.fail("Compound Keys should not be supported by the non-KV batch operation.");
} catch (UnsupportedOperationException exc) {
}
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testSimpleBatching.
@Test
public void testSimpleBatching() throws URISyntaxException {
String expectedProtocol1Uri = "/?fields=id,message&ids=1&ids=2&ids=3¶m1=value1¶m2=value2";
String expectedProtocol2Uri = "/?fields=id,message&ids=List(1,2,3)¶m1=value1¶m2=value2";
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("param2", "value2").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();
@SuppressWarnings("unchecked") BatchGetRequest<TestRecord> batchingRequest = BatchGetRequestBuilder.batch(Arrays.asList(batchRequest1, batchRequest2));
testUriGeneration(batchingRequest, expectedProtocol1Uri, expectedProtocol2Uri);
Assert.assertEquals(batchingRequest.getBaseUriTemplate(), batchRequest1.getBaseUriTemplate());
Assert.assertEquals(batchingRequest.getPathKeys(), batchRequest1.getPathKeys());
Assert.assertEquals(batchingRequest.getFields(), new HashSet<PathSpec>(Arrays.asList(FIELDS.id(), FIELDS.message())));
Assert.assertEquals(batchingRequest.getObjectIds(), new HashSet<Integer>(Arrays.asList(1, 2, 3)));
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestAbstractRequestBuilder method testPathKeysAreReadOnly.
@Test
@SuppressWarnings("unchecked")
public void testPathKeysAreReadOnly() {
final AbstractRequestBuilder<Object, ?, ?> builder = new DummyAbstractRequestBuilder();
TestRecord testRecord = new TestRecord();
TestRecord testRecord2 = new TestRecord();
ComplexResourceKey<TestRecord, TestRecord> originalKey = new ComplexResourceKey<TestRecord, TestRecord>(testRecord, testRecord2);
builder.pathKey("abc", originalKey);
Map<String, Object> pathKeys = builder.buildReadOnlyPathKeys();
Object key = pathKeys.get("abc");
Assert.assertNotSame(key, originalKey);
Assert.assertTrue(((ComplexResourceKey<TestRecord, TestRecord>) key).isReadOnly());
try {
pathKeys.put("xyz", "abc");
Assert.fail("The generated path keys should be read-only.");
} catch (Exception e) {
}
originalKey.makeReadOnly();
pathKeys = builder.buildReadOnlyPathKeys();
key = pathKeys.get("abc");
Assert.assertSame(key, originalKey);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBuilderPathKeys2.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subSubResourceAction2")
public void testBuilderPathKeys2(URIDetails expectedURIDetails) {
ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
// test with keys containing URL escaped chars
Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action").pathKey("key1", "http://example.com/images/1.png").pathKey("key2", "http://example.com/images/2.png").build();
URIDetails.testUriGeneration(request, expectedURIDetails);
Map<String, String> pathKeys1 = new HashMap<String, String>();
pathKeys1.put("key1", "http://example.com/images/1.png");
pathKeys1.put("key2", "http://example.com/images/2.png");
testPathKeys(request, SUBRESOURCE_URI, pathKeys1);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestSingleEntityRequestBuilder method testInputReadOnliness.
@Test()
public void testInputReadOnliness() {
SingleEntityRequestBuilder<Object, TestRecord, ?> builder = new DummySingleEntityRequestBuilder();
TestRecord originalInput = new TestRecord();
builder.input(originalInput);
Assert.assertNotSame(builder.buildReadOnlyInput(), originalInput);
originalInput.data().makeReadOnly();
Assert.assertSame(builder.buildReadOnlyInput(), originalInput);
}
Aggregations