use of org.alfresco.rest.framework.tests.api.mocks.Farmer 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\""));
}
use of org.alfresco.rest.framework.tests.api.mocks.Farmer in project alfresco-remote-api by Alfresco.
the class InspectorTests method testUniqueIdAnnotation.
@Test
public void testUniqueIdAnnotation() {
String uniqueId = ResourceInspector.findUniqueId(new Grass("34"));
assertNull(uniqueId);
uniqueId = ResourceInspector.findUniqueId(new Farmer("345"));
assertNotNull(uniqueId);
assertTrue("345".equals(uniqueId));
// inherited classes are ok (with overidden unique id method)
uniqueId = ResourceInspector.findUniqueId(new FarmersSon("567"));
assertNotNull(uniqueId);
assertTrue("567".equals(uniqueId));
// inherited classes are ok (with overidden unique id method but @UniqueId annotation not specified)
uniqueId = ResourceInspector.findUniqueId(new FarmersGrandson("12"));
assertNotNull(uniqueId);
assertTrue("12".equals(uniqueId));
// More than 1 annotation should throw IllegalArgumentException
try {
uniqueId = ResourceInspector.findUniqueId(new FarmersDaughter("21"));
fail("Should throw an InvalidArgumentException");
} catch (IllegalArgumentException error) {
// this is correct
}
}
use of org.alfresco.rest.framework.tests.api.mocks.Farmer in project alfresco-remote-api by Alfresco.
the class SearchQuerySerializerTests method testSerializeContext.
@Test
public void testSerializeContext() throws IOException {
ExecutionResult exec1 = new ExecutionResult(new Farmer("180"), null);
FacetFieldContext ffc = new FacetFieldContext("theLabel", Arrays.asList(new Bucket("b1", "name:b1", 23, "displayText1"), new Bucket("b2", null, 34, "displayText2")));
SearchContext searchContext = new SearchContext(23l, null, Arrays.asList(new FacetQueryContext("f1", "creator:bob", 15), new FacetQueryContext("f2", null, 20)), Arrays.asList(ffc), new SpellCheckContext("aFlag", Arrays.asList("bish", "bash")), null);
CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
String out = helper.writeResponse(coll);
assertTrue("There must 'context' json output", out.contains("\"context\":{\"consistency\":{\"lastTxId\":23}"));
assertTrue("There must 'facetQueries' json output", out.contains("\"facetQueries\":"));
assertTrue("There must 'facetQueries f1' json output", out.contains("{\"label\":\"f1\",\"filterQuery\":\"creator:bob\",\"count\":15}"));
assertTrue("There must 'facetQueries f2' json output", out.contains("{\"label\":\"f2\",\"count\":20}"));
assertTrue("There must 'spellCheck' json output", out.contains("\"spellCheck\":{\"type\":\"aFlag\",\"suggestions\":[\"bish\",\"bash\"]}"));
assertTrue("There must 'facetsFields' json output", out.contains("\"facetsFields\":[{\"label\":\"theLabel\",\"buckets\""));
assertTrue("There must 'bucket1' json output", out.contains("{\"label\":\"b1\",\"filterQuery\":\"name:b1\",\"count\":23,\"display\":\"displayText1\"}"));
assertTrue("There must 'bucket2' json output", out.contains("{\"label\":\"b2\",\"count\":34,\"display\":\"displayText2\"}"));
searchContext = new SearchContext(-1, null, null, null, null, null);
coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
out = helper.writeResponse(coll);
assertTrue("There must NOT BE a 'context' json output", out.contains("\"context\":{}"));
assertFalse("There must NOT BE a 'facetsFields' json output", out.contains("\"facetsFields\":{}"));
}
use of org.alfresco.rest.framework.tests.api.mocks.Farmer in project alfresco-remote-api by Alfresco.
the class JsonJacksonTests method testDeserializeFarmersAsList.
@Test
public void testDeserializeFarmersAsList() throws IOException {
List<Farmer> aFarmer = jsonHelper.constructList(new StringReader(COLLECTION_START + FARMER_JSON + COLLECTION_END), Farmer.class);
assertTrue(Collection.class.isAssignableFrom(aFarmer.getClass()));
assertEquals(1, aFarmer.size());
aFarmer = jsonHelper.constructList(new StringReader(FARMERS_COLLECTION_JSON), Farmer.class);
assertTrue(Collection.class.isAssignableFrom(aFarmer.getClass()));
assertEquals(3, aFarmer.size());
aFarmer = jsonHelper.constructList(new StringReader(FARMER_JSON), Farmer.class);
assertTrue(Collection.class.isAssignableFrom(aFarmer.getClass()));
assertEquals(1, aFarmer.size());
try {
aFarmer = jsonHelper.constructList(new StringReader(""), Farmer.class);
fail("Should not get here.");
} catch (InvalidArgumentException iae) {
// Must throw this exception
assertNotNull(iae);
}
try {
aFarmer = jsonHelper.constructList(new StringReader("rubbish"), Farmer.class);
fail("Should not get here.");
} catch (InvalidArgumentException iae) {
// Must throw this exception
assertNotNull(iae);
}
try {
aFarmer = jsonHelper.constructList(new StringReader("[]"), Farmer.class);
fail("Should not get here.");
} catch (InvalidArgumentException iae) {
// Must throw this exception
assertNotNull(iae);
}
}
use of org.alfresco.rest.framework.tests.api.mocks.Farmer in project alfresco-remote-api by Alfresco.
the class JsonJacksonTests method testDeserializeFarmer.
@Test
public void testDeserializeFarmer() throws IOException {
Farmer aFarmer = jsonHelper.construct(new StringReader(FARMER_JSON), Farmer.class);
assertEquals(Farmer.class, aFarmer.getClass());
assertEquals("Giles", aFarmer.getName());
assertEquals(54, aFarmer.getAge());
assertEquals(Farmer.size.LARGE, aFarmer.getFarm());
try {
aFarmer = jsonHelper.construct(new StringReader(""), Farmer.class);
fail("Should not get here.");
} catch (InvalidArgumentException iae) {
// Must throw this exception
assertNotNull(iae);
}
}
Aggregations