use of org.alfresco.rest.framework.jacksonextensions.ExecutionResult in project alfresco-remote-api by Alfresco.
the class SerializeTests method testExpandRelations.
@Test
public void testExpandRelations() throws IOException {
assertNotNull(helper);
Map<String, BeanPropertiesFilter> rFilter = getRelationFilter("blacksheep,baaahh");
ExecutionResult res = (ExecutionResult) helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, "sheep", ParamsExtender.valueOf(rFilter, "1"), new Farmer("180"));
assertNotNull(res);
String out = writeResponse(res);
assertTrue(Farmer.class.equals(res.getRoot().getClass()));
assertTrue("There must be json output", StringUtils.isNotBlank(out));
Paging pageRequest = Paging.valueOf(1, 2);
Object resultCollection = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, "sheep", ParamsExtender.valueOf(rFilter, "1"), CollectionWithPagingInfo.asPaged(pageRequest, Arrays.asList(new Farmer("180"), new Farmer("190"), new Farmer("280"))));
assertNotNull(resultCollection);
out = writeResponse(resultCollection);
assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
use of org.alfresco.rest.framework.jacksonextensions.ExecutionResult 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.jacksonextensions.ExecutionResult in project alfresco-remote-api by Alfresco.
the class SerializeTests method testExpandRecursiveRelations.
@Test
public void testExpandRecursiveRelations() throws IOException {
ExecutionResult exec1 = new ExecutionResult(new Farmer("180"), null);
ExecutionResult exec2 = new ExecutionResult(new Farmer("456"), getFilter("age"));
CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1, exec2));
ExecutionResult execResult = new ExecutionResult(new Sheep("ssheep"), null);
Map<String, Object> related = new HashMap<String, Object>();
related.put("farmers", coll);
execResult.addRelated(related);
String out = writeResponse(execResult);
assertTrue("There must be json output", StringUtils.isNotBlank(out));
assertFalse("collections should be serialized correctly. There may be a problem with this one.", StringUtils.contains(out, "\"collection\":["));
assertTrue("collections should be serialized correctly. There should be embed relations", StringUtils.contains(out, "\"relations\":{\"farmers\":{\"list\":"));
}
use of org.alfresco.rest.framework.jacksonextensions.ExecutionResult in project alfresco-remote-api by Alfresco.
the class SerializeTests method testFilter.
// note: exposed as "properties" query param
@Test
public void testFilter() throws IOException, JSONException {
assertNotNull(helper);
BeanPropertiesFilter theFilter = getFilter("age");
Object res = new ExecutionResult(new Sheep("bob"), theFilter);
String out = writeResponse(res);
assertTrue("Filter must only return the age.", StringUtils.contains(out, "{\"age\":3}"));
theFilter = getFilter("age,name");
res = new ExecutionResult(new Sheep("bob"), theFilter);
out = writeResponse(res);
JSONObject jsonRsp = new JSONObject(new JSONTokener(out));
assertEquals(1, jsonRsp.length());
JSONObject entry = jsonRsp.getJSONObject("entry");
assertEquals(2, entry.length());
assertEquals("The name should be 'Dolly'", "Dolly", entry.getString("name"));
assertTrue("The age should be 3", entry.getInt("age") == 3);
// unit test filter with "include" taking precendence over "fields" filter
List<String> theInclude = getIncludeClause("name");
theFilter = getFilter("age", theInclude);
res = new ExecutionResult(new Sheep("bob"), theFilter);
out = writeResponse(res);
jsonRsp = new JSONObject(new JSONTokener(out));
assertEquals(1, jsonRsp.length());
entry = jsonRsp.getJSONObject("entry");
assertEquals(2, entry.length());
assertEquals("The name should be 'Dolly'", "Dolly", entry.getString("name"));
assertTrue("The age should be 3", entry.getInt("age") == 3);
Api v3 = Api.valueOf(api.getName(), api.getScope().toString(), "3");
Map<String, BeanPropertiesFilter> relFiler = getRelationFilter("herd");
res = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), v3, "goat", ParamsExtender.valueOf(relFiler, "notUsed"), new SlimGoat());
out = writeResponse(res);
jsonRsp = new JSONObject(new JSONTokener(out));
entry = jsonRsp.getJSONObject("relations").getJSONObject("herd").getJSONObject("list").getJSONArray("entries").getJSONObject(0).getJSONObject("entry");
assertEquals("The name should be 'bigun'", "bigun", entry.getString("name"));
assertTrue("The quantity should be 56", entry.getInt("quantity") == 56);
relFiler = getRelationFilter("herd(name)");
res = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), v3, "goat", ParamsExtender.valueOf(relFiler, "notUsed"), new SlimGoat());
out = writeResponse(res);
assertTrue("Must return only the herd name.", StringUtils.contains(out, "{\"name\":\"bigun\"}"));
}
use of org.alfresco.rest.framework.jacksonextensions.ExecutionResult in project alfresco-remote-api by Alfresco.
the class SerializeTests method testIncludeSource.
@Test
public void testIncludeSource() throws IOException {
ExecutionResult exec1 = new ExecutionResult(new Farmer("180"), null);
ExecutionResult exec2 = new ExecutionResult(new Farmer("456"), null);
CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1, exec2));
Object resultCollection = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, "sheep", ParamsExtender.valueOf(true, "1"), coll);
assertNotNull(resultCollection);
String out = writeResponse(resultCollection);
assertTrue("There must 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"1\"}"));
resultCollection = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, "sheep", ParamsExtender.valueOf(false, "1"), coll);
assertNotNull(resultCollection);
out = writeResponse(resultCollection);
assertFalse("There must not 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"1\"}"));
coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1, exec2), false, 2, new Sheep("barbie"));
resultCollection = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, "sheep", ParamsExtender.valueOf(true, "1"), coll);
assertNotNull(resultCollection);
out = writeResponse(resultCollection);
assertTrue("There must 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"barbie\""));
}
Aggregations