mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126420 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 121807 gjames: RA-774 Added basic action support git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126766 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package org.alfresco.rest.framework.tests.api.mocks;
|
||||
|
||||
import org.alfresco.rest.framework.Action;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.WebApiParam;
|
||||
import org.alfresco.rest.framework.resource.EntityResource;
|
||||
@@ -42,4 +43,16 @@ public class GrassEntityResource implements EntityResourceAction.ReadById<Grass>
|
||||
return new Grass(id);
|
||||
}
|
||||
|
||||
@Action("cut")
|
||||
@WebApiDescription(title = "Cuts the grass")
|
||||
public String cutLawn(String id, Parameters parameters) {
|
||||
return "All done";
|
||||
}
|
||||
|
||||
@Action("grow")
|
||||
@WebApiDescription(title = "Grow the grass")
|
||||
public String growTheLawn(String id, Grass grass, Parameters parameters) {
|
||||
return "Growing well";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -40,13 +40,17 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.rest.api.model.Comment;
|
||||
import org.alfresco.rest.api.nodes.NodeCommentsRelation;
|
||||
import org.alfresco.rest.framework.Action;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.BinaryProperties;
|
||||
import org.alfresco.rest.framework.core.ResourceInspector;
|
||||
import org.alfresco.rest.framework.core.ResourceInspectorUtil;
|
||||
import org.alfresco.rest.framework.core.ResourceMetadata;
|
||||
import org.alfresco.rest.framework.core.ResourceOperation;
|
||||
import org.alfresco.rest.framework.core.ResourceParameter;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.Farmer;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.GoatEntityResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.Grass;
|
||||
@@ -61,6 +65,7 @@ import org.alfresco.rest.framework.tests.api.mocks.SheepNoActionEntityResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks2.FarmersDaughter;
|
||||
import org.alfresco.rest.framework.tests.api.mocks2.FarmersGrandson;
|
||||
import org.alfresco.rest.framework.tests.api.mocks2.FarmersSon;
|
||||
import org.alfresco.rest.framework.tests.api.mocks3.Flock;
|
||||
import org.alfresco.rest.framework.tests.api.mocks3.FlockEntityResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks3.FlocketEntityResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks3.GrassEntityResourceNowDeleted;
|
||||
@@ -358,13 +363,83 @@ public class InspectorTests
|
||||
op = ResourceInspector.inspectOperation(FlockEntityResource.class, aMethod, HttpMethod.GET);
|
||||
assertNotNull(op);
|
||||
assertTrue(op.getTitle().startsWith("Deletes a photo"));
|
||||
|
||||
|
||||
aMethod = ResourceInspector.findMethod(BinaryResourceAction.Update.class, FlockEntityResource.class);
|
||||
op = ResourceInspector.inspectOperation(FlockEntityResource.class, aMethod, HttpMethod.GET);
|
||||
assertNotNull(op);
|
||||
assertTrue(op.getTitle().startsWith("Updates a photo"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInspectBodyParam()
|
||||
{
|
||||
Method aMethod = ResourceInspector.findMethod(BinaryResourceAction.Update.class, FlockEntityResource.class);
|
||||
ResourceOperation op = ResourceInspector.inspectOperation(FlockEntityResource.class, aMethod, HttpMethod.PUT);
|
||||
assertNotNull(op);
|
||||
List<ResourceParameter> params = op.getParameters();
|
||||
assertNotNull(params);
|
||||
for (ResourceParameter param:params)
|
||||
{
|
||||
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(param.getParamType()))
|
||||
{
|
||||
assertEquals(Flock.class, param.getDataType());
|
||||
}
|
||||
}
|
||||
|
||||
aMethod = ResourceInspector.findMethod(RelationshipResourceAction.Create.class, SheepBlackSheepResource.class);
|
||||
op = ResourceInspector.inspectOperation(SheepBlackSheepResource.class, aMethod, HttpMethod.POST);
|
||||
assertNotNull(op);
|
||||
params = op.getParameters();
|
||||
assertNotNull(params);
|
||||
for (ResourceParameter param:params)
|
||||
{
|
||||
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(param.getParamType()))
|
||||
{
|
||||
assertEquals(Sheep.class, param.getDataType());
|
||||
}
|
||||
}
|
||||
|
||||
aMethod = ResourceInspector.findMethod(EntityResourceAction.Update.class, SheepEntityResourceWithDeletedMethods.class);
|
||||
op = ResourceInspector.inspectOperation(SheepEntityResourceWithDeletedMethods.class, aMethod, HttpMethod.POST);
|
||||
assertNotNull(op);
|
||||
params = op.getParameters();
|
||||
assertNotNull(params);
|
||||
for (ResourceParameter param:params)
|
||||
{
|
||||
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(param.getParamType()))
|
||||
{
|
||||
assertEquals(Sheep.class, param.getDataType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInspectActions()
|
||||
{
|
||||
Api api = Api.valueOf("alfrescomock", "private", "1");
|
||||
List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>();
|
||||
|
||||
ResourceInspector.inspectActions(api, GrassEntityResource.class,"-root-", metainfo);
|
||||
assertTrue(metainfo.size()==2);
|
||||
for (ResourceMetadata resourceMetadata : metainfo)
|
||||
{
|
||||
assertEquals(ResourceMetadata.RESOURCE_TYPE.ACTION, resourceMetadata.getType());
|
||||
switch (resourceMetadata.getUniqueId())
|
||||
{
|
||||
case "/-root-/{entityId}/grow":
|
||||
assertTrue("GrassEntityResource supports POST", resourceMetadata.supports(HttpMethod.POST));
|
||||
assertFalse("GrassEntityResource does not support DELETE", resourceMetadata.supports(HttpMethod.DELETE));
|
||||
break;
|
||||
case "/-root-/{entityId}/cut":
|
||||
assertTrue("GrassEntityResource supports POST", resourceMetadata.supports(HttpMethod.POST));
|
||||
assertFalse("GrassEntityResource does not support GET", resourceMetadata.supports(HttpMethod.GET));
|
||||
break;
|
||||
default:
|
||||
fail("Invalid action information.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInspectAddressedProperties()
|
||||
{
|
||||
|
@@ -455,6 +455,18 @@ public class ParamsExtractorTests
|
||||
//when(resourceMock.getObjectType(HttpMethod.POST)).thenReturn(Farmer.class);
|
||||
return resourceMock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks an action
|
||||
* @return ResourceMetadata a Entity
|
||||
*/
|
||||
private static ResourceMetadata mockAction()
|
||||
{
|
||||
ResourceMetadata resourceMock = mock(ResourceMetadata.class);
|
||||
when(resourceMock.getType()).thenReturn(ResourceMetadata.RESOURCE_TYPE.ACTION);
|
||||
return resourceMock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocks a Relationship Resource
|
||||
* @return ResourceMetadata a Relationship
|
||||
|
@@ -32,9 +32,11 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -51,6 +53,7 @@ import org.alfresco.rest.framework.resource.EntityResource;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.Farmer;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.GoatEntityResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.GrassEntityResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.SheepBaaaahResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.SheepBlackSheepResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.SheepEntityResource;
|
||||
@@ -148,7 +151,30 @@ public class ResourceLocatorTests
|
||||
collResource = locator.locateResource(api,templateVars, HttpMethod.GET);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLocateActions()
|
||||
{
|
||||
Map<String, String> templateVars = new HashMap<String, String>();
|
||||
ResourceWithMetadata collResource = null;
|
||||
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "grass");
|
||||
templateVars.put(ResourceLocator.ENTITY_ID, "grassId");
|
||||
templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "cut");
|
||||
try
|
||||
{
|
||||
collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
|
||||
fail("Should throw an UnsupportedResourceOperationException");
|
||||
}
|
||||
catch (UnsupportedResourceOperationException error)
|
||||
{
|
||||
//this is correct
|
||||
}
|
||||
|
||||
collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
|
||||
assertEquals(GrassEntityResource.class, collResource.getResource().getClass());
|
||||
assertEquals(ResourceMetadata.RESOURCE_TYPE.ACTION, collResource.getMetaData().getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocateProperties()
|
||||
{
|
||||
|
Reference in New Issue
Block a user