Search in sources :

Example 21 with ResourceWithMetadata

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);
}
Also used : HashMap(java.util.HashMap) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 22 with ResourceWithMetadata

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()));
}
Also used : HashMap(java.util.HashMap) GoatEntityResource(org.alfresco.rest.framework.tests.api.mocks.GoatEntityResource) SheepEntityResource(org.alfresco.rest.framework.tests.api.mocks.SheepEntityResource) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Pair(org.alfresco.util.Pair) Test(org.junit.Test)

Example 23 with ResourceWithMetadata

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\":"));
}
Also used : Read(org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.Read) EntityResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction) ReadById(org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 24 with ResourceWithMetadata

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,"));
}
Also used : Read(org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.Read) RelationshipResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 25 with ResourceWithMetadata

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);
}
Also used : AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) JSONObject(org.json.JSONObject) Api(org.alfresco.rest.framework.Api) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Aggregations

ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)27 Test (org.junit.Test)21 HashMap (java.util.HashMap)10 Api (org.alfresco.rest.framework.Api)7 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)7 AbstractResourceWebScript (org.alfresco.rest.framework.webscripts.AbstractResourceWebScript)5 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)4 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)4 Read (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.Read)4 RelationshipResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction)4 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)4 ResourceDictionary (org.alfresco.rest.framework.core.ResourceDictionary)3 EntityResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 ExecutionResult (org.alfresco.rest.framework.jacksonextensions.ExecutionResult)2 BinaryResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction)2 ReadById (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById)2 RelationshipResourceBinaryAction (org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction)2