use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method testLocateResource.
@Test(expected = org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException.class)
public void testLocateResource() {
Map<String, String> templateVars = new HashMap<String, String>();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
ResourceWithMetadata collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
assertNotNull(collResource);
assertNotNull(collResource.getMetaData().getOperation(HttpMethod.GET));
collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
assertNotNull(collResource);
assertNotNull(collResource.getMetaData().getOperation(HttpMethod.POST));
templateVars.put(ResourceLocator.ENTITY_ID, "farmersUniqueId");
ResourceWithMetadata entityResource = locator.locateResource(api, templateVars, HttpMethod.GET);
assertNotNull(entityResource);
assertNotNull(entityResource.getMetaData().getOperation(HttpMethod.GET));
entityResource = locator.locateResource(api, templateVars, HttpMethod.PUT);
assertNotNull(entityResource);
assertNotNull(entityResource.getMetaData().getOperation(HttpMethod.PUT));
templateVars.clear();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheepnoaction");
collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
}
use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class ResourceLocatorTests method testGetEmbeddedResources.
@Test
public void testGetEmbeddedResources() {
Map<String, Pair<String, Method>> embeddded = ResourceInspector.findEmbeddedResources(Farmer.class);
assertNotNull(embeddded);
final Map<String, ResourceWithMetadata> results = new HashMap<String, ResourceWithMetadata>(embeddded.size());
for (Entry<String, Pair<String, Method>> embeddedEntry : embeddded.entrySet()) {
ResourceWithMetadata res = locator.locateEntityResource(api, embeddedEntry.getValue().getFirst(), HttpMethod.GET);
results.put(embeddedEntry.getKey(), res);
}
assertNotNull(results);
assertTrue(results.size() == 2);
assertTrue(SheepEntityResource.class.equals(results.get("sheep").getResource().getClass()));
Object goatResource = results.get("goat").getResource();
assertTrue(GoatEntityResource.class.equals(goatResource.getClass()));
}
use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class SerializeTests method testInvokeEntity.
@Test
public void testInvokeEntity() throws IOException {
ResourceWithMetadata entityResource = locator.locateEntityResource(api, "sheep", HttpMethod.GET);
assertNotNull(entityResource);
EntityResourceAction.ReadById<?> getter = (ReadById<?>) entityResource.getResource();
String out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, NOT_USED, getter.readById("1234A3", NOT_USED)));
assertTrue("There must be json output", StringUtils.startsWith(out, "{\"entry\":"));
EntityResourceAction.Read<?> getAll = (Read<?>) entityResource.getResource();
CollectionWithPagingInfo<?> resources = getAll.readAll(null);
out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), resources));
assertTrue("There must be json output as List", StringUtils.startsWith(out, "{\"list\":"));
}
use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class SerializeTests method testPagedCollection.
@Test
public void testPagedCollection() throws IOException {
ResourceWithMetadata relationResource = locator.locateRelationResource(api, "sheep", "baaahh", HttpMethod.GET);
assertNotNull(relationResource);
RelationshipResourceAction.Read<?> getter = (RelationshipResourceAction.Read<?>) relationResource.getResource();
CollectionWithPagingInfo<?> resources = getter.readAll("123", Params.valueOf("", null, null));
assertNotNull(resources);
assertTrue(resources.getTotalItems().intValue() == 3);
assertFalse(resources.hasMoreItems());
String out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), resources));
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,"));
resources = getter.readAll("123", ParamsExtender.valueOf(Paging.valueOf(0, 1), "123"));
assertTrue(resources.getCollection().size() == 1);
assertTrue(resources.hasMoreItems());
out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), resources));
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":1,"));
}
use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.
the class SerializeTests method testInvokeProperty.
@Test
public void testInvokeProperty() throws IOException {
Api api3 = Api.valueOf("alfrescomock", "private", "3");
ResourceWithMetadata propResource = locator.locateRelationResource(api3, "flock", "photo", HttpMethod.GET);
AbstractResourceWebScript executor = getExecutor();
Object result = executor.execute(propResource, Params.valueOf("234", null, null), mock(WebScriptResponse.class), true);
assertNotNull(result);
}
Aggregations