use of org.alfresco.rest.framework.tests.api.mocks.Grass 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.Grass 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.Grass 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);
}
Aggregations