use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method checkKeyValueRecordCollectionIsReadOnly.
@SuppressWarnings("unchecked")
private <V extends RecordTemplate> void checkKeyValueRecordCollectionIsReadOnly(ComplexResourceKey<TestRecord, TestRecord> id1, ComplexResourceKey<TestRecord, TestRecord> id2, RecordTemplate t1, RecordTemplate t2, Class<V> valueClass, CollectionRequest<KeyValueRecord<?, V>> entries) {
for (KeyValueRecord<?, V> entry : entries.getElements()) {
ComplexResourceKey<TestRecord, TestRecord> generatedKey = entry.getComplexKey(TestRecord.class, TestRecord.class);
if (generatedKey.equals(id1)) {
checkComplexKeyIsReadOnly(id1, generatedKey);
} else {
checkComplexKeyIsReadOnly(id2, generatedKey);
}
Assert.assertTrue(generatedKey.isReadOnly());
RecordTemplate value = entry.getValue(valueClass);
if (value.equals(t1)) {
if (t1.data().isMadeReadOnly()) {
Assert.assertSame(t1.data(), value.data());
} else {
Assert.assertNotSame(t1.data(), value.data());
}
} else {
if (t2.data().isReadOnly()) {
Assert.assertSame(t2.data(), value.data());
} else {
Assert.assertNotSame(t2.data(), value.data());
}
}
Assert.assertTrue(value.data().isMadeReadOnly());
}
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testNoFieldBatchingFailure.
@Test
public void testNoFieldBatchingFailure() {
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);
batchRequestBuilder1.fields(FIELDS.id());
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);
batchRequestBuilder2.fields(FIELDS.message());
try {
@SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(batchRequestBuilder1.build(), batchRequestBuilder2.build());
BatchGetRequestBuilder.batch(requests, false);
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 testBatchingWithNoFields.
@Test
public void testBatchingWithNoFields() throws URISyntaxException {
String expectedProtocol1Uri = "/?ids=1&ids=2&ids=3";
String expectedProtocol2Uri = "/?ids=List(1,2,3)";
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);
batchRequestBuilder1.fields();
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);
batchRequestBuilder2.fields();
BatchGetRequest<TestRecord> batchRequest1 = batchRequestBuilder1.build();
@SuppressWarnings("unchecked") BatchGetRequest<TestRecord> batchingRequest = BatchGetRequestBuilder.batch(Arrays.asList(batchRequest1, batchRequestBuilder2.build()));
Assert.assertEquals(batchingRequest.getBaseUriTemplate(), batchRequest1.getBaseUriTemplate());
Assert.assertEquals(batchingRequest.getPathKeys(), batchRequest1.getPathKeys());
Assert.assertEquals(batchingRequest.getFields(), Collections.emptySet());
Assert.assertEquals(batchingRequest.getObjectIds(), new HashSet<Integer>(Arrays.asList(1, 2, 3)));
testUriGeneration(batchingRequest, expectedProtocol1Uri, expectedProtocol2Uri);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testBatchConversion.
@Test
public void testBatchConversion() throws URISyntaxException {
String expectedProtocol1Uri = "/?fields=message,id&ids=1¶m=paramValue";
String expectedProtocol2Uri = "/?fields=message,id&ids=List(1)¶m=paramValue";
GetRequestBuilder<Integer, TestRecord> requestBuilder = new GetRequestBuilder<Integer, TestRecord>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), null, null, int.class, TestRecord.class, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
requestBuilder.id(1).fields(FIELDS.id(), FIELDS.message()).setParam("param", "paramValue");
GetRequest<TestRecord> request = requestBuilder.build();
BatchGetRequest<TestRecord> batchRequest = BatchGetRequestBuilder.batch(request);
Assert.assertEquals(batchRequest.getBaseUriTemplate(), request.getBaseUriTemplate());
Assert.assertEquals(batchRequest.getPathKeys(), request.getPathKeys());
testUriGeneration(batchRequest, expectedProtocol1Uri, expectedProtocol2Uri);
Assert.assertEquals(batchRequest.getFields(), request.getFields());
Assert.assertEquals(batchRequest.getObjectIds(), new HashSet<Object>(Arrays.asList(request.getObjectId())));
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testBatchKVConversion.
@Test
public void testBatchKVConversion() throws URISyntaxException {
String expectedProtocol1Uri = "/?fields=message,id&ids=1¶m=paramValue";
String expectedProtocol2Uri = "/?fields=message,id&ids=List(1)¶m=paramValue";
GetRequestBuilder<Integer, TestRecord> requestBuilder = new GetRequestBuilder<Integer, TestRecord>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), null, null, Integer.class, TestRecord.class, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
requestBuilder.id(1).fields(FIELDS.id(), FIELDS.message()).setParam("param", "paramValue");
GetRequest<TestRecord> request = requestBuilder.build();
BatchGetKVRequest<Integer, TestRecord> batchRequest = BatchGetRequestBuilder.batchKV(request);
Assert.assertEquals(batchRequest.getBaseUriTemplate(), request.getBaseUriTemplate());
Assert.assertEquals(batchRequest.getPathKeys(), request.getPathKeys());
testUriGeneration(batchRequest, expectedProtocol1Uri, expectedProtocol2Uri);
Assert.assertEquals(batchRequest.getFields(), request.getFields());
Assert.assertEquals(batchRequest.getObjectIds(), new HashSet<Object>(Arrays.asList(request.getObjectId())));
}
Aggregations