chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sklev...@apache.org
Subject svn commit: r925375 - in /incubator/chemistry/trunk/opencmis/opencmis-client: opencmis-client-api/src/main/java/org/apache/opencmis/client/api/repository/ opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/ opencmis-client-impl/src/m...
Date Fri, 19 Mar 2010 18:37:22 GMT
Author: sklevenz
Date: Fri Mar 19 18:37:21 2010
New Revision: 925375

URL: http://svn.apache.org/viewvc?rev=925375&view=rev
Log:
Further improvements in r/w unit test cases.
Small API optimization in ObjectFactory

Modified:
    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/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/AbstractSessionTest.java
    incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/WriteObjectTest.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/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=925375&r1=925374&r2=925375&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 Fri Mar 19 18:37:21 2010
@@ -90,9 +90,9 @@ public interface ObjectFactory {
 
   // properties
 
-  <T> Property<T> createProperty(PropertyDefinition<T> type, T value);
+  <T> Property<T> createProperty(PropertyDefinition<?> type, T value);
 
-  <T> Property<T> createPropertyMultivalue(PropertyDefinition<T> type, List<T> values);
+  <T> Property<T> createPropertyMultivalue(PropertyDefinition<?> type, List<T> values);
 
   Map<String, Property<?>> convertProperties(ObjectType objectType, PropertiesData properties);
 

Modified: 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=925375&r1=925374&r2=925375&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/PersistentPropertyImpl.java Fri Mar 19 18:37:21 2010
@@ -42,7 +42,8 @@ public class PersistentPropertyImpl<T> i
   /**
    * Constructs a single-value property.
    */
-  public PersistentPropertyImpl(PropertyDefinition<T> type, T value) {
+  @SuppressWarnings("unchecked")
+  public PersistentPropertyImpl(PropertyDefinition<?> type, T value) {
     if (type == null) {
       throw new IllegalArgumentException("Type must be set!");
     }
@@ -51,19 +52,20 @@ public class PersistentPropertyImpl<T> i
       throw new IllegalArgumentException("Value must be set!");
     }
 
-    this.type = type;
+    this.type = (PropertyDefinition<T>) type;
     this.values = Collections.singletonList(value);
   }
 
   /**
    * Constructs a multi-value property.
    */
-  public PersistentPropertyImpl(PropertyDefinition<T> type, List<T> values) {
+  @SuppressWarnings("unchecked")
+  public PersistentPropertyImpl(PropertyDefinition<?> type, List<T> values) {
     if (type == null) {
       throw new IllegalArgumentException("Type must be set!");
     }
 
-    this.type = type;
+    this.type = (PropertyDefinition<T>) type;
     this.values = values;
   }
 

Modified: 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=925375&r1=925374&r2=925375&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/main/java/org/apache/opencmis/client/runtime/repository/PersistentObjectFactoryImpl.java Fri Mar 19 18:37:21 2010
@@ -173,7 +173,7 @@ public class PersistentObjectFactoryImpl
    */
   public AccessControlList convertAces(List<Ace> aces) {
     if (aces == null) {
-      throw new IllegalArgumentException("ACEs must be set!");
+      return null;
     }
 
     ProviderObjectFactory pof = getProviderObjectFactory();
@@ -349,7 +349,7 @@ public class PersistentObjectFactoryImpl
    * org.apache.opencmis.client.api.repository.ObjectFactory#createProperty(org.apache.opencmis.
    * commons.api.PropertyDefinition, java.lang.Object)
    */
-  public <T> Property<T> createProperty(PropertyDefinition<T> type, T value) {
+  public <T> Property<T> createProperty(PropertyDefinition<?> type, T value) {
     return new PersistentPropertyImpl<T>(type, value);
   }
 
@@ -360,7 +360,7 @@ public class PersistentObjectFactoryImpl
    * org.apache.opencmis.client.api.repository.ObjectFactory#createPropertyMultivalue(org.apache
    * .opencmis.commons.api.PropertyDefinition, java.util.List)
    */
-  public <T> Property<T> createPropertyMultivalue(PropertyDefinition<T> type, List<T> values) {
+  public <T> Property<T> createPropertyMultivalue(PropertyDefinition<?> type, List<T> values) {
     return new PersistentPropertyImpl<T>(type, values);
   }
 

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/AbstractSessionTest.java?rev=925375&r1=925374&r2=925375&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/AbstractSessionTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/AbstractSessionTest.java Fri Mar 19 18:37:21 2010
@@ -24,61 +24,84 @@ import java.util.Properties;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.log4j.PropertyConfigurator;
-import org.apache.opencmis.client.api.ObjectId;
 import org.apache.opencmis.client.api.Session;
 import org.apache.opencmis.client.api.SessionFactory;
 import org.apache.opencmis.client.runtime.mock.MockSessionFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.MethodRule;
+import org.junit.rules.TestWatchman;
+import org.junit.runners.model.FrameworkMethod;
 
 /**
  * Create a OpenCMIS test session based on fixture parameter.
  */
 public abstract class AbstractSessionTest {
 
-	protected Log log = LogFactory.getLog(this.getClass());
+  protected Log log = LogFactory.getLog(this.getClass());
 
-	@BeforeClass
-	public static void classSetup() {
-		AbstractSessionTest.initializeLogging();
-		Fixture.logHeader();
-	}
-
-	/**
-	 * Initialize logging support.
-	 */
-	private static void initializeLogging() {
-		Properties p = new Properties();
-		try {
-			p.load(AbstractSessionTest.class
-					.getResourceAsStream("/log4j.properties"));
-		} catch (IOException e) {
-			throw new RuntimeException(e);
-		}
-		PropertyConfigurator.configure(p);
-	}
-
-	/**
-	 * test session
-	 */
-	protected Session session = null;
-
-	@Before
-	public void setUp() throws Exception {
-		SessionFactory factory = Fixture.getSessionFactory();
-		this.session = factory.createSession(Fixture.getParamter());
-
-		if (!(factory instanceof MockSessionFactory)) {
-			Fixture.setUpTestData(this.session);
-		}
-	}
-
-	@After
-	public void tearDown() throws Exception {
-		SessionFactory factory = Fixture.getSessionFactory();
-		if (!(factory instanceof MockSessionFactory)) {
-			Fixture.teardownTestData(this.session);
-		}
-	}
+  /**
+   * trace each junit error
+   */
+  @Rule
+  public MethodRule watch = new TestWatchman() {
+    @Override
+    public void failed(Throwable e, FrameworkMethod method) {
+      super.failed(e, method);
+      AbstractSessionTest.this.log.error(method.getName(), e);
+    }
+  };
+
+  @BeforeClass
+  public static void classSetup() {
+    AbstractSessionTest.initializeLogging();
+    Fixture.logHeader();
+  }
+
+  /**
+   * Initialize logging support.
+   */
+  private static void initializeLogging() {
+    Properties p = new Properties();
+    try {
+      p.load(AbstractSessionTest.class.getResourceAsStream("/log4j.properties"));
+    }
+    catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    PropertyConfigurator.configure(p);
+  }
+
+  /**
+   * test session
+   */
+  protected Session session = null;
+
+  @Before
+  public void setUp() throws Exception {
+    SessionFactory factory = Fixture.getSessionFactory();
+    this.session = factory.createSession(Fixture.getParamter());
+
+    if (!(factory instanceof MockSessionFactory)) {
+      Fixture.setUpTestData(this.session);
+    }
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    SessionFactory factory = Fixture.getSessionFactory();
+    if (!(factory instanceof MockSessionFactory)) {
+      Fixture.teardownTestData(this.session);
+    }
+  }
+
+  /**
+   * skip tests not supported by mock implementation
+   * @return flag
+   */
+  protected boolean isMock() {
+    return Fixture.getSessionFactory() instanceof MockSessionFactory;
+  }
 }

Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/WriteObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/WriteObjectTest.java?rev=925375&r1=925374&r2=925375&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/WriteObjectTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/WriteObjectTest.java Fri Mar 19 18:37:21 2010
@@ -18,133 +18,136 @@
  */
 package org.apache.opencmis.client.runtime;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
-import java.util.Map;
 import java.util.UUID;
 
 import junit.framework.Assert;
 
-import org.apache.opencmis.client.api.Ace;
+import org.apache.opencmis.client.api.ContentStream;
+import org.apache.opencmis.client.api.Document;
 import org.apache.opencmis.client.api.ObjectId;
-import org.apache.opencmis.client.api.Policy;
 import org.apache.opencmis.client.api.Property;
 import org.apache.opencmis.client.api.objecttype.ObjectType;
 import org.apache.opencmis.commons.api.PropertyDefinition;
-import org.apache.opencmis.commons.enums.BaseObjectTypeIds;
 import org.apache.opencmis.commons.enums.CmisProperties;
+import org.apache.opencmis.commons.enums.VersioningState;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class WriteObjectTest extends AbstractSessionTest {
 
-	@Test
-	public void createFolder() {
-		ObjectId parentId = this.session
-				.createObjectId(Fixture.getTestRootId());
-		String folderName = UUID.randomUUID().toString();
-		String typeId = FixtureData.FOLDER_TYPE_ID.value();
-
-		ObjectType ot = this.session.getTypeDefinition(typeId);
-		Map<String, PropertyDefinition<?>> pdefs = ot.getPropertyDefintions();
-		List<Property<?>> properties = new ArrayList<Property<?>>();
-		Property<?> prop = null;
-
-		for (PropertyDefinition<?> pd : pdefs.values()) {
-			try {
-				CmisProperties cmisp = CmisProperties.fromValue(pd.getId());
-				switch (cmisp) {
-				case NAME:
-					prop = this.session.getObjectFactory().createProperty(
-							(PropertyDefinition<String>) pd, folderName);
-					properties.add(prop);
-					break;
-				case OBJECT_TYPE_ID:
-					prop = this.session.getObjectFactory().createProperty(
-							(PropertyDefinition<String>) pd, typeId);
-					properties.add(prop);
-					break;
-				default:
-					break;
-				}
-			} catch (Exception e) {
-				// custom property definition
-			}
-
-		}
-
-		List<Ace> addAce = new ArrayList<Ace>();
-		List<Ace> removeAce = new ArrayList<Ace>();
-		List<Policy> policies = new ArrayList<Policy>();
-		ObjectId id = this.session.createFolder(properties, parentId, policies,
-				addAce, removeAce);
-		Assert.assertNotNull(id);
-	}
-
-	/**
-	 * Method to create named and typed folder using a given parent id.
-	 * 
-	 * @param foldeName
-	 *            Name of folder to create
-	 * @param parentId
-	 *            Id of parent folder to create this folder as a child
-	 */
-	@SuppressWarnings("unchecked")
-	public void createFolder(String folderName, ObjectId parentId) {
-		// retrieve all property definitions for specific cmis type
-		ObjectType ot = this.session.getTypeDefinition("cmis:folder");
-		Map<String, PropertyDefinition<?>> pdefs = ot.getPropertyDefintions();
-
-		// get property definitions from object type
-		PropertyDefinition<String> pdName = (PropertyDefinition<String>) pdefs
-				.get(CmisProperties.NAME.value());
-		PropertyDefinition<String> pdType = (PropertyDefinition<String>) pdefs
-				.get(CmisProperties.OBJECT_TYPE_ID.value());
-
-		// create mandatory properties of object type
-		Property<?> propName = this.session.getObjectFactory().createProperty(
-				pdName, folderName);
-		Property<?> propType = this.session.getObjectFactory().createProperty(
-				pdType, "cmis:folder");
-
-		// fill properties list
-		List<Property<?>> properties = new ArrayList<Property<?>>();
-		properties.add(propName);
-		properties.add(propType);
-
-		// create additional optional parameter
-		List<Ace> ace = new ArrayList<Ace>();
-		List<Policy> pol = null;
-
-		// ready steady go
-		ObjectId id = this.session.createFolder(properties, parentId, pol, ace,
-				ace);
-		Assert.assertNotNull(id);
-	}
-
-	// public void createFolderOptimzed(String folderName, ObjectId parentId) {
-	// // retrieve all property definitions for specific cmis type
-	// ObjectType ot =
-	// this.session.getTypeDefinition(BaseObjectTypeIds.CMIS_FOLDER);
-	// Map<String, PropertyDefinition<?>> pdefs = ot.getPropertyDefintions();
-	//
-	// // get property definitions from object type
-	// PropertyDefinition<?> pdName = pdefs.get(CmisProperties.NAME);
-	// PropertyDefinition<?> pdType = pdefs.get(CmisProperties.OBJECT_TYPE_ID);
-	//
-	// // create mandatory properties of object type
-	// Property<?> propName = this.session.getObjectFactory().createProperty(
-	// pdName, folderName);
-	// Property<?> propType = this.session.getObjectFactory().createProperty(
-	// pdType, "cmis:folder");
-	//
-	// // fill properties list
-	// List<Property<?>> properties = new ArrayList<Property<?>>();
-	// properties.add(propName);
-	// properties.add(propType);
-	//
-	// // ready steady go
-	// ObjectId id = this.session.createFolder(properties, parentId);
-	// Assert.assertNotNull(id);
-	// }
-
+  @Test
+  public void createFolder() {
+    ObjectId parentId = this.session.createObjectId(Fixture.getTestRootId());
+    String folderName = UUID.randomUUID().toString();
+    String typeId = FixtureData.FOLDER_TYPE_ID.value();
+
+    ObjectType ot = this.session.getTypeDefinition(typeId);
+    Collection<PropertyDefinition<?>> pdefs = ot.getPropertyDefintions().values();
+    List<Property<?>> properties = new ArrayList<Property<?>>();
+    Property<?> prop = null;
+
+    for (PropertyDefinition<?> pd : pdefs) {
+      try {
+        CmisProperties cmisp = CmisProperties.fromValue(pd.getId());
+        switch (cmisp) {
+        case NAME:
+          prop = this.session.getObjectFactory().createProperty(pd, folderName);
+          properties.add(prop);
+          break;
+        case OBJECT_TYPE_ID:
+          prop = this.session.getObjectFactory().createProperty(pd, typeId);
+          properties.add(prop);
+          break;
+        default:
+          break;
+        }
+      }
+      catch (Exception e) {
+        // custom property definition
+      }
+
+    }
+
+    ObjectId id = this.session.createFolder(properties, parentId, null, null, null);
+    Assert.assertNotNull(id);
+  }
+
+  @Test
+  public void createDocument() throws IOException {
+    ObjectId parentId = this.session.createObjectId(Fixture.getTestRootId());
+    String folderName = UUID.randomUUID().toString();
+    String typeId = FixtureData.DOCUMENT_TYPE_ID.value();
+
+    ObjectType ot = this.session.getTypeDefinition(typeId);
+    Collection<PropertyDefinition<?>> pdefs = ot.getPropertyDefintions().values();
+    List<Property<?>> properties = new ArrayList<Property<?>>();
+    Property<?> prop = null;
+
+    for (PropertyDefinition<?> pd : pdefs) {
+      try {
+        CmisProperties cmisp = CmisProperties.fromValue(pd.getId());
+        switch (cmisp) {
+        case NAME:
+          prop = this.session.getObjectFactory().createProperty(pd, folderName);
+          properties.add(prop);
+          break;
+        case OBJECT_TYPE_ID:
+          prop = this.session.getObjectFactory().createProperty(pd, typeId);
+          properties.add(prop);
+          break;
+        default:
+          break;
+        }
+      }
+      catch (Exception e) {
+        // custom property definition (note: document type should not have further mandatory
+        // properties)
+      }
+
+    }
+
+    String filename = UUID.randomUUID().toString();
+    String mimetype = "text/html; charset=UTF-8";
+    String content1 = "Im Walde rauscht ein Wasserfall. Wenn's nicht mehr rauscht ist's Wasser all.";
+
+    byte[] buf1 = content1.getBytes("UTF-8");
+    ByteArrayInputStream in1 = new ByteArrayInputStream(buf1);
+    ContentStream contentStream = this.session.getObjectFactory().createContentStream(filename,
+        buf1.length, mimetype, in1);
+    Assert.assertNotNull(contentStream);
+
+    ObjectId id = this.session.createDocument(properties, parentId, contentStream,
+        VersioningState.NONE, null, null, null);
+    Assert.assertNotNull(id);
+
+    // verify content (which is not supported by mock)
+    if (this.isMock()) {
+      return;  
+    }
+    Document doc = (Document) this.session.getObject(id);
+    Assert.assertNotNull(doc);
+//    Assert.assertEquals(buf1.length, doc.getContentStreamLength());
+//    Assert.assertEquals(mimetype, doc.getContentStreamMimeType());
+//    Assert.assertEquals(filename, doc.getContentStreamFileName());
+    ContentStream readStream = doc.getContentStream();
+    InputStream in2 = readStream.getStream();
+    StringBuffer sbuf = null;
+    sbuf = new StringBuffer(in2.available());
+    int count;
+    byte[] buf2 = new byte[100];
+    while ((count = in2.read(buf2)) != -1) {
+      for (int i = 0; i < count; i++) {
+        sbuf.append((char) buf2[i]);
+      }
+    }
+    in2.close();
+    String content2 = sbuf.toString();
+    Assert.assertEquals(content1, content2);
+  }
 }

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=925375&r1=925374&r2=925375&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 Fri Mar 19 18:37:21 2010
@@ -18,12 +18,15 @@
  */
 package org.apache.opencmis.client.runtime.mock;
 
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 
 import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -79,6 +82,7 @@ import org.apache.opencmis.commons.enums
 import org.apache.opencmis.commons.enums.PropertyType;
 import org.apache.opencmis.commons.enums.SessionType;
 import org.apache.opencmis.commons.enums.TypeOfChanges;
+import org.apache.opencmis.commons.enums.VersioningState;
 import org.apache.opencmis.commons.exceptions.CmisNotSupportedException;
 
 /**
@@ -86,753 +90,686 @@ import org.apache.opencmis.commons.excep
  */
 public class MockSessionFactory implements SessionFactory {
 
-	private Session mockSession;
+  private Session mockSession;
 
-	{
-		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;
-
-	/*
-	 * properties
-	 */
-	private static String PROPERTY_VALUE_STRING = "abc";
-	private static Integer PROPERTY_VALUE_INTEGER = new Integer(4711);
-	private static Boolean PROPERTY_VALUE_BOOLEAN = new Boolean(true);
-	private static Double PROPERTY_VALUE_DOUBLE = new Double(1.0);
-	private static Float PROPERTY_VALUE_FLOAT = new Float(1.0);
-	private static String PROPERTY_VALUE_ID = "xyz";
-	private static String PROPERTY_VALUE_HTML = "<html><body>html value</body></html>";
-	private static Calendar PROPERTY_VALUE_DATETIME = GregorianCalendar
-			.getInstance();
-	private static URI PROPERTY_VALUE_URI = URI.create("http://foo.com");
-
-	@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;
-	}
-
-	@SuppressWarnings("unchecked")
-	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();
-
-		String id = rootFolder.getId();
-		ObjectId objectId = createMockObjectId(id);
-		expect(session.createObjectId(id)).andReturn(objectId).anyTimes();
-
-		expect(session.getDefaultContext()).andReturn(
-				this.createMockOperationContext()).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();
-
-		if (!FixtureData.DOCUMENT_TYPE_ID.toString().equalsIgnoreCase(
-				ObjectType.DOCUMENT_BASETYPE_ID)) {
-			expect(
-					session.getTypeDefinition(FixtureData.DOCUMENT_TYPE_ID
-							.toString())).andReturn(
-					this.idTypeIndex.get(FixtureData.DOCUMENT_TYPE_ID
-							.toString())).anyTimes();
-		}
-		if (!FixtureData.FOLDER_TYPE_ID.toString().equalsIgnoreCase(
-				ObjectType.FOLDER_BASETYPE_ID)) {
-			expect(
-					session.getTypeDefinition(FixtureData.FOLDER_TYPE_ID
-							.toString()))
-					.andReturn(
-							this.idTypeIndex.get(FixtureData.FOLDER_TYPE_ID
-									.toString())).anyTimes();
-		}
-		/* document child/descendants types */
-		List<ObjectType> dtl = new ArrayList<ObjectType>();
-		dtl.add(this.idTypeIndex.get(FixtureData.DOCUMENT_TYPE_ID.toString()));
-		PagingList<ObjectType> plot = this.createMockPaging(dtl);
-		Container<ObjectType> ctdoc = this.createMockContainer(this.idTypeIndex
-				.get(FixtureData.DOCUMENT_TYPE_ID.toString()), null);
-		expect(
-				session.getTypeChildren(
-						BaseObjectTypeIds.CMIS_DOCUMENT.value(), true, 2))
-				.andReturn(plot).anyTimes();
-		expect(
-				session.getTypeDescendants(BaseObjectTypeIds.CMIS_DOCUMENT
-						.value(), 1, true)).andReturn(
-				Collections.singletonList(ctdoc)).anyTimes();
-
-		/* folder child/descendants types */
-		List<ObjectType> ftl = new ArrayList<ObjectType>();
-		ftl.add(this.idTypeIndex.get(FixtureData.FOLDER_TYPE_ID.toString()));
-		PagingList<ObjectType> plfot = this.createMockPaging(ftl);
-		Container<ObjectType> ctfolder = this.createMockContainer(
-				this.idTypeIndex.get(FixtureData.FOLDER_TYPE_ID.toString()),
-				null);
-		expect(
-				session.getTypeChildren(BaseObjectTypeIds.CMIS_FOLDER.value(),
-						true, 2)).andReturn(plfot).anyTimes();
-		expect(
-				session.getTypeDescendants(BaseObjectTypeIds.CMIS_FOLDER
-						.value(), 1, true)).andReturn(
-				Collections.singletonList(ctfolder)).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<QueryResult> queryList = new ArrayList<QueryResult>();
-		for (CmisObject cm : this.idObjectIndex.values()) {
-			queryList.add(createMockQueryResult(cm));
-		}
-		PagingList<QueryResult> plq = this.createMockPaging(queryList);
-		expect(session.query(FixtureData.QUERY.toString(), false, 2))
-				.andReturn(plq).anyTimes();
-
-		this.makeObjectsAccessible(session);
-
-		/*
-		 * WRITE SUPPORT
-		 */
-		expect(
-				session.createFolder((List<Property<?>>) anyObject(),
-						(ObjectId) anyObject(), (List<Policy>) anyObject(),
-						(List<Ace>) anyObject(), (List<Ace>) anyObject()))
-				.andReturn(this.createMockObjectId()).anyTimes();
-
-		replay(session);
-
-		return session;
-	}
-
-	private ObjectId createMockObjectId() {
-		ObjectId id = createNiceMock(ObjectId.class);
-
-		replay(id);
-
-		return id;
-	}
-
-	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);
-
-			ObjectId objectId = createMockObjectId(id);
-			expect(s.getObject(objectId)).andReturn(obj).anyTimes();
-		}
-	}
-
-	private ObjectFactory createMockObjectFactory() {
-		ObjectFactory of = createNiceMock(ObjectFactory.class);
-
-		replay(of);
-
-		return of;
-	}
-
-	private ObjectId createMockObjectId(String id) {
-		ObjectId oid = createNiceMock(ObjectId.class);
-
-		expect(oid.getId()).andReturn(id).anyTimes();
-
-		replay(oid);
-
-		return oid;
-	}
-
-	private OperationContext createMockOperationContext() {
-		OperationContext oc = createNiceMock(OperationContext.class);
-
-		replay(oc);
-
-		return oc;
-	}
-
-	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(FixtureData.FOLDER_TYPE_ID.toString()))
-				.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 + "/"
-				+ FixtureData.FOLDER1_NAME.toString(), FixtureData.FOLDER1_NAME
-				.toString()));
-		children.add(this.createMockTestFolder(f, "/"
-				+ Fixture.TEST_ROOT_FOLDER_NAME + "/"
-				+ FixtureData.FOLDER2_NAME.toString(), FixtureData.FOLDER2_NAME
-				.toString()));
-		children.add(this.createMockTestDocument(f, "/"
-				+ Fixture.TEST_ROOT_FOLDER_NAME + "/"
-				+ FixtureData.DOCUMENT1_NAME.toString(),
-				FixtureData.DOCUMENT1_NAME.toString()));
-
-		PagingList<CmisObject> pl = this.createMockPaging(children);
-		expect(f.getChildren(1)).andReturn(pl).anyTimes();
-		expect(f.getChildren(2)).andReturn(pl).anyTimes();
-		expect(f.getChildren(1000)).andReturn(pl).anyTimes();
-
-		List<Container<FileableCmisObject>> ct = new ArrayList<Container<FileableCmisObject>>();
-		Folder f1 = this.createMockTestFolder(f, "/"
-				+ FixtureData.FOLDER1_NAME.toString(), FixtureData.FOLDER1_NAME
-				.toString());
-		Folder f2 = this.createMockTestFolder(f, "/"
-				+ FixtureData.FOLDER2_NAME.toString(), FixtureData.FOLDER2_NAME
-				.toString());
-		ct.add(this.createMockContainer((FileableCmisObject) f1, null));
-		ct.add(this.createMockContainer((FileableCmisObject) f2, null));
-
-		expect(f.getDescendants(1)).andReturn(ct).anyTimes();
-		expect(f.getDescendants(2)).andReturn(ct).anyTimes();
-		expect(f.getDescendants(1000)).andReturn(ct).anyTimes();
-		expect(f.getFolderTree(1)).andReturn(ct).anyTimes();
-		expect(f.getFolderTree(2)).andReturn(ct).anyTimes();
-		expect(f.getFolderTree(1000)).andReturn(ct).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(FixtureData.PROPERTY_NAME_STRING_MULTI_VALUED
-					.toString());
-			expect(
-					o.getProperty(FixtureData.PROPERTY_NAME_STRING_MULTI_VALUED
-							.toString())).andReturn(p2).anyTimes();
-			expect(
-					o
-							.getPropertyMultivalue(FixtureData.PROPERTY_NAME_STRING_MULTI_VALUED
-									.toString())).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(MockSessionFactory.PROPERTY_VALUE_STRING).anyTimes();
-		expect(p.isMultiValued()).andReturn(true).anyTimes();
-		List<String> v = new ArrayList<String>();
-		v.add(MockSessionFactory.PROPERTY_VALUE_STRING);
-		v.add(MockSessionFactory.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(
-				MockSessionFactory.PROPERTY_VALUE_DATETIME).anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_HTML)
-				.anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_ID)
-				.anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_URI)
-				.anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_DOUBLE).anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_FLOAT)
-				.anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(
-				MockSessionFactory.PROPERTY_VALUE_BOOLEAN).anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(
-				MockSessionFactory.PROPERTY_VALUE_INTEGER).anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_STRING).anyTimes();
-		expect(p.getValueAsString()).andReturn(
-				MockSessionFactory.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(FixtureData.DOCUMENT_TYPE_ID.toString()))
-				.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.getFileName()).andReturn("file.txt").anyTimes();
-		expect(cs.getMimeType()).andReturn("text/html").anyTimes();
-		expect(cs.getLength()).andReturn((long) 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(FixtureData.FOLDER_TYPE_ID.toString()))
-				.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 + "/"
-				+ FixtureData.DOCUMENT1_NAME.toString(),
-				FixtureData.DOCUMENT1_NAME.toString()));
-		children.add(this.createMockTestDocument(f, path + "/"
-				+ FixtureData.DOCUMENT2_NAME.toString(),
-				FixtureData.DOCUMENT2_NAME.toString()));
-
-		PagingList<CmisObject> pl = this.createMockPaging(children);
-		expect(f.getChildren(null, -1)).andReturn(pl).anyTimes();
-
-		List<Container<FileableCmisObject>> ctlist = new ArrayList<Container<FileableCmisObject>>();
-		expect(f.getDescendants(-1)).andReturn(ctlist).anyTimes();
-		expect(f.getFolderTree(-1)).andReturn(ctlist).anyTimes();
-		this.createMockProperties(f);
-
-		replay(f);
-		this.idObjectIndex.put(f.getId(), f);
-
-		return f;
-	}
-
-	private QueryResult createMockQueryResult(CmisObject cmisObject) {
-		QueryResult qr = createNiceMock(QueryResult.class);
-
-		return qr;
-	}
-
-	@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;
-	}
-
-	@SuppressWarnings("unchecked")
-	private <T> Container<T> createMockContainer(T item,
-			List<Container<T>> children) {
-		Container<T> c = createNiceMock(Container.class);
-
-		expect(c.getItem()).andReturn(item).anyTimes();
-		expect(c.getChildren()).andReturn(children).anyTimes();
-
-		replay(c);
-
-		return c;
-	}
-
-	private void createMockGlobalTypes() {
-		FolderType bft = createNiceMock(FolderType.class);
-		expect(bft.getId()).andReturn(ObjectType.FOLDER_BASETYPE_ID).anyTimes();
-		expect(bft.isBaseType()).andReturn(true);
-		expect(bft.getBaseType()).andReturn(null).anyTimes();
-		expect(bft.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>())).anyTimes();
-		
-		FolderType ft = createNiceMock(FolderType.class);
-		expect(ft.getId()).andReturn(FixtureData.FOLDER_TYPE_ID.toString())
-				.anyTimes();
-		expect(ft.isBaseType()).andReturn(false);
-		expect(ft.getBaseType()).andReturn(bft).anyTimes();
-		expect(ft.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>())).anyTimes();
-
-		PolicyType bpt = createNiceMock(PolicyType.class);
-		expect(bpt.getId()).andReturn(ObjectType.POLICY_BASETYPE_ID).anyTimes();
-		expect(bpt.isBaseType()).andReturn(true);
-		expect(bpt.getBaseType()).andReturn(null).anyTimes();
-		expect(bpt.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>())).anyTimes();
-
-		RelationshipType brt = createNiceMock(RelationshipType.class);
-		expect(brt.getId()).andReturn(ObjectType.RELATIONSHIP_BASETYPE_ID)
-				.anyTimes();
-		expect(brt.isBaseType()).andReturn(true);
-		expect(brt.getBaseType()).andReturn(null).anyTimes();
-		expect(brt.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>())).anyTimes();
-
-		DocumentType bdt = createNiceMock(DocumentType.class);
-		expect(bdt.getId()).andReturn(ObjectType.DOCUMENT_BASETYPE_ID)
-				.anyTimes();
-		expect(bdt.isBaseType()).andReturn(true);
-		expect(bdt.getBaseType()).andReturn(null).anyTimes();
-		expect(bdt.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>())).anyTimes();
-
-		DocumentType dt = createNiceMock(DocumentType.class);
-		expect(dt.getId()).andReturn(FixtureData.DOCUMENT_TYPE_ID.toString())
-				.anyTimes();
-		expect(dt.isBaseType()).andReturn(false);
-		expect(dt.getBaseType()).andReturn(bft).anyTimes();
-		expect(dt.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>())).anyTimes();
-
-		replay(bft);
-		replay(ft);
-		replay(bdt);
-		replay(dt);
-		replay(bpt);
-		replay(brt);
-
-		this.idTypeIndex.put(ft.getId(), ft);
-		this.idTypeIndex.put(bft.getId(), bft); // can overwrite ft
-
-		this.idTypeIndex.put(dt.getId(), dt);
-		this.idTypeIndex.put(bdt.getId(), bdt); // can overwrite 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(FixtureData.FOLDER_TYPE_ID.toString()))
-				.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 UriProperty extends Property<URI> {
-	}
-
-	private interface BooleanProperty extends Property<Boolean> {
-	}
-
-	public List<Repository> getRepositories(Map<String, String> parameters) {
-		return null;
-	}
+  {
+    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;
+
+  /*
+   * properties
+   */
+  private static String PROPERTY_VALUE_STRING = "abc";
+  private static Integer PROPERTY_VALUE_INTEGER = new Integer(4711);
+  private static Boolean PROPERTY_VALUE_BOOLEAN = new Boolean(true);
+  private static Double PROPERTY_VALUE_DOUBLE = new Double(1.0);
+  private static Float PROPERTY_VALUE_FLOAT = new Float(1.0);
+  private static String PROPERTY_VALUE_ID = "xyz";
+  private static String PROPERTY_VALUE_HTML = "<html><body>html value</body></html>";
+  private static Calendar PROPERTY_VALUE_DATETIME = GregorianCalendar.getInstance();
+  private static URI PROPERTY_VALUE_URI = URI.create("http://foo.com");
+
+  @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;
+  }
+
+  @SuppressWarnings("unchecked")
+  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();
+
+    String id = rootFolder.getId();
+    ObjectId objectId = createMockObjectId(id);
+    expect(session.createObjectId(id)).andReturn(objectId).anyTimes();
+
+    expect(session.getDefaultContext()).andReturn(this.createMockOperationContext()).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();
+
+    if (!FixtureData.DOCUMENT_TYPE_ID.toString().equalsIgnoreCase(ObjectType.DOCUMENT_BASETYPE_ID)) {
+      expect(session.getTypeDefinition(FixtureData.DOCUMENT_TYPE_ID.toString())).andReturn(
+          this.idTypeIndex.get(FixtureData.DOCUMENT_TYPE_ID.toString())).anyTimes();
+    }
+    if (!FixtureData.FOLDER_TYPE_ID.toString().equalsIgnoreCase(ObjectType.FOLDER_BASETYPE_ID)) {
+      expect(session.getTypeDefinition(FixtureData.FOLDER_TYPE_ID.toString())).andReturn(
+          this.idTypeIndex.get(FixtureData.FOLDER_TYPE_ID.toString())).anyTimes();
+    }
+    /* document child/descendants types */
+    List<ObjectType> dtl = new ArrayList<ObjectType>();
+    dtl.add(this.idTypeIndex.get(FixtureData.DOCUMENT_TYPE_ID.toString()));
+    PagingList<ObjectType> plot = this.createMockPaging(dtl);
+    Container<ObjectType> ctdoc = this.createMockContainer(this.idTypeIndex
+        .get(FixtureData.DOCUMENT_TYPE_ID.toString()), null);
+    expect(session.getTypeChildren(BaseObjectTypeIds.CMIS_DOCUMENT.value(), true, 2)).andReturn(
+        plot).anyTimes();
+    expect(session.getTypeDescendants(BaseObjectTypeIds.CMIS_DOCUMENT.value(), 1, true)).andReturn(
+        Collections.singletonList(ctdoc)).anyTimes();
+
+    /* folder child/descendants types */
+    List<ObjectType> ftl = new ArrayList<ObjectType>();
+    ftl.add(this.idTypeIndex.get(FixtureData.FOLDER_TYPE_ID.toString()));
+    PagingList<ObjectType> plfot = this.createMockPaging(ftl);
+    Container<ObjectType> ctfolder = this.createMockContainer(this.idTypeIndex
+        .get(FixtureData.FOLDER_TYPE_ID.toString()), null);
+    expect(session.getTypeChildren(BaseObjectTypeIds.CMIS_FOLDER.value(), true, 2))
+        .andReturn(plfot).anyTimes();
+    expect(session.getTypeDescendants(BaseObjectTypeIds.CMIS_FOLDER.value(), 1, true)).andReturn(
+        Collections.singletonList(ctfolder)).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<QueryResult> queryList = new ArrayList<QueryResult>();
+    for (CmisObject cm : this.idObjectIndex.values()) {
+      queryList.add(createMockQueryResult(cm));
+    }
+    PagingList<QueryResult> plq = this.createMockPaging(queryList);
+    expect(session.query(FixtureData.QUERY.toString(), false, 2)).andReturn(plq).anyTimes();
+
+    this.makeObjectsAccessible(session);
+
+    /*
+     * WRITE SUPPORT
+     */
+    expect(
+        session.createFolder((List<Property<?>>) anyObject(), (ObjectId) anyObject(),
+            (List<Policy>) anyObject(), (List<Ace>) anyObject(), (List<Ace>) anyObject()))
+        .andReturn(this.createMockObjectId()).anyTimes();
+    expect(
+        session.createDocument((List<Property<?>>) anyObject(), (ObjectId) anyObject(),
+            (ContentStream) anyObject(), (VersioningState) anyObject(), (List<Policy>) anyObject(),
+            (List<Ace>) anyObject(), (List<Ace>) anyObject())).andReturn(this.createMockObjectId())
+        .anyTimes();
+
+    replay(session);
+
+    return session;
+  }
+
+  private ObjectId createMockObjectId() {
+    ObjectId id = createNiceMock(ObjectId.class);
+
+    replay(id);
+
+    return id;
+  }
+
+  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);
+
+      ObjectId objectId = createMockObjectId(id);
+      expect(s.getObject(objectId)).andReturn(obj).anyTimes();
+    }
+  }
+
+  private ObjectFactory createMockObjectFactory() {
+    ObjectFactory of = createNiceMock(ObjectFactory.class);
+
+    expect(
+        of.createContentStream((String) anyObject(), anyLong(), (String) anyObject(),
+            (InputStream) anyObject())).andReturn(this.createMockContentStream()).anyTimes();
+
+    replay(of);
+
+    return of;
+  }
+
+  private ObjectId createMockObjectId(String id) {
+    ObjectId oid = createNiceMock(ObjectId.class);
+
+    expect(oid.getId()).andReturn(id).anyTimes();
+
+    replay(oid);
+
+    return oid;
+  }
+
+  private OperationContext createMockOperationContext() {
+    OperationContext oc = createNiceMock(OperationContext.class);
+
+    replay(oc);
+
+    return oc;
+  }
+
+  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(FixtureData.FOLDER_TYPE_ID.toString()))
+        .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 + "/"
+        + FixtureData.FOLDER1_NAME.toString(), FixtureData.FOLDER1_NAME.toString()));
+    children.add(this.createMockTestFolder(f, "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
+        + FixtureData.FOLDER2_NAME.toString(), FixtureData.FOLDER2_NAME.toString()));
+    children.add(this.createMockTestDocument(f, "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
+        + FixtureData.DOCUMENT1_NAME.toString(), FixtureData.DOCUMENT1_NAME.toString()));
+
+    PagingList<CmisObject> pl = this.createMockPaging(children);
+    expect(f.getChildren(1)).andReturn(pl).anyTimes();
+    expect(f.getChildren(2)).andReturn(pl).anyTimes();
+    expect(f.getChildren(1000)).andReturn(pl).anyTimes();
+
+    List<Container<FileableCmisObject>> ct = new ArrayList<Container<FileableCmisObject>>();
+    Folder f1 = this.createMockTestFolder(f, "/" + FixtureData.FOLDER1_NAME.toString(),
+        FixtureData.FOLDER1_NAME.toString());
+    Folder f2 = this.createMockTestFolder(f, "/" + FixtureData.FOLDER2_NAME.toString(),
+        FixtureData.FOLDER2_NAME.toString());
+    ct.add(this.createMockContainer((FileableCmisObject) f1, null));
+    ct.add(this.createMockContainer((FileableCmisObject) f2, null));
+
+    expect(f.getDescendants(1)).andReturn(ct).anyTimes();
+    expect(f.getDescendants(2)).andReturn(ct).anyTimes();
+    expect(f.getDescendants(1000)).andReturn(ct).anyTimes();
+    expect(f.getFolderTree(1)).andReturn(ct).anyTimes();
+    expect(f.getFolderTree(2)).andReturn(ct).anyTimes();
+    expect(f.getFolderTree(1000)).andReturn(ct).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(FixtureData.PROPERTY_NAME_STRING_MULTI_VALUED
+          .toString());
+      expect(o.getProperty(FixtureData.PROPERTY_NAME_STRING_MULTI_VALUED.toString())).andReturn(p2)
+          .anyTimes();
+      expect(o.getPropertyMultivalue(FixtureData.PROPERTY_NAME_STRING_MULTI_VALUED.toString()))
+          .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(MockSessionFactory.PROPERTY_VALUE_STRING).anyTimes();
+    expect(p.isMultiValued()).andReturn(true).anyTimes();
+    List<String> v = new ArrayList<String>();
+    v.add(MockSessionFactory.PROPERTY_VALUE_STRING);
+    v.add(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_DATETIME).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_HTML).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_ID).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_URI).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_DOUBLE).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_FLOAT).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_BOOLEAN).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_INTEGER).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(MockSessionFactory.PROPERTY_VALUE_STRING).anyTimes();
+    expect(p.getValueAsString()).andReturn(MockSessionFactory.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(FixtureData.DOCUMENT_TYPE_ID.toString()))
+        .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.getFileName()).andReturn("file.txt").anyTimes();
+    expect(cs.getMimeType()).andReturn("text/html").anyTimes();
+    expect(cs.getLength()).andReturn((long) 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(FixtureData.FOLDER_TYPE_ID.toString()))
+        .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 + "/" + FixtureData.DOCUMENT1_NAME.toString(),
+        FixtureData.DOCUMENT1_NAME.toString()));
+    children.add(this.createMockTestDocument(f, path + "/" + FixtureData.DOCUMENT2_NAME.toString(),
+        FixtureData.DOCUMENT2_NAME.toString()));
+
+    PagingList<CmisObject> pl = this.createMockPaging(children);
+    expect(f.getChildren(null, -1)).andReturn(pl).anyTimes();
+
+    List<Container<FileableCmisObject>> ctlist = new ArrayList<Container<FileableCmisObject>>();
+    expect(f.getDescendants(-1)).andReturn(ctlist).anyTimes();
+    expect(f.getFolderTree(-1)).andReturn(ctlist).anyTimes();
+    this.createMockProperties(f);
+
+    replay(f);
+    this.idObjectIndex.put(f.getId(), f);
+
+    return f;
+  }
+
+  private QueryResult createMockQueryResult(CmisObject cmisObject) {
+    QueryResult qr = createNiceMock(QueryResult.class);
+
+    return qr;
+  }
+
+  @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;
+  }
+
+  @SuppressWarnings("unchecked")
+  private <T> Container<T> createMockContainer(T item, List<Container<T>> children) {
+    Container<T> c = createNiceMock(Container.class);
+
+    expect(c.getItem()).andReturn(item).anyTimes();
+    expect(c.getChildren()).andReturn(children).anyTimes();
+
+    replay(c);
+
+    return c;
+  }
+
+  private void createMockGlobalTypes() {
+    FolderType bft = createNiceMock(FolderType.class);
+    expect(bft.getId()).andReturn(ObjectType.FOLDER_BASETYPE_ID).anyTimes();
+    expect(bft.isBaseType()).andReturn(true);
+    expect(bft.getBaseType()).andReturn(null).anyTimes();
+    expect(bft.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>()))
+        .anyTimes();
+
+    FolderType ft = createNiceMock(FolderType.class);
+    expect(ft.getId()).andReturn(FixtureData.FOLDER_TYPE_ID.toString()).anyTimes();
+    expect(ft.isBaseType()).andReturn(false);
+    expect(ft.getBaseType()).andReturn(bft).anyTimes();
+    expect(ft.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>()))
+        .anyTimes();
+
+    PolicyType bpt = createNiceMock(PolicyType.class);
+    expect(bpt.getId()).andReturn(ObjectType.POLICY_BASETYPE_ID).anyTimes();
+    expect(bpt.isBaseType()).andReturn(true);
+    expect(bpt.getBaseType()).andReturn(null).anyTimes();
+    expect(bpt.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>()))
+        .anyTimes();
+
+    RelationshipType brt = createNiceMock(RelationshipType.class);
+    expect(brt.getId()).andReturn(ObjectType.RELATIONSHIP_BASETYPE_ID).anyTimes();
+    expect(brt.isBaseType()).andReturn(true);
+    expect(brt.getBaseType()).andReturn(null).anyTimes();
+    expect(brt.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>()))
+        .anyTimes();
+
+    DocumentType bdt = createNiceMock(DocumentType.class);
+    expect(bdt.getId()).andReturn(ObjectType.DOCUMENT_BASETYPE_ID).anyTimes();
+    expect(bdt.isBaseType()).andReturn(true);
+    expect(bdt.getBaseType()).andReturn(null).anyTimes();
+    expect(bdt.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>()))
+        .anyTimes();
+
+    DocumentType dt = createNiceMock(DocumentType.class);
+    expect(dt.getId()).andReturn(FixtureData.DOCUMENT_TYPE_ID.toString()).anyTimes();
+    expect(dt.isBaseType()).andReturn(false);
+    expect(dt.getBaseType()).andReturn(bft).anyTimes();
+    expect(dt.getPropertyDefintions()).andReturn((new HashMap<String, PropertyDefinition<?>>()))
+        .anyTimes();
+
+    replay(bft);
+    replay(ft);
+    replay(bdt);
+    replay(dt);
+    replay(bpt);
+    replay(brt);
+
+    this.idTypeIndex.put(ft.getId(), ft);
+    this.idTypeIndex.put(bft.getId(), bft); // can overwrite ft
+
+    this.idTypeIndex.put(dt.getId(), dt);
+    this.idTypeIndex.put(bdt.getId(), bdt); // can overwrite 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(FixtureData.FOLDER_TYPE_ID.toString()))
+        .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 UriProperty extends Property<URI> {
+  }
+
+  private interface BooleanProperty extends Property<Boolean> {
+  }
+
+  public List<Repository> getRepositories(Map<String, String> parameters) {
+    return null;
+  }
 
 }



Mime
View raw message