Search in sources :

Example 41 with TestRecord

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

the class TestClientBuilders method testComplexKeyUpdateRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "complexKey")
public void testComplexKeyUpdateRequestBuilder(URIDetails expectedURIDetails) {
    UpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new UpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    ComplexResourceKey<TestRecord, TestRecord> key = buildComplexKey(1L, "keyMessage", 2L, "paramMessage");
    UpdateRequest<TestRecord> request = builder.id(key).input(new TestRecord()).build();
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), true);
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.UPDATE, new TestRecord(), Collections.<String, String>emptyMap(), null);
}
Also used : ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 42 with TestRecord

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

the class TestClientBuilders method buildComplexParam.

/**
   * Helper method to build complex param instance
   */
private RecordTemplate buildComplexParam(int id, String message) {
    TestRecord result = new TestRecord();
    result.setId(id);
    result.setMessage(message);
    return result;
}
Also used : TestRecord(com.linkedin.restli.client.test.TestRecord)

Example 43 with TestRecord

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

the class TestClientBuilders method testComplexKeyBatchPartialUpdateRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKey")
public void testComplexKeyBatchPartialUpdateRequestBuilder(URIDetails expectedURIDetails) {
    BatchPartialUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchPartialUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    Map<ComplexResourceKey<TestRecord, TestRecord>, PatchRequest<TestRecord>> inputs = new HashMap<ComplexResourceKey<TestRecord, TestRecord>, PatchRequest<TestRecord>>();
    ComplexResourceKey<TestRecord, TestRecord> key1 = buildComplexKey(1L, "keyMessage1", 2L, "paramMessage1");
    ComplexResourceKey<TestRecord, TestRecord> key2 = buildComplexKey(3L, "keyMessage2", 4L, "paramMessage2");
    TestRecord t1 = new TestRecord().setId(1L);
    TestRecord t2 = new TestRecord().setId(2L).setMessage("foo");
    TestRecord t3 = new TestRecord().setMessage("bar");
    PatchRequest<TestRecord> patch1 = PatchGenerator.diff(t1, t2);
    PatchRequest<TestRecord> patch2 = PatchGenerator.diff(t2, t3);
    inputs.put(key1, patch1);
    inputs.put(key2, patch2);
    BatchPartialUpdateRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.inputs(inputs).build();
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    // using .toStringFull (which is deprecated) because this is only used for checking v1
    @SuppressWarnings({ "unchecked", "rawtypes" }) BatchRequest<PatchRequest<TestRecord>> batchRequest = new BatchRequest(new DataMap(), PatchRequest.class);
    batchRequest.getEntities().put(toEntityKey(key1, expectedURIDetails.getProtocolVersion()), patch1);
    batchRequest.getEntities().put(toEntityKey(key2, expectedURIDetails.getProtocolVersion()), patch2);
    @SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<ComplexResourceKey, PatchRequest> factory = new KeyValueRecordFactory<ComplexResourceKey, PatchRequest>(ComplexResourceKey.class, TestRecord.class, TestRecord.class, null, PatchRequest.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new ComplexResourceKey[] { key1, key2 }, new PatchRequest[] { patch1, patch2 });
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_PARTIAL_UPDATE, collectionRequest, batchRequest, Collections.<String, String>emptyMap(), null);
}
Also used : BatchRequest(com.linkedin.restli.common.BatchRequest) HashMap(java.util.HashMap) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) PatchRequest(com.linkedin.restli.common.PatchRequest) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 44 with TestRecord

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

the class TestClientBuilders method testBatchPartialUpdateCompoundKeyRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchCompoundKey")
public void testBatchPartialUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) throws CloneNotSupportedException {
    BatchPartialUpdateRequestBuilder<CompoundKey, TestRecord> builder = new BatchPartialUpdateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    Map<CompoundKey, PatchRequest<TestRecord>> inputs = new HashMap<CompoundKey, PatchRequest<TestRecord>>();
    CompoundKey key1 = new CompoundKey().append("part1", 1L).append("part2", "2");
    CompoundKey key2 = new CompoundKey().append("part1", 11L).append("part2", "22");
    TestRecord t1 = new TestRecord().setId(1L).setMessage("1");
    TestRecord t2 = new TestRecord().setId(2L);
    TestRecord t3 = new TestRecord().setMessage("3");
    PatchRequest<TestRecord> patch1 = PatchGenerator.diff(t1, t2);
    PatchRequest<TestRecord> patch2 = PatchGenerator.diff(t2, t3);
    inputs.put(key1, patch1);
    inputs.put(key2, patch2);
    BatchPartialUpdateRequest<CompoundKey, TestRecord> request = builder.inputs(inputs).build();
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    @SuppressWarnings({ "unchecked", "rawtypes" }) BatchRequest<PatchRequest<TestRecord>> expectedRequest = new BatchRequest(new DataMap(), PatchRequest.class);
    expectedRequest.getEntities().put(toEntityKey(key1, expectedURIDetails.getProtocolVersion()), patch1);
    expectedRequest.getEntities().put(toEntityKey(key2, expectedURIDetails.getProtocolVersion()), patch2);
    @SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<CompoundKey, PatchRequest> factory = new KeyValueRecordFactory<CompoundKey, PatchRequest>(CompoundKey.class, null, null, getCompoundKeyFieldTypes(), PatchRequest.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new CompoundKey[] { key1, key2 }, new PatchRequest[] { patch1, patch2 });
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_PARTIAL_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), null);
}
Also used : BatchRequest(com.linkedin.restli.common.BatchRequest) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) PatchRequest(com.linkedin.restli.common.PatchRequest) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 45 with TestRecord

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

the class TestCollectionRequestUtil method testPrimitiveKeySingleEntity.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "versions")
public void testPrimitiveKeySingleEntity(ProtocolVersion version) {
    KeyValueRecordFactory<Long, TestRecord> factory = new KeyValueRecordFactory<Long, TestRecord>(Long.class, null, null, null, TestRecord.class);
    TestRecord testRecord = buildTestRecord(1L, "message");
    KeyValueRecord<Long, TestRecord> kvRecord = factory.create(1L, testRecord);
    @SuppressWarnings("rawtypes") CollectionRequest<KeyValueRecord> collectionRequest = new CollectionRequest<KeyValueRecord>(KeyValueRecord.class);
    collectionRequest.getElements().add(kvRecord);
    @SuppressWarnings("unchecked") BatchRequest<TestRecord> batchRequest = CollectionRequestUtil.convertToBatchRequest(collectionRequest, Long.class, null, null, null, TestRecord.class, version);
    Map<String, TestRecord> entities = batchRequest.getEntities();
    Assert.assertEquals(entities.size(), 1);
    Assert.assertEquals(entities.get("1"), testRecord);
}
Also used : KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) CollectionRequest(com.linkedin.restli.common.CollectionRequest) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) 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