Search in sources :

Example 61 with TestRecord

use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.

the class TestClientBuilders method checkKeyValueRecordCollectionIsReadOnly.

@SuppressWarnings("unchecked")
private <V extends RecordTemplate> void checkKeyValueRecordCollectionIsReadOnly(ComplexResourceKey<TestRecord, TestRecord> id1, ComplexResourceKey<TestRecord, TestRecord> id2, RecordTemplate t1, RecordTemplate t2, Class<V> valueClass, CollectionRequest<KeyValueRecord<?, V>> entries) {
    for (KeyValueRecord<?, V> entry : entries.getElements()) {
        ComplexResourceKey<TestRecord, TestRecord> generatedKey = entry.getComplexKey(TestRecord.class, TestRecord.class);
        if (generatedKey.equals(id1)) {
            checkComplexKeyIsReadOnly(id1, generatedKey);
        } else {
            checkComplexKeyIsReadOnly(id2, generatedKey);
        }
        Assert.assertTrue(generatedKey.isReadOnly());
        RecordTemplate value = entry.getValue(valueClass);
        if (value.equals(t1)) {
            if (t1.data().isMadeReadOnly()) {
                Assert.assertSame(t1.data(), value.data());
            } else {
                Assert.assertNotSame(t1.data(), value.data());
            }
        } else {
            if (t2.data().isReadOnly()) {
                Assert.assertSame(t2.data(), value.data());
            } else {
                Assert.assertNotSame(t2.data(), value.data());
            }
        }
        Assert.assertTrue(value.data().isMadeReadOnly());
    }
}
Also used : RecordTemplate(com.linkedin.data.template.RecordTemplate) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) TestRecord(com.linkedin.restli.client.test.TestRecord)

Example 62 with TestRecord

use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.

the class BatchGetRequestBuilderTest method testNoFieldBatchingFailure.

@Test
public void testNoFieldBatchingFailure() {
    BatchGetRequestBuilder<Integer, TestRecord> batchRequestBuilder1 = new BatchGetRequestBuilder<Integer, TestRecord>("/", 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<Integer, TestRecord>("/", 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());
    try {
        @SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(batchRequestBuilder1.build(), batchRequestBuilder2.build());
        BatchGetRequestBuilder.batch(requests, false);
        Assert.fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException ignored) {
    // Expected
    }
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 63 with TestRecord

use of com.linkedin.restli.client.test.TestRecord 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<Integer, TestRecord>("/", 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<Integer, TestRecord>("/", 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<Integer>(Arrays.asList(1, 2, 3)));
    testUriGeneration(batchingRequest, expectedProtocol1Uri, expectedProtocol2Uri);
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 64 with TestRecord

use of com.linkedin.restli.client.test.TestRecord 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<Integer, TestRecord>("/", 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<Object>(Arrays.asList(request.getObjectId())));
}
Also used : ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 65 with TestRecord

use of com.linkedin.restli.client.test.TestRecord 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<Integer, TestRecord>("/", 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<Object>(Arrays.asList(request.getObjectId())));
}
Also used : ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Aggregations

TestRecord (com.linkedin.restli.client.test.TestRecord)79 Test (org.testng.annotations.Test)74 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)19 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)18 ResourceMethod (com.linkedin.restli.common.ResourceMethod)16 HashMap (java.util.HashMap)16 CompoundKey (com.linkedin.restli.common.CompoundKey)15 ResourceSpec (com.linkedin.restli.common.ResourceSpec)14 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)13 DataMap (com.linkedin.data.DataMap)12 KeyValueRecord (com.linkedin.restli.common.KeyValueRecord)11 KeyValueRecordFactory (com.linkedin.restli.common.KeyValueRecordFactory)10 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)8 RecordTemplate (com.linkedin.data.template.RecordTemplate)7 CollectionRequest (com.linkedin.restli.common.CollectionRequest)7 BatchRequest (com.linkedin.restli.common.BatchRequest)6 ByteString (com.linkedin.data.ByteString)5 PathSpec (com.linkedin.data.schema.PathSpec)4 FieldDef (com.linkedin.data.template.FieldDef)4 PatchRequest (com.linkedin.restli.common.PatchRequest)3