Search in sources :

Example 6 with AbstractResourceWebScript

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);
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 7 with AbstractResourceWebScript

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);
}
Also used : HashMap(java.util.HashMap) AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 8 with AbstractResourceWebScript

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);
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Matchers.anyString(org.mockito.Matchers.anyString) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 9 with AbstractResourceWebScript

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);
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) HashMap(java.util.HashMap) AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) Grass(org.alfresco.rest.framework.tests.api.mocks.Grass) Matchers.anyString(org.mockito.Matchers.anyString) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 10 with AbstractResourceWebScript

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);
}
Also used : AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) JSONObject(org.json.JSONObject) Api(org.alfresco.rest.framework.Api) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Aggregations

AbstractResourceWebScript (org.alfresco.rest.framework.webscripts.AbstractResourceWebScript)11 Test (org.junit.Test)9 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)8 ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)5 Matchers.anyString (org.mockito.Matchers.anyString)5 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)4 HashMap (java.util.HashMap)3 Goat (org.alfresco.rest.framework.tests.api.mocks.Goat)2 Sheep (org.alfresco.rest.framework.tests.api.mocks.Sheep)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 Api (org.alfresco.rest.framework.Api)1 Grass (org.alfresco.rest.framework.tests.api.mocks.Grass)1 ApiAssistant (org.alfresco.rest.framework.tools.ApiAssistant)1 ResourceWebScriptDelete (org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete)1 WithResponse (org.alfresco.rest.framework.webscripts.WithResponse)1 TransactionService (org.alfresco.service.transaction.TransactionService)1 JSONObject (org.json.JSONObject)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1