Search in sources :

Example 6 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata 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)));
}
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 7 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class BatchGetRequestBuilderTest method testSimpleBatchingFailureWithDiffParams.

@Test
public void testSimpleBatchingFailureWithDiffParams() {
    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("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();
    try {
        @SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> batchRequestsList = Arrays.asList(batchRequest1, batchRequest2);
        BatchGetRequestBuilder.batch(batchRequestsList);
        Assert.fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ignored) {
    // Expected
    }
}
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 8 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class BatchGetRequestBuilderTest method testBatchingWithDifferentRequestOptionsFailure.

@Test
public void testBatchingWithDifferentRequestOptionsFailure() {
    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);
    RestliRequestOptions customOptions = new RestliRequestOptionsBuilder().setProtocolVersionOption(ProtocolVersionOption.FORCE_USE_NEXT).build();
    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()), customOptions);
    batchRequestBuilder2.ids(2, 3);
    try {
        @SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(batchRequestBuilder1.build(), batchRequestBuilder2.build());
        BatchGetRequestBuilder.batch(requests, false);
        Assert.fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException ignored) {
        Assert.assertTrue(ignored.getMessage().contains("Requests must have the same RestliRequestOptions to batch!"));
    }
}
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 9 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class BatchGetRequestBuilderTest method testNoFieldBatching.

@Test
public void testNoFieldBatching() throws URISyntaxException {
    String expectedProtocol1Uri = "/?fields=id&ids=1&ids=2&ids=3";
    String expectedProtocol2Uri = "/?fields=id&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(FIELDS.id());
    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.id());
    BatchGetRequest<TestRecord> batchRequest1 = batchRequestBuilder1.build();
    @SuppressWarnings("unchecked") BatchGetRequest<TestRecord> batchingRequest = BatchGetRequestBuilder.batch(Arrays.asList(batchRequest1, batchRequestBuilder2.build()), false);
    Assert.assertEquals(batchingRequest.getBaseUriTemplate(), batchRequest1.getBaseUriTemplate());
    Assert.assertEquals(batchingRequest.getPathKeys(), batchRequest1.getPathKeys());
    Assert.assertEquals(batchingRequest.getFields(), new HashSet<>(Arrays.asList(FIELDS.id())));
    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)

Example 10 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class BatchGetRequestBuilderTest method testBatchingWithDiffUris.

@Test
public void testBatchingWithDiffUris() {
    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);
    BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder2 = new BatchGetRequestBuilder<>("/a/", 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);
    @SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(batchRequestBuilder1.build(), batchRequestBuilder2.build());
    try {
        BatchGetRequestBuilder.batch(requests);
        Assert.fail("Expected IllegalArgumentException");
    } catch (IllegalArgumentException ignored) {
    // Expected
    }
}
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

DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)21 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)14 TestRecord (com.linkedin.restli.client.test.TestRecord)13 Test (org.testng.annotations.Test)13 ResourceMethod (com.linkedin.restli.common.ResourceMethod)10 FieldDef (com.linkedin.data.template.FieldDef)6 HashMap (java.util.HashMap)6 ByteString (com.linkedin.data.ByteString)5 ResourceSpec (com.linkedin.restli.common.ResourceSpec)4 CompoundKey (com.linkedin.restli.common.CompoundKey)3 ActionSchema (com.linkedin.restli.restspec.ActionSchema)3 ArrayList (java.util.ArrayList)3 DataSchema (com.linkedin.data.schema.DataSchema)2 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)2 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)2 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)2 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)2 DataMap (com.linkedin.data.DataMap)1 ActionRequestBuilder (com.linkedin.restli.client.ActionRequestBuilder)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1