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());
}
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());
}
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);
}
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));
}
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\":"));
}
Aggregations