use of com.linkedin.restli.common.ResourceSpecImpl in project rest.li by linkedin.
the class TestRequest method testHeadersCaseInsensitiveSet.
@Test
public void testHeadersCaseInsensitiveSet() {
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).setHeader("header", "value1").setHeader("HEADER", "value2").build();
Assert.assertEquals(request.getHeaders().get("header"), "value2");
}
use of com.linkedin.restli.common.ResourceSpecImpl in project rest.li by linkedin.
the class TestRequest method testHeadersCaseInsensitiveAdd.
@Test
public void testHeadersCaseInsensitiveAdd() {
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", "value1").addHeader("HEADER", "value2").build();
Assert.assertEquals(request.getHeaders().get("HEADER"), "value1,value2");
}
use of com.linkedin.restli.common.ResourceSpecImpl in project rest.li by linkedin.
the class TestRequest method testToSecureString.
@Test
public void testToSecureString() {
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(5L).build();
Assert.assertEquals(request.toSecureString(), "com.linkedin.restli.client.GetRequest{_method=get, _baseUriTemplate=abc, _methodName=null, " + "_requestOptions=RestliRequestOptions{_protocolVersionOption=USE_LATEST_IF_AVAILABLE, " + "_requestCompressionOverride=null, _responseCompressionOverride=null, _contentType=null, " + "_acceptTypes=null, _acceptResponseAttachments=false}}");
}
use of com.linkedin.restli.common.ResourceSpecImpl in project rest.li by linkedin.
the class TestCharacterEncoding method testQueryParamValueEncoding.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "protocolVersions")
public void testQueryParamValueEncoding(ProtocolVersion protocolVersion) {
RestLiConfig config = new RestLiConfig();
config.setResourcePackageNames(QueryParamMockCollection.class.getPackage().getName());
RestLiServer server = new RestLiServer(config, new PrototypeResourceFactory(), null);
for (char c = 0; c < 256; ++c) {
final String testValue = String.valueOf(c);
GetRequest<EmptyRecord> req = new GetRequestBuilder<String, EmptyRecord>(QueryParamMockCollection.RESOURCE_NAME, EmptyRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), String.class, null, null, EmptyRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS).id("dummy").setParam(QueryParamMockCollection.VALUE_KEY, testValue).build();
RestRequest restRequest = new RestRequestBuilder(RestliUriBuilderUtil.createUriBuilder(req, protocolVersion).build()).setMethod(req.getMethod().getHttpMethod().toString()).build();
// N.B. since QueryParamMockCollection is implemented using the synchronous rest.li interface,
// RestLiServer.handleRequest() will invoke the application resource *and* the callback
// *synchronously*, ensuring that the all instances of the callback are invoked before the
// loop terminates.
server.handleRequest(restRequest, new RequestContext(), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
Assert.fail();
}
@Override
public void onSuccess(RestResponse result) {
try {
DataMap data = new JacksonDataCodec().readMap(result.getEntity().asInputStream());
Assert.assertEquals(data.get(QueryParamMockCollection.VALUE_KEY), testValue);
Assert.assertEquals(QueryParamMockCollection._lastQueryParamValue, testValue);
} catch (IOException e) {
Assert.fail();
}
}
});
}
}
use of com.linkedin.restli.common.ResourceSpecImpl in project rest.li by linkedin.
the class TestRestClientRequestBuilder method buildInputForBatchPatchAndUpdate.
@SuppressWarnings({ "rawtypes", "deprecation" })
private void buildInputForBatchPatchAndUpdate(Request mockRequest) {
CollectionRequest mockCollectionRequest = EasyMock.createMock(CollectionRequest.class);
EasyMock.expect(mockCollectionRequest.getElements()).andReturn(Collections.emptyList()).once();
EasyMock.expect(mockRequest.getInputRecord()).andReturn(mockCollectionRequest).times(2);
EasyMock.replay(mockCollectionRequest);
ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), null, null, null, EmptyRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
EasyMock.expect(mockRequest.getResourceProperties()).andReturn(new ResourcePropertiesImpl(Collections.<ResourceMethod>emptySet(), null, null, TypeSpec.forClassMaybeNull(EmptyRecord.class), Collections.<String, CompoundKey.TypeInfo>emptyMap())).once();
}
Aggregations