Search in sources :

Example 51 with TestRecord

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

the class TestClientBuilders method testBatchGetCompoundKeyRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchGetWithEncoding")
public void testBatchGetCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
    BatchGetRequestBuilder<CompoundKey, TestRecord> builder = new BatchGetRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    CompoundKey key1 = new CompoundKey();
    key1.append("equals", "=");
    key1.append("ampersand", "&");
    CompoundKey key2 = new CompoundKey();
    key2.append("equals", "==");
    key2.append("ampersand", "&&");
    BatchGetKVRequest<CompoundKey, TestRecord> request = builder.ids(key1, key2).fields(TestRecord.fields().id(), TestRecord.fields().message()).buildKV();
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    // Compare key sets. Note that have to convert keys to Strings as the request internally converts them to string
    HashSet<CompoundKey> expectedIds = new HashSet<CompoundKey>(Arrays.asList(key1, key2));
    Assert.assertEquals(request.getObjectIds(), expectedIds);
    Assert.assertEquals(request.getFields(), new HashSet<PathSpec>(Arrays.asList(TestRecord.fields().id(), TestRecord.fields().message())));
    Assert.assertEquals(request.isSafe(), true);
    Assert.assertEquals(request.isIdempotent(), true);
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_GET, null, Collections.<String, String>emptyMap(), null);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) TestRecord(com.linkedin.restli.client.test.TestRecord) PathSpec(com.linkedin.data.schema.PathSpec) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 52 with TestRecord

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

the class TestClientBuilders method testComplexKeyBatchUpdateRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKeyAndParam")
public void testComplexKeyBatchUpdateRequestBuilder(URIDetails expectedURIDetails) throws Exception {
    BatchUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    ComplexResourceKey<TestRecord, TestRecord> id1 = buildComplexKey(1L, "KeyMessage1", 10L, "ParamMessage1");
    ComplexResourceKey<TestRecord, TestRecord> id2 = buildComplexKey(2L, "KeyMessage2", 20L, "ParamMessage2");
    RecordTemplate param = buildComplexParam(123, "ParamMessage");
    TestRecord t1 = new TestRecord().setMessage("foo");
    TestRecord t2 = new TestRecord().setMessage("bar");
    BatchUpdateRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.input(id1, t1).input(id2, t2).setParam("testParam", param).build();
    // using toStringFull (which is deprecated) because this is only used to check v1
    BatchRequest<TestRecord> expectedRequest = new BatchRequest<TestRecord>(new DataMap(), TestRecord.class);
    expectedRequest.getEntities().put(toEntityKey(id1, expectedURIDetails.getProtocolVersion()), t1);
    expectedRequest.getEntities().put(toEntityKey(id2, expectedURIDetails.getProtocolVersion()), t2);
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    Assert.assertTrue(request.isIdempotent());
    Assert.assertFalse(request.isSafe());
    @SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<ComplexResourceKey, TestRecord> factory = new KeyValueRecordFactory<ComplexResourceKey, TestRecord>(ComplexResourceKey.class, TestRecord.class, TestRecord.class, null, TestRecord.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new ComplexResourceKey[] { id1, id2 }, new TestRecord[] { t1, t2 });
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), null);
}
Also used : BatchRequest(com.linkedin.restli.common.BatchRequest) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) RecordTemplate(com.linkedin.data.template.RecordTemplate) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 53 with TestRecord

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

the class TestClientBuilders method testComplexKeyCreateRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "noEntity")
public void testComplexKeyCreateRequestBuilder(URIDetails expectedURIDetails) {
    CreateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new CreateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    CreateRequest<TestRecord> request = builder.input(new TestRecord()).build();
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.CREATE, 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 54 with TestRecord

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

the class TestClientBuilders method testBatchCreateIdRequestInputIsReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testBatchCreateIdRequestInputIsReadOnly() {
    BatchCreateIdRequestBuilder<Long, TestRecord> builder = new BatchCreateIdRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord testRecord = new TestRecord();
    List<TestRecord> newRecords = Arrays.asList(testRecord);
    BatchCreateIdRequest<Long, TestRecord> request = builder.inputs(newRecords).build();
    CollectionRequest<TestRecord> createInput = (CollectionRequest<TestRecord>) request.getInputRecord();
    Assert.assertNotSame(createInput.getElements().get(0), testRecord);
    Assert.assertTrue(createInput.getElements().get(0).data().isMadeReadOnly());
    testRecord.data().makeReadOnly();
    request = builder.build();
    createInput = (CollectionRequest<TestRecord>) request.getInputRecord();
    Assert.assertSame(createInput.getElements().get(0), testRecord);
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 55 with TestRecord

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

the class TestClientBuilders method testPartialUpdateCompoundKeyRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "compoundKey")
public void testPartialUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) throws CloneNotSupportedException {
    PartialUpdateRequestBuilder<CompoundKey, TestRecord> builder = new PartialUpdateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord t1 = new TestRecord();
    TestRecord t2 = new TestRecord(t1.data().copy());
    t2.setId(1L);
    t2.setMessage("Foo Bar Baz");
    PatchRequest<TestRecord> patch = PatchGenerator.diff(t1, t2);
    PartialUpdateRequest<TestRecord> request = builder.id(buildCompoundKey()).input(patch).build();
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.PARTIAL_UPDATE, patch, Collections.<String, String>emptyMap(), null);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) 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