You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by sk...@apache.org on 2010/02/24 17:19:48 UTC
svn commit: r915851 - in /incubator/chemistry/trunk/opencmis:
opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/
opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/
opencmis-client...
Author: sklevenz
Date: Wed Feb 24 16:19:48 2010
New Revision: 915851
URL: http://svn.apache.org/viewvc?rev=915851&view=rev
Log:
client runtime implementation
- path extension in client api
- continuous runtime implementation
https://issues.apache.org/jira/browse/CMIS-124
Added:
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java (with props)
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java (with props)
Modified:
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Document.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Policy.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/pom.xml
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.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/cache/CacheImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PropertyFactoryImpl.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyObjectTest.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlySessionTest.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/mock/MockSessionFactory.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/suite/otx/OtxInMemoryCmisTestSuite.java
incubator/chemistry/trunk/opencmis/src/site/site.xml
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/CmisObject.java Wed Feb 24 16:19:48 2010
@@ -124,10 +124,6 @@
<T> List<T> getPropertyMultivalue(String id);
- String getPathSegment();
-
- String getPath();
-
AllowableActions getAllowableActions();
List<Relationship> getRelationships();
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Document.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Document.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Document.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Document.java Wed Feb 24 16:19:48 2010
@@ -27,7 +27,9 @@
*/
public interface Document extends CmisObject {
- List<Rendition> getRenditions();
+ List<String> getPaths();
+
+ List<Rendition> getRenditions();
// object service
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Folder.java Wed Feb 24 16:19:48 2010
@@ -31,7 +31,9 @@
*/
public interface Folder extends CmisObject {
- // object service
+ String getPath();
+
+ // object service
Document createDocument(String name);
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Policy.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Policy.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Policy.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/Policy.java Wed Feb 24 16:19:48 2010
@@ -18,11 +18,14 @@
*/
package org.apache.opencmis.client.api;
+
/**
* Domain Model 2.7
*/
public interface Policy extends CmisObject {
+ String getPath();
+
public String getPolicyText(); // cmis:policyText
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ObjectFactory.java Wed Feb 24 16:19:48 2010
@@ -39,31 +39,36 @@
*/
public interface ObjectFactory {
- // object factory
+ // object factory
- Ace createAce(String principal, List<AclPermission> permissions);
+ Ace createAce(String principal, List<AclPermission> permissions);
- Acl createAcl(List<Ace> aces);
+ Acl createAcl(List<Ace> aces);
- ContentStream createContentStream(int length, String mimetype, String filename, InputStream stream);
+ ContentStream createContentStream(int length, String mimetype,
+ String filename, InputStream stream);
- // object service
+ // object service
- // shortcut
- Document createDocument(Folder parentfolder, String name);
+ // shortcut
+ Document createDocument(Folder parentfolder, String name);
- Document createDocument(List<Property<?>> properties, Folder parentfolder,
- ContentStream contentstream, VersioningState versioningState, List<Policy> policies,
- List<Ace> addACEs, List<Ace> removeACEs);
+ Document createDocument(List<Property<?>> properties, Folder parentfolder,
+ ContentStream contentstream, VersioningState versioningState,
+ List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs);
- Document createDocumentFromSource(Document source, List<Property<?>> properties,
- Folder parentfolder, VersioningState versioningState, List<Policy> policies,
- List<Ace> addACEs, List<Ace> removeACEs);
+ Document createDocumentFromSource(Document source,
+ List<Property<?>> properties, Folder parentfolder,
+ VersioningState versioningState, List<Policy> policies,
+ List<Ace> addACEs, List<Ace> removeACEs);
- Relationship createRelationship(List<Property<?>> properties, List<Policy> policies,
- List<Ace> addACEs, List<Ace> removeACEs);
+ Relationship createRelationship(List<Property<?>> properties,
+ List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs);
- Policy createPolicy(List<Property<?>> properties, Folder parentfolder, List<Policy> policies,
- List<Ace> addACEs, List<Ace> removeACEs);
+ Policy createPolicy(List<Property<?>> properties, Folder parentfolder,
+ List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs);
+
+ Folder createFolder(Folder parent, List<Property<?>> properties,
+ List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs);
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/pom.xml?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/pom.xml (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/pom.xml Wed Feb 24 16:19:48 2010
@@ -46,7 +46,7 @@
<groupId>org.opencmis</groupId>
<artifactId>opencmis-provider-impl</artifactId>
<version>${version}</version>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentFolderImpl.java Wed Feb 24 16:19:48 2010
@@ -18,6 +18,7 @@
*/
package org.apache.opencmis.client.runtime;
+import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TreeMap;
@@ -34,13 +35,24 @@
import org.apache.opencmis.client.api.repository.AllowableActions;
import org.apache.opencmis.client.api.util.AceList;
import org.apache.opencmis.client.api.util.PagingList;
+import org.apache.opencmis.commons.PropertyIds;
import org.apache.opencmis.commons.enums.AclPropagation;
import org.apache.opencmis.commons.enums.BaseObjectTypeIds;
+import org.apache.opencmis.commons.enums.IncludeRelationships;
import org.apache.opencmis.commons.enums.RelationshipDirection;
import org.apache.opencmis.commons.enums.UnfileObjects;
import org.apache.opencmis.commons.enums.VersioningState;
import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.opencmis.commons.impl.dataobjects.AccessControlEntryImpl;
+import org.apache.opencmis.commons.impl.dataobjects.AccessControlListImpl;
+import org.apache.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertiesDataImpl;
+import org.apache.opencmis.commons.impl.dataobjects.PropertyBooleanDataImpl;
+import org.apache.opencmis.commons.provider.AccessControlEntry;
+import org.apache.opencmis.commons.provider.AccessControlList;
import org.apache.opencmis.commons.provider.ObjectData;
+import org.apache.opencmis.commons.provider.PropertiesData;
+import org.apache.opencmis.commons.provider.PropertyData;
public class PersistentFolderImpl implements Folder {
@@ -53,6 +65,10 @@
this.objectData = od;
}
+ public PersistentFolderImpl(PersistentSessionImpl session) {
+ this.session = session;
+ }
+
public Document createDocument(String name) {
throw new CmisRuntimeException("not implemented");
}
@@ -75,7 +91,10 @@
public Folder createFolder(List<Property<?>> properties,
List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs) {
- throw new CmisRuntimeException("not implemented");
+
+ Folder f = this.session.getObjectFactory().createFolder(this,
+ properties, policies, addACEs, removeACEs);
+ return f;
}
public Policy createPolicy(List<Property<?>> properties,
@@ -288,4 +307,114 @@
throw new CmisRuntimeException("not implemented");
}
+ /**
+ * Create folder in backend
+ *
+ * @param parent
+ * @param properties
+ * @param policies
+ * @param addACEs
+ * @param removeACEs
+ */
+ public void create(Folder parent, List<Property<?>> properties,
+ List<Policy> policies, List<Ace> addAce, List<Ace> removeAce) {
+
+ List<PropertyData<?>> propList = new ArrayList<PropertyData<?>>();
+ propList.add(this.session.getProvider().getObjectFactory().createPropertyStringData(PropertyIds.CMIS_NAME, "testfolder"));
+ propList.add(this.session.getProvider().getObjectFactory().createPropertyIdData(PropertyIds.CMIS_OBJECT_TYPE_ID,
+ "cmis_Folder"));
+
+ PropertiesData xxx = this.session.getProvider().getObjectFactory().createPropertiesData(propList);
+
+
+
+ String repositoryId = this.session.getRepositoryInfo().getId();
+ String parentFolderId = parent.getId();
+ PropertiesData pd = this.convertToPropertiesData(properties);
+ List<String> pol = this.convertToPoliciesData(policies);
+ AccessControlList addAcl = this.convertToAcl(addAce);
+ AccessControlList removeAcl = this.convertToAcl(removeAce);
+
+ String objectId = this.session.getProvider().getObjectService()
+ .createFolder(repositoryId, pd, parentFolderId, pol, addAcl,
+ removeAcl, null);
+ this.objectData = this.session.getProvider().getObjectService()
+ .getObject(repositoryId, objectId, null, false,
+ IncludeRelationships.NONE, null, true, true, null);
+
+ this.session.getCache().put(this);
+ }
+
+ private AccessControlList convertToAcl(List<Ace> aceList) {
+ AccessControlListImpl acli = null;
+ AccessControlEntryImpl acei;
+ List<AccessControlEntry> aceiList = null;
+ AccessControlPrincipalDataImpl acpdi = null;
+
+ if (aceList != null) {
+ acli = new AccessControlListImpl();
+ aceiList = new ArrayList<AccessControlEntry>();
+
+ for (Ace aceEntry : aceList) {
+ acei = new AccessControlEntryImpl();
+ acei.setPermissions(aceEntry.getPermissionsNames());
+ acpdi = new AccessControlPrincipalDataImpl(aceEntry
+ .getPrincipalId());
+ acei.setPrincipal(acpdi);
+
+ aceiList.add(acei);
+ }
+
+ acli.setAces(aceiList);
+ }
+ return acli;
+ }
+
+ private List<String> convertToPoliciesData(List<Policy> policies) {
+ List<String> pList = null;
+
+ if (policies != null) {
+ pList = new ArrayList<String>();
+ for (Policy pol : policies) {
+ pList.add(pol.getPolicyText());
+ }
+ }
+ return pList;
+ }
+
+ private PropertiesData convertToPropertiesData(List<Property<?>> properties) {
+ PropertiesDataImpl pdi = new PropertiesDataImpl();
+ PropertyData<?> pd = null;
+
+ for (Property<?> property : properties) {
+ switch (property.getType()) {
+ case BOOLEAN:
+// pd = new PropertyBooleanDataImpl(null, );
+// pd.
+ break;
+ case DATETIME:
+ break;
+ case DECIMAL:
+ break;
+ case HTML:
+ break;
+ case ID:
+ break;
+ case INTEGER:
+ break;
+ case STRING:
+ break;
+ case URI:
+ break;
+ default:
+ throw new CmisRuntimeException("unsupported property type"
+ + property.getType());
+ }
+
+ pdi.addProperty(pd);
+ }
+
+ return pdi;
+ }
+
}
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java?rev=915851&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java Wed Feb 24 16:19:48 2010
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.opencmis.client.api.Property;
+import org.apache.opencmis.commons.api.PropertyDefinition;
+import org.apache.opencmis.commons.enums.CmisProperties;
+import org.apache.opencmis.commons.enums.PropertyType;
+import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
+
+public class PersistentPropertyImpl<T> implements Property<T>, Serializable {
+
+ /**
+ * serialization
+ */
+ private static final long serialVersionUID = -6586532350183649719L;
+
+ public PersistentPropertyImpl(PersistentSessionImpl session,
+ CmisProperties cmisProperties, T value) {
+ }
+
+ public PersistentPropertyImpl(PersistentSessionImpl session,
+ PropertyType type, T value) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public PersistentPropertyImpl(PersistentSessionImpl session,
+ PropertyType type, List<T> value) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public PropertyDefinition<T> getDefinition() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public String getDisplayName() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public String getId() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public String getLocalName() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public String getQueryName() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public PropertyType getType() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public T getValue() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public String getValueAsString() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public List<T> getValues() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public boolean isMultiValued() {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=915851&r1=915850&r2=915851&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 Wed Feb 24 16:19:48 2010
@@ -44,6 +44,7 @@
import org.apache.opencmis.client.provider.factory.CmisProviderFactory;
import org.apache.opencmis.client.runtime.cache.Cache;
import org.apache.opencmis.client.runtime.cache.CacheImpl;
+import org.apache.opencmis.client.runtime.repository.PersistentObjectFactoryImpl;
import org.apache.opencmis.client.runtime.repository.PropertyFactoryImpl;
import org.apache.opencmis.commons.SessionParameter;
import org.apache.opencmis.commons.enums.BindingType;
@@ -90,7 +91,7 @@
/*
* helper factory (non serializable)
*/
- private transient PropertyFactory propertyFactory = new PropertyFactoryImpl();
+ private transient PropertyFactory propertyFactory = PropertyFactoryImpl.newInstance(this);
/*
* Object cache (serializable)
@@ -103,6 +104,11 @@
*/
private RepositoryInfo repositoryInfo;
+ /*
+ * helper factory (non serializable)
+ */
+ private transient ObjectFactory objectFactory = PersistentObjectFactoryImpl.newInstance(this);
+
/**
* required for serialization
*/
@@ -211,7 +217,7 @@
}
public ObjectFactory getObjectFactory() {
- throw new CmisRuntimeException("not implemented");
+ return this.objectFactory ;
}
public PropertyFactory getPropertyFactory() {
@@ -388,4 +394,12 @@
return provider;
}
+ public CmisProvider getProvider() {
+ return this.provider;
+ }
+
+ public Cache getCache() {
+ return this.cache;
+ }
+
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/cache/CacheImpl.java Wed Feb 24 16:19:48 2010
@@ -104,7 +104,6 @@
public void put(CmisObject object) {
this.idMap.put(object.getId(), object);
- this.pathMap.put(object.getPath(), object);
}
public int size() {
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java?rev=915851&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java Wed Feb 24 16:19:48 2010
@@ -0,0 +1,106 @@
+/*
+ * 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.repository;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.opencmis.client.api.Ace;
+import org.apache.opencmis.client.api.Acl;
+import org.apache.opencmis.client.api.AclPermission;
+import org.apache.opencmis.client.api.ContentStream;
+import org.apache.opencmis.client.api.Document;
+import org.apache.opencmis.client.api.Folder;
+import org.apache.opencmis.client.api.Policy;
+import org.apache.opencmis.client.api.Property;
+import org.apache.opencmis.client.api.Relationship;
+import org.apache.opencmis.client.api.repository.ObjectFactory;
+import org.apache.opencmis.client.runtime.PersistentFolderImpl;
+import org.apache.opencmis.client.runtime.PersistentSessionImpl;
+import org.apache.opencmis.commons.enums.VersioningState;
+import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.opencmis.commons.impl.dataobjects.ObjectDataImpl;
+
+public class PersistentObjectFactoryImpl implements ObjectFactory {
+
+ private PersistentSessionImpl session = null;
+
+ protected PersistentObjectFactoryImpl(PersistentSessionImpl session) {
+ this.session = session;
+ }
+
+ public static ObjectFactory newInstance(PersistentSessionImpl session) {
+ ObjectFactory f = new PersistentObjectFactoryImpl(session);
+ return f;
+ }
+
+ public Ace createAce(String principal, List<AclPermission> permissions) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public Acl createAcl(List<Ace> aces) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public ContentStream createContentStream(int length, String mimetype,
+ String filename, InputStream stream) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public Document createDocument(Folder parentfolder, String name) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public Document createDocument(List<Property<?>> properties,
+ Folder parentfolder, ContentStream contentstream,
+ VersioningState versioningState, List<Policy> policies,
+ List<Ace> addACEs, List<Ace> removeACEs) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public Document createDocumentFromSource(Document source,
+ List<Property<?>> properties, Folder parentfolder,
+ VersioningState versioningState, List<Policy> policies,
+ List<Ace> addACEs, List<Ace> removeACEs) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public Folder createFolder(Folder parent, List<Property<?>> properties,
+ List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs) {
+
+ PersistentFolderImpl f = new PersistentFolderImpl(this.session);
+
+ /* create folder in backend */
+ f.create(parent, properties, policies, addACEs, removeACEs);
+
+ return f;
+ }
+
+ public Policy createPolicy(List<Property<?>> properties,
+ Folder parentfolder, List<Policy> policies, List<Ace> addACEs,
+ List<Ace> removeACEs) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+ public Relationship createRelationship(List<Property<?>> properties,
+ List<Policy> policies, List<Ace> addACEs, List<Ace> removeACEs) {
+ throw new CmisRuntimeException("not implemented");
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PropertyFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PropertyFactoryImpl.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PropertyFactoryImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PropertyFactoryImpl.java Wed Feb 24 16:19:48 2010
@@ -22,23 +22,41 @@
import org.apache.opencmis.client.api.Property;
import org.apache.opencmis.client.api.repository.PropertyFactory;
+import org.apache.opencmis.client.runtime.PersistentPropertyImpl;
+import org.apache.opencmis.client.runtime.PersistentSessionImpl;
import org.apache.opencmis.commons.enums.CmisProperties;
import org.apache.opencmis.commons.enums.PropertyType;
-import org.apache.opencmis.commons.exceptions.CmisRuntimeException;
public class PropertyFactoryImpl implements PropertyFactory {
- public <T> Property<T> createCmisProperty(CmisProperties p, T value) {
- throw new CmisRuntimeException("not implemented");
+ private PersistentSessionImpl session = null;
+
+ protected PropertyFactoryImpl(PersistentSessionImpl session) {
+ this.session = session;
+ }
+
+ public static PropertyFactoryImpl newInstance(PersistentSessionImpl session) {
+ return new PropertyFactoryImpl(session);
+ }
+
+ public <T> Property<T> createCmisProperty(CmisProperties cmisProperties,
+ T value) {
+ Property<T> p = new PersistentPropertyImpl<T>(this.session,
+ cmisProperties, value);
+ return p;
}
public <T> Property<T> createProperty(String id, PropertyType type, T value) {
- throw new CmisRuntimeException("not implemented");
+ Property<T> p = new PersistentPropertyImpl<T>(this.session,
+ type, value);
+ return p;
}
public <T> Property<T> createPropertyMultivalue(String id,
PropertyType type, List<T> value) {
- throw new CmisRuntimeException("not implemented");
+ Property<T> p = new PersistentPropertyImpl<T>(this.session,
+ type, value);
+ return p;
}
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyObjectTest.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyObjectTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyObjectTest.java Wed Feb 24 16:19:48 2010
@@ -46,14 +46,12 @@
Assert.assertEquals("", root.getName());
Assert.assertNotNull(root.getId());
- Assert.assertEquals("/", root.getPath());
Assert.assertNull(root.getFolderParent());
Assert.assertNotNull(root.getType());
Assert.assertEquals(Fixture.FOLDER_TYPE_ID, root.getType().getId());
Assert.assertEquals("", root.getName());
Assert.assertNotNull(root.getId());
- Assert.assertEquals("/", root.getPath());
Assert.assertNull(root.getFolderParent());
Assert.assertNotNull(root.getType());
Assert.assertEquals(Fixture.FOLDER_TYPE_ID, root.getType().getId());
@@ -67,7 +65,6 @@
Assert.assertEquals(Fixture.TEST_ROOT_FOLDER_NAME, folder.getName());
Assert.assertNotNull(folder.getId());
- Assert.assertEquals("/" + Fixture.TEST_ROOT_FOLDER_NAME, folder.getPath());
Assert.assertNotNull(folder.getFolderParent());
Assert.assertNotNull(folder.getType());
Assert.assertEquals(Fixture.FOLDER_TYPE_ID, folder.getType().getId());
@@ -94,7 +91,6 @@
Assert.assertNotNull(document.getBaseType());
Assert.assertEquals(ObjectType.DOCUMENT_BASETYPE_ID, document.getBaseType().getId());
Assert.assertEquals(Fixture.DOCUMENT1_NAME, document.getName());
- Assert.assertEquals(path, document.getPath());
Assert.assertNotNull(document.getType());
Assert.assertEquals(Fixture.DOCUMENT_TYPE_ID, document.getType().getId());
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlySessionTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlySessionTest.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlySessionTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlySessionTest.java Wed Feb 24 16:19:48 2010
@@ -42,8 +42,6 @@
Assert.assertNotNull(root);
String id = root.getId();
Assert.assertNotNull(this.session.getObject(id));
- String path = root.getPath();
- Assert.assertNotNull(this.session.getObjectByPath(path));
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/misc/CacheTest.java Wed Feb 24 16:19:48 2010
@@ -47,34 +47,28 @@
Cache cache = CacheImpl.newInstance();
String id = "1";
- String path = "/1";
+ // String path = "/1";
// add object
- CmisObject obj1 = this.createCmisObject(id, path);
+ CmisObject obj1 = this.createCmisObject(id);
cache.put(obj1);
// access object
Assert.assertTrue(cache.containsId(id));
- Assert.assertTrue(cache.containsPath(path));
// access object
CmisObject obj2 = cache.get(id);
Assert.assertEquals(obj1, obj2);
- CmisObject obj3 = cache.getByPath(path);
- Assert.assertEquals(obj1, obj3);
// clear cache
cache.clear();
// access object (not found)
Assert.assertFalse(cache.containsId(id));
- Assert.assertFalse(cache.containsPath(path));
// access object (not found)
CmisObject obj4 = cache.get(id);
Assert.assertNull(obj4);
- CmisObject obj5 = cache.getByPath(path);
- Assert.assertNull(obj5);
}
@Test
@@ -90,7 +84,7 @@
Cache cache = CacheImpl.newInstance(cacheSize);
for (int i = 0; i < cacheSize + 1; i++) {
- CmisObject obj = this.createCmisObject("id" + i, "path" + i);
+ CmisObject obj = this.createCmisObject("id" + i);
cache.put(obj);
}
@@ -106,7 +100,7 @@
Cache cache = CacheImpl.newInstance(cacheSize);
for (int i = 0; i < cacheSize; i++) {
- CmisObject obj = this.createCmisObject("id" + i, "path" + i);
+ CmisObject obj = this.createCmisObject("id" + i);
cache.put(obj);
}
@@ -134,11 +128,10 @@
* @param path
* @return a mocked object
*/
- private CmisObject createCmisObject(String id, String path) {
+ private CmisObject createCmisObject(String id) {
CmisObject obj = createNiceMock(CmisObject.class);
expect(obj.getId()).andReturn(id).anyTimes();
- expect(obj.getPath()).andReturn(path).anyTimes();
replay(obj);
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=915851&r1=915850&r2=915851&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 Wed Feb 24 16:19:48 2010
@@ -75,563 +75,628 @@
*/
public class MockSessionFactory implements SessionFactory {
- private Session mockSession;
+ private Session mockSession;
- {
- this.idObjectIndex = new Hashtable<String, CmisObject>();
- this.idTypeIndex = new Hashtable<String, ObjectType>();
- this.mockSession = this.createMockSession();
- }
-
- private Hashtable<String, CmisObject> idObjectIndex = null;
- private Hashtable<String, ObjectType> idTypeIndex = null;
-
- @SuppressWarnings("unchecked")
- public <T extends Session> T createSession(Map<String, String> parameters) {
- T session = null;
- SessionType st;
- String p = parameters.get(SessionParameter.SESSION_TYPE);
-
- if (p == null) {
- st = SessionType.PERSISTENT; // default, if type is not set
- }
- else {
- st = SessionType.fromValue(p);
- }
-
- switch (st) {
- case PERSISTENT:
- session = (T) this.mockSession;
- break;
- case TRANSIENT:
- throw new CmisNotSupportedException("SessionType = " + st);
- }
-
- return session;
- }
-
- private Session createMockSession() {
- this.createMockGlobalTypes();
-
- Session session = createNiceMock(Session.class);
- Folder rootFolder = this.createMockRepositoryRootFolder();
- this.createMockTestRootFolder(rootFolder);
-
- expect(session.getRepositoryInfo()).andReturn(this.createMockRepositoryInfo()).anyTimes();
- expect(session.getRootFolder()).andReturn(rootFolder).anyTimes();
-
- expect(session.getContext()).andReturn(this.createMockSessionContext()).anyTimes();
- expect(session.getLocale()).andReturn(new Locale("EN")).anyTimes();
- expect(session.getObjectFactory()).andReturn(this.createMockObjectFactory()).anyTimes();
-
- expect(session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID)).andReturn(
- this.idTypeIndex.get(ObjectType.DOCUMENT_BASETYPE_ID)).anyTimes();
- expect(session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID)).andReturn(
- this.idTypeIndex.get(ObjectType.FOLDER_BASETYPE_ID)).anyTimes();
- expect(session.getTypeDefinition(ObjectType.POLICY_BASETYPE_ID)).andReturn(
- this.idTypeIndex.get(ObjectType.POLICY_BASETYPE_ID)).anyTimes();
- expect(session.getTypeDefinition(ObjectType.RELATIONSHIP_BASETYPE_ID)).andReturn(
- this.idTypeIndex.get(ObjectType.RELATIONSHIP_BASETYPE_ID)).anyTimes();
- expect(session.getTypeDefinition(Fixture.DOCUMENT_TYPE_ID)).andReturn(
- this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID)).anyTimes();
- expect(session.getTypeDefinition(Fixture.FOLDER_TYPE_ID)).andReturn(
- this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
-
- /* document child/descendants types */
- List<ObjectType> dtl = new ArrayList<ObjectType>();
- dtl.add(this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID));
- PagingList<ObjectType> plot = this.createMockPaging(dtl);
- expect(
- session.getTypeChildren(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_DOCUMENT.value()),
- true, -1)).andReturn(plot).anyTimes();
- expect(
- session.getTypeDescendants(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_DOCUMENT.value()),
- 1, true, -1)).andReturn(plot).anyTimes();
-
- /* folder child/descendants types */
- List<ObjectType> ftl = new ArrayList<ObjectType>();
- ftl.add(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID));
- PagingList<ObjectType> plfot = this.createMockPaging(ftl);
- expect(
- session.getTypeChildren(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()), true,
- -1)).andReturn(plfot).anyTimes();
- expect(
- session.getTypeDescendants(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()), 1,
- true, -1)).andReturn(plfot).anyTimes();
-
- /* change support */
- List<ChangeEvent> cel = this.createMockChangeEvents();
- PagingList<ChangeEvent> plce = this.createMockPaging(cel);
- expect(session.getContentChanges(null, -1)).andReturn(plce).anyTimes();
-
- /* query support */
- List<CmisObject> queryList = new ArrayList<CmisObject>(this.idObjectIndex.values());
- PagingList<CmisObject> plq = this.createMockPaging(queryList);
- expect(session.query(Fixture.QUERY, false, -1)).andReturn(plq).anyTimes();
-
- this.makeObjectsAccessible(session);
-
- replay(session);
-
- return session;
- }
-
- private List<ChangeEvent> createMockChangeEvents() {
- List<ChangeEvent> cel = new ArrayList<ChangeEvent>();
- ChangeEvent ce = createNiceMock(ChangeEvent.class);
- List<Property<?>> pl = new ArrayList<Property<?>>();
-
- expect(ce.getObjectId()).andReturn(UUID.randomUUID().toString()).anyTimes();
- expect(ce.getChangeType()).andReturn(TypeOfChanges.CREATED).anyTimes();
- expect(ce.getNewProperties()).andReturn(pl).anyTimes();
-
- replay(ce);
-
- cel.add(ce);
-
- return cel;
- }
-
- private void makeObjectsAccessible(Session s) {
- Enumeration<String> e = this.idObjectIndex.keys();
- String id;
- String path;
- CmisObject obj;
-
- while (e.hasMoreElements()) {
- id = e.nextElement();
- obj = this.idObjectIndex.get(id);
- path = obj.getPath();
-
- expect(s.getObjectByPath(path)).andReturn(obj).anyTimes();
- expect(s.getObject(id)).andReturn(obj).anyTimes();
- }
- }
-
- private ObjectFactory createMockObjectFactory() {
- ObjectFactory of = createNiceMock(ObjectFactory.class);
-
- replay(of);
-
- return of;
- }
-
- private SessionContext createMockSessionContext() {
- SessionContext sc = createNiceMock(SessionContext.class);
-
- replay(sc);
-
- return sc;
- }
-
- private Folder createMockTestRootFolder(Folder parent) {
- Folder f = createNiceMock(Folder.class);
-
- expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
- expect(f.getName()).andReturn(Fixture.TEST_ROOT_FOLDER_NAME).anyTimes();
- expect(f.getPath()).andReturn("/" + Fixture.TEST_ROOT_FOLDER_NAME).anyTimes();
- expect(f.getFolderParent()).andReturn(parent).anyTimes();
- expect(f.getType()).andReturn(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
- expect(f.getBaseType()).andReturn(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()))
- .anyTimes();
- List<CmisObject> children = new ArrayList<CmisObject>();
- children.add(this.createMockTestFolder(f, "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
- + Fixture.FOLDER1_NAME, Fixture.FOLDER1_NAME));
- children.add(this.createMockTestFolder(f, "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
- + Fixture.FOLDER2_NAME, Fixture.FOLDER2_NAME));
- children.add(this.createMockTestDocument(f, "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
- + Fixture.DOCUMENT1_NAME, Fixture.DOCUMENT1_NAME));
-
- PagingList<CmisObject> pl = this.createMockPaging(children);
- expect(f.getChildren(null, -1)).andReturn(pl).anyTimes();
-
- TreeMap<String, CmisObject> tree = new TreeMap<String, CmisObject>();
- Folder f1 = this.createMockTestFolder(f, "/" + Fixture.FOLDER1_NAME, Fixture.FOLDER1_NAME);
- Folder f2 = this.createMockTestFolder(f, "/" + Fixture.FOLDER2_NAME, Fixture.FOLDER2_NAME);
- tree.put(f1.getId(), f1);
- tree.put(f2.getId(), f2);
- expect(f.getDescendants(-1)).andReturn(tree).anyTimes();
- expect(f.getFolderTree(-1)).andReturn(tree).anyTimes();
- this.createMockProperties(f);
-
- replay(f);
- this.idObjectIndex.put(f.getId(), f);
-
- return f;
- }
-
- @SuppressWarnings("unchecked")
- private void createMockProperties(CmisObject o) {
- GregorianCalendar date = new GregorianCalendar();
-
- expect(o.getCreatedBy()).andReturn(Fixture.getParamter().get(SessionParameter.USER)).anyTimes();
- expect(o.getLastModifiedBy()).andReturn(Fixture.getParamter().get(SessionParameter.USER))
- .anyTimes();
- expect(o.getLastModificationDate()).andReturn(date).anyTimes();
- expect(o.getCreationDate()).andReturn(date).anyTimes();
-
- {
- ArrayList a = new ArrayList<Property<Property>>();
-
- // mandatory default properties
- a.add(this.createMockStringProperty(PropertyIds.CMIS_BASE_TYPE_ID));
- a.add(this.createMockStringProperty(PropertyIds.CMIS_NAME));
- a.add(this.createMockIntegerProperty(PropertyIds.CMIS_CONTENT_STREAM_LENGTH));
-
- // other properties
- a.add(this.createMockBooleanProperty(UUID.randomUUID().toString()));
- a.add(this.createMockDateTimeProperty(UUID.randomUUID().toString()));
- a.add(this.createMockFloatProperty(UUID.randomUUID().toString()));
- a.add(this.createMockDoubleProperty(UUID.randomUUID().toString()));
- a.add(this.createMockHtmlProperty(UUID.randomUUID().toString()));
- a.add(this.createMockIdProperty(UUID.randomUUID().toString()));
- a.add(this.createMockUriProperty(UUID.randomUUID().toString()));
-
- expect(o.getProperties()).andReturn(a).anyTimes();
- expect(o.getProperties(Fixture.PROPERTY_FILTER)).andReturn(a).anyTimes();
-
- /* single property */
- Property<Object> p1 = (Property<Object>) createMockStringProperty(CmisProperties.OBJECT_ID
- .value());
- expect(o.getProperty(CmisProperties.OBJECT_ID.value())).andReturn(p1).anyTimes();
- expect(o.getPropertyValue(CmisProperties.OBJECT_ID.value())).andReturn(p1.getValue())
- .anyTimes();
-
- /* multi valued property */
- Property<Object> p2 = (Property<Object>) createMockMultiValuedStringProperty(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED);
- expect(o.getProperty(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED)).andReturn(p2).anyTimes();
- expect(o.getPropertyMultivalue(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED)).andReturn(
- p2.getValues()).anyTimes();
- }
-
- }
-
- private Property<?> createMockMultiValuedStringProperty(String id) {
- Property<String> p = createNiceMock(StringProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.STRING).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_STRING).anyTimes();
- expect(p.isMultiValued()).andReturn(true).anyTimes();
- List<String> v = new ArrayList<String>();
- v.add(Fixture.PROPERTY_VALUE_STRING);
- v.add(Fixture.PROPERTY_VALUE_STRING);
- expect(p.getValues()).andReturn(v).anyTimes();
- expect(p.getValueAsString()).andReturn(v.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockDateTimeProperty(String id) {
- Property<Calendar> p = createNiceMock(DateTimeProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.DATETIME).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_DATETIME).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_DATETIME.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockHtmlProperty(String id) {
- Property<String> p = createNiceMock(StringProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.HTML).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_HTML).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_HTML.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockIdProperty(String id) {
- Property<String> p = createNiceMock(StringProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.ID).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_ID).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_ID.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockUriProperty(String id) {
- Property<URI> p = createNiceMock(UriProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.URI).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_URI).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_URI.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockDoubleProperty(String id) {
- Property<Double> p = createNiceMock(DoubleProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.DECIMAL).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_DOUBLE).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_DOUBLE.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockFloatProperty(String id) {
- Property<Float> p = createNiceMock(FloatProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.DECIMAL).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_FLOAT).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_FLOAT.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockBooleanProperty(String id) {
- Property<Boolean> p = createNiceMock(BooleanProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.BOOLEAN).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_BOOLEAN).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_BOOLEAN.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockIntegerProperty(String id) {
- Property<Integer> p = createNiceMock(IntegerProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.INTEGER).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_INTEGER).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_INTEGER.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private Property<?> createMockStringProperty(String id) {
- Property<String> p = createNiceMock(StringProperty.class);
-
- expect(p.getType()).andReturn(PropertyType.STRING).anyTimes();
- expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_STRING).anyTimes();
- expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_STRING.toString()).anyTimes();
-
- replay(p);
-
- return p;
- }
-
- private CmisObject createMockTestDocument(Folder parent, String path, String name) {
- Document d = createNiceMock(Document.class);
-
- expect(d.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
- expect(d.getName()).andReturn(name).anyTimes();
- expect(d.getPath()).andReturn(path).anyTimes();
- expect(d.getType()).andReturn(this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID)).anyTimes();
- expect(d.getBaseType())
- .andReturn(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_DOCUMENT.value())).anyTimes();
- this.createMockProperties(d);
- expect(d.getContentStream()).andReturn(this.createMockContentStream()).anyTimes();
-
- replay(d);
- this.idObjectIndex.put(d.getId(), d);
-
- return d;
- }
-
- private ContentStream createMockContentStream() {
- ContentStream cs = createNiceMock(ContentStream.class);
-
- byte[] b = "abc".getBytes();
- ByteArrayInputStream bais = new ByteArrayInputStream(b);
-
- expect(cs.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
- expect(cs.getFileName()).andReturn("file.txt").anyTimes();
- expect(cs.getMimeType()).andReturn("text/html").anyTimes();
- expect(cs.getLength()).andReturn(b.length).anyTimes();
- expect(cs.getStream()).andReturn(bais).anyTimes();
-
- replay(cs);
-
- return cs;
- }
-
- private Folder createMockTestFolder(Folder parent, String path, String name) {
- Folder f = createNiceMock(Folder.class);
-
- expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
- expect(f.getName()).andReturn(name).anyTimes();
- expect(f.getPath()).andReturn(path).anyTimes();
- expect(f.getFolderParent()).andReturn(parent).anyTimes();
- expect(f.getType()).andReturn(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
- expect(f.getBaseType()).andReturn(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()))
- .anyTimes();
- List<CmisObject> children = new ArrayList<CmisObject>();
- children.add(this.createMockTestDocument(f, path + "/" + Fixture.DOCUMENT1_NAME,
- Fixture.DOCUMENT1_NAME));
- children.add(this.createMockTestDocument(f, path + "/" + Fixture.DOCUMENT2_NAME,
- Fixture.DOCUMENT2_NAME));
-
- PagingList<CmisObject> pl = this.createMockPaging(children);
- expect(f.getChildren(null, -1)).andReturn(pl).anyTimes();
-
- TreeMap<String, CmisObject> tree = new TreeMap<String, CmisObject>();
- expect(f.getDescendants(-1)).andReturn(tree).anyTimes();
- expect(f.getFolderTree(-1)).andReturn(tree).anyTimes();
- this.createMockProperties(f);
-
- replay(f);
- this.idObjectIndex.put(f.getId(), f);
-
- return f;
- }
-
- @SuppressWarnings( { "unchecked" })
- private <T> PagingList<T> createMockPaging(List<T> items) {
- PagingList<T> pl = createNiceMock(PagingList.class);
-
- ArrayList<List<T>> a = new ArrayList<List<T>>();
- a.add(items);
- Iterator<List<T>> i = a.iterator();
-
- expect(pl.get(0)).andReturn(items).anyTimes();
- expect(pl.isEmpty()).andReturn(false).anyTimes();
- expect(pl.iterator()).andReturn(i).anyTimes();
-
- replay(pl);
-
- return pl;
- }
-
- private void createMockGlobalTypes() {
- FolderType bft = createNiceMock(FolderType.class);
- expect(bft.getId()).andReturn(ObjectType.FOLDER_BASETYPE_ID).anyTimes();
- expect(bft.isBase()).andReturn(true);
- expect(bft.getBaseType()).andReturn(null).anyTimes();
-
- FolderType ft = createNiceMock(FolderType.class);
- expect(ft.getId()).andReturn(Fixture.FOLDER_TYPE_ID).anyTimes();
- expect(ft.isBase()).andReturn(false);
- expect(ft.getBaseType()).andReturn(bft).anyTimes();
-
- PolicyType bpt = createNiceMock(PolicyType.class);
- expect(bpt.getId()).andReturn(ObjectType.POLICY_BASETYPE_ID).anyTimes();
- expect(bpt.isBase()).andReturn(true);
- expect(bpt.getBaseType()).andReturn(null).anyTimes();
-
- RelationshipType brt = createNiceMock(RelationshipType.class);
- expect(brt.getId()).andReturn(ObjectType.RELATIONSHIP_BASETYPE_ID).anyTimes();
- expect(brt.isBase()).andReturn(true);
- expect(brt.getBaseType()).andReturn(null).anyTimes();
-
- DocumentType bdt = createNiceMock(DocumentType.class);
- expect(bdt.getId()).andReturn(ObjectType.DOCUMENT_BASETYPE_ID).anyTimes();
- expect(bdt.isBase()).andReturn(true);
- expect(bdt.getBaseType()).andReturn(null).anyTimes();
-
- DocumentType dt = createNiceMock(DocumentType.class);
- expect(dt.getId()).andReturn(Fixture.DOCUMENT_TYPE_ID).anyTimes();
- expect(dt.isBase()).andReturn(false);
- expect(dt.getBaseType()).andReturn(bft).anyTimes();
-
- replay(bft);
- replay(ft);
- replay(bdt);
- replay(dt);
- replay(bpt);
- replay(brt);
-
- this.idTypeIndex.put(bft.getId(), bft);
- this.idTypeIndex.put(ft.getId(), ft);
- this.idTypeIndex.put(bdt.getId(), bdt);
- this.idTypeIndex.put(dt.getId(), dt);
- this.idTypeIndex.put(bpt.getId(), bpt);
- this.idTypeIndex.put(brt.getId(), brt);
-
- }
-
- private Folder createMockRepositoryRootFolder() {
- Folder f = createNiceMock(Folder.class);
-
- expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
- expect(f.getName()).andReturn("").anyTimes(); // or "root" ?
- expect(f.getPath()).andReturn("/").anyTimes();
- expect(f.getFolderParent()).andReturn(null).anyTimes();
- expect(f.getType()).andReturn(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
- this.createMockProperties(f);
-
- replay(f);
- this.idObjectIndex.put(f.getId(), f);
-
- return f;
- }
-
- private RepositoryInfo createMockRepositoryInfo() {
- RepositoryInfo ri = createNiceMock(RepositoryInfo.class);
-
- expect(ri.getName()).andReturn("MockRepository").anyTimes();
- expect(ri.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
- expect(ri.getDescription()).andReturn("description").anyTimes();
- expect(ri.getCmisVersionSupported()).andReturn("1.0").anyTimes();
- expect(ri.getVendorName()).andReturn("Apache").anyTimes();
- expect(ri.getProductName()).andReturn("OpenCMIS").anyTimes();
- expect(ri.getPrincipalIdAnonymous()).andReturn("anonymous").anyTimes();
- expect(ri.getPrincipalIdAnyone()).andReturn("anyone").anyTimes();
- expect(ri.getThinClientUri()).andReturn("http://foo.com").anyTimes();
- expect(ri.getChangesOnType()).andReturn(new ArrayList<BaseObjectTypeIds>()).anyTimes();
-
- expect(ri.getCapabilities()).andReturn(this.createMockRepositoryCapabilities()).anyTimes();
-
- replay(ri);
-
- return ri;
- }
-
- private RepositoryCapabilities createMockRepositoryCapabilities() {
- RepositoryCapabilities rc = createNiceMock(RepositoryCapabilities.class);
-
- expect(rc.getAclSupport()).andReturn(CapabilityAcl.NONE).anyTimes();
- expect(rc.getChangesSupport()).andReturn(CapabilityChanges.ALL).anyTimes();
- expect(rc.getContentStreamUpdatabilitySupport()).andReturn(CapabilityContentStreamUpdates.NONE)
- .anyTimes();
- expect(rc.getJoinSupport()).andReturn(CapabilityJoin.NONE).anyTimes();
- expect(rc.getQuerySupport()).andReturn(CapabilityQuery.BOTHCOMBINED).anyTimes();
- expect(rc.getRenditionsSupport()).andReturn(CapabilityRendition.NONE).anyTimes();
-
- replay(rc);
-
- return rc;
- }
-
- private interface StringProperty extends Property<String> {
- }
-
- private interface IntegerProperty extends Property<Integer> {
- }
-
- private interface DoubleProperty extends Property<Double> {
- }
-
- private interface FloatProperty extends Property<Float> {
- }
+ {
+ this.idObjectIndex = new Hashtable<String, CmisObject>();
+ this.pathObjectIndex = new Hashtable<String, CmisObject>();
+ this.idTypeIndex = new Hashtable<String, ObjectType>();
+ this.mockSession = this.createMockSession();
+ }
+
+ private Hashtable<String, CmisObject> idObjectIndex = null;
+ private Hashtable<String, ObjectType> idTypeIndex = null;
+ private Hashtable<String, CmisObject> pathObjectIndex = null;
+
+ @SuppressWarnings("unchecked")
+ public <T extends Session> T createSession(Map<String, String> parameters) {
+ T session = null;
+ SessionType st;
+ String p = parameters.get(SessionParameter.SESSION_TYPE);
+
+ if (p == null) {
+ st = SessionType.PERSISTENT; // default, if type is not set
+ } else {
+ st = SessionType.fromValue(p);
+ }
+
+ switch (st) {
+ case PERSISTENT:
+ session = (T) this.mockSession;
+ break;
+ case TRANSIENT:
+ throw new CmisNotSupportedException("SessionType = " + st);
+ }
+
+ return session;
+ }
+
+ private Session createMockSession() {
+ this.createMockGlobalTypes();
+
+ Session session = createNiceMock(Session.class);
+ Folder rootFolder = this.createMockRepositoryRootFolder();
+ this.createMockTestRootFolder("/", rootFolder);
+
+ for (String path : this.pathObjectIndex.keySet()) {
+ CmisObject o = this.pathObjectIndex.get(path);
+ expect(session.getObjectByPath(path)).andReturn(o).anyTimes();
+ }
+
+ expect(session.getRepositoryInfo()).andReturn(
+ this.createMockRepositoryInfo()).anyTimes();
+ expect(session.getRootFolder()).andReturn(rootFolder).anyTimes();
+
+ expect(session.getContext()).andReturn(this.createMockSessionContext())
+ .anyTimes();
+ expect(session.getLocale()).andReturn(new Locale("EN")).anyTimes();
+ expect(session.getObjectFactory()).andReturn(
+ this.createMockObjectFactory()).anyTimes();
+
+ expect(session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID))
+ .andReturn(
+ this.idTypeIndex.get(ObjectType.DOCUMENT_BASETYPE_ID))
+ .anyTimes();
+ expect(session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID))
+ .andReturn(this.idTypeIndex.get(ObjectType.FOLDER_BASETYPE_ID))
+ .anyTimes();
+ expect(session.getTypeDefinition(ObjectType.POLICY_BASETYPE_ID))
+ .andReturn(this.idTypeIndex.get(ObjectType.POLICY_BASETYPE_ID))
+ .anyTimes();
+ expect(session.getTypeDefinition(ObjectType.RELATIONSHIP_BASETYPE_ID))
+ .andReturn(
+ this.idTypeIndex
+ .get(ObjectType.RELATIONSHIP_BASETYPE_ID))
+ .anyTimes();
+ expect(session.getTypeDefinition(Fixture.DOCUMENT_TYPE_ID)).andReturn(
+ this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID)).anyTimes();
+ expect(session.getTypeDefinition(Fixture.FOLDER_TYPE_ID)).andReturn(
+ this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
+
+ /* document child/descendants types */
+ List<ObjectType> dtl = new ArrayList<ObjectType>();
+ dtl.add(this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID));
+ PagingList<ObjectType> plot = this.createMockPaging(dtl);
+ expect(
+ session
+ .getTypeChildren(this.idTypeIndex
+ .get(BaseObjectTypeIds.CMIS_DOCUMENT.value()),
+ true, -1)).andReturn(plot).anyTimes();
+ expect(
+ session.getTypeDescendants(this.idTypeIndex
+ .get(BaseObjectTypeIds.CMIS_DOCUMENT.value()), 1, true,
+ -1)).andReturn(plot).anyTimes();
+
+ /* folder child/descendants types */
+ List<ObjectType> ftl = new ArrayList<ObjectType>();
+ ftl.add(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID));
+ PagingList<ObjectType> plfot = this.createMockPaging(ftl);
+ expect(
+ session.getTypeChildren(this.idTypeIndex
+ .get(BaseObjectTypeIds.CMIS_FOLDER.value()), true, -1))
+ .andReturn(plfot).anyTimes();
+ expect(
+ session.getTypeDescendants(this.idTypeIndex
+ .get(BaseObjectTypeIds.CMIS_FOLDER.value()), 1, true,
+ -1)).andReturn(plfot).anyTimes();
+
+ /* change support */
+ List<ChangeEvent> cel = this.createMockChangeEvents();
+ PagingList<ChangeEvent> plce = this.createMockPaging(cel);
+ expect(session.getContentChanges(null, -1)).andReturn(plce).anyTimes();
+
+ /* query support */
+ List<CmisObject> queryList = new ArrayList<CmisObject>(
+ this.idObjectIndex.values());
+ PagingList<CmisObject> plq = this.createMockPaging(queryList);
+ expect(session.query(Fixture.QUERY, false, -1)).andReturn(plq)
+ .anyTimes();
+
+ this.makeObjectsAccessible(session);
+
+ replay(session);
+
+ return session;
+ }
+
+ private List<ChangeEvent> createMockChangeEvents() {
+ List<ChangeEvent> cel = new ArrayList<ChangeEvent>();
+ ChangeEvent ce = createNiceMock(ChangeEvent.class);
+ List<Property<?>> pl = new ArrayList<Property<?>>();
+
+ expect(ce.getObjectId()).andReturn(UUID.randomUUID().toString())
+ .anyTimes();
+ expect(ce.getChangeType()).andReturn(TypeOfChanges.CREATED).anyTimes();
+ expect(ce.getNewProperties()).andReturn(pl).anyTimes();
+
+ replay(ce);
+
+ cel.add(ce);
+
+ return cel;
+ }
+
+ private void makeObjectsAccessible(Session s) {
+ Enumeration<String> e = this.idObjectIndex.keys();
+ String id;
+ CmisObject obj;
+
+ while (e.hasMoreElements()) {
+ id = e.nextElement();
+ obj = this.idObjectIndex.get(id);
+
+ expect(s.getObject(id)).andReturn(obj).anyTimes();
+ }
+ }
+
+ private ObjectFactory createMockObjectFactory() {
+ ObjectFactory of = createNiceMock(ObjectFactory.class);
+
+ replay(of);
+
+ return of;
+ }
+
+ private SessionContext createMockSessionContext() {
+ SessionContext sc = createNiceMock(SessionContext.class);
+
+ replay(sc);
+
+ return sc;
+ }
+
+ private Folder createMockTestRootFolder(String parentPath, Folder parent) {
+ Folder f = createNiceMock(Folder.class);
+
+ expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(f.getName()).andReturn(Fixture.TEST_ROOT_FOLDER_NAME).anyTimes();
+ expect(f.getFolderParent()).andReturn(parent).anyTimes();
+ expect(f.getType()).andReturn(
+ this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
+ expect(f.getBaseType()).andReturn(
+ this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()))
+ .anyTimes();
+ List<CmisObject> children = new ArrayList<CmisObject>();
+ children.add(this.createMockTestFolder(f, "/"
+ + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.FOLDER1_NAME,
+ Fixture.FOLDER1_NAME));
+ children.add(this.createMockTestFolder(f, "/"
+ + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.FOLDER2_NAME,
+ Fixture.FOLDER2_NAME));
+ children.add(this.createMockTestDocument(f, "/"
+ + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.DOCUMENT1_NAME,
+ Fixture.DOCUMENT1_NAME));
+
+ PagingList<CmisObject> pl = this.createMockPaging(children);
+ expect(f.getChildren(null, -1)).andReturn(pl).anyTimes();
+
+ TreeMap<String, CmisObject> tree = new TreeMap<String, CmisObject>();
+ Folder f1 = this.createMockTestFolder(f, "/" + Fixture.FOLDER1_NAME,
+ Fixture.FOLDER1_NAME);
+ Folder f2 = this.createMockTestFolder(f, "/" + Fixture.FOLDER2_NAME,
+ Fixture.FOLDER2_NAME);
+ tree.put(f1.getId(), f1);
+ tree.put(f2.getId(), f2);
+ expect(f.getDescendants(-1)).andReturn(tree).anyTimes();
+ expect(f.getFolderTree(-1)).andReturn(tree).anyTimes();
+ this.createMockProperties(f);
+
+ replay(f);
+ this.idObjectIndex.put(f.getId(), f);
+ this.pathObjectIndex.put(parentPath + Fixture.TEST_ROOT_FOLDER_NAME, f);
+
+ return f;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void createMockProperties(CmisObject o) {
+ GregorianCalendar date = new GregorianCalendar();
+
+ expect(o.getCreatedBy()).andReturn(
+ Fixture.getParamter().get(SessionParameter.USER)).anyTimes();
+ expect(o.getLastModifiedBy()).andReturn(
+ Fixture.getParamter().get(SessionParameter.USER)).anyTimes();
+ expect(o.getLastModificationDate()).andReturn(date).anyTimes();
+ expect(o.getCreationDate()).andReturn(date).anyTimes();
+
+ {
+ ArrayList a = new ArrayList<Property<Property>>();
+
+ // mandatory default properties
+ a.add(this.createMockStringProperty(PropertyIds.CMIS_BASE_TYPE_ID));
+ a.add(this.createMockStringProperty(PropertyIds.CMIS_NAME));
+ a
+ .add(this
+ .createMockIntegerProperty(PropertyIds.CMIS_CONTENT_STREAM_LENGTH));
+
+ // other properties
+ a.add(this.createMockBooleanProperty(UUID.randomUUID().toString()));
+ a
+ .add(this.createMockDateTimeProperty(UUID.randomUUID()
+ .toString()));
+ a.add(this.createMockFloatProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockDoubleProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockHtmlProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockIdProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockUriProperty(UUID.randomUUID().toString()));
+
+ expect(o.getProperties()).andReturn(a).anyTimes();
+ expect(o.getProperties(Fixture.PROPERTY_FILTER)).andReturn(a)
+ .anyTimes();
+
+ /* single property */
+ Property<Object> p1 = (Property<Object>) createMockStringProperty(CmisProperties.OBJECT_ID
+ .value());
+ expect(o.getProperty(CmisProperties.OBJECT_ID.value())).andReturn(
+ p1).anyTimes();
+ expect(o.getPropertyValue(CmisProperties.OBJECT_ID.value()))
+ .andReturn(p1.getValue()).anyTimes();
+
+ /* multi valued property */
+ Property<Object> p2 = (Property<Object>) createMockMultiValuedStringProperty(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED);
+ expect(o.getProperty(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED))
+ .andReturn(p2).anyTimes();
+ expect(
+ o
+ .getPropertyMultivalue(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED))
+ .andReturn(p2.getValues()).anyTimes();
+ }
+
+ }
+
+ private Property<?> createMockMultiValuedStringProperty(String id) {
+ Property<String> p = createNiceMock(StringProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.STRING).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_STRING)
+ .anyTimes();
+ expect(p.isMultiValued()).andReturn(true).anyTimes();
+ List<String> v = new ArrayList<String>();
+ v.add(Fixture.PROPERTY_VALUE_STRING);
+ v.add(Fixture.PROPERTY_VALUE_STRING);
+ expect(p.getValues()).andReturn(v).anyTimes();
+ expect(p.getValueAsString()).andReturn(v.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockDateTimeProperty(String id) {
+ Property<Calendar> p = createNiceMock(DateTimeProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.DATETIME).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_DATETIME)
+ .anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_DATETIME.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockHtmlProperty(String id) {
+ Property<String> p = createNiceMock(StringProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.HTML).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_HTML).anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_HTML.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockIdProperty(String id) {
+ Property<String> p = createNiceMock(StringProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.ID).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_ID).anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_ID.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockUriProperty(String id) {
+ Property<URI> p = createNiceMock(UriProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.URI).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_URI).anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_URI.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockDoubleProperty(String id) {
+ Property<Double> p = createNiceMock(DoubleProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.DECIMAL).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_DOUBLE)
+ .anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_DOUBLE.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockFloatProperty(String id) {
+ Property<Float> p = createNiceMock(FloatProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.DECIMAL).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_FLOAT).anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_FLOAT.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockBooleanProperty(String id) {
+ Property<Boolean> p = createNiceMock(BooleanProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.BOOLEAN).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_BOOLEAN)
+ .anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_BOOLEAN.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockIntegerProperty(String id) {
+ Property<Integer> p = createNiceMock(IntegerProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.INTEGER).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_INTEGER)
+ .anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_INTEGER.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockStringProperty(String id) {
+ Property<String> p = createNiceMock(StringProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.STRING).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_STRING)
+ .anyTimes();
+ expect(p.getValueAsString()).andReturn(
+ Fixture.PROPERTY_VALUE_STRING.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private CmisObject createMockTestDocument(Folder parent, String path,
+ String name) {
+ Document d = createNiceMock(Document.class);
+
+ expect(d.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(d.getName()).andReturn(name).anyTimes();
+ expect(d.getType()).andReturn(
+ this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID)).anyTimes();
+ expect(d.getBaseType()).andReturn(
+ this.idTypeIndex.get(BaseObjectTypeIds.CMIS_DOCUMENT.value()))
+ .anyTimes();
+ this.createMockProperties(d);
+ expect(d.getContentStream()).andReturn(this.createMockContentStream())
+ .anyTimes();
+
+ replay(d);
+ this.idObjectIndex.put(d.getId(), d);
+ this.pathObjectIndex.put(path, d);
+
+ return d;
+ }
+
+ private ContentStream createMockContentStream() {
+ ContentStream cs = createNiceMock(ContentStream.class);
+
+ byte[] b = "abc".getBytes();
+ ByteArrayInputStream bais = new ByteArrayInputStream(b);
+
+ expect(cs.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(cs.getFileName()).andReturn("file.txt").anyTimes();
+ expect(cs.getMimeType()).andReturn("text/html").anyTimes();
+ expect(cs.getLength()).andReturn(b.length).anyTimes();
+ expect(cs.getStream()).andReturn(bais).anyTimes();
+
+ replay(cs);
+
+ return cs;
+ }
+
+ private Folder createMockTestFolder(Folder parent, String path, String name) {
+ Folder f = createNiceMock(Folder.class);
+
+ expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(f.getName()).andReturn(name).anyTimes();
+ expect(f.getFolderParent()).andReturn(parent).anyTimes();
+ expect(f.getType()).andReturn(
+ this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
+ expect(f.getBaseType()).andReturn(
+ this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()))
+ .anyTimes();
+ List<CmisObject> children = new ArrayList<CmisObject>();
+ children.add(this.createMockTestDocument(f, path + "/"
+ + Fixture.DOCUMENT1_NAME, Fixture.DOCUMENT1_NAME));
+ children.add(this.createMockTestDocument(f, path + "/"
+ + Fixture.DOCUMENT2_NAME, Fixture.DOCUMENT2_NAME));
+
+ PagingList<CmisObject> pl = this.createMockPaging(children);
+ expect(f.getChildren(null, -1)).andReturn(pl).anyTimes();
+
+ TreeMap<String, CmisObject> tree = new TreeMap<String, CmisObject>();
+ expect(f.getDescendants(-1)).andReturn(tree).anyTimes();
+ expect(f.getFolderTree(-1)).andReturn(tree).anyTimes();
+ this.createMockProperties(f);
+
+ replay(f);
+ this.idObjectIndex.put(f.getId(), f);
+
+ return f;
+ }
+
+ @SuppressWarnings( { "unchecked" })
+ private <T> PagingList<T> createMockPaging(List<T> items) {
+ PagingList<T> pl = createNiceMock(PagingList.class);
+
+ ArrayList<List<T>> a = new ArrayList<List<T>>();
+ a.add(items);
+ Iterator<List<T>> i = a.iterator();
+
+ expect(pl.get(0)).andReturn(items).anyTimes();
+ expect(pl.isEmpty()).andReturn(false).anyTimes();
+ expect(pl.iterator()).andReturn(i).anyTimes();
+
+ replay(pl);
+
+ return pl;
+ }
+
+ private void createMockGlobalTypes() {
+ FolderType bft = createNiceMock(FolderType.class);
+ expect(bft.getId()).andReturn(ObjectType.FOLDER_BASETYPE_ID).anyTimes();
+ expect(bft.isBase()).andReturn(true);
+ expect(bft.getBaseType()).andReturn(null).anyTimes();
+
+ FolderType ft = createNiceMock(FolderType.class);
+ expect(ft.getId()).andReturn(Fixture.FOLDER_TYPE_ID).anyTimes();
+ expect(ft.isBase()).andReturn(false);
+ expect(ft.getBaseType()).andReturn(bft).anyTimes();
+
+ PolicyType bpt = createNiceMock(PolicyType.class);
+ expect(bpt.getId()).andReturn(ObjectType.POLICY_BASETYPE_ID).anyTimes();
+ expect(bpt.isBase()).andReturn(true);
+ expect(bpt.getBaseType()).andReturn(null).anyTimes();
+
+ RelationshipType brt = createNiceMock(RelationshipType.class);
+ expect(brt.getId()).andReturn(ObjectType.RELATIONSHIP_BASETYPE_ID)
+ .anyTimes();
+ expect(brt.isBase()).andReturn(true);
+ expect(brt.getBaseType()).andReturn(null).anyTimes();
+
+ DocumentType bdt = createNiceMock(DocumentType.class);
+ expect(bdt.getId()).andReturn(ObjectType.DOCUMENT_BASETYPE_ID)
+ .anyTimes();
+ expect(bdt.isBase()).andReturn(true);
+ expect(bdt.getBaseType()).andReturn(null).anyTimes();
+
+ DocumentType dt = createNiceMock(DocumentType.class);
+ expect(dt.getId()).andReturn(Fixture.DOCUMENT_TYPE_ID).anyTimes();
+ expect(dt.isBase()).andReturn(false);
+ expect(dt.getBaseType()).andReturn(bft).anyTimes();
+
+ replay(bft);
+ replay(ft);
+ replay(bdt);
+ replay(dt);
+ replay(bpt);
+ replay(brt);
+
+ this.idTypeIndex.put(bft.getId(), bft);
+ this.idTypeIndex.put(ft.getId(), ft);
+ this.idTypeIndex.put(bdt.getId(), bdt);
+ this.idTypeIndex.put(dt.getId(), dt);
+ this.idTypeIndex.put(bpt.getId(), bpt);
+ this.idTypeIndex.put(brt.getId(), brt);
+
+ }
+
+ private Folder createMockRepositoryRootFolder() {
+ Folder f = createNiceMock(Folder.class);
+
+ expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(f.getName()).andReturn("").anyTimes(); // or "root" ?
+ expect(f.getFolderParent()).andReturn(null).anyTimes();
+ expect(f.getType()).andReturn(
+ this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
+ this.createMockProperties(f);
+
+ replay(f);
+ this.idObjectIndex.put(f.getId(), f);
+ this.pathObjectIndex.put("/", f);
+ return f;
+ }
+
+ private RepositoryInfo createMockRepositoryInfo() {
+ RepositoryInfo ri = createNiceMock(RepositoryInfo.class);
+
+ expect(ri.getName()).andReturn("MockRepository").anyTimes();
+ expect(ri.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(ri.getDescription()).andReturn("description").anyTimes();
+ expect(ri.getCmisVersionSupported()).andReturn("1.0").anyTimes();
+ expect(ri.getVendorName()).andReturn("Apache").anyTimes();
+ expect(ri.getProductName()).andReturn("OpenCMIS").anyTimes();
+ expect(ri.getPrincipalIdAnonymous()).andReturn("anonymous").anyTimes();
+ expect(ri.getPrincipalIdAnyone()).andReturn("anyone").anyTimes();
+ expect(ri.getThinClientUri()).andReturn("http://foo.com").anyTimes();
+ expect(ri.getChangesOnType()).andReturn(
+ new ArrayList<BaseObjectTypeIds>()).anyTimes();
+
+ expect(ri.getCapabilities()).andReturn(
+ this.createMockRepositoryCapabilities()).anyTimes();
+
+ replay(ri);
+
+ return ri;
+ }
+
+ private RepositoryCapabilities createMockRepositoryCapabilities() {
+ RepositoryCapabilities rc = createNiceMock(RepositoryCapabilities.class);
+
+ expect(rc.getAclSupport()).andReturn(CapabilityAcl.NONE).anyTimes();
+ expect(rc.getChangesSupport()).andReturn(CapabilityChanges.ALL)
+ .anyTimes();
+ expect(rc.getContentStreamUpdatabilitySupport()).andReturn(
+ CapabilityContentStreamUpdates.NONE).anyTimes();
+ expect(rc.getJoinSupport()).andReturn(CapabilityJoin.NONE).anyTimes();
+ expect(rc.getQuerySupport()).andReturn(CapabilityQuery.BOTHCOMBINED)
+ .anyTimes();
+ expect(rc.getRenditionsSupport()).andReturn(CapabilityRendition.NONE)
+ .anyTimes();
+
+ replay(rc);
+
+ return rc;
+ }
+
+ private interface StringProperty extends Property<String> {
+ }
+
+ private interface IntegerProperty extends Property<Integer> {
+ }
+
+ private interface DoubleProperty extends Property<Double> {
+ }
+
+ private interface FloatProperty extends Property<Float> {
+ }
- private interface DateTimeProperty extends Property<Calendar> {
- }
+ private interface DateTimeProperty extends Property<Calendar> {
+ }
- private interface UriProperty extends Property<URI> {
- }
+ private interface UriProperty extends Property<URI> {
+ }
- private interface BooleanProperty extends Property<Boolean> {
- }
+ private interface BooleanProperty extends Property<Boolean> {
+ }
}
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/suite/otx/OtxInMemoryCmisTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/suite/otx/OtxInMemoryCmisTestSuite.java?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/suite/otx/OtxInMemoryCmisTestSuite.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/suite/otx/OtxInMemoryCmisTestSuite.java Wed Feb 24 16:19:48 2010
@@ -22,11 +22,6 @@
import java.util.Locale;
import java.util.Map;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite.SuiteClasses;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.RunnerBuilder;
-import org.apache.opencmis.client.provider.factory.CmisProviderFactory;
import org.apache.opencmis.client.runtime.Fixture;
import org.apache.opencmis.client.runtime.ReadOnlyAclCapabilityTest;
import org.apache.opencmis.client.runtime.ReadOnlyCreateSessionTest;
@@ -38,6 +33,10 @@
import org.apache.opencmis.commons.SessionParameter;
import org.apache.opencmis.commons.enums.BindingType;
import org.apache.opencmis.commons.enums.SessionType;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
/**
* Test suite to run InMemory binding.
@@ -69,7 +68,7 @@
.value());
parameter.put(SessionParameter.REPOSITORY_ID, "InMemory");
parameter.put(SessionParameter.BINDING_SPI_CLASS,
- CmisProviderFactory.BINDING_SPI_INMEMORY);
+ "org.apache.opencmis.inmemory.clientprovider.CmisInMemorySpiFactory");
Fixture.DOCUMENT_TYPE_ID = "cmis:document";
Fixture.FOLDER_TYPE_ID = "cmis:folder";
Modified: incubator/chemistry/trunk/opencmis/src/site/site.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/src/site/site.xml?rev=915851&r1=915850&r2=915851&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/src/site/site.xml (original)
+++ incubator/chemistry/trunk/opencmis/src/site/site.xml Wed Feb 24 16:19:48 2010
@@ -25,7 +25,7 @@
<bannerRight>
<name>${project.name}</name>
<src>http://incubator.apache.org/images/apache-incubator-logo.png</src>
- <href>http://maven.apache.org/</href>
+ <href>http://www.apache.org/</href>
</bannerRight>
<skin>