use of org.alfresco.rest.framework.core.ResourceMetadata in project alfresco-remote-api by Alfresco.
the class InspectorTests method testInspectOperations.
@Test
public void testInspectOperations() throws IllegalAccessException, InstantiationException, Throwable {
Api api = Api.valueOf("alfrescomock", "private", "1");
List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>();
GrassEntityResource grassEntityResource = new GrassEntityResource();
ResourceInspector.inspectOperations(api, GrassEntityResource.class, "-root-", metainfo);
assertEquals(3, metainfo.size());
for (ResourceMetadata resourceMetadata : metainfo) {
assertEquals(ResourceMetadata.RESOURCE_TYPE.OPERATION, resourceMetadata.getType());
OperationResourceMetaData operationResourceMetaData = (OperationResourceMetaData) resourceMetadata;
Method actionMethod = operationResourceMetaData.getOperationMethod();
String result = null;
final WithResponse wr = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
switch(resourceMetadata.getUniqueId()) {
case "/-root-/{id}/grow":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
assertNull("GrassEntityResource does not support DELETE", resourceMetadata.getOperation(HttpMethod.DELETE));
ResourceOperation op = resourceMetadata.getOperation(HttpMethod.POST);
assertEquals("grow should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
Class paramType = resourceMetadata.getObjectType(op);
Object paramObj = paramType.newInstance();
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", paramObj, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("Growing well", result);
assertFalse(operationResourceMetaData.isNoAuth(null));
break;
case "/-root-/{id}/cut":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
assertNull("GrassEntityResource does not support GET", resourceMetadata.getOperation(HttpMethod.GET));
op = resourceMetadata.getOperation(HttpMethod.POST);
assertNull(resourceMetadata.getObjectType(op));
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("All done", result);
assertFalse(operationResourceMetaData.isNoAuth(null));
break;
case "/-root-/{id}/cut-noAuth":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
op = resourceMetadata.getOperation(HttpMethod.POST);
assertNull(resourceMetadata.getObjectType(op));
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("All done without Auth", result);
assertTrue(operationResourceMetaData.isNoAuth(null));
break;
default:
fail("Invalid action information.");
}
}
}
use of org.alfresco.rest.framework.core.ResourceMetadata in project alfresco-remote-api by Alfresco.
the class InspectorTests method testNodesCommentsRelation.
@Test
public void testNodesCommentsRelation() {
List<ResourceMetadata> metainfo = ResourceInspector.inspect(NodeCommentsRelation.class);
assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
ResourceMetadata metaData = metainfo.get(0);
assertNotNull(metaData);
ResourceOperation op = metaData.getOperation(HttpMethod.POST);
assertTrue("NodeCommentsRelation must support Comment", Comment.class.equals(metaData.getObjectType(op)));
}
use of org.alfresco.rest.framework.core.ResourceMetadata in project alfresco-remote-api by Alfresco.
the class InspectorTests method testInspectRelationshipProperties.
@Test
public void testInspectRelationshipProperties() {
List<ResourceMetadata> metainfo = ResourceInspector.inspect(GoatRelationshipResource.class);
assertTrue(metainfo.size() == 2);
for (ResourceMetadata resourceMetadata : metainfo) {
switch(resourceMetadata.getUniqueId()) {
case "/goat/{entityId}/herd":
assertNotNull("GoatRelationshipResource supports GET", resourceMetadata.getOperation(HttpMethod.GET));
break;
case "/goat/{entityId}/herd/{id}/content":
assertNotNull("GoatRelationshipResource supports GET", resourceMetadata.getOperation(HttpMethod.GET));
break;
default:
fail("Invalid information.");
}
}
}
use of org.alfresco.rest.framework.core.ResourceMetadata 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)));
}
use of org.alfresco.rest.framework.core.ResourceMetadata 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;
}
Aggregations