use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBuilderPathKeys1.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subSubResourceAction1")
public void testBuilderPathKeys1(URIDetails expectedURIDetails) {
List<FieldDef<?>> fieldDefs = new ArrayList<FieldDef<?>>();
fieldDefs.add(new FieldDef<Integer>("key1", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
fieldDefs.add(new FieldDef<Integer>("key2", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", fieldDefs);
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<String, DynamicRecordMetadata>();
requestMetadataMap.put("action", requestMetadata);
DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<String, DynamicRecordMetadata>();
responseMetadataMap.put("action", responseMetadata);
ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
Map<String, Integer> expectedPathKeys = new HashMap<String, Integer>();
expectedPathKeys.put("key1", 1);
expectedPathKeys.put("key2", 2);
Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action").pathKey("key1", 1).pathKey("key2", 2).build();
URIDetails.testUriGeneration(request, expectedURIDetails);
testPathKeys(request, SUBRESOURCE_URI, expectedPathKeys);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testUpdateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "singleEntity")
public void testUpdateRequestBuilder(URIDetails expectedURIDetails) {
UpdateRequestBuilder<Long, TestRecord> builder = new UpdateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
UpdateRequest<TestRecord> request = builder.id(1L).input(new TestRecord()).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), true);
checkBasicRequest(request, expectedURIDetails, ResourceMethod.UPDATE, new TestRecord(), Collections.<String, String>emptyMap(), _streamingDataSources);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testActionRequestNullOptionalParams.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "action")
public void testActionRequestNullOptionalParams(URIDetails expectedURIDetails) {
FieldDef<String> pParam = new FieldDef<String>("p", String.class, DataTemplateUtil.getSchema(String.class));
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<String, DynamicRecordMetadata>();
DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>singleton(pParam));
requestMetadataMap.put("action", requestMetadata);
DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<String, DynamicRecordMetadata>();
responseMetadataMap.put("action", responseMetadata);
ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap, Long.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
ActionRequestBuilder<Long, TestRecord> builder = new ActionRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
pParam.getField().setOptional(true);
ActionRequest<TestRecord> requestNullOptionalValue = builder.name("action").setParam(pParam, null).id(2L).build();
Assert.assertEquals(requestNullOptionalValue.getMethod(), ResourceMethod.ACTION);
Assert.assertEquals(requestNullOptionalValue.getHeaders(), Collections.<String, String>emptyMap());
Assert.assertEquals(requestNullOptionalValue.isSafe(), false);
Assert.assertEquals(requestNullOptionalValue.isIdempotent(), false);
Assert.assertEquals(requestNullOptionalValue.getResponseDecoder().getEntityClass(), Void.class);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBatchPartialUpdateRequestBuilder.
// need suppress on the method because the more specific suppress isn't being obeyed.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batch")
public void testBatchPartialUpdateRequestBuilder(URIDetails expectedURIDetails) {
BatchPartialUpdateRequestBuilder<Long, TestRecord> builder = new BatchPartialUpdateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
builder.input(1L, new PatchRequest<TestRecord>());
builder.input(2L, new PatchRequest<TestRecord>());
builder.input(3L, new PatchRequest<TestRecord>());
BatchPartialUpdateRequest<Long, TestRecord> request = builder.appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertEquals(request.getObjectIds(), new HashSet<Long>(Arrays.asList(1L, 2L, 3L)));
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
@SuppressWarnings({ "unchecked", "rawtypes" }) BatchRequest<PatchRequest<TestRecord>> expectedRequest = new BatchRequest(new DataMap(), PatchRequest.class);
expectedRequest.getEntities().put("1", new PatchRequest<TestRecord>());
expectedRequest.getEntities().put("2", new PatchRequest<TestRecord>());
expectedRequest.getEntities().put("3", new PatchRequest<TestRecord>());
KeyValueRecordFactory<Long, PatchRequest> factory = new KeyValueRecordFactory<Long, PatchRequest>(Long.class, null, null, null, PatchRequest.class);
CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new Long[] { 1L, 2L, 3L }, new PatchRequest[] { new PatchRequest(), new PatchRequest(), new PatchRequest() });
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_PARTIAL_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), _streamingDataSources);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestClientBuilders method testBuilderPathKeys20.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "simpleSubResourceAction2")
public void testBuilderPathKeys20(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", "http://example.com/images/1.png").build();
URIDetails.testUriGeneration(request, expectedURIDetails);
testPathKeys(request, SUBRESOURCE_SIMPLE_SUB_URI, Collections.singletonMap("key1", "http://example.com/images/1.png"));
}
Aggregations