Search in sources :

Example 36 with ResourceMethod

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);
}
Also used : HashMap(java.util.HashMap) ResourcePropertiesImpl(com.linkedin.restli.internal.common.ResourcePropertiesImpl) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ResourceProperties(com.linkedin.restli.common.ResourceProperties) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 37 with ResourceMethod

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&param1=value1&param2=value2";
    String expectedProtocol2Uri = "/?fields=id,message&ids=List(1,2,3)&param1=value1&param2=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)));
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 38 with ResourceMethod

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&param=paramValue";
    String expectedProtocol2Uri = "/?fields=message,id&ids=List(1)&param=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())));
}
Also used : TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 39 with ResourceMethod

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&param=paramValue";
    String expectedProtocol2Uri = "/?fields=message,id&ids=List(1)&param=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())));
}
Also used : TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 40 with ResourceMethod

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);
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Aggregations

ResourceMethod (com.linkedin.restli.common.ResourceMethod)54 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)18 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)13 DataMap (com.linkedin.data.DataMap)12 TestRecord (com.linkedin.restli.client.test.TestRecord)12 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)10 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)6 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)6 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)5 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)4 RecordTemplate (com.linkedin.data.template.RecordTemplate)4 Foo (com.linkedin.pegasus.generator.examples.Foo)4 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)4 ResourceSchemaArray (com.linkedin.restli.restspec.ResourceSchemaArray)4 JClass (com.sun.codemodel.JClass)4 JDefinedClass (com.sun.codemodel.JDefinedClass)4 ByteString (com.linkedin.data.ByteString)3