Search in sources :

Example 26 with ComplexResourceKey

use of com.linkedin.restli.common.ComplexResourceKey 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 27 with ComplexResourceKey

use of com.linkedin.restli.common.ComplexResourceKey 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 28 with ComplexResourceKey

use of com.linkedin.restli.common.ComplexResourceKey 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)

Example 29 with ComplexResourceKey

use of com.linkedin.restli.common.ComplexResourceKey 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 30 with ComplexResourceKey

use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.

the class TestUriParamUtils method testComplexKeyToString.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "complexKey")
public void testComplexKeyToString(ProtocolVersion version, String full, String notFull) {
    MyComplexKey myComplexKey1 = new MyComplexKey();
    myComplexKey1.setA("stringVal");
    myComplexKey1.setB(3);
    MyComplexKey myComplexKey2 = new MyComplexKey();
    myComplexKey2.setA("anotherStringVal");
    myComplexKey2.setB(4);
    ComplexResourceKey<MyComplexKey, MyComplexKey> complexKey = new ComplexResourceKey<MyComplexKey, MyComplexKey>(myComplexKey1, myComplexKey2);
    String complexKeyString = URIParamUtils.keyToString(complexKey, NO_ESCAPING, null, true, version);
    Assert.assertEquals(complexKeyString, full);
    // not full
    String complexKeyStringNotFull = URIParamUtils.keyToString(complexKey, NO_ESCAPING, null, false, version);
    Assert.assertEquals(complexKeyStringNotFull, notFull);
}
Also used : MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Test(org.testng.annotations.Test)

Aggregations

ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)71 Test (org.testng.annotations.Test)36 TestRecord (com.linkedin.restli.client.test.TestRecord)18 DataMap (com.linkedin.data.DataMap)15 CompoundKey (com.linkedin.restli.common.CompoundKey)15 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)15 HashMap (java.util.HashMap)15 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)12 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)11 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)11 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)11 DiscoveredItemKey (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey)11 DiscoveredItemKeyParams (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams)11 AfterTest (org.testng.annotations.AfterTest)11 BeforeTest (org.testng.annotations.BeforeTest)11 Message (com.linkedin.restli.examples.greetings.api.Message)10 ArrayList (java.util.ArrayList)10 RecordTemplate (com.linkedin.data.template.RecordTemplate)9 Key (com.linkedin.restli.server.Key)9 DiscoveredItem (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItem)9