You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2009/07/15 22:09:04 UTC
svn commit: r794388 - in /incubator/chemistry/trunk/chemistry:
chemistry-api/src/main/java/org/apache/chemistry/
chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/
chemistry-atompub-client/src/main/java/org/apache/chemistry/ato...
Author: fguillaume
Date: Wed Jul 15 20:09:04 2009
New Revision: 794388
URL: http://svn.apache.org/viewvc?rev=794388&view=rev
Log:
CMIS-30: implement navigation services for AtomPub and Simple client
Modified:
incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPFolder.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Request.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java
incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java
incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestSimpleDirect.java
Modified: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java Wed Jul 15 20:09:04 2009
@@ -72,7 +72,7 @@
* Returns the descendant objects contained at one or more levels in the
* tree rooted at the specified folder. The ordering and tree walk algorithm
* is repository-specific, but should be consistent. A depth of 1 means
- * returning only the direct children (same as {@link #getChildren}
+ * returning only the direct children (same as {@link #getChildren}).
* <p>
* Only the filter-selected properties associated with each object are
* returned. The content stream is not returned.
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java Wed Jul 15 20:09:04 2009
@@ -25,6 +25,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -58,6 +59,8 @@
*/
public class APPConnection implements Connection, SPI {
+ public static final int DEFAULT_MAX_CHILDREN = 20;
+
protected APPFolder root;
protected Connector connector;
@@ -167,33 +170,132 @@
* ----- Navigation Services -----
*/
+ /**
+ * Accumulates the descendants into a list recursively.
+ */
+ protected void accumulateDescendants(ObjectId folder, BaseType type,
+ int depth, String filter, boolean includeAllowableActions,
+ boolean includeRelationships, String orderBy, List<ObjectEntry> list) {
+ // TODO deal with paging properly
+ List<ObjectEntry> children = getChildren(folder, type, filter,
+ includeAllowableActions, includeRelationships,
+ Integer.MAX_VALUE, 0, orderBy, new boolean[1]);
+ for (ObjectEntry child : children) {
+ BaseType childType = repository.getType(child.getTypeId()).getBaseType();
+ if (type == null || childType.equals(type)) {
+ list.add(child);
+ }
+ if (depth > 1 && childType == BaseType.FOLDER) {
+ accumulateDescendants(child, type, depth - 1, filter,
+ includeAllowableActions, includeRelationships, orderBy,
+ list);
+ }
+ }
+ }
+
public List<ObjectEntry> getDescendants(ObjectId folder, BaseType type,
int depth, String filter, boolean includeAllowableActions,
boolean includeRelationships, String orderBy) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ // TODO includeRelationship, includeAllowableActions, orderBy
+ List<ObjectEntry> list = new ArrayList<ObjectEntry>();
+ accumulateDescendants(folder, type, depth, filter,
+ includeAllowableActions, includeRelationships, orderBy, list);
+ return list;
}
public List<ObjectEntry> getChildren(ObjectId folder, BaseType type,
String filter, boolean includeAllowableActions,
boolean includeRelationships, int maxItems, int skipCount,
String orderBy, boolean[] hasMoreItems) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ // TODO filter, includeRelationship, includeAllowableActions, orderBy
+ if (maxItems <= 0) {
+ maxItems = DEFAULT_MAX_CHILDREN;
+ }
+ if (skipCount < 0) {
+ skipCount = 0;
+ }
+
+ String href = getObjectEntry(folder).getLink(CMIS.LINK_CHILDREN);
+ Response resp = connector.get(new Request(href));
+ if (!resp.isOk()) {
+ throw new ContentManagerException(
+ "Remote server returned error code: "
+ + resp.getStatusCode());
+ }
+ List<ObjectEntry> feed = resp.getObjectFeed(new ReadContext(this));
+
+ List<ObjectEntry> result = new LinkedList<ObjectEntry>();
+ hasMoreItems[0] = false;
+ boolean done = false;
+ for (ObjectEntry entry : feed) {
+ // type filtering
+ if (type != null
+ && !repository.getType(entry.getTypeId()).getBaseType().equals(
+ type)) {
+ continue;
+ }
+ // skip
+ if (skipCount > 0) {
+ skipCount--;
+ continue;
+ }
+ // entry is ok
+ if (done) {
+ hasMoreItems[0] = true;
+ break;
+ }
+ result.add(entry);
+ if (result.size() >= maxItems) {
+ done = true;
+ // don't break now, we still have to find out if there are more
+ // non-filtered entries to fill in hasMoreItems
+ }
+ }
+ return result;
}
public List<ObjectEntry> getFolderParent(ObjectId folder, String filter,
boolean includeAllowableActions, boolean includeRelationships,
boolean returnToRoot) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ // TODO filter, includeRelationship, includeAllowableActions
+ List<ObjectEntry> result = new LinkedList<ObjectEntry>();
+ APPObjectEntry current = getObjectEntry(folder);
+ Type type = repository.getType(current.getTypeId());
+ if (!type.getBaseType().equals(BaseType.FOLDER)) {
+ throw new IllegalArgumentException("Not a folder: " + folder);
+ }
+ String rootId = current.connection.getRootFolder().getId();
+ ReadContext ctx = new ReadContext(this);
+ do {
+ if (current.getId().equals(rootId)) {
+ break;
+ }
+ String href = current.getLink(CMIS.LINK_PARENTS);
+ Response resp = connector.get(new Request(href));
+ if (!resp.isOk()) {
+ throw new ContentManagerException(
+ "Remote server returned error code: "
+ + resp.getStatusCode());
+ }
+ current = (APPObjectEntry) resp.getObject(ctx);
+ result.add(current);
+ } while (returnToRoot);
+ return result;
}
public Collection<ObjectEntry> getObjectParents(ObjectId object,
String filter, boolean includeAllowableActions,
boolean includeRelationships) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ // TODO filter, includeRelationship, includeAllowableActions
+ APPObjectEntry current = getObjectEntry(object);
+ String href = current.getLink(CMIS.LINK_PARENTS);
+ Response resp = connector.get(new Request(href));
+ if (!resp.isOk()) {
+ throw new ContentManagerException(
+ "Remote server returned error code: "
+ + resp.getStatusCode());
+ }
+ return resp.getObjectFeed(new ReadContext(this));
}
public Collection<ObjectEntry> getCheckedoutDocuments(ObjectId folder,
@@ -208,32 +310,40 @@
* ----- Object Services -----
*/
- /**
- * TODO temporary implementation to have something working until search is
- * implemented Versions not yet supported
+ /*
+ * TODO hardcoded Chemistry URL pattern here...
+ *
+ * Will use URI templates (or, failing that, search) in future versions.
*/
- public CMISObject getObject(ObjectId object, ReturnVersion returnVersion) {
- String objectId = object.getId();
- if (returnVersion == null) {
- returnVersion = ReturnVersion.THIS;
+ protected APPObjectEntry getObjectEntry(ObjectId objectId) {
+ if (objectId instanceof APPObjectEntry) {
+ return ((APPObjectEntry) objectId);
}
- // TODO hardcoded URL pattern here...
String href = repository.getCollectionHref(CMIS.COL_ROOT_CHILDREN);
- if (!href.matches(".*/children/[0-9a-f-]{36}")) {
- throw new AssertionError(href);
+ if (href.matches(".*/children/[0-9a-f-]{36}")) {
+ href = href.substring(0, href.length() - "/children/".length() - 36);
+ } else {
+ if (href.matches(".*/children$")) {
+ href = href.substring(0, href.length() - "/children".length());
+ } else {
+ throw new AssertionError(href);
+ }
}
- href = href.substring(0, href.length() - "/children/".length() - 36);
- href += "/object/" + objectId;
- Request req = new Request(href);
- Response resp = connector.get(req);
+ href += "/object/" + objectId.getId();
+ Response resp = connector.get(new Request(href));
if (!resp.isOk()) {
throw new ContentManagerException(
"Remote server returned error code: "
+ resp.getStatusCode());
}
+ return (APPObjectEntry) resp.getObject(new ReadContext(this));
+ }
- APPObjectEntry entry = (APPObjectEntry) resp.getObject(new ReadContext(
- this));
+ public CMISObject getObject(ObjectId object, ReturnVersion returnVersion) {
+ if (returnVersion == null) {
+ returnVersion = ReturnVersion.THIS;
+ }
+ APPObjectEntry entry = getObjectEntry(object);
Type type = getRepository().getType(entry.getTypeId());
switch (type.getBaseType()) {
case DOCUMENT:
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPFolder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPFolder.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPFolder.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPFolder.java Wed Jul 15 20:09:04 2009
@@ -63,7 +63,6 @@
}
public List<CMISObject> getChildren(BaseType type) {
- // TODO type
String href = entry.getLink(CMIS.LINK_CHILDREN);
Response resp = entry.connection.getConnector().get(new Request(href));
if (!resp.isOk()) {
@@ -74,8 +73,14 @@
List<ObjectEntry> feed = resp.getObjectFeed(new ReadContext(
entry.connection));
List<CMISObject> children = new ArrayList<CMISObject>(feed.size());
- for (ObjectEntry e : feed) {
- children.add(APPObject.construct((APPObjectEntry) e));
+ APPRepository repository = entry.connection.repository;
+ for (ObjectEntry child : feed) {
+ if (type != null
+ && !repository.getType(child.getTypeId()).getBaseType().equals(
+ type)) {
+ continue;
+ }
+ children.add(APPObject.construct((APPObjectEntry) child));
}
return children;
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Request.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Request.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Request.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Request.java Wed Jul 15 20:09:04 2009
@@ -31,6 +31,9 @@
protected List<String> params;
public Request(String url) {
+ if (url == null) {
+ throw new NullPointerException("Null url");
+ }
this.url = url;
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java Wed Jul 15 20:09:04 2009
@@ -143,13 +143,13 @@
// CMIS links
entry.addLink(getRepositoryLink(request), CMIS.LINK_REPOSITORY);
entry.addLink(getTypeLink(object.getTypeId(), request), CMIS.LINK_TYPE);
+ String oid = object.getId();
+ entry.addLink(getParentsLink(oid, request), CMIS.LINK_PARENTS);
Type objectType = repository.getType(object.getTypeId());
if (objectType.getBaseType() == BaseType.FOLDER) {
- String oid = object.getId();
entry.addLink(getChildrenLink(oid, request), CMIS.LINK_CHILDREN);
entry.addLink(getDescendantsLink(oid, request),
CMIS.LINK_DESCENDANTS);
- entry.addLink(getParentsLink(oid, request), CMIS.LINK_PARENTS);
}
// entry.addLink("XXX", CMIS.LINK_ALLOWABLE_ACTIONS);
// entry.addLink("XXX", CMIS.LINK_RELATIONSHIPS);
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java Wed Jul 15 20:09:04 2009
@@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -244,11 +245,37 @@
* ----- Navigation Services -----
*/
+ /**
+ * Accumulates the descendants into a list recursively.
+ */
+ protected void accumulateDescendants(ObjectId folder, BaseType type,
+ int depth, String filter, boolean includeAllowableActions,
+ boolean includeRelationships, String orderBy, List<ObjectEntry> list) {
+ // TODO deal with paging properly
+ List<ObjectEntry> children = getChildren(folder, type, filter,
+ includeAllowableActions, includeRelationships,
+ Integer.MAX_VALUE, 0, orderBy, new boolean[1]);
+ for (ObjectEntry child : children) {
+ BaseType childType = repository.getType(child.getTypeId()).getBaseType();
+ if (type == null || childType.equals(type)) {
+ list.add(child);
+ }
+ if (depth > 1 && childType == BaseType.FOLDER) {
+ accumulateDescendants(child, type, depth - 1, filter,
+ includeAllowableActions, includeRelationships, orderBy,
+ list);
+ }
+ }
+ }
+
public List<ObjectEntry> getDescendants(ObjectId folder, BaseType type,
int depth, String filter, boolean includeAllowableActions,
boolean includeRelationships, String orderBy) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ // TODO includeRelationship, includeAllowableActions, orderBy
+ List<ObjectEntry> list = new ArrayList<ObjectEntry>();
+ accumulateDescendants(folder, type, depth, filter,
+ includeAllowableActions, includeRelationships, orderBy, list);
+ return list;
}
public List<ObjectEntry> getChildren(ObjectId folder, BaseType type,
@@ -294,8 +321,32 @@
public List<ObjectEntry> getFolderParent(ObjectId folder, String filter,
boolean includeAllowableActions, boolean includeRelationships,
boolean returnToRoot) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ // TODO filter, includeRelationship, includeAllowableActions
+ List<ObjectEntry> result = new LinkedList<ObjectEntry>();
+ SimpleData data = repository.datas.get(folder.getId());
+ if (data == null) {
+ throw new RuntimeException("No such folder: " + folder);
+ }
+ String typeId = (String) data.get(Property.TYPE_ID);
+ Type type = repository.getType(typeId);
+ if (!type.getBaseType().equals(BaseType.FOLDER)) {
+ throw new IllegalArgumentException("Not a folder: " + folder);
+ }
+ String currentId = (String) data.get(Property.ID);
+ do {
+ Set<String> parents = repository.parents.get(currentId);
+ if (parents == null || parents.isEmpty()) {
+ break;
+ }
+ if (parents.size() > 1) {
+ throw new AssertionError(currentId + " has " + parents.size()
+ + " parents");
+ }
+ currentId = parents.iterator().next();
+ data = repository.datas.get(currentId);
+ result.add(new SimpleObjectEntry(data, this));
+ } while (returnToRoot);
+ return result;
}
public Collection<ObjectEntry> getObjectParents(ObjectId object,
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleFolder.java Wed Jul 15 20:09:04 2009
@@ -26,6 +26,7 @@
import org.apache.chemistry.Document;
import org.apache.chemistry.Folder;
import org.apache.chemistry.ObjectId;
+import org.apache.chemistry.Property;
import org.apache.chemistry.Unfiling;
public class SimpleFolder extends SimpleObject implements Folder {
@@ -54,11 +55,16 @@
}
public List<CMISObject> getChildren(BaseType type) {
- // TODO type
- Set<String> ids = entry.connection.repository.children.get(getId());
+ SimpleRepository repository = entry.connection.repository;
+ Set<String> ids = repository.children.get(getId());
List<CMISObject> children = new ArrayList<CMISObject>(ids.size());
for (String id : ids) {
- SimpleData d = entry.connection.repository.datas.get(id);
+ SimpleData d = repository.datas.get(id);
+ if (type != null
+ && !repository.getType((String) d.get(Property.TYPE_ID)).getBaseType().equals(
+ type)) {
+ continue;
+ }
children.add(SimpleObject.construct(new SimpleObjectEntry(d,
entry.connection)));
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObject.java Wed Jul 15 20:09:04 2009
@@ -144,4 +144,10 @@
}
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + '(' + getTypeId() + ',' + getId()
+ + ')';
+ }
+
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleObjectEntry.java Wed Jul 15 20:09:04 2009
@@ -81,4 +81,10 @@
throw new UnsupportedOperationException();
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + '(' + getTypeId() + ',' + getId()
+ + ')';
+ }
+
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java Wed Jul 15 20:09:04 2009
@@ -13,6 +13,7 @@
*
* Authors:
* Florent Guillaume, Nuxeo
+ * Ugo Cei, Sourcesense
*/
package org.apache.chemistry.test;
@@ -22,15 +23,22 @@
import junit.framework.TestCase;
+import org.apache.chemistry.BaseType;
import org.apache.chemistry.CMISObject;
import org.apache.chemistry.Connection;
+import org.apache.chemistry.Document;
import org.apache.chemistry.Folder;
+import org.apache.chemistry.ObjectEntry;
+import org.apache.chemistry.ObjectId;
import org.apache.chemistry.Property;
import org.apache.chemistry.Repository;
+import org.apache.chemistry.SPI;
import org.apache.chemistry.Type;
/**
* Basic test on a repository created with {@link BasicHelper#makeRepository}.
+ * <p>
+ * The {@link #setUp} method must initialize repository, conn and spi.
*/
public abstract class BasicTestCase extends TestCase {
@@ -38,11 +46,19 @@
public Repository repository;
+ public Connection conn;
+
+ public SPI spi;
+
+ @Override
+ public void tearDown() throws Exception {
+ conn.close();
+ super.tearDown();
+ }
+
public void testBasic() {
assertNotNull(repository);
- Connection conn = repository.getConnection(null);
assertNotNull(conn);
-
Folder root = conn.getRootFolder();
assertNotNull(root);
Type rootType = root.getType();
@@ -68,4 +84,62 @@
assertEquals(2, res.size());
}
+ public void testGetChildren() {
+ boolean[] hasMoreItems = new boolean[1];
+ Folder root = conn.getRootFolder();
+ assertEquals(1, spi.getChildren(root, BaseType.FOLDER, null, true,
+ false, 20, 0, null, hasMoreItems).size());
+ assertFalse(hasMoreItems[0]);
+ ObjectId folder1 = root.getChildren(null).get(0);
+ assertEquals(2, spi.getChildren(folder1, null, null, false, false, 20,
+ 0, null, hasMoreItems).size());
+ assertFalse(hasMoreItems[0]);
+ assertEquals(1, spi.getChildren(folder1, null, null, false, false, 1,
+ 0, null, hasMoreItems).size());
+ assertTrue(hasMoreItems[0]);
+ assertEquals(1, spi.getChildren(folder1, null, null, false, false, 1,
+ 1, null, hasMoreItems).size());
+ assertFalse(hasMoreItems[0]);
+ List<ObjectEntry> temp = spi.getChildren(folder1, null, null, false,
+ false, 2, 0, null, hasMoreItems);
+ ObjectId folder2 = temp.get(0).getTypeId().equals("fold") ? temp.get(0)
+ : temp.get(1);
+ assertEquals(1, spi.getChildren(folder2, null, null, false, false, 1,
+ 1, null, hasMoreItems).size());
+ assertTrue(hasMoreItems[0]);
+ assertEquals(2, spi.getChildren(folder2, null, null, false, false, 2,
+ 0, null, hasMoreItems).size());
+ assertTrue(hasMoreItems[0]);
+ }
+
+ public void testGetDescendants() {
+ Folder root = conn.getRootFolder();
+ assertEquals(6, spi.getDescendants(root, null, 4, null, false, false,
+ null).size());
+ List<ObjectEntry> desc = spi.getDescendants(root, BaseType.FOLDER, 4,
+ null, false, false, null);
+ assertEquals(2, desc.size());
+ }
+
+ public void testGetFolderParent() {
+ Folder root = conn.getRootFolder();
+ assertEquals(0,
+ spi.getFolderParent(root, null, false, false, false).size());
+ ObjectId folder1 = root.getChildren(null).get(0);
+ assertEquals(1,
+ spi.getFolderParent(folder1, null, false, false, true).size());
+ assertEquals(root.getId(), spi.getFolderParent(folder1, null, false,
+ false, false).get(0).getId());
+ }
+
+ public void testGetObjectParents() {
+ Folder root = conn.getRootFolder();
+ ObjectId folder1Id = root.getChildren(null).get(0);
+ Folder folder1 = (Folder) conn.getObject(folder1Id, null);
+ Document doc = (Document) folder1.getChildren(BaseType.DOCUMENT).get(0);
+ Collection<ObjectEntry> parents = spi.getObjectParents(doc, null,
+ false, false);
+ assertEquals(1, parents.size());
+ }
+
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestAtomPubClientServer.java Wed Jul 15 20:09:04 2009
@@ -76,10 +76,13 @@
String serverUrl = startServer();
ContentManager cm = new APPContentManager(serverUrl);
repository = cm.getDefaultRepository();
+ conn = repository.getConnection(null);
+ spi = conn.getSPI();
}
@Override
public void tearDown() throws Exception {
+ super.tearDown();
stopServer();
}
Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestSimpleDirect.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestSimpleDirect.java?rev=794388&r1=794387&r2=794388&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestSimpleDirect.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/test/java/org/apache/chemistry/test/TestSimpleDirect.java Wed Jul 15 20:09:04 2009
@@ -24,6 +24,8 @@
@Override
public void setUp() throws Exception {
repository = BasicHelper.makeRepository(null);
+ conn = repository.getConnection(null);
+ spi = conn.getSPI();
}
}