Search in sources :

Example 76 with CompoundKey

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

the class TestBatchGetResponseBuilder method unsupportedNullKeyMapData.

/* Note that we use java.util.concurrent.ConcurrentHashMap when possible. This is because rest.li checks
  * for the presence of nulls returned from maps which are returned from resource methods. The checking for nulls
  * is prone to a NullPointerException since contains(null) can throw an NPE from certain map implementations such as
  * java.util.concurrent.ConcurrentHashMap. We want to make sure our check for the presence of nulls is done in a
  * way that doesn't throw an NullPointerException.
  */
@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "unsupportedNullKeyMapData")
public Object[][] unsupportedNullKeyMapData() {
    Map<CompoundKey, Foo> results = new ConcurrentHashMap<CompoundKey, Foo>();
    CompoundKey c1 = new CompoundKey().append("a", "a1").append("b", 1);
    Foo record1 = new Foo().setStringField("record1").setFruitsField(Fruits.APPLE);
    results.put(c1, record1);
    Map<CompoundKey, HttpStatus> statuses = new ConcurrentHashMap<CompoundKey, HttpStatus>();
    statuses.put(c1, HttpStatus.S_200_OK);
    final BatchResult<CompoundKey, Foo> batchResult = new BatchResult<CompoundKey, Foo>(results, statuses, new ConcurrentHashMap<CompoundKey, RestLiServiceException>());
    final Map<String, Foo> protocol1TransformedResults = new ConcurrentHashMap<String, Foo>();
    protocol1TransformedResults.put("a=a1&b=1", record1);
    final Map<String, Foo> protocol2TransformedResults = new ConcurrentHashMap<String, Foo>();
    protocol2TransformedResults.put("(a:a1,b:1)", record1);
    ProtocolVersion protocolVersion1 = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
    ProtocolVersion protocolVersion2 = AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion();
    return new Object[][] { { results, protocolVersion1, protocol1TransformedResults }, { results, protocolVersion2, protocol2TransformedResults }, { batchResult, protocolVersion1, protocol1TransformedResults }, { batchResult, protocolVersion2, protocol2TransformedResults } };
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) HttpStatus(com.linkedin.restli.common.HttpStatus) Foo(com.linkedin.pegasus.generator.examples.Foo) BatchResult(com.linkedin.restli.server.BatchResult) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DataProvider(org.testng.annotations.DataProvider)

Example 77 with CompoundKey

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

the class TestCreateResponseBuilder method testDataProvider.

@DataProvider(name = "testData")
public Object[][] testDataProvider() {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    Map<String, AlternativeKey<?, ?>> alternativeKeyMap = new HashMap<String, AlternativeKey<?, ?>>();
    alternativeKeyMap.put("alt", new AlternativeKey<String, CompoundKey>(new TestKeyCoercer(), String.class, new StringDataSchema()));
    return new Object[][] { { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), compoundKey, "/foo/a=a&b=1", "a=a&b=1", null, null }, { AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), compoundKey, "/foo/(a:a,b:1)", "(a:a,b:1)", null, null }, { AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "aaxb1", "/foo/aaxb1?altkey=alt", "aaxb1", "alt", alternativeKeyMap }, { AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "aaxb1", "/foo/aaxb1?altkey=alt", "aaxb1", "alt", alternativeKeyMap } };
}
Also used : StringDataSchema(com.linkedin.data.schema.StringDataSchema) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) AlternativeKey(com.linkedin.restli.server.AlternativeKey) DataProvider(org.testng.annotations.DataProvider)

Example 78 with CompoundKey

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

the class TestRestClientRequestBuilder method setResourceMethodExpectations.

private void setResourceMethodExpectations(final ResourceMethod method, final Request<?> mockRequest, final RecordTemplate mockRecordTemplate, final DataMap entityBody) {
    if (method == ResourceMethod.BATCH_PARTIAL_UPDATE || method == ResourceMethod.BATCH_UPDATE) {
        buildInputForBatchPatchAndUpdate(mockRequest);
    } else {
        EasyMock.expect(mockRequest.getInputRecord()).andReturn(mockRecordTemplate).times(2);
    }
    if (method == ResourceMethod.GET) {
        EasyMock.expect(((GetRequest) mockRequest).getObjectId()).andReturn(null).once();
        EasyMock.expect(mockRequest.getResourceProperties()).andReturn(new ResourcePropertiesImpl(Collections.<ResourceMethod>emptySet(), null, null, null, Collections.<String, CompoundKey.TypeInfo>emptyMap())).once();
        EasyMock.expect(mockRequest.getMethodName()).andReturn(null);
    } else if (method == ResourceMethod.BATCH_GET) {
        EasyMock.expect(mockRequest.getMethodName()).andReturn(null);
    } else if (method == ResourceMethod.ACTION) {
        EasyMock.expect(((ActionRequest) mockRequest).getId()).andReturn(null);
        EasyMock.expect(mockRequest.getMethodName()).andReturn("testAction");
    } else if (method == ResourceMethod.FINDER) {
        EasyMock.expect(((FindRequest) mockRequest).getAssocKey()).andReturn(new CompoundKey());
        EasyMock.expect(mockRequest.getMethodName()).andReturn("testFinder");
    } else if (method == ResourceMethod.GET_ALL) {
        EasyMock.expect(((GetAllRequest) mockRequest).getAssocKey()).andReturn(new CompoundKey());
        EasyMock.expect(mockRequest.getMethodName()).andReturn(null);
    } else if (method == ResourceMethod.UPDATE) {
        EasyMock.expect(mockRequest.getResourceProperties()).andReturn(new ResourcePropertiesImpl(Collections.<ResourceMethod>emptySet(), null, null, null, Collections.<String, CompoundKey.TypeInfo>emptyMap())).once();
        EasyMock.expect(((UpdateRequest) mockRequest).getId()).andReturn(null);
        EasyMock.expect(mockRequest.getMethodName()).andReturn(null);
    } else if (method == ResourceMethod.PARTIAL_UPDATE) {
        EasyMock.expect(mockRequest.getResourceProperties()).andReturn(new ResourcePropertiesImpl(Collections.<ResourceMethod>emptySet(), null, null, null, Collections.<String, CompoundKey.TypeInfo>emptyMap())).once();
        EasyMock.expect(((PartialUpdateRequest) mockRequest).getId()).andReturn(null);
        EasyMock.expect(mockRequest.getMethodName()).andReturn(null);
    } else if (method == ResourceMethod.DELETE) {
        EasyMock.expect(mockRequest.getResourceProperties()).andReturn(new ResourcePropertiesImpl(Collections.<ResourceMethod>emptySet(), null, null, null, Collections.<String, CompoundKey.TypeInfo>emptyMap())).once();
        EasyMock.expect(((DeleteRequest) mockRequest).getId()).andReturn(null);
        EasyMock.expect(mockRequest.getMethodName()).andReturn(null);
    } else {
        EasyMock.expect(mockRequest.getMethodName()).andReturn(null);
    }
    EasyMock.expect(mockRecordTemplate.data()).andReturn(entityBody).once();
}
Also used : ResourcePropertiesImpl(com.linkedin.restli.internal.common.ResourcePropertiesImpl) CompoundKey(com.linkedin.restli.common.CompoundKey) ByteString(com.linkedin.data.ByteString) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 79 with CompoundKey

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

the class TestClientBuilders method testCreateCompoundKeyRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "noEntity")
public void testCreateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
    CreateRequestBuilder<CompoundKey, TestRecord> builder = new CreateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    TestRecord record = new TestRecord().setMessage("foo");
    CreateRequest<TestRecord> request = builder.input(record).build();
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.CREATE, record, Collections.<String, String>emptyMap(), null);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 80 with CompoundKey

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

the class TestTyperefPrimitiveLongAssociationKeyResource method testGet.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    GetRequest<Message> req = new TyperefPrimitiveLongAssociationKeyResourceBuilders(requestOptions).get().id(new CompoundKey().append("src", 1).append("dest", 2)).build();
    Response<Message> resp = REST_CLIENT.sendRequest(req).getResponse();
    Message result = resp.getEntity();
    Assert.assertEquals(result.getId(), "1->2");
    Assert.assertEquals(result.getMessage(), "I need some $20");
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) CompoundKey(com.linkedin.restli.common.CompoundKey) TyperefPrimitiveLongAssociationKeyResourceBuilders(com.linkedin.restli.examples.greetings.client.TyperefPrimitiveLongAssociationKeyResourceBuilders) Test(org.testng.annotations.Test)

Aggregations

CompoundKey (com.linkedin.restli.common.CompoundKey)94 Test (org.testng.annotations.Test)48 HashMap (java.util.HashMap)26 DataProvider (org.testng.annotations.DataProvider)20 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)17 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)16 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)15 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)14 AfterTest (org.testng.annotations.AfterTest)13 BeforeTest (org.testng.annotations.BeforeTest)13 DataMap (com.linkedin.data.DataMap)12 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)12 Key (com.linkedin.restli.server.Key)11 Followed (com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed)10 HashSet (java.util.HashSet)10 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)9 TestRecord (com.linkedin.restli.client.test.TestRecord)9 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)9 AsyncFollowsAssociativeResource (com.linkedin.restli.server.twitter.AsyncFollowsAssociativeResource)9 EmptyRecord (com.linkedin.restli.common.EmptyRecord)8