Search in sources :

Example 16 with ResourceWithMetadata

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);
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) HashMap(java.util.HashMap) AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) Sheep(org.alfresco.rest.framework.tests.api.mocks.Sheep) Goat(org.alfresco.rest.framework.tests.api.mocks.Goat) Grass(org.alfresco.rest.framework.tests.api.mocks.Grass) Matchers.anyString(org.mockito.Matchers.anyString) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 17 with ResourceWithMetadata

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

Example 18 with ResourceWithMetadata

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

Example 19 with ResourceWithMetadata

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

Example 20 with ResourceWithMetadata

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

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