Search in sources :

Example 66 with TestRecord

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

the class BatchGetRequestBuilderTest method testCompoundKeyBatchingWithoutTypedKeys.

@Test
public void testCompoundKeyBatchingWithoutTypedKeys() {
    GetRequestBuilder<CompoundKey, TestRecord> requestBuilder2 = new GetRequestBuilder<CompoundKey, TestRecord>("/", TestRecord.class, _compoundResourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
    CompoundKey key = new CompoundKey().append("abc", 1).append("def", 2);
    requestBuilder2.id(key);
    GetRequest<TestRecord> request2 = requestBuilder2.build();
    try {
        BatchGetRequestBuilder.batch(request2);
        Assert.fail("Compound Keys should not be supported by the non-KV batch operation.");
    } catch (UnsupportedOperationException exc) {
    }
    Map<String, Object> queryParams = new HashMap<String, Object>();
    queryParams.put("ids", Arrays.asList((Object) key));
    BatchGetRequest<TestRecord> request4 = new BatchGetRequest<TestRecord>(Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new BatchResponseDecoder<TestRecord>(TestRecord.class), queryParams, Collections.<String, Class<?>>emptyMap(), _compoundResourceSpec, "/", Collections.<String, Object>emptyMap(), RestliRequestOptions.DEFAULT_OPTIONS);
    try {
        @SuppressWarnings("unchecked") List<BatchGetRequest<TestRecord>> requests = Arrays.asList(request4);
        BatchGetRequestBuilder.batch(requests);
        Assert.fail("Compound Keys should not be supported by the non-KV batch operation.");
    } catch (UnsupportedOperationException exc) {
    }
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 67 with TestRecord

use of com.linkedin.restli.client.test.TestRecord 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<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, 2).fields(FIELDS.id()).setParam("param2", "value2").setParam("param1", "value1");
    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).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<PathSpec>(Arrays.asList(FIELDS.id(), FIELDS.message())));
    Assert.assertEquals(batchingRequest.getObjectIds(), new HashSet<Integer>(Arrays.asList(1, 2, 3)));
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) 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 68 with TestRecord

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

the class TestAbstractRequestBuilder method testPathKeysAreReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testPathKeysAreReadOnly() {
    final AbstractRequestBuilder<Object, ?, ?> builder = new DummyAbstractRequestBuilder();
    TestRecord testRecord = new TestRecord();
    TestRecord testRecord2 = new TestRecord();
    ComplexResourceKey<TestRecord, TestRecord> originalKey = new ComplexResourceKey<TestRecord, TestRecord>(testRecord, testRecord2);
    builder.pathKey("abc", originalKey);
    Map<String, Object> pathKeys = builder.buildReadOnlyPathKeys();
    Object key = pathKeys.get("abc");
    Assert.assertNotSame(key, originalKey);
    Assert.assertTrue(((ComplexResourceKey<TestRecord, TestRecord>) key).isReadOnly());
    try {
        pathKeys.put("xyz", "abc");
        Assert.fail("The generated path keys should be read-only.");
    } catch (Exception e) {
    }
    originalKey.makeReadOnly();
    pathKeys = builder.buildReadOnlyPathKeys();
    key = pathKeys.get("abc");
    Assert.assertSame(key, originalKey);
}
Also used : ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 69 with TestRecord

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

the class TestClientBuilders method testBuilderPathKeys2.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subSubResourceAction2")
public void testBuilderPathKeys2(URIDetails expectedURIDetails) {
    ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
    // test with keys containing URL escaped chars
    Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action").pathKey("key1", "http://example.com/images/1.png").pathKey("key2", "http://example.com/images/2.png").build();
    URIDetails.testUriGeneration(request, expectedURIDetails);
    Map<String, String> pathKeys1 = new HashMap<String, String>();
    pathKeys1.put("key1", "http://example.com/images/1.png");
    pathKeys1.put("key2", "http://example.com/images/2.png");
    testPathKeys(request, SUBRESOURCE_URI, pathKeys1);
}
Also used : HashMap(java.util.HashMap) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ByteString(com.linkedin.data.ByteString) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 70 with TestRecord

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

the class TestSingleEntityRequestBuilder method testInputReadOnliness.

@Test()
public void testInputReadOnliness() {
    SingleEntityRequestBuilder<Object, TestRecord, ?> builder = new DummySingleEntityRequestBuilder();
    TestRecord originalInput = new TestRecord();
    builder.input(originalInput);
    Assert.assertNotSame(builder.buildReadOnlyInput(), originalInput);
    originalInput.data().makeReadOnly();
    Assert.assertSame(builder.buildReadOnlyInput(), originalInput);
}
Also used : TestRecord(com.linkedin.restli.client.test.TestRecord) 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