Search in sources :

Example 1 with ResourcePropertiesImpl

use of com.linkedin.restli.internal.common.ResourcePropertiesImpl 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 2 with ResourcePropertiesImpl

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

the class TestRestClientRequestBuilder method buildInputForBatchPatchAndUpdate.

@SuppressWarnings({ "rawtypes", "deprecation" })
private void buildInputForBatchPatchAndUpdate(Request mockRequest) {
    CollectionRequest mockCollectionRequest = EasyMock.createMock(CollectionRequest.class);
    EasyMock.expect(mockCollectionRequest.getElements()).andReturn(Collections.emptyList()).once();
    EasyMock.expect(mockRequest.getInputRecord()).andReturn(mockCollectionRequest).times(2);
    EasyMock.replay(mockCollectionRequest);
    ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), Collections.<String, DynamicRecordMetadata>emptyMap(), Collections.<String, DynamicRecordMetadata>emptyMap(), null, null, null, EmptyRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
    EasyMock.expect(mockRequest.getResourceProperties()).andReturn(new ResourcePropertiesImpl(Collections.<ResourceMethod>emptySet(), null, null, TypeSpec.forClassMaybeNull(EmptyRecord.class), Collections.<String, CompoundKey.TypeInfo>emptyMap())).once();
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) EmptyRecord(com.linkedin.restli.common.EmptyRecord) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourcePropertiesImpl(com.linkedin.restli.internal.common.ResourcePropertiesImpl) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl)

Example 3 with ResourcePropertiesImpl

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

the class TestRequest method testResourceProperties.

@Test
public void testResourceProperties() {
    Set<ResourceMethod> expectedSupportedMethods = new HashSet<ResourceMethod>();
    expectedSupportedMethods.add(ResourceMethod.GET);
    expectedSupportedMethods.add(ResourceMethod.BATCH_PARTIAL_UPDATE);
    ResourceSpec expectedResourceSpec = new ResourceSpecImpl(expectedSupportedMethods, null, null, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, Object>emptyMap());
    Map<String, Object> pathKeys = new HashMap<String, Object>();
    pathKeys.put("id", new ComplexResourceKey<TestRecord, TestRecord>(new TestRecord(), new TestRecord()));
    Request<TestRecord> request = new Request<TestRecord>(ResourceMethod.GET, null, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new EntityResponseDecoder<TestRecord>(TestRecord.class), expectedResourceSpec, Collections.<String, Object>emptyMap(), Collections.<String, Class<?>>emptyMap(), null, "testRecord", pathKeys, RestliRequestOptions.DEFAULT_OPTIONS, null);
    ResourceProperties expectedResourceProperties = new ResourcePropertiesImpl(expectedResourceSpec.getSupportedMethods(), expectedResourceSpec.getKeyType(), expectedResourceSpec.getComplexKeyType(), expectedResourceSpec.getValueType(), expectedResourceSpec.getKeyParts());
    Assert.assertEquals(request.getResourceProperties(), expectedResourceProperties);
}
Also used : HashMap(java.util.HashMap) ResourcePropertiesImpl(com.linkedin.restli.internal.common.ResourcePropertiesImpl) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ResourceProperties(com.linkedin.restli.common.ResourceProperties) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

ResourcePropertiesImpl (com.linkedin.restli.internal.common.ResourcePropertiesImpl)3 CompoundKey (com.linkedin.restli.common.CompoundKey)2 ResourceMethod (com.linkedin.restli.common.ResourceMethod)2 ResourceSpec (com.linkedin.restli.common.ResourceSpec)2 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)2 ByteString (com.linkedin.data.ByteString)1 TestRecord (com.linkedin.restli.client.test.TestRecord)1 CollectionRequest (com.linkedin.restli.common.CollectionRequest)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 ResourceProperties (com.linkedin.restli.common.ResourceProperties)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.testng.annotations.Test)1