use of org.alfresco.rest.framework.tests.api.mocks3.SlimGoat 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\"}"));
}
Aggregations