Search in sources :

Example 21 with TestRecord

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

the class TestClientBuilders method testPartialUpdateRequestBuilderWithKeylessResource.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "noEntity")
public void testPartialUpdateRequestBuilderWithKeylessResource(URIDetails expectedURIDetails) throws Exception {
    PartialUpdateRequestBuilder<Long, TestRecord> builder = new PartialUpdateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _SIMPLE_RESOURCE_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.input(patch).build();
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.PARTIAL_UPDATE, patch, Collections.<String, String>emptyMap(), null);
}
Also used : TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 22 with TestRecord

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

the class TestClientBuilders method testBuilderParam.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "builderParam")
public void testBuilderParam(URIDetails expectedURIDetails) {
    final GetRequestBuilder<Long, TestRecord> builder = new GetRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    final Collection<Integer> coll = Arrays.asList(3, 4, 5);
    final IntegerArray array = new IntegerArray(coll);
    final GetRequest<TestRecord> request = builder.id(1L).setReqParam("simpleKey", 2).setParam("arrayKey1", coll).setParam("arrayKey2", array).build();
    URIDetails.testUriGeneration(request, expectedURIDetails);
}
Also used : TestRecord(com.linkedin.restli.client.test.TestRecord) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Example 23 with TestRecord

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

the class TestClientBuilders method checkKeyValueMapIsReadOnly.

private void checkKeyValueMapIsReadOnly(ComplexResourceKey<TestRecord, TestRecord> id1, ComplexResourceKey<TestRecord, TestRecord> id2, RecordTemplate t1, RecordTemplate t2, Class<? extends RecordTemplate> valueClass, Map<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> entries) {
    for (Map.Entry<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> entry : entries.entrySet()) {
        ComplexResourceKey<TestRecord, TestRecord> generatedKey = entry.getKey();
        if (generatedKey.equals(id1)) {
            checkComplexKeyIsReadOnly(id1, generatedKey);
        } else {
            checkComplexKeyIsReadOnly(id2, generatedKey);
        }
        Assert.assertTrue(generatedKey.isReadOnly());
        RecordTemplate value = entry.getValue();
        if (value.equals(t1)) {
            if (t1.data().isMadeReadOnly()) {
                Assert.assertSame(t1, value);
            } else {
                Assert.assertNotSame(t1, value);
            }
        } else {
            if (t2.data().isReadOnly()) {
                Assert.assertSame(t2, value);
            } else {
                Assert.assertNotSame(t2, value);
            }
        }
        Assert.assertTrue(value.data().isMadeReadOnly());
    }
}
Also used : RecordTemplate(com.linkedin.data.template.RecordTemplate) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Map(java.util.Map) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) TestRecord(com.linkedin.restli.client.test.TestRecord)

Example 24 with TestRecord

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

the class TestClientBuilders method testBuilderPathKeys11.

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

Example 25 with TestRecord

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

the class TestClientBuilders method testCrudBuilderParams8.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "noEntityWithParam")
public void testCrudBuilderParams8(URIDetails expectedURIDetails) {
    Request<CollectionResponse<CreateStatus>> request = new BatchCreateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS).input(new TestRecord()).setParam("foo", "bar").build();
    URIDetails.testUriGeneration(request, expectedURIDetails);
}
Also used : CollectionResponse(com.linkedin.restli.common.CollectionResponse) 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