Search in sources :

Example 1 with MultiPartTestResponse

use of org.alfresco.rest.framework.tests.api.mocks.MultiPartTestResponse in project alfresco-remote-api by Alfresco.

the class InspectorTests method testInspectEntity.

@Test
public void testInspectEntity() {
    List<ResourceMetadata> metainfo = ResourceInspector.inspect(SheepEntityResource.class);
    assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
    ResourceMetadata metaData = metainfo.get(0);
    assertNotNull(metaData);
    assertNotNull("SheepEntityResource supports GET", metaData.getOperation(HttpMethod.GET));
    assertNotNull("SheepEntityResource supports PUT", metaData.getOperation(HttpMethod.PUT));
    assertNotNull("SheepEntityResource supports DELETE", metaData.getOperation(HttpMethod.DELETE));
    assertNull("SheepEntityResource does not support POST", metaData.getOperation(HttpMethod.POST));
    ResourceOperation op = metaData.getOperation(HttpMethod.GET);
    assertEquals("Sheep ReadALL should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
    op = metaData.getOperation(HttpMethod.PUT);
    assertTrue("SheepEntityResource must support Sheep", Sheep.class.equals(metaData.getObjectType(op)));
    metainfo = ResourceInspector.inspect(SheepNoActionEntityResource.class);
    assertTrue("SheepNoActionEntityResource has no actions.", metainfo.isEmpty());
    metainfo = ResourceInspector.inspect(GoatEntityResource.class);
    assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
    metaData = metainfo.get(0);
    assertNotNull(metaData);
    assertNotNull("GoatEntityResource supports GET", metaData.getOperation(HttpMethod.GET));
    op = metaData.getOperation(HttpMethod.GET);
    List<ResourceParameter> params = op.getParameters();
    assertTrue("readById method should have 1 url param", params.size() == 1);
    metainfo = ResourceInspector.inspect(FlockEntityResource.class);
    assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
    metaData = metainfo.get(0);
    assertNotNull(metaData);
    assertNotNull("FlockEntityResource supports GET", metaData.getOperation(HttpMethod.GET));
    assertNotNull("FlockEntityResource supports PUT", metaData.getOperation(HttpMethod.PUT));
    assertNotNull("FlockEntityResource supports DELETE", metaData.getOperation(HttpMethod.DELETE));
    assertNull("FlockEntityResource does not support POST", metaData.getOperation(HttpMethod.POST));
    metainfo = ResourceInspector.inspect(MultiPartTestEntityResource.class);
    assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
    metaData = metainfo.get(0);
    assertNotNull(metaData);
    assertNotNull("MultiPartTestEntityResource support POST", metaData.getOperation(HttpMethod.POST));
    assertNull("MultiPartTestEntityResource does not supports GET", metaData.getOperation(HttpMethod.GET));
    assertNull("MultiPartTestEntityResource does not supports PUT", metaData.getOperation(HttpMethod.PUT));
    assertNull("MultiPartTestEntityResource does not supports DELETE", metaData.getOperation(HttpMethod.DELETE));
    op = metaData.getOperation(HttpMethod.POST);
    assertTrue("MultiPartTestEntityResource must support MultiPartTestResponse", MultiPartTestResponse.class.equals(metaData.getObjectType(op)));
    assertEquals("MultiPartTestEntityResource should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
}
Also used : SheepNoActionEntityResource(org.alfresco.rest.framework.tests.api.mocks.SheepNoActionEntityResource) ResourceParameter(org.alfresco.rest.framework.core.ResourceParameter) GoatEntityResource(org.alfresco.rest.framework.tests.api.mocks.GoatEntityResource) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) ResourceMetadata(org.alfresco.rest.framework.core.ResourceMetadata) MultiPartTestEntityResource(org.alfresco.rest.framework.tests.api.mocks.MultiPartTestEntityResource) MultiPartTestResponse(org.alfresco.rest.framework.tests.api.mocks.MultiPartTestResponse) ResourceOperation(org.alfresco.rest.framework.core.ResourceOperation) FlockEntityResource(org.alfresco.rest.framework.tests.api.mocks3.FlockEntityResource) Test(org.junit.Test)

Example 2 with MultiPartTestResponse

use of org.alfresco.rest.framework.tests.api.mocks.MultiPartTestResponse 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)

Aggregations

ResourceMetadata (org.alfresco.rest.framework.core.ResourceMetadata)2 ResourceOperation (org.alfresco.rest.framework.core.ResourceOperation)2 ResourceParameter (org.alfresco.rest.framework.core.ResourceParameter)2 MultiPartTestResponse (org.alfresco.rest.framework.tests.api.mocks.MultiPartTestResponse)2 Sheep (org.alfresco.rest.framework.tests.api.mocks.Sheep)2 Test (org.junit.Test)2 GoatEntityResource (org.alfresco.rest.framework.tests.api.mocks.GoatEntityResource)1 MultiPartTestEntityResource (org.alfresco.rest.framework.tests.api.mocks.MultiPartTestEntityResource)1 MultiPartTestRelationshipResource (org.alfresco.rest.framework.tests.api.mocks.MultiPartTestRelationshipResource)1 SheepNoActionEntityResource (org.alfresco.rest.framework.tests.api.mocks.SheepNoActionEntityResource)1 FlockEntityResource (org.alfresco.rest.framework.tests.api.mocks3.FlockEntityResource)1