Search in sources :

Example 51 with ComplexResourceKey

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;
}
Also used : GroupMembershipParam(com.linkedin.restli.examples.groups.api.GroupMembershipParam) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey)

Example 52 with ComplexResourceKey

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");
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Test(org.testng.annotations.Test)

Example 53 with ComplexResourceKey

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)");
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) Message(com.linkedin.restli.examples.greetings.api.Message) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Test(org.testng.annotations.Test)

Example 54 with ComplexResourceKey

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);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Message(com.linkedin.restli.examples.greetings.api.Message) HashMap(java.util.HashMap) PatchRequest(com.linkedin.restli.common.PatchRequest) EntityResponse(com.linkedin.restli.common.EntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) ComplexKeys(com.linkedin.restli.examples.greetings.client.ComplexKeys) ComplexKeysFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Test(org.testng.annotations.Test)

Example 55 with ComplexResourceKey

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);
}
Also used : ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) AlternativeKey(com.linkedin.restli.server.AlternativeKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey)

Aggregations

ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)89 Test (org.testng.annotations.Test)43 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)19 TestRecord (com.linkedin.restli.client.test.TestRecord)18 CompoundKey (com.linkedin.restli.common.CompoundKey)18 HashMap (java.util.HashMap)17 EmptyRecord (com.linkedin.restli.common.EmptyRecord)16 DataMap (com.linkedin.data.DataMap)15 Message (com.linkedin.restli.examples.greetings.api.Message)14 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)13 Key (com.linkedin.restli.server.Key)13 RecordTemplate (com.linkedin.data.template.RecordTemplate)11 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)11 EntityResponse (com.linkedin.restli.common.EntityResponse)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 HashSet (java.util.HashSet)11 AfterTest (org.testng.annotations.AfterTest)11