use of com.linkedin.restli.common.ResourceSpecImpl 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");
}
use of com.linkedin.restli.common.ResourceSpecImpl in project rest.li by linkedin.
the class TestTyperefCustomDoubleAssociationKeyResource method testGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testGet(RestliRequestOptions requestOptions) throws RemoteInvocationException, URISyntaxException {
HashMap<String, CompoundKey.TypeInfo> keyParts = new HashMap<>();
keyParts.put("src", new CompoundKey.TypeInfo(CustomDouble.class, CustomDoubleRef.class));
keyParts.put("dest", new CompoundKey.TypeInfo(URI.class, UriRef.class));
GetRequestBuilder<CompoundKey, Message> getBuilder = new GetRequestBuilder<>("typerefCustomDoubleAssociationKeyResource", Message.class, new ResourceSpecImpl(EnumSet.of(ResourceMethod.GET), new HashMap<>(), new HashMap<>(), CompoundKey.class, null, null, Message.class, keyParts), requestOptions);
final String[] stringArray = { "foo" };
GetRequest<Message> req = getBuilder.id(new CompoundKey().append("src", new CustomDouble(100.0)).append("dest", new URI("http://www.linkedin.com/"))).setReqParam("array", stringArray).build();
Response<Message> resp = REST_CLIENT.sendRequest(req).getResponse();
Message result = resp.getEntity();
Assert.assertEquals(result.getId(), "100.0->www.linkedin.com");
Assert.assertEquals(result.getMessage(), String.format("I need some $20. Array contents %s.", Arrays.asList(stringArray)));
// key validation failure scenario
try {
req = getBuilder.id(new CompoundKey().append("src", new CustomDouble(100.02)).append("dest", new URI("http://www.linkedin.com/"))).setReqParam("array", stringArray).build();
REST_CLIENT.sendRequest(req).getResponse();
} catch (RestLiResponseException ex) {
Assert.assertEquals(ex.getServiceErrorMessage(), "Input field validation failure, reason: ERROR :: :: \"100.02\" does not match [0-9]*\\.[0-9]\n");
Assert.assertEquals(ex.getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
}
}
use of com.linkedin.restli.common.ResourceSpecImpl 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<>("p", String.class, DataTemplateUtil.getSchema(String.class));
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<>();
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<>();
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<>(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<>("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.ResourceSpecImpl 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<>("p", String.class, DataTemplateUtil.getSchema(String.class));
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<>();
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<>();
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<>(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.common.ResourceSpecImpl in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testBatchingWithNullProjectionFirst.
@Test
public void testBatchingWithNullProjectionFirst() {
BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder1 = new BatchGetRequestBuilder<>("/", 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);
BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder2 = new BatchGetRequestBuilder<>("/", 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());
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<>(Arrays.asList(1, 2, 3)));
}
Aggregations