use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class TestRequest method testResourceProperties.
@Test
public void testResourceProperties() {
Set<ResourceMethod> expectedSupportedMethods = new HashSet<>();
expectedSupportedMethods.add(ResourceMethod.GET);
expectedSupportedMethods.add(ResourceMethod.BATCH_PARTIAL_UPDATE);
ResourceSpec expectedResourceSpec = new ResourceSpecImpl(expectedSupportedMethods, null, null, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, Object>emptyMap());
Map<String, Object> pathKeys = new HashMap<>();
pathKeys.put("id", new ComplexResourceKey<>(new TestRecord(), new TestRecord()));
Request<TestRecord> request = new Request<>(ResourceMethod.GET, null, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new EntityResponseDecoder<>(TestRecord.class), expectedResourceSpec, Collections.<String, Object>emptyMap(), Collections.<String, Class<?>>emptyMap(), null, "testRecord", pathKeys, RestliRequestOptions.DEFAULT_OPTIONS, null);
ResourceProperties expectedResourceProperties = new ResourcePropertiesImpl(expectedResourceSpec.getSupportedMethods(), expectedResourceSpec.getKeyType(), expectedResourceSpec.getComplexKeyType(), expectedResourceSpec.getValueType(), expectedResourceSpec.getKeyParts());
Assert.assertEquals(request.getResourceProperties(), expectedResourceProperties);
}
use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testSimpleBatching.
@Test
public void testSimpleBatching() throws URISyntaxException {
String expectedProtocol1Uri = "/?fields=id,message&ids=1&ids=2&ids=3¶m1=value1¶m2=value2";
String expectedProtocol2Uri = "/?fields=id,message&ids=List(1,2,3)¶m1=value1¶m2=value2";
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, 2).fields(FIELDS.id()).setParam("param2", "value2").setParam("param1", "value1");
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).fields(FIELDS.id(), FIELDS.message()).setParam("param1", "value1").setParam("param2", "value2");
BatchGetRequest<TestRecord> batchRequest1 = batchRequestBuilder1.build();
BatchGetRequest<TestRecord> batchRequest2 = batchRequestBuilder2.build();
@SuppressWarnings("unchecked") BatchGetRequest<TestRecord> batchingRequest = BatchGetRequestBuilder.batch(Arrays.asList(batchRequest1, batchRequest2));
testUriGeneration(batchingRequest, expectedProtocol1Uri, expectedProtocol2Uri);
Assert.assertEquals(batchingRequest.getBaseUriTemplate(), batchRequest1.getBaseUriTemplate());
Assert.assertEquals(batchingRequest.getPathKeys(), batchRequest1.getPathKeys());
Assert.assertEquals(batchingRequest.getFields(), new HashSet<>(Arrays.asList(FIELDS.id(), FIELDS.message())));
Assert.assertEquals(batchingRequest.getObjectIds(), new HashSet<>(Arrays.asList(1, 2, 3)));
}
use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testBatchKVConversion.
@Test
public void testBatchKVConversion() throws URISyntaxException {
String expectedProtocol1Uri = "/?fields=message,id&ids=1¶m=paramValue";
String expectedProtocol2Uri = "/?fields=message,id&ids=List(1)¶m=paramValue";
GetRequestBuilder<Integer, TestRecord> requestBuilder = new GetRequestBuilder<>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), null, null, Integer.class, TestRecord.class, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
requestBuilder.id(1).fields(FIELDS.id(), FIELDS.message()).setParam("param", "paramValue");
GetRequest<TestRecord> request = requestBuilder.build();
BatchGetKVRequest<Integer, TestRecord> batchRequest = BatchGetRequestBuilder.batchKV(request);
Assert.assertEquals(batchRequest.getBaseUriTemplate(), request.getBaseUriTemplate());
Assert.assertEquals(batchRequest.getPathKeys(), request.getPathKeys());
testUriGeneration(batchRequest, expectedProtocol1Uri, expectedProtocol2Uri);
Assert.assertEquals(batchRequest.getFields(), request.getFields());
Assert.assertEquals(batchRequest.getObjectIds(), new HashSet<>(Arrays.asList(request.getObjectId())));
}
use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testBatchConversion.
@Test
public void testBatchConversion() throws URISyntaxException {
String expectedProtocol1Uri = "/?fields=message,id&ids=1¶m=paramValue";
String expectedProtocol2Uri = "/?fields=message,id&ids=List(1)¶m=paramValue";
GetRequestBuilder<Integer, TestRecord> requestBuilder = new GetRequestBuilder<>("/", TestRecord.class, new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), null, null, int.class, TestRecord.class, Collections.<String, Object>emptyMap()), RestliRequestOptions.DEFAULT_OPTIONS);
requestBuilder.id(1).fields(FIELDS.id(), FIELDS.message()).setParam("param", "paramValue");
GetRequest<TestRecord> request = requestBuilder.build();
BatchGetRequest<TestRecord> batchRequest = BatchGetRequestBuilder.batch(request);
Assert.assertEquals(batchRequest.getBaseUriTemplate(), request.getBaseUriTemplate());
Assert.assertEquals(batchRequest.getPathKeys(), request.getPathKeys());
testUriGeneration(batchRequest, expectedProtocol1Uri, expectedProtocol2Uri);
Assert.assertEquals(batchRequest.getFields(), request.getFields());
Assert.assertEquals(batchRequest.getObjectIds(), new HashSet<>(Arrays.asList(request.getObjectId())));
}
use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.
the class BatchGetRequestBuilderTest method testBatchingWithNoFields.
@Test
public void testBatchingWithNoFields() throws URISyntaxException {
String expectedProtocol1Uri = "/?ids=1&ids=2&ids=3";
String expectedProtocol2Uri = "/?ids=List(1,2,3)";
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);
batchRequestBuilder1.fields();
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();
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)));
testUriGeneration(batchingRequest, expectedProtocol1Uri, expectedProtocol2Uri);
}
Aggregations