Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

122762 gjames: RA-211: Improving the test coverage of WithResponse


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126505 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:14:35 +00:00
parent dfdba82274
commit bb9995a536
3 changed files with 180 additions and 3 deletions

View File

@@ -0,0 +1,92 @@
package org.alfresco.rest.framework.tests.api.mocks;
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.core.exceptions.RelationshipResourceNotFoundException;
import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.RelationshipResource;
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction;
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;
import org.alfresco.rest.framework.webscripts.WithResponse;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
@RelationshipResource(name = "calf", entityResource=CowEntityResource.class, title = "Muma")
public class CalfRelationshipResource implements RelationshipResourceAction.ReadByIdWithResponse<Goat>,
RelationshipResourceAction.ReadWithResponse<Goat>,
RelationshipResourceAction.CreateWithResponse<Goat>,
RelationshipResourceAction.UpdateWithResponse<Goat>,
RelationshipResourceAction.DeleteWithResponse,
RelationshipResourceBinaryAction.ReadWithResponse,
RelationshipResourceBinaryAction.DeleteWithResponse,
RelationshipResourceBinaryAction.UpdateWithResponse {
@Override
public List<Goat> create(String entityResourceId, List<Goat> entities, Parameters parameters, WithResponse withResponse)
{
return entities;
}
@Override
public void delete(String entityResourceId, String id, Parameters parameters, WithResponse withResponse)
{
}
@Override
public Goat readById(String entityResourceId, String id, Parameters parameters, WithResponse withResponse) throws RelationshipResourceNotFoundException
{
return null;
}
@Override
public CollectionWithPagingInfo<Goat> readAll(String entityResourceId, Parameters params, WithResponse withResponse)
{
return CollectionWithPagingInfo.asPaged(params.getPaging(), Arrays.asList(new Goat("Cow1")));
}
@Override
public Goat update(String entityResourceId, Goat entity, Parameters parameters, WithResponse withResponse)
{
return entity;
}
@Operation("chew")
public String chewTheGrass(String entityId, String id, Void notused, Parameters parameters, WithResponse withResponse) {
return "Yum";
}
@Override
@WebApiDescription(title = "Reads a photo")
@BinaryProperties("photo")
public BinaryResource readProperty(String entityId, String id, Parameters parameters, WithResponse withResponse) throws EntityNotFoundException
{
return null;
}
@Override
@WebApiDescription(title = "Deletes a photo")
@BinaryProperties("photo")
public void deleteProperty(String entityId, String entityResourceId, Parameters parameters, WithResponse withResponse)
{
}
@Override
@WebApiDescription(title = "Updates a photo")
@BinaryProperties("photo")
public Object updateProperty(String entityId, String entityResourceId, BasicContentInfo contentInfo, InputStream stream, Parameters params, WithResponse withResponse)
{
return null;
}
}

View File

@@ -1,12 +1,17 @@
package org.alfresco.rest.framework.tests.api.mocks;
import org.alfresco.rest.framework.BinaryProperties;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction;
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
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;
import org.alfresco.rest.framework.webscripts.WithResponse;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
@@ -15,7 +20,11 @@ public class CowEntityResource implements EntityResourceAction.ReadByIdWithRespo
EntityResourceAction.ReadWithResponse<Goat>,
EntityResourceAction.CreateWithResponse<Goat>,
EntityResourceAction.UpdateWithResponse<Goat>,
EntityResourceAction.DeleteWithResponse{
EntityResourceAction.DeleteWithResponse,
BinaryResourceAction.ReadWithResponse,
BinaryResourceAction.DeleteWithResponse,
BinaryResourceAction.UpdateWithResponse<Goat>
{
@Override
public Goat readById(String id, Parameters parameters, WithResponse withResponse)
@@ -46,4 +55,26 @@ public class CowEntityResource implements EntityResourceAction.ReadByIdWithRespo
{
return entity;
}
@Override
@BinaryProperties("photo")
public void deleteProperty(String entityId, Parameters parameters, WithResponse withResponse)
{
}
@Override
@BinaryProperties("photo")
public BinaryResource readProperty(String entityId, Parameters parameters, WithResponse withResponse) throws EntityNotFoundException
{
return null;
}
@Override
@BinaryProperties("photo")
public Goat updateProperty(String entityId, BasicContentInfo contentInfo, InputStream stream, Parameters params, WithResponse withResponse)
{
return null;
}
}

View File

@@ -17,6 +17,7 @@ import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rest.framework.tests.api.mocks.Goat;
import org.alfresco.rest.framework.tests.api.mocks.Grass;
import org.alfresco.rest.framework.tests.api.mocks.Sheep;
import org.alfresco.rest.framework.tests.api.mocks3.FlockEntityResource;
import org.alfresco.rest.framework.webscripts.AbstractResourceWebScript;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -63,6 +64,21 @@ public class ExecutionTests extends AbstractContextTest
executor.execute(baa, Params.valueOf("4", "45", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
ResourceWithMetadata cowResource = locator.locateRelationResource(api,"cow","photo", HttpMethod.GET);
result = executor.execute(cowResource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNull(result);
ResourceWithMetadata calf = locator.locateRelationResource(api,"cow", "calf", HttpMethod.GET);
result = executor.execute(calf, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
executor.execute(calf, Params.valueOf("4", "45", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
calf = locator.locateRelationResource(api,"cow/{entityId}/calf", "photo", HttpMethod.GET);
executor.execute(calf, Params.valueOf("4", "45", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
ResourceWithMetadata baaPhoto = locator.locateRelationResource(api,"sheep/{entityId}/baaahh", "photo", HttpMethod.GET);
executor.execute(baaPhoto, Params.valueOf("4", "45", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
@@ -85,14 +101,19 @@ public class ExecutionTests extends AbstractContextTest
result = executor.execute(grassResource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(grr), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals(grr,((ExecutionResult)result).getRoot());
final Goat goat = new Goat("xyz");
ResourceWithMetadata cowresource = locator.locateEntityResource(api,"cow", HttpMethod.POST);
result = executor.execute(cowresource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(grr), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals(grr,((ExecutionResult)result).getRoot());
result = executor.execute(cowresource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(goat), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals(goat,((ExecutionResult)result).getRoot());
ResourceWithMetadata entityResource = locator.locateRelationResource(api,"grass", "grow", HttpMethod.POST);
result = executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, grr, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals("Growing well",result);
ResourceWithMetadata calfResource = locator.locateRelationResource(api,"cow", "calf", HttpMethod.POST);
result = executor.execute(calfResource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(goat), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals(goat,((ExecutionResult)result).getRoot());
Map<String, String> templateVars = new HashMap();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
templateVars.put(ResourceLocator.ENTITY_ID, "sheepId");
@@ -115,10 +136,26 @@ public class ExecutionTests extends AbstractContextTest
result = executor.execute(cowResource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
cowResource = locator.locateRelationResource(api,"cow","photo", HttpMethod.DELETE);
result = executor.execute(cowResource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.DELETE);
result = executor.execute(resource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata calf = locator.locateRelationResource(api,"cow", "calf", HttpMethod.DELETE);
result = executor.execute(calf, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata flockEntityResource = locator.locateRelationResource(api3,"flock","photo", HttpMethod.DELETE);
result = executor.execute(flockEntityResource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
calf = locator.locateRelationResource(api,"cow/{entityId}/calf", "photo", HttpMethod.DELETE);
result = executor.execute(calf, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata goatDelete = locator.locateRelationResource(api3,"goat/{entityId}/herd", "content", HttpMethod.DELETE);
result = executor.execute(goatDelete, Params.valueOf("4", "56", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
@@ -149,5 +186,22 @@ public class ExecutionTests extends AbstractContextTest
ResourceWithMetadata baaPhoto = locator.locateRelationResource(api,"sheep/{entityId}/baaahh", "photo", HttpMethod.PUT);
result = executor.execute(baaPhoto, Params.valueOf("4", "56", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata flockEntityResource = locator.locateRelationResource(api3,"flock","photo", HttpMethod.PUT);
result = executor.execute(flockEntityResource, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata calf = locator.locateRelationResource(api,"cow", "calf", HttpMethod.PUT);
result = executor.execute(calf, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNotNull(result);
assertEquals(goat,((ExecutionResult)result).getRoot());
cowResource = locator.locateRelationResource(api,"cow","photo", HttpMethod.PUT);
result = executor.execute(cowResource, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
calf = locator.locateRelationResource(api,"cow/{entityId}/calf", "photo", HttpMethod.PUT);
result = executor.execute(calf, Params.valueOf("4", "56", mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
}
}