use of com.linkedin.restli.common.ResourceSpec 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"));
}
use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class TestClientBuilders method testBuilderPathKeys11.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subResourceAction2")
public void testBuilderPathKeys11(URIDetails expectedURIDetails) {
ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_SIMPLE_ROOT_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_ROOT_URI, Collections.singletonMap("key1", "http://example.com/images/1.png"));
}
use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class TestClientBuilders method testActionRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "action")
public void testActionRequestBuilder(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);
ActionRequest<TestRecord> request = builder.name("action").setParam(pParam, "42").id(1L).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
DataMap d = new DataMap();
d.put("p", "42");
@SuppressWarnings("unchecked") DynamicRecordTemplate expectedRecordTemplate = new DynamicRecordTemplate(d, DynamicRecordMetadata.buildSchema("action", Arrays.asList(new FieldDef<String>("p", String.class, DataTemplateUtil.getSchema(String.class)))));
URIDetails.testUriGeneration(request, expectedURIDetails);
Assert.assertEquals(request.getMethod(), ResourceMethod.ACTION);
Assert.assertEquals(request.getHeaders(), Collections.<String, String>emptyMap());
Assert.assertEquals(request.getInputRecord(), expectedRecordTemplate);
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);
}
Assert.assertEquals(request.getResponseDecoder().getEntityClass(), Void.class);
}
use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class TestClientBuilders method testBuilderPathKeys10.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subResourceAction1")
public void testBuilderPathKeys10(URIDetails expectedURIDetails) {
ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
// simple resource & sub resources tests
Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_SIMPLE_ROOT_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action").pathKey("key1", 1).build();
URIDetails.testUriGeneration(request, expectedURIDetails);
testPathKeys(request, SUBRESOURCE_SIMPLE_ROOT_URI, Collections.singletonMap("key1", 1));
}
use of com.linkedin.restli.common.ResourceSpec in project rest.li by linkedin.
the class TestRequest method testHeadersCaseInsensitiveGet.
@Test
public void testHeadersCaseInsensitiveGet() {
final long id = 42l;
final ResourceSpec spec = new ResourceSpecImpl(EnumSet.allOf(ResourceMethod.class), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Long.class, null, null, TestRecord.class, Collections.<String, Class<?>>emptyMap());
GetRequestBuilder<Long, TestRecord> builder = new GetRequestBuilder<Long, TestRecord>("abc", TestRecord.class, spec, RestliRequestOptions.DEFAULT_OPTIONS);
Request<TestRecord> request = builder.id(id).addHeader("header", "value").build();
Assert.assertEquals(request.getHeaders().get("HEADER"), "value");
}
Aggregations