use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestGroupsClient method buildComplexKey.
private static ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> buildComplexKey(int memberID, int groupID, int intParam, String stringParam) {
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey = new ComplexResourceKey<>(new GroupMembershipKey(), new GroupMembershipParam());
complexKey.getKey().setMemberID(memberID);
complexKey.getKey().setGroupID(groupID);
complexKey.getParams().setIntParameter(intParam);
complexKey.getParams().setStringParameter(stringParam);
return complexKey;
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestComplexKeysResource method testSubGet.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubGet(RootBuilderWrapper<String, TwoPartKey> builders) throws ExecutionException, InterruptedException {
TwoPartKey key = new TwoPartKey();
key.setMajor("a");
key.setMinor("b");
TwoPartKey param = new TwoPartKey();
param.setMajor("c");
param.setMinor("d");
ComplexResourceKey<TwoPartKey, TwoPartKey> complexKey = new ComplexResourceKey<>(key, param);
Request<TwoPartKey> request = builders.get().setPathKey("keys", complexKey).id("stringKey").build();
TwoPartKey response = getClient().sendRequest(request).get().getEntity();
Assert.assertEquals(response.getMajor(), "aANDc");
Assert.assertEquals(response.getMinor(), "bANDd");
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestEscapeCharsInStringKeys method testGetWithComplexKey.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestComplexKeysBuilderDataProvider")
public void testGetWithComplexKey(RootBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> builders) throws Exception {
TwoPartKey key = new TwoPartKey();
key.setMajor(key1());
key.setMinor(key2());
TwoPartKey params = new TwoPartKey();
params.setMajor(key1());
params.setMinor(key3());
ComplexResourceKey<TwoPartKey, TwoPartKey> complexKey = new ComplexResourceKey<>(key, params);
Request<Message> request = builders.get().id(complexKey).build();
Message response = getClient().sendRequest(request).get().getEntity();
Assert.assertNotNull(response);
Assert.assertEquals(response.getId(), key.getMajor() + " " + key.getMinor(), "Message should be key1 + ' ' + key2 for complexKey(key1,key2)");
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testComplexKey_partialUpdate.
@Test
public void testComplexKey_partialUpdate() throws Exception {
ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Message message = new Message();
message.setTone(Tone.FRIENDLY);
PatchRequest<Message> patch = PatchGenerator.diffEmpty(message);
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>> inputs = new HashMap<>();
ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(StringTestKeys.URL, StringTestKeys.URL2);
inputs.put(key1, patch);
inputs.put(key2, patch);
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> result = complexKeyClient.batchPartialUpdate(inputs).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
// Update return valid result
Assert.assertEquals(result.get(key1).getStatus().intValue(), 204);
Assert.assertEquals(result.get(key2).getStatus().intValue(), 204);
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> getResult = complexKeyClient.batchGet(new HashSet<>(Arrays.asList(key1, key2))).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(getResult.get(key1).getEntity().getTone(), Tone.FRIENDLY);
Assert.assertEquals(getResult.get(key2).getEntity().getTone(), Tone.FRIENDLY);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class ArgumentUtils method parseSimplePathKey.
/**
* The method parses out and returns the correct simple type of the key out of the Object.
* It does not handle {@link CompoundKey}s or {@link ComplexResourceKey}s.
*
* @param value key value string representation to parse
* @param resource {@link com.linkedin.restli.internal.server.model.ResourceModel} containing the key type
* @param version the {@link com.linkedin.restli.common.ProtocolVersion}
* @param validateKey if set throws RoutingException on validation failure
* @return parsed key value in the correct type for the key
* @throws IllegalArgumentException
* @throws NumberFormatException
*/
public static Object parseSimplePathKey(final String value, final ResourceModel resource, final ProtocolVersion version, boolean validateKey) throws IllegalArgumentException {
Key key = resource.getPrimaryKey();
String decodedValue;
if (version.compareTo(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()) >= 0) {
decodedValue = UriComponent.decode(value, UriComponent.Type.PATH_SEGMENT);
} else {
decodedValue = URLEscaper.unescape(value, URLEscaper.Escaping.URL_ESCAPING);
}
return convertSimpleValue(decodedValue, key.getDataSchema(), key.getType(), validateKey);
}
Aggregations