Search in sources :

Example 16 with TestRecord

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

the class TestClientBuilders method testBatchGetEntityInputIsReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testBatchGetEntityInputIsReadOnly() {
    BatchGetEntityRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchGetEntityRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord testRecord1 = new TestRecord();
    TestRecord testRecord2 = new TestRecord();
    ComplexResourceKey<TestRecord, TestRecord> key = new ComplexResourceKey<TestRecord, TestRecord>(testRecord1, testRecord2);
    BatchGetEntityRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.ids(key).build();
    ComplexResourceKey<TestRecord, TestRecord> requestKey = (ComplexResourceKey<TestRecord, TestRecord>) request.getObjectIds().iterator().next();
    Assert.assertNotSame(requestKey, key);
    Assert.assertTrue(requestKey.isReadOnly());
    key.makeReadOnly();
    request = builder.build();
    requestKey = (ComplexResourceKey<TestRecord, TestRecord>) request.getObjectIds().iterator().next();
    Assert.assertSame(requestKey, key);
}
Also used : ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 17 with TestRecord

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

the class TestClientBuilders method testActionRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "action")
public void testActionRequestBuilder(URIDetails expectedURIDetails) {
    FieldDef<String> pParam = new FieldDef<String>("p", String.class, DataTemplateUtil.getSchema(String.class));
    Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<String, DynamicRecordMetadata>();
    DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>singleton(pParam));
    requestMetadataMap.put("action", requestMetadata);
    DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
    Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<String, DynamicRecordMetadata>();
    responseMetadataMap.put("action", responseMetadata);
    ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap, Long.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
    ActionRequestBuilder<Long, TestRecord> builder = new ActionRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
    ActionRequest<TestRecord> request = builder.name("action").setParam(pParam, "42").id(1L).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
    DataMap d = new DataMap();
    d.put("p", "42");
    @SuppressWarnings("unchecked") DynamicRecordTemplate expectedRecordTemplate = new DynamicRecordTemplate(d, DynamicRecordMetadata.buildSchema("action", Arrays.asList(new FieldDef<String>("p", String.class, DataTemplateUtil.getSchema(String.class)))));
    URIDetails.testUriGeneration(request, expectedURIDetails);
    Assert.assertEquals(request.getMethod(), ResourceMethod.ACTION);
    Assert.assertEquals(request.getHeaders(), Collections.<String, String>emptyMap());
    Assert.assertEquals(request.getInputRecord(), expectedRecordTemplate);
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    Assert.assertEquals(request.getStreamingAttachments(), _streamingDataSources);
    try {
        request.getStreamingAttachments().add(new RestLiTestAttachmentDataSource("1", ByteString.empty()));
        Assert.fail("Should not be able to add to an immutable list");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof UnsupportedOperationException);
    }
    Assert.assertEquals(request.getResponseDecoder().getEntityClass(), Void.class);
}
Also used : HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) RestLiTestAttachmentDataSource(com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 18 with TestRecord

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

the class TestClientBuilders method testBuilderPathKeys10.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subResourceAction1")
public void testBuilderPathKeys10(URIDetails expectedURIDetails) {
    ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
    // simple resource & sub resources tests
    Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_SIMPLE_ROOT_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action").pathKey("key1", 1).build();
    URIDetails.testUriGeneration(request, expectedURIDetails);
    testPathKeys(request, SUBRESOURCE_SIMPLE_ROOT_URI, Collections.singletonMap("key1", 1));
}
Also used : ResourceSpec(com.linkedin.restli.common.ResourceSpec) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 19 with TestRecord

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

the class TestClientBuilders method testBatchCreateRequestInputIsReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testBatchCreateRequestInputIsReadOnly() {
    BatchCreateRequestBuilder<Long, TestRecord> builder = new BatchCreateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord testRecord = new TestRecord();
    List<TestRecord> newRecords = Arrays.asList(testRecord);
    BatchCreateRequest<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 20 with TestRecord

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

the class TestSingleEntityRequestBuilder method testIdReadOnliness.

@Test()
public void testIdReadOnliness() {
    SingleEntityRequestBuilder<Object, TestRecord, ?> builder = new DummySingleEntityRequestBuilder();
    ComplexResourceKey<TestRecord, TestRecord> originalKey = new ComplexResourceKey<TestRecord, TestRecord>(new TestRecord(), new TestRecord());
    builder.id(originalKey);
    Assert.assertNotSame(builder.buildReadOnlyId(), originalKey);
    originalKey.makeReadOnly();
    Assert.assertSame(builder.buildReadOnlyId(), originalKey);
}
Also used : ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) 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