use of org.alfresco.rest.framework.webscripts.AbstractResourceWebScript in project alfresco-remote-api by Alfresco.
the class ExecutionTests method testInvokeDelete.
@Test
public void testInvokeDelete() throws IOException {
ResourceWithMetadata grassResource = locator.locateEntityResource(api, "grass", HttpMethod.DELETE);
AbstractResourceWebScript executor = getExecutor("executorOfDelete");
Object result = executor.execute(grassResource, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNull(result);
ResourceWithMetadata cowResource = locator.locateEntityResource(api, "cow", HttpMethod.DELETE);
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);
}
use of org.alfresco.rest.framework.webscripts.AbstractResourceWebScript in project alfresco-remote-api by Alfresco.
the class ExecutionTests method testInvokeAbstract.
@Test
public void testInvokeAbstract() throws IOException {
AbstractResourceWebScript executor = getExecutor();
Map<String, String> templateVars = new HashMap();
templateVars.put("apiScope", "private");
templateVars.put("apiVersion", "1");
templateVars.put("apiName", "alfrescomock");
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
executor.execute(ApiAssistant.determineApi(templateVars), mockRequest(templateVars, new HashMap<String, List<String>>(1)), mock(WebScriptResponse.class));
WebScriptResponse response = mockResponse();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "bad");
executor.execute(api, mockRequest(templateVars, new HashMap<String, List<String>>(1)), response);
// throws a runtime exception so INTERNAL_SERVER_ERROR
verify(response, times(1)).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response = mockResponse();
templateVars.put(ResourceLocator.ENTITY_ID, "badId");
executor.execute(api, mockRequest(templateVars, new HashMap<String, List<String>>(1)), response);
// throws a IntegrityException so 422
verify(response, times(1)).setStatus(422);
}
use of org.alfresco.rest.framework.webscripts.AbstractResourceWebScript in project alfresco-remote-api by Alfresco.
the class ExecutionTests method testInvokeGet.
@Test
public void testInvokeGet() throws IOException {
ResourceWithMetadata entityResource = locator.locateEntityResource(api, "sheep", HttpMethod.GET);
AbstractResourceWebScript executor = getExecutor();
Object result = executor.execute(entityResource, Params.valueOf((String) null, null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
WebScriptResponse response = mock(WebScriptResponse.class);
entityResource = locator.locateEntityResource(api, "cow", HttpMethod.GET);
result = executor.execute(entityResource, Params.valueOf((String) null, null, mock(WebScriptRequest.class)), response, true);
assertNotNull(result);
verify(response, times(1)).setCache((Cache) ResponseWriter.CACHE_NEVER);
response = mock(WebScriptResponse.class);
result = executor.execute(entityResource, Params.valueOf("543", null, mock(WebScriptRequest.class)), response, true);
assertNotNull(result);
verify(response, times(1)).setCache((Cache) CowEntityResource.CACHE_COW);
ResourceWithMetadata baa = locator.locateRelationResource(api, "sheep", "baaahh", HttpMethod.GET);
result = executor.execute(baa, Params.valueOf("4", null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), true);
assertNotNull(result);
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);
}
use of org.alfresco.rest.framework.webscripts.AbstractResourceWebScript in project alfresco-remote-api by Alfresco.
the class ExecutionTests method testInvokePost.
@Test
public void testInvokePost() throws IOException {
AbstractResourceWebScript executor = getExecutor("executorOfPost");
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.POST);
final Sheep aSheep = new Sheep("xyz");
Object result = executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(aSheep), mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNotNull(result);
assertEquals(aSheep, ((ExecutionResult) result).getRoot());
ResourceWithMetadata grassResource = locator.locateEntityResource(api, "grass", HttpMethod.POST);
final Grass grr = new Grass("grr");
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);
WebScriptResponse response = mock(WebScriptResponse.class);
result = executor.execute(cowresource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(goat), mock(WebScriptRequest.class)), response, false);
assertEquals(goat, ((ExecutionResult) result).getRoot());
verify(response, times(1)).setStatus(Status.STATUS_ACCEPTED);
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");
templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "baaahh");
templateVars.put(ResourceLocator.PROPERTY, "chew");
ResourceWithMetadata collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
result = executor.execute(collResource, Params.valueOf("654", "345", NULL_PARAMS, null, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertEquals("All done", result);
}
use of org.alfresco.rest.framework.webscripts.AbstractResourceWebScript in project alfresco-remote-api by Alfresco.
the class SerializeTests method testInvokeProperty.
@Test
public void testInvokeProperty() throws IOException {
Api api3 = Api.valueOf("alfrescomock", "private", "3");
ResourceWithMetadata propResource = locator.locateRelationResource(api3, "flock", "photo", HttpMethod.GET);
AbstractResourceWebScript executor = getExecutor();
Object result = executor.execute(propResource, Params.valueOf("234", null, null), mock(WebScriptResponse.class), true);
assertNotNull(result);
}
Aggregations