Search in sources :

Example 1 with ResourceWithMetadata

use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.

the class ResourceLocatorTests method testLocateActions.

@Test
public void testLocateActions() {
    Map<String, String> templateVars = new HashMap<String, String>();
    ResourceWithMetadata collResource = null;
    templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "grass");
    templateVars.put(ResourceLocator.ENTITY_ID, "grassId");
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "cut");
    try {
        collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
        fail("Should throw an UnsupportedResourceOperationException");
    } catch (UnsupportedResourceOperationException error) {
    // this is correct
    }
    collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
    assertEquals(GrassEntityResource.class, collResource.getResource().getClass());
    assertEquals(ResourceMetadata.RESOURCE_TYPE.OPERATION, collResource.getMetaData().getType());
    templateVars = new HashMap<String, String>();
    templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
    templateVars.put(ResourceLocator.ENTITY_ID, "sheepId");
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "baaahh");
    templateVars.put(ResourceLocator.PROPERTY, "chew");
    collResource = locator.locateResource(api, templateVars, HttpMethod.POST);
    assertEquals(SheepBaaaahResource.class, collResource.getResource().getClass());
    assertEquals(ResourceMetadata.RESOURCE_TYPE.OPERATION, collResource.getMetaData().getType());
}
Also used : HashMap(java.util.HashMap) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 2 with ResourceWithMetadata

use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.

the class ResourceLocatorTests method testLocateProperties.

@Test
public void testLocateProperties() {
    Api api3 = Api.valueOf("alfrescomock", "private", "3");
    Map<String, String> templateVars = new HashMap<String, String>();
    templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "flock");
    templateVars.put(ResourceLocator.ENTITY_ID, "flockId");
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "photo");
    ResourceWithMetadata collResource = locator.locateResource(api3, templateVars, HttpMethod.GET);
    assertNotNull(collResource);
    assertNotNull(collResource.getMetaData().getOperation(HttpMethod.GET));
    assertEquals(FlockEntityResource.class, collResource.getResource().getClass());
    templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "flocket");
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "madeUpProp");
    try {
        collResource = locator.locateResource(api3, templateVars, HttpMethod.PUT);
        fail("Should throw an UnsupportedResourceOperationException");
    } catch (UnsupportedResourceOperationException error) {
    // this is correct
    }
    try {
        collResource = locator.locateResource(api3, templateVars, HttpMethod.DELETE);
        fail("Should throw an UnsupportedResourceOperationException");
    } catch (UnsupportedResourceOperationException error) {
    // this is correct
    }
    collResource = locator.locateResource(api3, templateVars, HttpMethod.GET);
    assertNotNull(collResource);
    assertNotNull(collResource.getMetaData().getOperation(HttpMethod.GET));
    assertEquals(FlocketEntityResource.class, collResource.getResource().getClass());
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "album");
    try {
        collResource = locator.locateResource(api3, templateVars, HttpMethod.DELETE);
        fail("Should throw an UnsupportedResourceOperationException");
    } catch (UnsupportedResourceOperationException error) {
    // this is correct
    }
    collResource = locator.locateResource(api3, templateVars, HttpMethod.GET);
    assertNotNull(collResource);
    assertNotNull(collResource.getMetaData().getOperation(HttpMethod.GET));
    assertEquals(FlocketEntityResource.class, collResource.getResource().getClass());
    collResource = locator.locateResource(api3, templateVars, HttpMethod.PUT);
    assertNotNull(collResource);
    assertNotNull(collResource.getMetaData().getOperation(HttpMethod.PUT));
    assertEquals(FlocketEntityResource.class, collResource.getResource().getClass());
}
Also used : HashMap(java.util.HashMap) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) Api(org.alfresco.rest.framework.Api) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 3 with ResourceWithMetadata

use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.

the class ResourceLocatorTests method testLocateResourcesByType.

@Test(expected = org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException.class)
public void testLocateResourcesByType() {
    Api api1 = Api.valueOf("alfrescomock", "private", "1");
    ResourceWithMetadata entityResource = locator.locateEntityResource(api1, "sheep", HttpMethod.GET);
    assertNotNull(entityResource);
    assertEquals(SheepEntityResource.class, entityResource.getResource().getClass());
    assertTrue(ResourceMetadata.RESOURCE_TYPE.ENTITY.equals(entityResource.getMetaData().getType()));
    Api api2 = Api.valueOf("alfrescomock", "private", "2");
    locateByVersion(api1);
    locateByVersion(api2);
    @SuppressWarnings("unused") ResourceWithMetadata relationResource = locator.locateRelationResource(api1, "sheep", "baah", HttpMethod.GET);
}
Also used : Api(org.alfresco.rest.framework.Api) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Example 4 with ResourceWithMetadata

use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.

the class ResourceLocatorTests method testLocateRelationshipProperties.

@Test
public void testLocateRelationshipProperties() {
    Api api3 = Api.valueOf("alfrescomock", "private", "3");
    Map<String, String> templateVars = new HashMap<String, String>();
    templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "goat");
    templateVars.put(ResourceLocator.ENTITY_ID, "herdId");
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "herd");
    ResourceWithMetadata collResource;
    try {
        collResource = locator.locateResource(api3, templateVars, HttpMethod.PUT);
        fail("Should throw an UnsupportedResourceOperationException");
    } catch (UnsupportedResourceOperationException error) {
    // this is correct
    }
    templateVars.put(ResourceLocator.PROPERTY, "content");
    collResource = locator.locateResource(api3, templateVars, HttpMethod.GET);
    assertNotNull(collResource);
    assertNotNull(collResource.getMetaData().getOperation(HttpMethod.GET));
    templateVars = new HashMap<String, String>();
    templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
    templateVars.put(ResourceLocator.ENTITY_ID, "sheepId");
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "baaahh");
    templateVars.put(ResourceLocator.PROPERTY, "content");
    try {
        // Tests by passing invalid propery
        collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
        fail("Should throw an NotFoundException");
    } catch (NotFoundException error) {
    // this is correct
    }
    templateVars.put(ResourceLocator.PROPERTY, "photo");
    collResource = locator.locateResource(api, templateVars, HttpMethod.GET);
    assertNotNull(collResource);
    assertNotNull(collResource.getMetaData().getOperation(HttpMethod.GET));
    assertNotNull(collResource.getMetaData().getOperation(HttpMethod.PUT));
    assertNotNull(collResource.getMetaData().getOperation(HttpMethod.DELETE));
}
Also used : HashMap(java.util.HashMap) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) 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 5 with ResourceWithMetadata

use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.

the class SerializeTests method testSerializeResponse.

@Test
public void testSerializeResponse() 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));
    String 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) RelationshipResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction) 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