Search in sources :

Example 11 with ResourceOperation

use of org.alfresco.rest.framework.core.ResourceOperation in project alfresco-remote-api by Alfresco.

the class InspectorTests method testInspectRelationship.

@Test
public void testInspectRelationship() {
    List<ResourceMetadata> metainfo = ResourceInspector.inspect(SheepBlackSheepResource.class);
    assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
    ResourceMetadata metaData = metainfo.get(0);
    assertNotNull(metaData);
    assertNotNull("SheepBlackSheepResource supports GET", metaData.getOperation(HttpMethod.GET));
    ResourceOperation op = metaData.getOperation(HttpMethod.GET);
    List<ResourceParameter> params = op.getParameters();
    assertTrue("readAll method should have 1 url param and 3 query params", params.size() == 4);
    assertNotNull("SheepBlackSheepResource supports PUT", metaData.getOperation(HttpMethod.PUT));
    op = metaData.getOperation(HttpMethod.PUT);
    params = op.getParameters();
    assertTrue("update method should have 2 url params and 1 HTTP_OBJECT param ", params.size() == 3);
    assertNotNull("SheepBlackSheepResource supports POST", metaData.getOperation(HttpMethod.POST));
    op = metaData.getOperation(HttpMethod.POST);
    params = op.getParameters();
    assertTrue("SheepBlackSheepResource must support Sheep", Sheep.class.equals(metaData.getObjectType(op)));
    assertTrue("create method should have 1 url param and 1 HTTP_OBJECT param ", params.size() == 2);
    assertNotNull(params);
    for (ResourceParameter resourceParameter : params) {
        if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(resourceParameter.getParamType())) {
            // set to not allow multiple
            assertFalse(resourceParameter.isAllowMultiple());
        }
    }
    assertNotNull("SheepBlackSheepResource supports DELETE", metaData.getOperation(HttpMethod.DELETE));
    op = metaData.getOperation(HttpMethod.DELETE);
    assertEquals("SheepBlackSheepResource should return STATUS_CONFLICT", Status.STATUS_CONFLICT, op.getSuccessStatus());
    params = op.getParameters();
    assertTrue("DELETE method on a relations should have 2 url params.", params.size() == 2);
    metainfo = ResourceInspector.inspect(MultiPartTestRelationshipResource.class);
    assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
    metaData = metainfo.get(0);
    assertNotNull(metaData);
    assertNotNull("MultiPartTestRelationshipResource support POST", metaData.getOperation(HttpMethod.POST));
    assertNull("MultiPartTestRelationshipResource does not supports GET", metaData.getOperation(HttpMethod.GET));
    assertNull("MultiPartTestRelationshipResource does not supports PUT", metaData.getOperation(HttpMethod.PUT));
    assertNull("MultiPartTestRelationshipResource does not supports DELETE", metaData.getOperation(HttpMethod.DELETE));
    op = metaData.getOperation(HttpMethod.POST);
    assertTrue("MultiPartTestRelationshipResource must support MultiPartTestResponse", MultiPartTestResponse.class.equals(metaData.getObjectType(op)));
}
Also used : ResourceParameter(org.alfresco.rest.framework.core.ResourceParameter) MultiPartTestRelationshipResource(org.alfresco.rest.framework.tests.api.mocks.MultiPartTestRelationshipResource) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) ResourceMetadata(org.alfresco.rest.framework.core.ResourceMetadata) MultiPartTestResponse(org.alfresco.rest.framework.tests.api.mocks.MultiPartTestResponse) ResourceOperation(org.alfresco.rest.framework.core.ResourceOperation) Test(org.junit.Test)

Example 12 with ResourceOperation

use of org.alfresco.rest.framework.core.ResourceOperation in project alfresco-remote-api by Alfresco.

the class ParamsExtractorTests method mockEntity.

/**
 * Mocks a Entity Resource
 * @return ResourceMetadata a Entity
 */
private static ResourceMetadata mockEntity() {
    ResourceMetadata resourceMock = mock(ResourceMetadata.class);
    ResourceOperation resourceOperation = mock(ResourceOperation.class);
    when(resourceMock.getType()).thenReturn(ResourceMetadata.RESOURCE_TYPE.ENTITY);
    when(resourceMock.getOperation(notNull(HttpMethod.class))).thenReturn(resourceOperation);
    when(resourceMock.getObjectType(notNull(ResourceOperation.class))).thenReturn(Farmer.class);
    return resourceMock;
}
Also used : ResourceMetadata(org.alfresco.rest.framework.core.ResourceMetadata) HttpMethod(org.springframework.http.HttpMethod) ResourceOperation(org.alfresco.rest.framework.core.ResourceOperation)

Example 13 with ResourceOperation

use of org.alfresco.rest.framework.core.ResourceOperation in project alfresco-remote-api by Alfresco.

the class ParamsExtractorTests method mockRelationship.

/**
 * Mocks a Relationship Resource
 * @return ResourceMetadata a Relationship
 */
private static ResourceMetadata mockRelationship() {
    ResourceMetadata resourceMock = mock(ResourceMetadata.class);
    ResourceOperation resourceOperation = mock(ResourceOperation.class);
    when(resourceMock.getOperation(notNull(HttpMethod.class))).thenReturn(resourceOperation);
    when(resourceMock.getType()).thenReturn(ResourceMetadata.RESOURCE_TYPE.RELATIONSHIP);
    when(resourceMock.getObjectType(notNull(ResourceOperation.class))).thenReturn(Farmer.class);
    return resourceMock;
}
Also used : ResourceMetadata(org.alfresco.rest.framework.core.ResourceMetadata) HttpMethod(org.springframework.http.HttpMethod) ResourceOperation(org.alfresco.rest.framework.core.ResourceOperation)

Aggregations

ResourceOperation (org.alfresco.rest.framework.core.ResourceOperation)13 ResourceMetadata (org.alfresco.rest.framework.core.ResourceMetadata)7 Test (org.junit.Test)7 HttpMethod (org.springframework.http.HttpMethod)6 ResourceParameter (org.alfresco.rest.framework.core.ResourceParameter)5 Method (java.lang.reflect.Method)4 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)3 EntityResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction)2 RecognizedParams (org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams)2 GrassEntityResource (org.alfresco.rest.framework.tests.api.mocks.GrassEntityResource)2 MultiPartTestResponse (org.alfresco.rest.framework.tests.api.mocks.MultiPartTestResponse)2 Sheep (org.alfresco.rest.framework.tests.api.mocks.Sheep)2 FlockEntityResource (org.alfresco.rest.framework.tests.api.mocks3.FlockEntityResource)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 Comment (org.alfresco.rest.api.model.Comment)1 Api (org.alfresco.rest.framework.Api)1