use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.
the class SerializeTests method testExpandEmbedded.
@Test
public void testExpandEmbedded() throws IOException {
assertNotNull(helper);
Farmer aFarmer = new Farmer("180");
aFarmer.setGoatId("1111");
aFarmer.setSheepId("2222");
ExecutionResult res = (ExecutionResult) helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), aFarmer);
assertNotNull(res);
assertTrue(Farmer.class.equals(res.getRoot().getClass()));
Map<String, Object> embeds = res.getEmbedded();
assertNotNull(embeds);
assertTrue(embeds.size() > 0);
ExecutionResult goat = (ExecutionResult) embeds.get("goat");
assertTrue(Goat.class.equals(goat.getRoot().getClass()));
ExecutionResult grassEmbed = (ExecutionResult) goat.getEmbedded().get("grass");
Grass grass = (Grass) grassEmbed.getRoot();
assertNotNull(grass);
assertTrue("Goat1111".equals(grass.getId()));
ExecutionResult sheep = (ExecutionResult) embeds.get("sheep");
assertTrue(Sheep.class.equals(sheep.getRoot().getClass()));
Sheep aSheep = (Sheep) sheep.getRoot();
assertTrue("2222".equals(aSheep.getId()));
String out = writeResponse(res);
assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.
the class SerializeTests method testSerializeList.
@Test
public void testSerializeList() throws IOException {
assertNotNull(helper);
Object res = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")));
String out = writeResponse(res);
assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.
the class SerializeTests method testInvokeVersions.
@Test
public void testInvokeVersions() throws IOException {
final Map<String, Object> respons = new HashMap<String, Object>();
ResourceWithMetadata entityResource = locator.locateEntityResource(api, "goat", HttpMethod.GET);
assertNotNull(entityResource);
EntityResourceAction.ReadById<?> getter = (ReadById<?>) entityResource.getResource();
Object readById = getter.readById("1234A3", NOT_USED);
assertTrue("Version 1 must be a goat.", Goat.class.equals(readById.getClass()));
String out = writeResponse(readById);
assertNotNull(out);
Api v3 = Api.valueOf(api.getName(), api.getScope().toString(), "3");
entityResource = locator.locateEntityResource(v3, "goat", HttpMethod.GET);
assertNotNull(entityResource);
getter = (ReadById<?>) entityResource.getResource();
Object readByIdForNewVersion = getter.readById("1234A3", NOT_USED);
assertTrue("Version 3 must be a slim goat.", SlimGoat.class.equals(readByIdForNewVersion.getClass()));
respons.put("v3Goat", readByIdForNewVersion);
out = writeResponse(readByIdForNewVersion);
entityResource = locator.locateEntityResource(api, "grass", HttpMethod.GET);
// ok for version 1
assertNotNull(entityResource);
try {
entityResource = locator.locateEntityResource(v3, "grass", HttpMethod.GET);
fail("Should throw an UnsupportedResourceOperationException");
} catch (UnsupportedResourceOperationException error) {
// this is correct
}
}
use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.
the class SerializeTests method testSerializeMap.
@Test
public void testSerializeMap() throws IOException {
assertNotNull(helper);
Map<String, Object> aMap = new HashMap<String, Object>();
aMap.put("goatie", new Goat());
aMap.put("sheepie", new Sheep("ABCD"));
aMap.put("sheepy", new Sheep("XYZ"));
Object res = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), aMap);
String out = writeResponse(res);
assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
use of org.alfresco.rest.framework.tests.api.mocks.Goat in project alfresco-remote-api by Alfresco.
the class ExecutionTests method testInvokePut.
@Test
public void testInvokePut() throws IOException {
ResourceWithMetadata entityResource = locator.locateEntityResource(api, "sheep", HttpMethod.PUT);
AbstractResourceWebScript executor = getExecutor("executorOfPut");
final Sheep aSheep = new Sheep("xyz");
Object result = executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, aSheep, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNotNull(result);
assertEquals(aSheep, ((ExecutionResult) result).getRoot());
final Goat goat = new Goat("xyz");
ResourceWithMetadata cowResource = locator.locateEntityResource(api, "cow", HttpMethod.PUT);
result = executor.execute(cowResource, Params.valueOf("654", null, NULL_PARAMS, goat, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNotNull(result);
assertEquals(goat, ((ExecutionResult) result).getRoot());
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.PUT);
result = executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, aSheep, mock(WebScriptRequest.class)), mock(WebScriptResponse.class), false);
assertNotNull(result);
assertEquals(aSheep, ((ExecutionResult) result).getRoot());
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);
}
Aggregations