Search in sources :

Example 6 with Goat

use of org.alfresco.rest.framework.tests.api.mocks.Goat 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 7 with Goat

use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.

the class SerializeTests method testSerializePagedCollection.

@SuppressWarnings({ "rawtypes" })
@Test
public void testSerializePagedCollection() throws IOException {
    assertNotNull(helper);
    CollectionWithPagingInfo paged = CollectionWithPagingInfo.asPaged(null, null);
    String out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), paged));
    assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":0,"));
    Paging pageRequest = Paging.valueOf(1, 2);
    paged = CollectionWithPagingInfo.asPaged(pageRequest, Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")));
    out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), paged));
    assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,"));
    paged = CollectionWithPagingInfo.asPaged(pageRequest, Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")), true, 5000);
    out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), paged));
    assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,\"hasMoreItems\":true,\"totalItems\":5000"));
}
Also used : Paging(org.alfresco.rest.framework.resource.parameters.Paging) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) CollectionWithPagingInfo(org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) SlimGoat(org.alfresco.rest.framework.tests.api.mocks3.SlimGoat) Test(org.junit.Test)

Example 8 with Goat

use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.

the class SerializeTests method testSerializeSet.

@Test
public void testSerializeSet() throws IOException {
    assertNotNull(helper);
    Set<Object> aSet = new HashSet<Object>();
    aSet.add(new Goat());
    aSet.add(new Sheep("ABCD"));
    aSet.add(new Sheep("XYZ"));
    Object res = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), aSet);
    String out = writeResponse(res);
    assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
Also used : WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) JSONObject(org.json.JSONObject) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) SlimGoat(org.alfresco.rest.framework.tests.api.mocks3.SlimGoat) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Goat (org.alfresco.rest.framework.tests.api.mocks.Goat)8 Test (org.junit.Test)8 Sheep (org.alfresco.rest.framework.tests.api.mocks.Sheep)7 SlimGoat (org.alfresco.rest.framework.tests.api.mocks3.SlimGoat)6 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)6 JSONObject (org.json.JSONObject)5 HashMap (java.util.HashMap)3 ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)3 Grass (org.alfresco.rest.framework.tests.api.mocks.Grass)2 AbstractResourceWebScript (org.alfresco.rest.framework.webscripts.AbstractResourceWebScript)2 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)2 HashSet (java.util.HashSet)1 Api (org.alfresco.rest.framework.Api)1 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)1 ExecutionResult (org.alfresco.rest.framework.jacksonextensions.ExecutionResult)1 EntityResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction)1 ReadById (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById)1 CollectionWithPagingInfo (org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 Farmer (org.alfresco.rest.framework.tests.api.mocks.Farmer)1