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());
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations