use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBatchGetCompoundKeyRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchGetWithEncoding")
public void testBatchGetCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
BatchGetRequestBuilder<CompoundKey, TestRecord> builder = new BatchGetRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
CompoundKey key1 = new CompoundKey();
key1.append("equals", "=");
key1.append("ampersand", "&");
CompoundKey key2 = new CompoundKey();
key2.append("equals", "==");
key2.append("ampersand", "&&");
BatchGetKVRequest<CompoundKey, TestRecord> request = builder.ids(key1, key2).fields(TestRecord.fields().id(), TestRecord.fields().message()).buildKV();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
// Compare key sets. Note that have to convert keys to Strings as the request internally converts them to string
HashSet<CompoundKey> expectedIds = new HashSet<CompoundKey>(Arrays.asList(key1, key2));
Assert.assertEquals(request.getObjectIds(), expectedIds);
Assert.assertEquals(request.getFields(), new HashSet<PathSpec>(Arrays.asList(TestRecord.fields().id(), TestRecord.fields().message())));
Assert.assertEquals(request.isSafe(), true);
Assert.assertEquals(request.isIdempotent(), true);
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_GET, null, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyBatchUpdateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKeyAndParam")
public void testComplexKeyBatchUpdateRequestBuilder(URIDetails expectedURIDetails) throws Exception {
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");
RecordTemplate param = buildComplexParam(123, "ParamMessage");
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).setParam("testParam", param).build();
// using toStringFull (which is deprecated) because this is only used to check v1
BatchRequest<TestRecord> expectedRequest = new BatchRequest<TestRecord>(new DataMap(), TestRecord.class);
expectedRequest.getEntities().put(toEntityKey(id1, expectedURIDetails.getProtocolVersion()), t1);
expectedRequest.getEntities().put(toEntityKey(id2, expectedURIDetails.getProtocolVersion()), t2);
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertTrue(request.isIdempotent());
Assert.assertFalse(request.isSafe());
@SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<ComplexResourceKey, TestRecord> factory = new KeyValueRecordFactory<ComplexResourceKey, TestRecord>(ComplexResourceKey.class, TestRecord.class, TestRecord.class, null, TestRecord.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new ComplexResourceKey[] { id1, id2 }, new TestRecord[] { t1, t2 });
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyCreateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "noEntity")
public void testComplexKeyCreateRequestBuilder(URIDetails expectedURIDetails) {
CreateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new CreateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
CreateRequest<TestRecord> request = builder.input(new TestRecord()).build();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
checkBasicRequest(request, expectedURIDetails, ResourceMethod.CREATE, new TestRecord(), Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBatchCreateIdRequestInputIsReadOnly.
@Test
@SuppressWarnings("unchecked")
public void testBatchCreateIdRequestInputIsReadOnly() {
BatchCreateIdRequestBuilder<Long, TestRecord> builder = new BatchCreateIdRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
TestRecord testRecord = new TestRecord();
List<TestRecord> newRecords = Arrays.asList(testRecord);
BatchCreateIdRequest<Long, TestRecord> request = builder.inputs(newRecords).build();
CollectionRequest<TestRecord> createInput = (CollectionRequest<TestRecord>) request.getInputRecord();
Assert.assertNotSame(createInput.getElements().get(0), testRecord);
Assert.assertTrue(createInput.getElements().get(0).data().isMadeReadOnly());
testRecord.data().makeReadOnly();
request = builder.build();
createInput = (CollectionRequest<TestRecord>) request.getInputRecord();
Assert.assertSame(createInput.getElements().get(0), testRecord);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testPartialUpdateCompoundKeyRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "compoundKey")
public void testPartialUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) throws CloneNotSupportedException {
PartialUpdateRequestBuilder<CompoundKey, TestRecord> builder = new PartialUpdateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_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(buildCompoundKey()).input(patch).build();
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
checkBasicRequest(request, expectedURIDetails, ResourceMethod.PARTIAL_UPDATE, patch, Collections.<String, String>emptyMap(), null);
}
Aggregations