You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2010/03/01 15:58:05 UTC
svn commit: r917554 - in /incubator/chemistry/trunk/opencmis/opencmis-client:
opencmis-client-api/src/main/java/org/apache/opencmis/client/api/
opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/
opencmis-client-impl/src/main/java/or...
Author: fmui
Date: Mon Mar 1 14:58:05 2010
New Revision: 917554
URL: http://svn.apache.org/viewvc?rev=917554&view=rev
Log:
- implemented PagingList and Container
Added:
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java (with props)
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/ContainerImpl.java (with props)
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java (with props)
Modified:
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/Container.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/PagingList.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/objecttype/AbstractObjectType.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyDiscoverTest.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyNavigationTest.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyTypeTest.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/mock/MockSessionFactory.java
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Session.java Mon Mar 1 14:58:05 2010
@@ -89,10 +89,10 @@
ObjectType getTypeDefinition(String typeId);
- PagingList<ObjectType> getTypeChildren(ObjectType t, boolean includePropertyDefinitions,
+ PagingList<ObjectType> getTypeChildren(String typeId, boolean includePropertyDefinitions,
int itemsPerPage);
- List<Container<ObjectType>> getTypeDescendants(ObjectType t, int depth, boolean includePropertyDefinitions);
+ List<Container<ObjectType>> getTypeDescendants(String typeId, int depth, boolean includePropertyDefinitions);
// navigation
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/Container.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/Container.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/Container.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/Container.java Mon Mar 1 14:58:05 2010
@@ -33,5 +33,5 @@
/**
* Returns the children.
*/
- List<T> getChildren();
+ List<Container<T>> getChildren();
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/PagingList.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/PagingList.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/PagingList.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/util/PagingList.java Mon Mar 1 14:58:05 2010
@@ -23,7 +23,7 @@
/**
* Basically this is a nested list of lists where the outer list represent pages and the inner list
* is the result set with items of type T. <code>PagingList</code> implementations can support lazy
- * load of result sets.
+ * load of result sets. The first page has the page number 0.
*
* @param <T>
*/
@@ -40,10 +40,10 @@
int getNumItems();
/**
- * This is the maximum number of items to return in one page. The repository MUST NOT exceed
- * this maximum. Default is repository-specific.
+ * This is the maximum number of items to return in one page. The repository MUST NOT exceed this
+ * maximum.
*/
- void setMaxItems();
+ int getMaxItemsPerPage();
/**
* This is the maximum number of pages calculated from number of <code>totalItems</code> and
@@ -62,10 +62,4 @@
* @return a page of items
*/
List<T> get(int pageNumber);
-
- /**
- * Returns true if the server does not return any items.
- * @return true for empty list
- */
- boolean isEmpty();
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentSessionImpl.java Mon Mar 1 14:58:05 2010
@@ -19,6 +19,7 @@
package org.apache.opencmis.client.runtime;
import java.io.Serializable;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -34,6 +35,7 @@
import org.apache.opencmis.client.api.Folder;
import org.apache.opencmis.client.api.PersistentSession;
import org.apache.opencmis.client.api.Property;
+import org.apache.opencmis.client.api.Session;
import org.apache.opencmis.client.api.SessionContext;
import org.apache.opencmis.client.api.objecttype.ObjectType;
import org.apache.opencmis.client.api.repository.ObjectFactory;
@@ -47,10 +49,14 @@
import org.apache.opencmis.client.runtime.cache.CacheImpl;
import org.apache.opencmis.client.runtime.repository.PersistentObjectFactoryImpl;
import org.apache.opencmis.client.runtime.repository.PersistentPropertyFactoryImpl;
+import org.apache.opencmis.client.runtime.util.AbstractPagingList;
+import org.apache.opencmis.client.runtime.util.ContainerImpl;
import org.apache.opencmis.commons.PropertyIds;
import org.apache.opencmis.commons.SessionParameter;
import org.apache.opencmis.commons.api.ExtensionsData;
import org.apache.opencmis.commons.api.TypeDefinition;
+import org.apache.opencmis.commons.api.TypeDefinitionContainer;
+import org.apache.opencmis.commons.api.TypeDefinitionList;
import org.apache.opencmis.commons.enums.BindingType;
import org.apache.opencmis.commons.enums.Cardinality;
import org.apache.opencmis.commons.enums.CmisProperties;
@@ -63,6 +69,7 @@
import org.apache.opencmis.commons.provider.ObjectData;
import org.apache.opencmis.commons.provider.PropertyData;
import org.apache.opencmis.commons.provider.PropertyIdData;
+import org.apache.opencmis.commons.provider.RepositoryService;
import org.apache.opencmis.util.repository.ObjectGenerator;
public class PersistentSessionImpl implements PersistentSession, Testable, Serializable {
@@ -314,20 +321,97 @@
return rootFolder;
}
- public PagingList<ObjectType> getTypeChildren(ObjectType t, boolean includePropertyDefinitions,
- int itemsPerPage) {
- throw new CmisRuntimeException("not implemented");
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.Session#getTypeChildren(java.lang.String, boolean, int)
+ */
+ public PagingList<ObjectType> getTypeChildren(final String typeId,
+ final boolean includePropertyDefinitions, final int itemsPerPage) {
+ if (itemsPerPage < 1) {
+ throw new IllegalArgumentException("itemsPerPage must be > 0!");
+ }
+
+ final Session thisSession = this;
+ final String repositoryId = getRepositoryId();
+ final RepositoryService repositoryService = getProvider().getRepositoryService();
+
+ return new AbstractPagingList<ObjectType>() {
+
+ @Override
+ protected List<ObjectType> fetchPage(int pageNumber) {
+ int skipCount = pageNumber * getMaxItemsPerPage();
+
+ // fetch the data
+ TypeDefinitionList tdl = repositoryService.getTypeChildren(repositoryId, typeId,
+ includePropertyDefinitions, BigInteger.valueOf(getMaxItemsPerPage()), BigInteger
+ .valueOf(skipCount), null);
+
+ // set num items
+ if (tdl.getNumItems() != null) {
+ setNumItems(tdl.getNumItems().intValue());
+ }
+ else {
+ setNumItems(-1);
+ }
+
+ // convert type definitions
+ List<ObjectType> result = new ArrayList<ObjectType>(tdl.getList().size());
+ for (TypeDefinition typeDefinition : tdl.getList()) {
+ result.add(SessionUtil.convertTypeDefinition(thisSession, typeDefinition));
+ }
+
+ return result;
+ }
+
+ @Override
+ public int getMaxItemsPerPage() {
+ return itemsPerPage;
+ }
+ };
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.Session#getTypeDefinition(java.lang.String)
+ */
public ObjectType getTypeDefinition(String typeId) {
TypeDefinition typeDefinition = getProvider().getRepositoryService().getTypeDefinition(
getRepositoryId(), typeId, null);
return SessionUtil.convertTypeDefinition(this, typeDefinition);
}
- public List<Container<ObjectType>> getTypeDescendants(ObjectType t, int depth,
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.Session#getTypeDescendants(java.lang.String, int, boolean)
+ */
+ public List<Container<ObjectType>> getTypeDescendants(String typeId, int depth,
boolean includePropertyDefinitions) {
- throw new CmisRuntimeException("not implemented");
+ List<TypeDefinitionContainer> descendants = getProvider().getRepositoryService()
+ .getTypeDescendants(getRepositoryId(), typeId, BigInteger.valueOf(depth),
+ includePropertyDefinitions, null);
+
+ return convertTypeDescendants(descendants);
+ }
+
+ /**
+ * Converts provider <code>TypeDefinitionContainer</code> to API <code>Container</code>.
+ */
+ private List<Container<ObjectType>> convertTypeDescendants(
+ List<TypeDefinitionContainer> descendantsList) {
+ List<Container<ObjectType>> result = new ArrayList<Container<ObjectType>>();
+
+ for (TypeDefinitionContainer container : descendantsList) {
+ ObjectType objectType = SessionUtil
+ .convertTypeDefinition(this, container.getTypeDefinition());
+ List<Container<ObjectType>> children = convertTypeDescendants(container.getChildren());
+
+ result.add(new ContainerImpl<ObjectType>(objectType, children));
+ }
+
+ return result;
}
public PagingList<CmisObject> query(String statement, boolean searchAllVersions, int itemsPerPage) {
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/objecttype/AbstractObjectType.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/objecttype/AbstractObjectType.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/objecttype/AbstractObjectType.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/objecttype/AbstractObjectType.java Mon Mar 1 14:58:05 2010
@@ -249,7 +249,7 @@
* @see org.apache.opencmis.client.api.objecttype.ObjectType#getChildren(int)
*/
public PagingList<ObjectType> getChildren(int itemsPerPage) {
- return getSession().getTypeChildren(this, true, itemsPerPage);
+ return getSession().getTypeChildren(getId(), true, itemsPerPage);
}
/*
@@ -258,6 +258,6 @@
* @see org.apache.opencmis.client.api.objecttype.ObjectType#getDescendants(int)
*/
public List<Container<ObjectType>> getDescendants(int depth) {
- return getSession().getTypeDescendants(this, depth, true);
+ return getSession().getTypeDescendants(getId(), depth, true);
}
}
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java?rev=917554&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java Mon Mar 1 14:58:05 2010
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.client.runtime.util;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.opencmis.client.api.util.PagingList;
+
+/**
+ * Base <code>PagingList</code> implementation.
+ */
+public abstract class AbstractPagingList<T> implements PagingList<T> {
+
+ // number of item is unknown before the fist fetch
+ private int numItems = -1;
+
+ // cache is disabled by default
+ private int cacheSize = 0;
+ private LinkedHashMap<Integer, List<T>> cache = null;
+
+ /**
+ * Initializes the cache.
+ *
+ * @param cacheSize
+ * size of the cache in pages. cacheSize < 1 disables the cache.
+ */
+ protected void initializeCache(final int cacheSize) {
+ this.cacheSize = cacheSize;
+
+ if (cacheSize > 0) {
+ cache = new LinkedHashMap<Integer, List<T>>(cacheSize + 1, 0.70f, true) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean removeEldestEntry(Map.Entry<Integer, List<T>> eldest) {
+ return size() > cacheSize;
+ }
+ };
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.util.PagingList#get(int)
+ */
+ public List<T> get(int pageNumber) {
+ if (pageNumber < 0) {
+ throw new IllegalArgumentException("pageNumber must be >= 0!");
+ }
+
+ List<T> result = null;
+
+ if (cacheSize > 0) {
+ result = cache.get(pageNumber);
+ if (result == null) {
+ result = fetchPage(pageNumber);
+ cache.put(pageNumber, result);
+ }
+ }
+ else {
+ result = fetchPage(pageNumber);
+ }
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.util.PagingList#getNumItems()
+ */
+ public int getNumItems() {
+ return numItems;
+ }
+
+ /**
+ * Sets the number of items. Should be updated by {@link #fetchPage(int)}.
+ */
+ protected void setNumItems(int numItems) {
+ this.numItems = numItems;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.util.PagingList#size()
+ */
+ public int size() {
+ if (getNumItems() < 1) {
+ return -1;
+ }
+
+ if (getMaxItemsPerPage() < 1) {
+ return -1;
+ }
+
+ return (int) Math.ceil(((double) getNumItems() / (double) getMaxItemsPerPage()));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<List<T>> iterator() {
+ return new PageIterator();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.util.PagingList#getMaxItemsPerPage()
+ */
+ public abstract int getMaxItemsPerPage();
+
+ /**
+ * Fetches the given page from the server.
+ *
+ * @param pageNumber
+ * number of the page (>= 0).
+ */
+ protected abstract List<T> fetchPage(int pageNumber);
+
+ // --- iterator class ---
+
+ /**
+ * Page iterator.
+ */
+ class PageIterator implements Iterator<List<T>> {
+
+ private int currentPage = -1;
+ private boolean lastPageEmpty = false;
+
+ public boolean hasNext() {
+ if (lastPageEmpty) {
+ // the last page was empty, so we don't expect the next page will have items
+ return false;
+ }
+
+ int size = size();
+ if (size < 0) {
+ // we don't know better
+ return true;
+ }
+
+ return currentPage < size - 1;
+ }
+
+ public List<T> next() {
+ currentPage++;
+ List<T> next = get(currentPage);
+
+ if ((next == null) || (next.isEmpty())) {
+ lastPageEmpty = true;
+ }
+
+ return next;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/AbstractPagingList.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/ContainerImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/ContainerImpl.java?rev=917554&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/ContainerImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/ContainerImpl.java Mon Mar 1 14:58:05 2010
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.client.runtime.util;
+
+import java.util.List;
+
+import org.apache.opencmis.client.api.util.Container;
+
+public class ContainerImpl<T> implements Container<T> {
+
+ private T item;
+ private List<Container<T>> children;
+
+ public ContainerImpl(T item, List<Container<T>> children) {
+ if (item == null) {
+ throw new IllegalArgumentException("Item must be set!");
+ }
+
+ this.item = item;
+ this.children = children;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.util.Container#getItem()
+ */
+ public T getItem() {
+ return item;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.opencmis.client.api.util.Container#getChildren()
+ */
+ public List<Container<T>> getChildren() {
+ return this.children;
+ }
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/util/ContainerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyDiscoverTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyDiscoverTest.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyDiscoverTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyDiscoverTest.java Mon Mar 1 14:58:05 2010
@@ -48,7 +48,7 @@
default:
PagingList<CmisObject> resultSet = this.session.query(Fixture.QUERY, false, -1);
Assert.assertNotNull(resultSet);
- Assert.assertFalse(resultSet.isEmpty());
+ //Assert.assertFalse(resultSet.isEmpty());
for (List<CmisObject> lo : resultSet) {
for (CmisObject o : lo) {
Assert.assertNotNull(o);
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyNavigationTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyNavigationTest.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyNavigationTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyNavigationTest.java Mon Mar 1 14:58:05 2010
@@ -41,7 +41,7 @@
PagingList<CmisObject> pl = folder.getChildren(null, -1);
Assert.assertNotNull(pl);
- Assert.assertFalse(pl.isEmpty());
+ //Assert.assertFalse(pl.isEmpty());
for (List<CmisObject> cl : pl) {
for (CmisObject o : cl) {
@@ -90,7 +90,7 @@
PagingList<CmisObject> pl = folder.getChildren(null, -1);
Assert.assertNotNull(pl);
- Assert.assertFalse(pl.isEmpty());
+ //Assert.assertFalse(pl.isEmpty());
List<CmisObject> firstPage = pl.get(0);
Assert.assertNotNull(firstPage);
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyTypeTest.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyTypeTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyTypeTest.java Mon Mar 1 14:58:05 2010
@@ -74,7 +74,7 @@
public void readTypeChildrenDocument() {
ObjectType otd = this.session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID);
Assert.assertNotNull(otd);
- PagingList<ObjectType> pc = this.session.getTypeChildren(otd, true, -1);
+ PagingList<ObjectType> pc = this.session.getTypeChildren(otd.getId(), true, -1);
Assert.assertNotNull(pc);
for (List<ObjectType> children : pc) {
@@ -89,7 +89,7 @@
public void readTypeChildrenFolder() {
ObjectType otd = this.session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID);
Assert.assertNotNull(otd);
- PagingList<ObjectType> pc = this.session.getTypeChildren(otd, true, -1);
+ PagingList<ObjectType> pc = this.session.getTypeChildren(otd.getId(), true, -1);
Assert.assertNotNull(pc);
for (List<ObjectType> children : pc) {
@@ -104,7 +104,7 @@
public void readTypeDescandantsDocument() {
ObjectType otd = this.session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID);
Assert.assertNotNull(otd);
- List<Container<ObjectType>> desc = this.session.getTypeDescendants(otd, 1, true);
+ List<Container<ObjectType>> desc = this.session.getTypeDescendants(otd.getId(), 1, true);
Assert.assertNotNull(desc);
Assert.assertFalse(desc.isEmpty());
}
@@ -113,7 +113,7 @@
public void readTypeDescandantsFolder() {
ObjectType otd = this.session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID);
Assert.assertNotNull(otd);
- List<Container<ObjectType>> desc = this.session.getTypeDescendants(otd, 1, true);
+ List<Container<ObjectType>> desc = this.session.getTypeDescendants(otd.getId(), 1, true);
Assert.assertNotNull(desc);
Assert.assertFalse(desc.isEmpty());
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/mock/MockSessionFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/mock/MockSessionFactory.java?rev=917554&r1=917553&r2=917554&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/mock/MockSessionFactory.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/mock/MockSessionFactory.java Mon Mar 1 14:58:05 2010
@@ -161,13 +161,10 @@
PagingList<ObjectType> plot = this.createMockPaging(dtl);
Container<ObjectType> ctdoc = this.createMockContainer(this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID), null);
expect(
- session
- .getTypeChildren(this.idTypeIndex
- .get(BaseObjectTypeIds.CMIS_DOCUMENT.value()),
- true, -1)).andReturn(plot).anyTimes();
+ session.getTypeChildren(BaseObjectTypeIds.CMIS_DOCUMENT.value(), true, -1))
+ .andReturn(plot).anyTimes();
expect(
- session.getTypeDescendants(this.idTypeIndex
- .get(BaseObjectTypeIds.CMIS_DOCUMENT.value()), 1, true))
+ session.getTypeDescendants(BaseObjectTypeIds.CMIS_DOCUMENT.value(), 1, true))
.andReturn(Collections.singletonList(ctdoc)).anyTimes();
/* folder child/descendants types */
@@ -176,12 +173,10 @@
PagingList<ObjectType> plfot = this.createMockPaging(ftl);
Container<ObjectType> ctfolder = this.createMockContainer(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID), null);
expect(
- session.getTypeChildren(this.idTypeIndex
- .get(BaseObjectTypeIds.CMIS_FOLDER.value()), true, -1))
- .andReturn(plfot).anyTimes();
+ session.getTypeChildren(BaseObjectTypeIds.CMIS_FOLDER.value(), true, -1))
+ .andReturn(plfot).anyTimes();
expect(
- session.getTypeDescendants(this.idTypeIndex
- .get(BaseObjectTypeIds.CMIS_FOLDER.value()), 1, true))
+ session.getTypeDescendants(BaseObjectTypeIds.CMIS_FOLDER.value(), 1, true))
.andReturn(Collections.singletonList(ctfolder)).anyTimes();
/* change support */
@@ -568,7 +563,7 @@
Iterator<List<T>> i = a.iterator();
expect(pl.get(0)).andReturn(items).anyTimes();
- expect(pl.isEmpty()).andReturn(false).anyTimes();
+ //expect(pl.isEmpty()).andReturn(false).anyTimes();
expect(pl.iterator()).andReturn(i).anyTimes();
replay(pl);
@@ -577,7 +572,7 @@
}
@SuppressWarnings("unchecked")
- private <T> Container<T> createMockContainer(T item, List<T> children) {
+ private <T> Container<T> createMockContainer(T item, List<Container<T>> children) {
Container<T> c = createNiceMock(Container.class);
expect(c.getItem()).andReturn(item).anyTimes();
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java?rev=917554&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java Mon Mar 1 14:58:05 2010
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.client.runtime.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import org.apache.opencmis.client.api.util.PagingList;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PagingListTest {
+
+ private static final int ITEMS = 201;
+ private static final int MAX_ITEMS_PER_PAGE = 20;
+
+ private static final String PREFIX_1 = "1$";
+ private static final String PREFIX_2 = "2$";
+
+ private String[] sourceData;
+ private PagingList<String> testList;
+ private PagingList<String> testCacheList;
+
+ @Before
+ public void setUp() throws Exception {
+ sourceData = new String[ITEMS];
+ for (int i = 0; i < sourceData.length; i++) {
+ sourceData[i] = PREFIX_1 + i;
+ }
+
+ testList = new TestPagingList(0);
+ testCacheList = new TestPagingList(2);
+ }
+
+ @Test
+ public void testPagingList() {
+ // test setup
+ assertNotNull(testList);
+
+ // test number of items per pages
+ assertEquals(MAX_ITEMS_PER_PAGE, testList.getMaxItemsPerPage());
+
+ // we haven't fetched data yet -> number of item should be unknown
+ assertEquals(-1, testList.getNumItems());
+
+ // fetch first page and check it
+ List<String> page = testList.get(0);
+ assertPage(page, 0, MAX_ITEMS_PER_PAGE, PREFIX_1);
+
+ // number of item should be known now
+ assertEquals(sourceData.length, testList.getNumItems());
+
+ // number of pages should be known too
+ assertEquals(11, testList.size());
+
+ // check all pages
+ for (int i = 0; i < testList.size(); i++) {
+ page = testList.get(i);
+
+ int pageSize = (i == testList.size() - 1 ? ITEMS % MAX_ITEMS_PER_PAGE : MAX_ITEMS_PER_PAGE);
+ assertPage(page, i, pageSize, PREFIX_1);
+ }
+ }
+
+ @Test
+ public void testPagingListIterator() {
+ // test setup
+ assertNotNull(testList);
+
+ // test iterator
+ int pageNumber = 0;
+ for (List<String> page : testList) {
+ assertTrue(pageNumber < testList.size());
+
+ int pageSize = (pageNumber == testList.size() - 1 ? ITEMS % MAX_ITEMS_PER_PAGE
+ : MAX_ITEMS_PER_PAGE);
+
+ assertPage(page, pageNumber, pageSize, PREFIX_1);
+
+ pageNumber++;
+ }
+ }
+
+ @Test
+ public void testPagingListExceptions() {
+ // test setup
+ assertNotNull(testList);
+
+ // check negative page numbers
+ try {
+ testList.get(-1);
+ fail("Should throw a IllegalArgumentException!");
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ // check page numbers greater than the last page
+ try {
+ testList.get(12);
+ fail("Should throw a NoSuchElementException!");
+ }
+ catch (NoSuchElementException e) {
+ }
+ }
+
+ @Test
+ public void testPagingCache() {
+ // test setup
+ assertNotNull(testList);
+
+ // read first page, should be cached now
+ List<String> firstPage = testCacheList.get(0);
+ assertPage(firstPage, 0, MAX_ITEMS_PER_PAGE, PREFIX_1);
+
+ // change original data
+ for (int i = 0; i < sourceData.length; i++) {
+ sourceData[i] = PREFIX_2 + i;
+ }
+
+ // get second page with new content
+ List<String> secondPage = testCacheList.get(1);
+ assertPage(secondPage, 1, MAX_ITEMS_PER_PAGE, PREFIX_2);
+
+ // fetch first page again, should have the old values since it is cached
+ firstPage = testCacheList.get(0);
+ assertPage(firstPage, 0, MAX_ITEMS_PER_PAGE, PREFIX_1);
+
+ // read a few more pages
+ testCacheList.get(2);
+ testCacheList.get(3);
+
+ // fetch first page again, should have the new values since it is not cached anymore
+ firstPage = testCacheList.get(0);
+ assertPage(firstPage, 0, MAX_ITEMS_PER_PAGE, PREFIX_2);
+ }
+
+ void assertPage(List<String> page, int pageNumber, int size, String prefix) {
+ assertNotNull(page);
+
+ // the first page should be full
+ assertEquals(size, page.size());
+
+ // check page content
+ int counter = 0;
+ for (String s : page) {
+ assertEquals(prefix + ((pageNumber * MAX_ITEMS_PER_PAGE) + counter), s);
+ counter++;
+ }
+ }
+
+ // --- Test PagingList ---
+
+ class TestPagingList extends AbstractPagingList<String> {
+
+ public TestPagingList(int cacheSize) {
+ initializeCache(cacheSize);
+ }
+
+ @Override
+ protected List<String> fetchPage(int pageNumber) {
+ int skipCount = pageNumber * getMaxItemsPerPage();
+ int lastIndex = skipCount + getMaxItemsPerPage() - 1;
+ if (lastIndex >= sourceData.length) {
+ lastIndex = sourceData.length - 1;
+ }
+
+ setNumItems(sourceData.length);
+
+ if (skipCount >= sourceData.length) {
+ throw new NoSuchElementException();
+ }
+
+ List<String> result = new ArrayList<String>();
+ for (int i = skipCount; i <= lastIndex; i++) {
+ result.add(sourceData[i]);
+ }
+
+ return result;
+ }
+
+ @Override
+ public int getMaxItemsPerPage() {
+ return MAX_ITEMS_PER_PAGE;
+ }
+ }
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/util/PagingListTest.java
------------------------------------------------------------------------------
svn:eol-style = native