use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestComplexArrayResource method testBatchGet.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "versionWithRequestOptionsDataProvider")
public void testBatchGet(ProtocolVersion version, RestliRequestOptions options) throws RemoteInvocationException {
List<ComplexResourceKey<ComplexArray, ComplexArray>> complexKeys = getBatchCompleKeys();
ComplexArrayBuilders builders = new ComplexArrayBuilders(options);
Request<BatchKVResponse<ComplexResourceKey<ComplexArray, ComplexArray>, Greeting>> request = builders.batchGet().ids(complexKeys).buildKV();
Response<BatchKVResponse<ComplexResourceKey<ComplexArray, ComplexArray>, Greeting>> response = getClient().sendRequest(request).getResponse();
Greeting greeting1 = response.getEntity().getResults().get(complexKeys.get(0));
Assert.assertNotNull(greeting1);
Greeting greeting2 = response.getEntity().getResults().get(complexKeys.get(1));
Assert.assertNotNull(greeting2);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestComplexArrayResource method getBatchCompleKeys.
private static List<ComplexResourceKey<ComplexArray, ComplexArray>> getBatchCompleKeys() {
LongArray singleton1 = new LongArray(1L);
ComplexArray next1 = new ComplexArray().setArray(singleton1);
ComplexArray key1 = new ComplexArray().setArray(singleton1).setNext(next1);
ComplexArray params1 = new ComplexArray().setArray(singleton1).setNext(next1);
ComplexResourceKey<ComplexArray, ComplexArray> complexKey1 = new ComplexResourceKey<>(key1, params1);
LongArray singleton2 = new LongArray(2L);
ComplexArray next2 = new ComplexArray().setArray(singleton2);
ComplexArray key2 = new ComplexArray().setArray(singleton2).setNext(next2);
ComplexArray params2 = new ComplexArray().setArray(singleton2).setNext(next2);
ComplexResourceKey<ComplexArray, ComplexArray> complexKey2 = new ComplexResourceKey<>(key2, params2);
List<ComplexResourceKey<ComplexArray, ComplexArray>> complexKeys = new ArrayList<>();
complexKeys.add(complexKey1);
complexKeys.add(complexKey2);
return complexKeys;
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestAltKeyResource method testComplexKeyAltKeyCreate.
@Test
public void testComplexKeyAltKeyCreate() throws Throwable {
// In ComplexKeyAltKeyResource create method, we predefine a ComplexKey,
// here we coerce that key to Alternative Key,
// which will be used as expected key which will be returned by response.
StringComplexKeyCoercer coercer = new StringComplexKeyCoercer();
TwoPartKey key = new TwoPartKey();
key.setMajor("testKey");
key.setMinor("testKey");
ComplexResourceKey<TwoPartKey, TwoPartKey> complexKey = new ComplexResourceKey<>(key, new TwoPartKey());
String altKey = coercer.coerceFromKey(complexKey);
Message message = new Message().setMessage("message");
byte[] byteArray = dataTemplateToBytes(message);
URI altKeyUri = URI.create(URI_PREFIX + RestLiIntTestServer.DEFAULT_PORT + "/complexKeyAltKey?altkey=alt");
RestRequest altKeyRequest = new RestRequestBuilder(altKeyUri).setHeader(HEADER_RESTLI_PROTOCOL_VERSION, PROTOCOL_VERSION_2).setEntity(byteArray).setMethod(RestMethod.POST).build();
RestResponse response = client.restRequest(altKeyRequest).get();
Assert.assertNotNull(response);
Assert.assertEquals(response.getStatus(), 201);
Assert.assertEquals(response.getHeader(HEADER_RESTLI_ID), altKey);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method generateKey.
private Object generateKey(ResourceSpec resourceSpec, ResourceSchema resourceSchema, Integer batchIdx) {
if (resourceSpec.getKeyType() == null) {
throw new IllegalArgumentException("Cannot generate key for keyless resource.");
}
switch(toResourceKeyType(resourceSpec.getKeyType().getType())) {
case COMPLEX:
RecordDataSchema keySchema = (RecordDataSchema) resourceSpec.getComplexKeyType().getKeyType().getSchema();
DataMap keyData = (DataMap) _dataGenerator.buildData(postfixBatchIdx(keySchema.getName() + "Key", batchIdx), keySchema);
RecordDataSchema paramsSchema = (RecordDataSchema) resourceSpec.getComplexKeyType().getParamsType().getSchema();
DataMap paramsData = (DataMap) _dataGenerator.buildData(postfixBatchIdx(keySchema.getName() + "Params", batchIdx), paramsSchema);
return new ComplexResourceKey<>(new RecordTemplatePlaceholder(keyData, keySchema), new RecordTemplatePlaceholder(paramsData, paramsSchema));
case COMPOUND:
CompoundKey compoundKey = new CompoundKey();
for (Map.Entry<String, CompoundKey.TypeInfo> keyPart : resourceSpec.getKeyParts().entrySet()) {
String key = keyPart.getKey();
CompoundKey.TypeInfo typeInfo = keyPart.getValue();
compoundKey.append(key, _dataGenerator.buildData(postfixBatchIdx(key, batchIdx), typeInfo.getBinding().getSchema()), typeInfo);
}
return compoundKey;
case PRIMITIVE:
String keyName = resourceSchema.getCollection().getIdentifier().getName();
return _dataGenerator.buildData(postfixBatchIdx(keyName, batchIdx), resourceSpec.getKeyType().getSchema());
case NONE:
return null;
default:
throw new IllegalStateException("Unknown enum value: " + resourceSpec.getKeyType().getType());
}
}
Aggregations