mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
122240 gjames: RA-833: Initial framework changes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126461 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
package org.alfresco.rest.framework.tests.api.mocks;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.rest.framework.BinaryProperties;
|
||||
import org.alfresco.rest.framework.Operation;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
|
||||
@@ -14,7 +22,7 @@ import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
* @author Gethin James
|
||||
*/
|
||||
@RelationshipResource(name = "baaahh", entityResource=SheepEntityResource.class, title = "Sheep baaah")
|
||||
public class SheepBaaaahResource implements RelationshipResourceAction.Read<Sheep>, RelationshipResourceAction.ReadById<Sheep>
|
||||
public class SheepBaaaahResource implements RelationshipResourceAction.Read<Sheep>, RelationshipResourceAction.ReadById<Sheep>, BinaryResourceAction.Read, BinaryResourceAction.Delete,BinaryResourceAction.Update
|
||||
{
|
||||
|
||||
@Override
|
||||
@@ -31,4 +39,33 @@ public class SheepBaaaahResource implements RelationshipResourceAction.Read<Shee
|
||||
return CollectionWithPagingInfo.asPaged(params.getPaging(),toReturn,toReturn.size()!=3 ,3);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Deletes a photo")
|
||||
@BinaryProperties("photo")
|
||||
public void deleteProperty(String entityId, Parameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Reads a photo")
|
||||
@BinaryProperties("photo")
|
||||
public BinaryResource readProperty(String entityId, Parameters parameters) throws EntityNotFoundException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@WebApiDescription(title = "Updates a photo")
|
||||
@BinaryProperties("photo")
|
||||
public Object updateProperty(String entityId, BasicContentInfo contentInfo, InputStream stream, Parameters params)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Operation("chew")
|
||||
public String chewTheGrass(String entityId, String id, Void notused, Parameters parameters) {
|
||||
return "All done";
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,18 @@
|
||||
package org.alfresco.rest.framework.tests.api.mocks3;
|
||||
|
||||
import org.alfresco.rest.framework.BinaryProperties;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||
import org.alfresco.rest.framework.resource.content.FileBinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.TempFileProvider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* The goat has a herd
|
||||
@@ -11,7 +20,7 @@ import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
* @author Gethin James
|
||||
*/
|
||||
@RelationshipResource(name = "herd",entityResource=GoatEntityResourceForV3.class, title = "Goat Herd")
|
||||
public class GoatRelationshipResource implements RelationshipResourceAction.Read<Herd>
|
||||
public class GoatRelationshipResource implements RelationshipResourceAction.Read<Herd>, BinaryResourceAction.Read
|
||||
{
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Herd> readAll(String entityResourceId, Parameters params)
|
||||
@@ -19,4 +28,12 @@ public class GoatRelationshipResource implements RelationshipResourceAction.Read
|
||||
return CollectionWithPagingInfo.asPagedCollection(new Herd("bigun"));
|
||||
}
|
||||
|
||||
@WebApiDescription(title = "Download content", description = "Download content")
|
||||
@BinaryProperties({"content"})
|
||||
public BinaryResource readProperty(String herdId, Parameters parameters) throws EntityNotFoundException
|
||||
{
|
||||
File file = TempFileProvider.createTempFile("Its a goat", ".txt");
|
||||
return new FileBinaryResource(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.rest.api.model.Comment;
|
||||
import org.alfresco.rest.api.nodes.NodeCommentsRelation;
|
||||
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.core.OperationResourceMetaData;
|
||||
import org.alfresco.rest.framework.core.ResourceInspector;
|
||||
@@ -34,6 +35,7 @@ import org.alfresco.rest.framework.tests.api.mocks.MultiPartTestEntityResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.MultiPartTestRelationshipResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.MultiPartTestResponse;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.Sheep;
|
||||
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;
|
||||
import org.alfresco.rest.framework.tests.api.mocks.SheepNoActionEntityResource;
|
||||
@@ -43,6 +45,7 @@ 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.GoatRelationshipResource;
|
||||
import org.alfresco.rest.framework.tests.api.mocks3.GrassEntityResourceNowDeleted;
|
||||
import org.alfresco.rest.framework.tests.api.mocks3.SheepBlackSheepResourceIsNoMore;
|
||||
import org.alfresco.rest.framework.tests.api.mocks3.SheepEntityResourceWithDeletedMethods;
|
||||
@@ -335,12 +338,27 @@ public class InspectorTests
|
||||
assertTrue(op.getTitle().startsWith("Reads a photo as a Stream"));
|
||||
|
||||
aMethod = ResourceInspector.findMethod(BinaryResourceAction.Delete.class, FlockEntityResource.class);
|
||||
op = ResourceInspector.inspectOperation(FlockEntityResource.class, aMethod, HttpMethod.GET);
|
||||
op = ResourceInspector.inspectOperation(FlockEntityResource.class, aMethod, HttpMethod.DELETE);
|
||||
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);
|
||||
op = ResourceInspector.inspectOperation(FlockEntityResource.class, aMethod, HttpMethod.PUT);
|
||||
assertNotNull(op);
|
||||
assertTrue(op.getTitle().startsWith("Updates a photo"));
|
||||
|
||||
aMethod = ResourceInspector.findMethod(BinaryResourceAction.Read.class, SheepBaaaahResource.class);
|
||||
op = ResourceInspector.inspectOperation(SheepBaaaahResource.class, aMethod, HttpMethod.GET);
|
||||
assertNotNull(op);
|
||||
assertTrue(op.getTitle().startsWith("Reads a photo"));
|
||||
|
||||
aMethod = ResourceInspector.findMethod(BinaryResourceAction.Delete.class, SheepBaaaahResource.class);
|
||||
op = ResourceInspector.inspectOperation(SheepBaaaahResource.class, aMethod, HttpMethod.DELETE);
|
||||
assertNotNull(op);
|
||||
assertTrue(op.getTitle().startsWith("Deletes a photo"));
|
||||
|
||||
aMethod = ResourceInspector.findMethod(BinaryResourceAction.Update.class, SheepBaaaahResource.class);
|
||||
op = ResourceInspector.inspectOperation(SheepBaaaahResource.class, aMethod, HttpMethod.PUT);
|
||||
assertNotNull(op);
|
||||
assertTrue(op.getTitle().startsWith("Updates a photo"));
|
||||
}
|
||||
@@ -406,7 +424,7 @@ public class InspectorTests
|
||||
String result = null;
|
||||
switch (resourceMetadata.getUniqueId())
|
||||
{
|
||||
case "/-root-/{entityId}/grow":
|
||||
case "/-root-/{id}/grow":
|
||||
assertTrue("GrassEntityResource supports POST", resourceMetadata.supports(HttpMethod.POST));
|
||||
assertFalse("GrassEntityResource does not support DELETE", resourceMetadata.supports(HttpMethod.DELETE));
|
||||
Class paramType = resourceMetadata.getObjectType(HttpMethod.POST);
|
||||
@@ -414,7 +432,7 @@ public class InspectorTests
|
||||
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", paramObj, Params.valueOf("notUsed", null));
|
||||
assertEquals("Growing well",result);
|
||||
break;
|
||||
case "/-root-/{entityId}/cut":
|
||||
case "/-root-/{id}/cut":
|
||||
assertTrue("GrassEntityResource supports POST", resourceMetadata.supports(HttpMethod.POST));
|
||||
assertFalse("GrassEntityResource does not support GET", resourceMetadata.supports(HttpMethod.GET));
|
||||
assertNull(resourceMetadata.getObjectType(HttpMethod.POST));
|
||||
@@ -425,8 +443,29 @@ public class InspectorTests
|
||||
fail("Invalid action information.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@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":
|
||||
assertTrue("GoatRelationshipResource supports GET", resourceMetadata.supports(HttpMethod.GET));
|
||||
break;
|
||||
case "/goat/{entityId}/herd/{id}/content":
|
||||
assertTrue("GoatRelationshipResource supports GET", resourceMetadata.supports(HttpMethod.GET));
|
||||
break;
|
||||
default:
|
||||
fail("Invalid information.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,7 +478,7 @@ public class InspectorTests
|
||||
ResourceInspector.inspectAddressedProperties(api, FlockEntityResource.class, "myroot", metainfo);
|
||||
assertTrue(metainfo.size()==1);
|
||||
ResourceMetadata metaData = metainfo.get(0);
|
||||
assertEquals("/myroot/photo",metaData.getUniqueId());
|
||||
assertEquals("/myroot/{id}/photo",metaData.getUniqueId());
|
||||
assertTrue(metaData.getOperations().size()==3);
|
||||
assertTrue("FlockEntityResource supports GET", metaData.supports(HttpMethod.GET));
|
||||
assertTrue("FlockEntityResource supports PUT", metaData.supports(HttpMethod.PUT));
|
||||
@@ -472,7 +511,7 @@ public class InspectorTests
|
||||
// fail("Invalid address property information.");
|
||||
// }
|
||||
|
||||
if ("/myroot/photo".equals(resourceMetadata.getUniqueId()))
|
||||
if ("/myroot/{id}/photo".equals(resourceMetadata.getUniqueId()))
|
||||
{
|
||||
assertTrue("FlocketEntityResource supports GET", resourceMetadata.supports(HttpMethod.GET));
|
||||
assertTrue("FlocketEntityResource supports PUT", resourceMetadata.supports(HttpMethod.PUT));
|
||||
@@ -480,7 +519,7 @@ public class InspectorTests
|
||||
}
|
||||
else
|
||||
{
|
||||
if ("/myroot/album".equals(resourceMetadata.getUniqueId()))
|
||||
if ("/myroot/{id}/album".equals(resourceMetadata.getUniqueId()))
|
||||
{
|
||||
assertTrue("FlocketEntityResource supports GET", resourceMetadata.supports(HttpMethod.GET));
|
||||
assertTrue("FlocketEntityResource supports PUT", resourceMetadata.supports(HttpMethod.PUT));
|
||||
@@ -488,7 +527,7 @@ public class InspectorTests
|
||||
}
|
||||
else
|
||||
{
|
||||
if ("/myroot/madeUpProp".equals(resourceMetadata.getUniqueId()))
|
||||
if ("/myroot/{id}/madeUpProp".equals(resourceMetadata.getUniqueId()))
|
||||
{
|
||||
assertTrue("FlocketEntityResource supports GET", resourceMetadata.supports(HttpMethod.GET));
|
||||
assertTrue("FlocketEntityResource does not supports PUT", !resourceMetadata.supports(HttpMethod.PUT));
|
||||
|
@@ -146,6 +146,15 @@ public class ResourceLocatorTests
|
||||
collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
|
||||
assertEquals(GrassEntityResource.class, collResource.getResource().getClass());
|
||||
assertEquals(ResourceMetadata.RESOURCE_TYPE.OPERATION, collResource.getMetaData().getType());
|
||||
|
||||
templateVars = new HashMap<String, String>();
|
||||
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
|
||||
templateVars.put(ResourceLocator.ENTITY_ID, "sheepId");
|
||||
templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "baaahh");
|
||||
templateVars.put(ResourceLocator.PROPERTY, "chew");
|
||||
collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
|
||||
assertEquals(SheepBaaaahResource.class, collResource.getResource().getClass());
|
||||
assertEquals(ResourceMetadata.RESOURCE_TYPE.OPERATION, collResource.getMetaData().getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,6 +214,56 @@ public class ResourceLocatorTests
|
||||
assertTrue(collResource.getMetaData().supports(HttpMethod.PUT));
|
||||
assertEquals(FlocketEntityResource.class, collResource.getResource().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocateRelationshipProperties()
|
||||
{
|
||||
Api api3 = Api.valueOf("alfrescomock", "private", "3");
|
||||
Map<String, String> templateVars = new HashMap<String, String>();
|
||||
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "goat");
|
||||
templateVars.put(ResourceLocator.ENTITY_ID, "herdId");
|
||||
templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "herd");
|
||||
|
||||
ResourceWithMetadata collResource;
|
||||
try
|
||||
{
|
||||
collResource = locator.locateResource(api3, templateVars, HttpMethod.PUT);
|
||||
fail("Should throw an UnsupportedResourceOperationException");
|
||||
}
|
||||
catch (UnsupportedResourceOperationException error)
|
||||
{
|
||||
//this is correct
|
||||
}
|
||||
|
||||
templateVars.put(ResourceLocator.PROPERTY, "content");
|
||||
collResource = locator.locateResource(api3, templateVars, HttpMethod.GET);
|
||||
assertNotNull(collResource);
|
||||
assertTrue(collResource.getMetaData().supports(HttpMethod.GET));
|
||||
|
||||
templateVars = new HashMap<String, String>();
|
||||
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
|
||||
templateVars.put(ResourceLocator.ENTITY_ID, "sheepId");
|
||||
templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "baaahh");
|
||||
templateVars.put(ResourceLocator.PROPERTY, "content");
|
||||
|
||||
try
|
||||
{
|
||||
//Tests by passing invalid propery
|
||||
collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
|
||||
fail("Should throw an InvalidArgumentException");
|
||||
}
|
||||
catch (InvalidArgumentException error)
|
||||
{
|
||||
//this is correct
|
||||
}
|
||||
|
||||
templateVars.put(ResourceLocator.PROPERTY, "photo");
|
||||
collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
|
||||
assertNotNull(collResource);
|
||||
assertTrue(collResource.getMetaData().supports(HttpMethod.GET));
|
||||
assertTrue(collResource.getMetaData().supports(HttpMethod.PUT));
|
||||
assertTrue(collResource.getMetaData().supports(HttpMethod.DELETE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApiValues()
|
||||
|
Reference in New Issue
Block a user