Search in sources :

Example 36 with TestRecord

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

the class TestClientBuilders method testBatchGetKVInputIsReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testBatchGetKVInputIsReadOnly() {
    BatchGetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchGetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord testRecord1 = new TestRecord();
    TestRecord testRecord2 = new TestRecord();
    ComplexResourceKey<TestRecord, TestRecord> key = new ComplexResourceKey<TestRecord, TestRecord>(testRecord1, testRecord2);
    BatchGetKVRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.ids(key).buildKV();
    ComplexResourceKey<TestRecord, TestRecord> requestKey = (ComplexResourceKey<TestRecord, TestRecord>) request.getObjectIds().iterator().next();
    Assert.assertNotSame(requestKey, key);
    Assert.assertTrue(requestKey.isReadOnly());
    key.makeReadOnly();
    request = builder.buildKV();
    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 37 with TestRecord

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

the class TestRequest method testHeadersCaseInsensitiveGet.

@Test
public void testHeadersCaseInsensitiveGet() {
    final long id = 42l;
    final ResourceSpec spec = new ResourceSpecImpl(EnumSet.allOf(ResourceMethod.class), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), Long.class, null, null, TestRecord.class, Collections.<String, Class<?>>emptyMap());
    GetRequestBuilder<Long, TestRecord> builder = new GetRequestBuilder<Long, TestRecord>("abc", TestRecord.class, spec, RestliRequestOptions.DEFAULT_OPTIONS);
    Request<TestRecord> request = builder.id(id).addHeader("header", "value").build();
    Assert.assertEquals(request.getHeaders().get("HEADER"), "value");
}
Also used : ResourceSpec(com.linkedin.restli.common.ResourceSpec) 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 38 with TestRecord

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

the class ParSeqRestClientTest method mockClient.

/**
   * @return a mock ParSeqRestClient that returns a TestRecord with the given id.
   */
private ParSeqRestClient mockClient(final long id, final int httpCode, final ProtocolVersion protocolVersion) {
    final TestRecord record = new TestRecord().setId(id);
    byte[] mapBytes;
    try {
        mapBytes = new JacksonDataCodec().mapToBytes(record.data());
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
    final Map<String, String> headers = new HashMap<>();
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
    return new ParSeqRestClient(new RestClient(new MockClient(httpCode, headers, mapBytes), "http://localhost"), RequestConfigProvider.build(new ParSeqRestliClientConfigBuilder().build(), () -> Optional.empty()));
}
Also used : JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) HashMap(java.util.HashMap) IOException(java.io.IOException) TestRecord(com.linkedin.restli.client.test.TestRecord)

Example 39 with TestRecord

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

the class TestClientBuilders method testActionRequestInputIsReadOnly.

@Test
@SuppressWarnings("unchecked")
public void testActionRequestInputIsReadOnly() {
    FieldDef<TestRecord> pParam = new FieldDef<TestRecord>("p", TestRecord.class, DataTemplateUtil.getSchema(TestRecord.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, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
    ActionRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new ActionRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord testRecord1 = new TestRecord();
    TestRecord testRecord2 = new TestRecord();
    ComplexResourceKey<TestRecord, TestRecord> key = new ComplexResourceKey<TestRecord, TestRecord>(testRecord1, testRecord2);
    ActionRequest<TestRecord> request = builder.name("action").setParam(pParam, testRecord1).id(key).build();
    DynamicRecordTemplate inputParams = (DynamicRecordTemplate) request.getInputRecord();
    Assert.assertNotSame(inputParams.getValue(pParam).data(), testRecord1.data());
    Assert.assertTrue(inputParams.data().isReadOnly());
    Assert.assertTrue(inputParams.getValue(pParam).data().isMadeReadOnly());
    Assert.assertNotSame(request.getId(), key);
    Assert.assertTrue(((ComplexResourceKey<TestRecord, TestRecord>) request.getId()).isReadOnly());
    testRecord1.data().makeReadOnly();
    testRecord2.data().makeReadOnly();
    request = builder.build();
    inputParams = (DynamicRecordTemplate) request.getInputRecord();
    Assert.assertSame(inputParams.getValue(pParam).data(), testRecord1.data());
    Assert.assertTrue(inputParams.data().isReadOnly());
    Assert.assertSame(request.getId(), key);
}
Also used : HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ByteString(com.linkedin.data.ByteString) FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) Test(org.testng.annotations.Test)

Example 40 with TestRecord

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

the class TestClientBuilders method testPartialUpdateRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "singleEntity")
public void testPartialUpdateRequestBuilder(URIDetails expectedURIDetails) throws Exception {
    PartialUpdateRequestBuilder<Long, TestRecord> builder = new PartialUpdateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_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(1L).input(patch).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.PARTIAL_UPDATE, patch, Collections.<String, String>emptyMap(), _streamingDataSources);
}
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