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:
@@ -10,6 +10,8 @@
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}/</url>
|
||||
<authentication>user</authentication>
|
||||
<format default="json">argument</format>
|
||||
<transaction>none</transaction>
|
||||
|
@@ -10,6 +10,8 @@
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}/</url>
|
||||
<authentication>user</authentication>
|
||||
<format default="json">argument</format>
|
||||
<!-- Note: the transaction is created in AbstractResourceWebScript -->
|
||||
|
@@ -10,6 +10,8 @@
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}/</url>
|
||||
<authentication>user</authentication>
|
||||
<format default="json">argument</format>
|
||||
<!-- Note: the transaction is created in AbstractResourceWebScript -->
|
||||
|
@@ -10,6 +10,8 @@
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}/</url>
|
||||
<authentication>user</authentication>
|
||||
<format default="json">argument</format>
|
||||
<!-- Note: the transaction is created in AbstractResourceWebScript -->
|
||||
|
@@ -10,6 +10,8 @@
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}</url>
|
||||
<url>/{apiScope}/{apiName}/versions/{apiVersion}/{collectionResource}/{entityId}/{relationResource}/{relationshipId}/{property}/</url>
|
||||
<authentication>user</authentication>
|
||||
<format default="json">argument</format>
|
||||
<!-- Note: the transaction is created in AbstractResourceWebScript -->
|
||||
|
@@ -42,11 +42,12 @@ public class ResourceDictionary
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a key by combining the entity and property ids
|
||||
* Return a key by combining the rootEntity and property ids
|
||||
*/
|
||||
public static String propertyResourceKey(String entity, String property)
|
||||
{
|
||||
return "/"+entity+"/"+property;
|
||||
String rootEntity = entity.startsWith("/")?entity:"/"+entity;
|
||||
return rootEntity+"/{id}/"+property;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -195,6 +195,9 @@ public class ResourceInspector
|
||||
Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
|
||||
String urlPath = String.valueOf(annotAttribs.get("name"));
|
||||
String entityPath = findEntityNameByAnnotationAttributes(annotAttribs);
|
||||
String relationshipKey = ResourceDictionary.resourceKey(entityPath,urlPath);
|
||||
Api api = inspectApi(resource);
|
||||
List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>();
|
||||
|
||||
MetaHelper helper = new MetaHelper(resource);
|
||||
findOperation(RelationshipResourceAction.Create.class, HttpMethod.POST, helper);
|
||||
@@ -214,13 +217,16 @@ public class ResourceInspector
|
||||
|
||||
if (resource.isAnnotationPresent(WebApiDeleted.class))
|
||||
{
|
||||
return Arrays.asList(new ResourceMetadata(ResourceDictionary.resourceKey(entityPath,urlPath), RESOURCE_TYPE.RELATIONSHIP, null, inspectApi(resource), ALL_RELATIONSHIP_RESOURCE_INTERFACES, apiNoAuth, entityPath));
|
||||
metainfo.add(new ResourceMetadata(relationshipKey, RESOURCE_TYPE.RELATIONSHIP, null, inspectApi(resource), ALL_RELATIONSHIP_RESOURCE_INTERFACES, apiNoAuth, entityPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Arrays.asList(new ResourceMetadata(ResourceDictionary.resourceKey(entityPath,urlPath), RESOURCE_TYPE.RELATIONSHIP, helper.operations, inspectApi(resource), helper.apiDeleted, apiNoAuth, entityPath));
|
||||
metainfo.add(new ResourceMetadata(relationshipKey, RESOURCE_TYPE.RELATIONSHIP, helper.operations, inspectApi(resource), helper.apiDeleted, apiNoAuth, entityPath));
|
||||
}
|
||||
|
||||
inspectAddressedProperties(api, resource, relationshipKey, metainfo);
|
||||
inspectOperations(api, resource, relationshipKey, metainfo);
|
||||
return metainfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,7 +605,7 @@ public class ResourceInspector
|
||||
{
|
||||
Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
|
||||
String actionName = String.valueOf(annotAttribs.get("value"));
|
||||
String actionPath = ResourceDictionary.resourceKey(entityPath,actionName);
|
||||
String actionPath = ResourceDictionary.propertyResourceKey(entityPath,actionName);
|
||||
ResourceOperation ro = inspectOperation(anyClass, annotatedMethod, HttpMethod.POST);
|
||||
embeds.put(actionPath, new Pair<ResourceOperation,Method>(ro,annotatedMethod));
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ public interface ResourceLocator
|
||||
public static final String ENTITY_ID = "entityId";
|
||||
public static final String RELATIONSHIP_RESOURCE = "relationResource";
|
||||
public static final String RELATIONSHIP_ID = "relationshipId";
|
||||
public static final String PROPERTY = "property";
|
||||
|
||||
/**
|
||||
* Finds an Entity Resource and returns it in ResourceWithMetadata wrapper.
|
||||
@@ -32,6 +33,19 @@ public interface ResourceLocator
|
||||
*/
|
||||
ResourceWithMetadata locateEntityResource(Api api, String resourceName, HttpMethod httpMethod) throws InvalidArgumentException, UnsupportedResourceOperationException;
|
||||
|
||||
/**
|
||||
* Finds a property or action on a Relationship Resource and returns it in ResourceWithMetadata wrapper.
|
||||
* @param api - The API being used.
|
||||
* @param resourceName - The entity resource name - this is the "entityResourceName" property on the @RelationshipResource annotation.
|
||||
* @param relationName - The relationship resource name - this is the "name" property on the @RelationshipResource annotation.
|
||||
* @param property - The property resource name - can be either an action or a @BinaryProperty
|
||||
* @param httpMethod - A permitted HttpMethod
|
||||
* @return ResourceWithMetadata - The resource and its metadata.
|
||||
* @throws InvalidArgumentException - thrown if either the api or resourceName's are invalid. ie. A resource doesn't exist.
|
||||
* @throws UnsupportedResourceOperationException - throw if the resource does not support the specified HttpMethod.
|
||||
*/
|
||||
ResourceWithMetadata locateRelationPropertyResource(Api api, String entityResource, String relationResource, String property, HttpMethod httpMethod) throws InvalidArgumentException,UnsupportedResourceOperationException;
|
||||
|
||||
/**
|
||||
* Finds an Relationship Resource and returns it in ResourceWithMetadata wrapper.
|
||||
* @param api - The API being used.
|
||||
|
@@ -33,6 +33,29 @@ public class ResourceLookupDictionary implements ResourceLocator
|
||||
return locateRelationResource(api, entityResource, (String)null, httpMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceWithMetadata locateRelationPropertyResource(Api api, String entityResource, String relationResource, String property, HttpMethod httpMethod) throws InvalidArgumentException,UnsupportedResourceOperationException
|
||||
{
|
||||
String resourceKey = ResourceDictionary.resourceKey(entityResource, relationResource);
|
||||
String propertyResourceKey = ResourceDictionary.propertyResourceKey(resourceKey, property);
|
||||
Map<String, ResourceWithMetadata> apiResources = dictionary.getAllResources().get(api);
|
||||
if (apiResources == null)
|
||||
{
|
||||
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_INVALID_API);
|
||||
}
|
||||
|
||||
ResourceWithMetadata resource = apiResources.get(propertyResourceKey);
|
||||
if (resource != null)
|
||||
{
|
||||
if (!resource.getMetaData().supports(httpMethod)) { throw new UnsupportedResourceOperationException(); }
|
||||
return resource;
|
||||
}
|
||||
|
||||
logger.warn("Unable to locate resource resource for :"+entityResource+" "+relationResource==null?"":relationResource+" "+property==null?"":property);
|
||||
throw new InvalidArgumentException("Unable to locate resource resource for :"+entityResource+" "+(relationResource==null?"":relationResource+" "+property==null?"":property));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceWithMetadata locateRelationResource(Api api, String entityResource, String relationResource, HttpMethod httpMethod) throws InvalidArgumentException,UnsupportedResourceOperationException
|
||||
{
|
||||
@@ -83,7 +106,12 @@ public class ResourceLookupDictionary implements ResourceLocator
|
||||
String collectionName = templateVars.get(COLLECTION_RESOURCE);
|
||||
String entityId = templateVars.get(ENTITY_ID);
|
||||
String resourceName = templateVars.get(RELATIONSHIP_RESOURCE);
|
||||
String property = templateVars.get(PROPERTY);
|
||||
|
||||
if (StringUtils.isNotBlank(property))
|
||||
{
|
||||
return locateRelationPropertyResource(api,collectionName ,resourceName, property,httpMethod);
|
||||
}
|
||||
if (StringUtils.isNotBlank(resourceName))
|
||||
{
|
||||
return locateRelationResource(api,collectionName ,resourceName,httpMethod);
|
||||
|
@@ -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
|
||||
@@ -206,6 +215,56 @@ public class ResourceLocatorTests
|
||||
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