use of org.alfresco.rest.framework.core.ResourceWithMetadata 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);
}
use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method testResourceVersions.
@Test
public void testResourceVersions() {
ResourceWithMetadata aResource = null;
try {
aResource = locator.locateEntityResource(api, "sheepnoaction", HttpMethod.GET);
fail("Should throw an NotFoundException");
} catch (NotFoundException error) {
// this is correct
}
// Previously no actions for this entity, with v2 now have a GET action
Api v2 = Api.valueOf(api.getName(), api.getScope().toString(), "2");
aResource = locator.locateEntityResource(v2, "sheepnoaction", HttpMethod.GET);
assertNotNull(aResource);
// Not defined in v2 but now available because all v1 are available in v2.
aResource = locator.locateEntityResource(v2, "sheep", HttpMethod.GET);
assertNotNull(aResource);
try {
// Not defined in v1
aResource = locator.locateRelationResource(api, "sheepnoaction", "v3isaresource", HttpMethod.GET);
fail("Only available in v3");
} catch (NotFoundException error) {
// this is correct
}
try {
// Not defined in v2
aResource = locator.locateRelationResource(v2, "sheepnoaction", "v3isaresource", HttpMethod.GET);
fail("Only available in v3");
} catch (NotFoundException error) {
// this is correct
}
// Only defined in V3
Api v3 = Api.valueOf(api.getName(), api.getScope().toString(), "3");
aResource = locator.locateRelationResource(v3, "sheepnoaction", "v3isaresource", HttpMethod.GET);
assertNotNull("This resource is only available in v3", aResource);
// Defined in v1 but available in v3
aResource = locator.locateEntityResource(v3, "sheep", HttpMethod.GET);
assertNotNull("This resource should be available in v3", aResource);
}
use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method testInvalidApis.
@Test
public void testInvalidApis() {
ResourceWithMetadata entityResource = null;
try {
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "public", "1"), "sheep", HttpMethod.GET);
fail("Should throw an NotFoundException");
} catch (NotFoundException error) {
// this is correct
}
try {
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "public", "999"), "sheep", HttpMethod.GET);
fail("Should throw an NotFoundException");
} catch (NotFoundException error) {
// this is correct
}
entityResource = locator.locateEntityResource(Api.valueOf("alfrescomock", "private", "1"), "sheep", HttpMethod.GET);
assertNotNull(entityResource);
}
use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method testFindEntityCollectionName.
@Test
public void testFindEntityCollectionName() {
ResourceWithMetadata collResource = locator.locateEntityResource(api, "sheep", HttpMethod.GET);
String name = ResourceInspector.findEntityCollectionNameName(collResource.getMetaData());
assertEquals("sheep", name);
ResourceWithMetadata relationResource = locator.locateRelationResource(api, "sheep", "baaahh", HttpMethod.GET);
name = ResourceInspector.findEntityCollectionNameName(relationResource.getMetaData());
assertEquals("sheep", name);
relationResource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.GET);
name = ResourceInspector.findEntityCollectionNameName(relationResource.getMetaData());
assertEquals("sheep", name);
Api v2 = Api.valueOf(api.getName(), api.getScope().toString(), "2");
Map<String, String> templateVars = new HashMap<String, String>();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheepnoaction");
collResource = locator.locateResource(v2, templateVars, HttpMethod.GET);
name = ResourceInspector.findEntityCollectionNameName(collResource.getMetaData());
assertEquals("sheepnoaction", name);
}
use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method locateByVersion.
protected void locateByVersion(Api api) {
ResourceWithMetadata relationResource = locator.locateRelationResource(api, "sheep", "baaahh", HttpMethod.GET);
assertNotNull(relationResource);
assertEquals(SheepBaaaahResource.class, relationResource.getResource().getClass());
assertTrue(ResourceMetadata.RESOURCE_TYPE.RELATIONSHIP.equals(relationResource.getMetaData().getType()));
relationResource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.GET);
assertNotNull(relationResource);
assertEquals(SheepBlackSheepResource.class, relationResource.getResource().getClass());
assertTrue(ResourceMetadata.RESOURCE_TYPE.RELATIONSHIP.equals(relationResource.getMetaData().getType()));
}
Aggregations