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);
}
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"));
}
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));
}
Aggregations