use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBatchUpdateCompoundKeyRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchCompoundKey")
public void testBatchUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
BatchUpdateRequestBuilder<CompoundKey, TestRecord> builder = new BatchUpdateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
Map<CompoundKey, TestRecord> inputs = new HashMap<CompoundKey, TestRecord>();
CompoundKey key1 = new CompoundKey().append("part1", 1L).append("part2", "2");
CompoundKey key2 = new CompoundKey().append("part1", 11L).append("part2", "22");
TestRecord t1 = new TestRecord().setId(1L).setMessage("1");
TestRecord t2 = new TestRecord().setId(2L);
inputs.put(key1, t1);
inputs.put(key2, t2);
BatchRequest<TestRecord> expectedRequest = new BatchRequest<TestRecord>(new DataMap(), TestRecord.class);
expectedRequest.getEntities().put(toEntityKey(key1, expectedURIDetails.getProtocolVersion()), t1);
expectedRequest.getEntities().put(toEntityKey(key2, expectedURIDetails.getProtocolVersion()), t2);
BatchUpdateRequest<CompoundKey, TestRecord> request = builder.inputs(inputs).build();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), true);
KeyValueRecordFactory<CompoundKey, TestRecord> factory = new KeyValueRecordFactory<CompoundKey, TestRecord>(CompoundKey.class, null, null, getCompoundKeyFieldTypes(), TestRecord.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new CompoundKey[] { key1, key2 }, 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 testUpdateCompoundKeyRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "compoundKey")
public void testUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
UpdateRequestBuilder<CompoundKey, TestRecord> builder = new UpdateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
TestRecord record = new TestRecord().setMessage("foo");
UpdateRequest<TestRecord> request = builder.id(buildCompoundKey()).input(record).build();
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), true);
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
checkBasicRequest(request, expectedURIDetails, ResourceMethod.UPDATE, record, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBuilderPathKeys19.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "simpleSubResourceAction1")
public void testBuilderPathKeys19(URIDetails expectedURIDetails) {
ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_SIMPLE_SUB_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action").pathKey("key1", 1).build();
URIDetails.testUriGeneration(request, expectedURIDetails);
testPathKeys(request, SUBRESOURCE_SIMPLE_SUB_URI, Collections.singletonMap("key1", 1));
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBatchCreateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "noEntity")
public void testBatchCreateRequestBuilder(URIDetails expectedURIDetails) {
BatchCreateRequestBuilder<Long, TestRecord> builder = new BatchCreateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
List<TestRecord> newRecords = Arrays.asList(new TestRecord(), new TestRecord(), new TestRecord());
BatchCreateRequest<TestRecord> request = builder.inputs(newRecords).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
Assert.assertEquals(request.getStreamingAttachments(), _streamingDataSources);
try {
request.getStreamingAttachments().add(new RestLiTestAttachmentDataSource("1", ByteString.empty()));
Assert.fail("Should not be able to add to an immutable list");
} catch (Exception e) {
Assert.assertTrue(e instanceof UnsupportedOperationException);
}
CollectionRequest<TestRecord> expectedRequest = new CollectionRequest<TestRecord>(new DataMap(), TestRecord.class);
expectedRequest.getElements().addAll(newRecords);
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_CREATE, expectedRequest, Collections.<String, String>emptyMap(), _streamingDataSources);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testCreateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "noEntity")
public void testCreateRequestBuilder(URIDetails expectedURIDetails) {
CreateRequestBuilder<Long, TestRecord> builder = new CreateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
CreateRequest<TestRecord> request = builder.input(new TestRecord()).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
Assert.assertEquals(request.getStreamingAttachments(), _streamingDataSources);
try {
request.getStreamingAttachments().add(new RestLiTestAttachmentDataSource("1", ByteString.empty()));
Assert.fail("Should not be able to add to an immutable list");
} catch (Exception e) {
Assert.assertTrue(e instanceof UnsupportedOperationException);
}
checkBasicRequest(request, expectedURIDetails, ResourceMethod.CREATE, new TestRecord(), Collections.<String, String>emptyMap(), _streamingDataSources);
}
Aggregations