You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2010/04/16 16:00:25 UTC

svn commit: r934878 [9/13] - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/ main/java/org/apache/chemistry/opencmis/inmemory/clientprovider/ mai...

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTst.java Fri Apr 16 14:00:23 2010
@@ -43,322 +43,332 @@ import org.apache.chemistry.opencmis.inm
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public class AbstractServiceTst /* extends TestCase*/ {
-  private static Log LOG = LogFactory.getLog(AbstractServiceTst.class);
-  protected static final String REPOSITORY_ID = "UnitTestRepository";
-  protected BindingsObjectFactory fFactory = new BindingsObjectFactoryImpl();
-  protected String fRootFolderId;
-  protected String fRepositoryId;
-  protected ObjectService fObjSvc;
-  protected NavigationService fNavSvc;
-  protected RepositoryService fRepSvc;
-  protected VersioningService fVerSvc;
-  protected MultiFilingService fMultiSvc;
-  protected DummyCallContext fTestCallContext;
-  private String fTypeCreatorClassName;
-  private boolean fUseClientProviderInterface;
-
-  public AbstractServiceTst() {
-    // The in-memory server unit tests can either be run directly against the
-    // service implementation or against a client provider interface. The client
-    // provider interfaces offers some benefits like type system caching etc
-    // The default is using the direct implementation. Subclasses may override
-    // this behavior
-    fUseClientProviderInterface = false;
-      // Init with default types, can be overridden by subclasses:
-    fTypeCreatorClassName = UnitTestTypeSystemCreator.class.getName();
-  }
-
-  // Subclasses may want to use their own types
-  protected void setTypeCreatorClass(String typeCreatorClassName) {
-    fTypeCreatorClassName = typeCreatorClassName;
-  }
-
-  protected void setUp() throws Exception {
-    //super.setUp();
-    LOG.debug("Initializing InMemory Test with type creator class: " + fTypeCreatorClassName);
-    Map<String, String> parameters = new HashMap<String, String>();
-    parameters.put(SessionParameter.BINDING_SPI_CLASS, CmisBindingFactory.BINDING_SPI_INMEMORY);
-    // attach TypeSystem to the session
-
-    // attach repository info to the session:
-    parameters.put(ConfigConstants.TYPE_CREATOR_CLASS, fTypeCreatorClassName);
-    parameters.put(ConfigConstants.REPOSITORY_ID, REPOSITORY_ID);
-
-    // attach repository info to the session:
-    parameters
-        .put(ConfigConstants.REPOSITORY_INFO_CREATOR_CLASS, UnitTestRepositoryInfo.class.getName());
-
-    // give subclasses a chance to provide additional parameters for special tests
-    addParameters(parameters);
-
-    fTestCallContext = new DummyCallContext();
-    // Attach a standatrd CallContext to a thread before the services are initialized.
-    RuntimeContext.attachCfg(fTestCallContext);
-
-    if (fUseClientProviderInterface)
-      initializeUsingClientProvider(parameters);
-    else
-      initializeDirect(parameters);
-
-    assertNotNull(fRepSvc);
-    assertNotNull(fObjSvc);
-    assertNotNull(fNavSvc);
-
-    RepositoryInfo rep = fRepSvc.getRepositoryInfo(REPOSITORY_ID, null);
-    fRootFolderId = rep.getRootFolderId();
-    fRepositoryId = rep.getId();
-
-    assertNotNull(fRepositoryId);
-    assertNotNull(fRootFolderId);
-  }
-
-  // Override this method in subclasses if you want to provide additional configuration
-  // parameters. Default implementation is empty
-  protected void addParameters(Map<String, String> parameters) {
-  }
-
-  protected void tearDown() throws Exception {
-    // super.tearDown();
-  }
-
-  public void testDummy() {
-    // dummy test to make tools happy that complain if there are no tests available in a test class
-  }
-
-  protected String createFolder(String folderName, String parentFolderId, String typeId) {
-    Properties props = createFolderProperties(folderName, typeId);
-    String id = null;
-    try {
-      id = fObjSvc.createFolder(fRepositoryId, props, parentFolderId, null, null, null, null);
-      if (null == id)
-        fail("createFolder failed.");
-    } catch (Exception e) {
-      fail("createFolder() failed with exception: " + e);
-    }
-    return id;
-  }
-
-  protected String createDocument(String name, String folderId, String typeId, VersioningState versioningState, boolean withContent) {
-    ContentStream contentStream = null;
-    List<String> policies = null;
-    Acl addACEs = null;
-    Acl removeACEs = null;
-    ExtensionsData extension = null;
-
-    Properties props = createDocumentProperties(name, typeId);
-
-    if (withContent)
-      contentStream = createContent();
-
-    String id = null;
-    try {
-      id = fObjSvc.createDocument(fRepositoryId, props, folderId, contentStream, versioningState,
-          policies, addACEs, removeACEs, extension);
-      if (null == id)
-        fail("createDocument failed.");
-    } catch (Exception e) {
-      fail("createDocument() failed with exception: " + e);
-    }
-    return id;
-
-  }
-  protected String createDocument(String name, String folderId, String typeId, boolean withContent) {
-    VersioningState versioningState = VersioningState.NONE;
-    return createDocument(name, folderId, typeId, versioningState, withContent);
-  }
-
-  protected Properties createDocumentProperties(String name, String typeId) {
-    List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
-    properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, name));
-    properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, typeId));
-    Properties props = fFactory.createPropertiesData(properties);
-    return props;
-  }
-
-  protected Properties createFolderProperties(String folderName, String typeId) {
-    List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
-    properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, folderName));
-    properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, typeId));
-    Properties props = fFactory.createPropertiesData(properties);
-    return props;
-  }
-
-  protected ContentStream createContent() {
-    ContentStreamDataImpl content = new ContentStreamDataImpl();
-    content.setFileName("data.txt");
-    content.setMimeType("text/plain");
-    int len = 32 * 1024;
-    byte[] b = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
-                0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a,
-                0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
-                0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a
-                }; // 32 Bytes
-    ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
-    try {
-      for (int i=0; i<1024; i++)
-        ba.write(b);
-      content.setContent(new ByteArrayInputStream(ba.toByteArray()));
-    } catch (IOException e) {
-        throw new RuntimeException("Failed to fill content stream with data", e) ;
-    }
-    return content;
-  }
-
-  protected ContentStream createContent(char ch) {
-    ContentStreamDataImpl content = new ContentStreamDataImpl();
-    content.setFileName("data.txt");
-    content.setMimeType("text/plain");
-    int len = 32 * 1024;
-    byte[] b = new byte[32];
-    for (int i=0; i<32; i++)
-      b[i] = (byte) Character.getNumericValue(ch);
-    ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
-    try {
-      for (int i=0; i<1024; i++)
-        ba.write(b);
-      content.setContent(new ByteArrayInputStream(ba.toByteArray()));
-    } catch (IOException e) {
-        throw new RuntimeException("Failed to fill content stream with data", e) ;
-    }
-    return content;
-  }
-  protected void verifyContentResult(ContentStream sd) {
-    assertEquals("text/plain", sd.getMimeType());
-    assertEquals("data.txt", sd.getFileName());
-    assertEquals(32 * 1024, sd.getBigLength().longValue());
-    byte[] ba = new byte[32];
-    InputStream is = sd.getStream();
-    int counter = 0;
-    try {
-      while (is.read(ba) == ba.length) {
-        ++counter;
-        assertEquals(0x61, ba[0]);
-        assertEquals(0x6e, ba[29]);
-        assertEquals(0x0c, ba[30]);
-        assertEquals(0x0a, ba[31]);
-      }
-    }
-    catch (IOException e) {
-      fail("reading from content stream failed");
-    }
-    assertEquals(1024, counter);
-  }
-
-  protected String getByPath(String id, String path) {
-    ObjectData res = null;
-    try {
-      res = fObjSvc.getObjectByPath(fRepositoryId, path, "*", false, IncludeRelationships.NONE,
-          null, false, false, null);
-      assertNotNull(res);
-      assertEquals(id, res.getId());
-    } catch (Exception e) {
-      fail("getObject() failed with exception: " + e);
-    }
-    return res.getId();
-  }
-
-  @SuppressWarnings("unchecked")
-  protected String getPathOfFolder(String id) {
-    String path=null;
-    try {
-      String filter = PropertyIds.PATH;
-      Properties res = fObjSvc.getProperties(fRepositoryId, id, filter, null);
-      assertNotNull(res);
-      PropertyData<String> pd = (PropertyData<String>) res.getProperties().get(PropertyIds.PATH);
-      assertNotNull(pd);
-      path = pd.getFirstValue();
-      assertNotNull(path);
-    } catch (Exception e) {
-      fail("getProperties() failed with exception: " + e);
-    }
-    return path;
-  }
-
-  @SuppressWarnings("unchecked")
-  protected String getPathOfDocument(String id) {
-    String path=null;
-    String filter = "*";
-    List<ObjectParentData> parentData = fNavSvc.getObjectParents(fRepositoryId, id, filter, false, IncludeRelationships.NONE, null, true, null);
-    String name = parentData.get(0).getRelativePathSegment();
-    PropertyData<String> pd = (PropertyData<String>) parentData.get(0).getObject().getProperties().getProperties().get(PropertyIds.PATH);
-    assertNotNull(pd);
-    path = pd.getFirstValue() + "/" + name;
-    return path;
-  }
-
-  protected ObjectData getDocumentObjectData(String id) {
-    ObjectData res = null;
-    try {
-      String returnedId=null;
-      res = fObjSvc.getObject(fRepositoryId, id, "*", false, IncludeRelationships.NONE,
-          null, false, false, null);
-      assertNotNull(res);
-      returnedId = res.getId();
-      testReturnedProperties(returnedId, res.getProperties().getProperties());
-      assertEquals(id, returnedId);
-    } catch (Exception e) {
-      fail("getObject() failed with exception: " + e);
-    }
-    return res;
-  }
-
-  protected String getDocument(String id) {
-    ObjectData res = getDocumentObjectData(id);
-    assertNotNull(res);
-    return res.getId();
-  }
-
-  protected void testReturnedProperties(String objectId, Map<String, PropertyData<?>> props) {
-    for (PropertyData<?> pd : props.values()) {
-      LOG.debug("return property id: " + pd.getId() + ", value: " + pd.getValues());
-    }
-
-    PropertyData<?> pd = props.get(PropertyIds.OBJECT_ID);
-    assertNotNull(pd);
-    assertEquals(objectId, pd.getFirstValue());
-  }
-
-
-  /**
-   * Instantiates the services by using directly the service implementations.
-   * @param parameters
-   *    configuration parameters for client provider interface and in-memory provider
-   */
-  private void initializeDirect(Map<String, String> parameters) {
-    CmisInMemoryProvider inMemSpi = new CmisInMemoryProvider(parameters);
-    fRepSvc = inMemSpi.getRepositoryService();
-    fObjSvc = inMemSpi.getObjectService();
-    fNavSvc = inMemSpi.getNavigationService();
-    fVerSvc = inMemSpi.getVersioningService();
-    fMultiSvc = inMemSpi.getMultiFilingService();
-  }
-
-  /**
-   * Instantiates the services by using the client provider interface.
-   * @param parameters
-   *    configuration parameters for client provider interface and in-memory provider
-   */
-  private void initializeUsingClientProvider(Map<String, String> parameters) {
-      CmisBinding provider;
-
-    // get factory and create provider
-    CmisBindingFactory factory = CmisBindingFactory.newInstance();
-    provider = factory.createCmisBinding(parameters);
-    assertNotNull(provider);
-    fFactory = provider.getObjectFactory();
-    fRepSvc = provider.getRepositoryService();
-    fObjSvc = provider.getObjectService();
-    fNavSvc = provider.getNavigationService();
-    fVerSvc = provider.getVersioningService();
-    fMultiSvc = provider.getMultiFilingService();
-  }
-
-  protected String getStringProperty(ObjectData objData, String propertyKey) {
-    PropertyData<? extends Object> pd = (PropertyData<? extends Object>) objData.getProperties()
-        .getProperties().get(PropertyIds.PATH);
-    assertNotNull(pd.getFirstValue());
-    assertTrue(pd.getFirstValue() instanceof String);
-    return (String)pd.getFirstValue();
-  }
+public class AbstractServiceTst /* extends TestCase */{
+	private static Log LOG = LogFactory.getLog(AbstractServiceTst.class);
+	protected static final String REPOSITORY_ID = "UnitTestRepository";
+	protected BindingsObjectFactory fFactory = new BindingsObjectFactoryImpl();
+	protected String fRootFolderId;
+	protected String fRepositoryId;
+	protected ObjectService fObjSvc;
+	protected NavigationService fNavSvc;
+	protected RepositoryService fRepSvc;
+	protected VersioningService fVerSvc;
+	protected MultiFilingService fMultiSvc;
+	protected DummyCallContext fTestCallContext;
+	private String fTypeCreatorClassName;
+	private boolean fUseClientProviderInterface;
+
+	public AbstractServiceTst() {
+		// The in-memory server unit tests can either be run directly against
+		// the
+		// service implementation or against a client provider interface. The
+		// client
+		// provider interfaces offers some benefits like type system caching etc
+		// The default is using the direct implementation. Subclasses may
+		// override
+		// this behavior
+		fUseClientProviderInterface = false;
+		// Init with default types, can be overridden by subclasses:
+		fTypeCreatorClassName = UnitTestTypeSystemCreator.class.getName();
+	}
+
+	// Subclasses may want to use their own types
+	protected void setTypeCreatorClass(String typeCreatorClassName) {
+		fTypeCreatorClassName = typeCreatorClassName;
+	}
+
+	protected void setUp() throws Exception {
+		// super.setUp();
+		LOG.debug("Initializing InMemory Test with type creator class: " + fTypeCreatorClassName);
+		Map<String, String> parameters = new HashMap<String, String>();
+		parameters.put(SessionParameter.BINDING_SPI_CLASS, CmisBindingFactory.BINDING_SPI_INMEMORY);
+		// attach TypeSystem to the session
+
+		// attach repository info to the session:
+		parameters.put(ConfigConstants.TYPE_CREATOR_CLASS, fTypeCreatorClassName);
+		parameters.put(ConfigConstants.REPOSITORY_ID, REPOSITORY_ID);
+
+		// attach repository info to the session:
+		parameters.put(ConfigConstants.REPOSITORY_INFO_CREATOR_CLASS, UnitTestRepositoryInfo.class.getName());
+
+		// give subclasses a chance to provide additional parameters for special
+		// tests
+		addParameters(parameters);
+
+		fTestCallContext = new DummyCallContext();
+		// Attach a standatrd CallContext to a thread before the services are
+		// initialized.
+		RuntimeContext.attachCfg(fTestCallContext);
+
+		if (fUseClientProviderInterface)
+			initializeUsingClientProvider(parameters);
+		else
+			initializeDirect(parameters);
+
+		assertNotNull(fRepSvc);
+		assertNotNull(fObjSvc);
+		assertNotNull(fNavSvc);
+
+		RepositoryInfo rep = fRepSvc.getRepositoryInfo(REPOSITORY_ID, null);
+		fRootFolderId = rep.getRootFolderId();
+		fRepositoryId = rep.getId();
+
+		assertNotNull(fRepositoryId);
+		assertNotNull(fRootFolderId);
+	}
+
+	// Override this method in subclasses if you want to provide additional
+	// configuration
+	// parameters. Default implementation is empty
+	protected void addParameters(Map<String, String> parameters) {
+	}
+
+	protected void tearDown() throws Exception {
+		// super.tearDown();
+	}
+
+	public void testDummy() {
+		// dummy test to make tools happy that complain if there are no tests
+		// available in a test class
+	}
+
+	protected String createFolder(String folderName, String parentFolderId, String typeId) {
+		Properties props = createFolderProperties(folderName, typeId);
+		String id = null;
+		try {
+			id = fObjSvc.createFolder(fRepositoryId, props, parentFolderId, null, null, null, null);
+			if (null == id)
+				fail("createFolder failed.");
+		} catch (Exception e) {
+			fail("createFolder() failed with exception: " + e);
+		}
+		return id;
+	}
+
+	protected String createDocument(String name, String folderId, String typeId, VersioningState versioningState,
+			boolean withContent) {
+		ContentStream contentStream = null;
+		List<String> policies = null;
+		Acl addACEs = null;
+		Acl removeACEs = null;
+		ExtensionsData extension = null;
+
+		Properties props = createDocumentProperties(name, typeId);
+
+		if (withContent)
+			contentStream = createContent();
+
+		String id = null;
+		try {
+			id = fObjSvc.createDocument(fRepositoryId, props, folderId, contentStream, versioningState, policies,
+					addACEs, removeACEs, extension);
+			if (null == id)
+				fail("createDocument failed.");
+		} catch (Exception e) {
+			fail("createDocument() failed with exception: " + e);
+		}
+		return id;
+
+	}
+
+	protected String createDocument(String name, String folderId, String typeId, boolean withContent) {
+		VersioningState versioningState = VersioningState.NONE;
+		return createDocument(name, folderId, typeId, versioningState, withContent);
+	}
+
+	protected Properties createDocumentProperties(String name, String typeId) {
+		List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+		properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, name));
+		properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, typeId));
+		Properties props = fFactory.createPropertiesData(properties);
+		return props;
+	}
+
+	protected Properties createFolderProperties(String folderName, String typeId) {
+		List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+		properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, folderName));
+		properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, typeId));
+		Properties props = fFactory.createPropertiesData(properties);
+		return props;
+	}
+
+	protected ContentStream createContent() {
+		ContentStreamDataImpl content = new ContentStreamDataImpl();
+		content.setFileName("data.txt");
+		content.setMimeType("text/plain");
+		int len = 32 * 1024;
+		byte[] b = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a,
+				0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a }; // 32
+																													// Bytes
+		ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
+		try {
+			for (int i = 0; i < 1024; i++)
+				ba.write(b);
+			content.setContent(new ByteArrayInputStream(ba.toByteArray()));
+		} catch (IOException e) {
+			throw new RuntimeException("Failed to fill content stream with data", e);
+		}
+		return content;
+	}
+
+	protected ContentStream createContent(char ch) {
+		ContentStreamDataImpl content = new ContentStreamDataImpl();
+		content.setFileName("data.txt");
+		content.setMimeType("text/plain");
+		int len = 32 * 1024;
+		byte[] b = new byte[32];
+		for (int i = 0; i < 32; i++)
+			b[i] = (byte) Character.getNumericValue(ch);
+		ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
+		try {
+			for (int i = 0; i < 1024; i++)
+				ba.write(b);
+			content.setContent(new ByteArrayInputStream(ba.toByteArray()));
+		} catch (IOException e) {
+			throw new RuntimeException("Failed to fill content stream with data", e);
+		}
+		return content;
+	}
+
+	protected void verifyContentResult(ContentStream sd) {
+		assertEquals("text/plain", sd.getMimeType());
+		assertEquals("data.txt", sd.getFileName());
+		assertEquals(32 * 1024, sd.getBigLength().longValue());
+		byte[] ba = new byte[32];
+		InputStream is = sd.getStream();
+		int counter = 0;
+		try {
+			while (is.read(ba) == ba.length) {
+				++counter;
+				assertEquals(0x61, ba[0]);
+				assertEquals(0x6e, ba[29]);
+				assertEquals(0x0c, ba[30]);
+				assertEquals(0x0a, ba[31]);
+			}
+		} catch (IOException e) {
+			fail("reading from content stream failed");
+		}
+		assertEquals(1024, counter);
+	}
+
+	protected String getByPath(String id, String path) {
+		ObjectData res = null;
+		try {
+			res = fObjSvc.getObjectByPath(fRepositoryId, path, "*", false, IncludeRelationships.NONE, null, false,
+					false, null);
+			assertNotNull(res);
+			assertEquals(id, res.getId());
+		} catch (Exception e) {
+			fail("getObject() failed with exception: " + e);
+		}
+		return res.getId();
+	}
+
+	@SuppressWarnings("unchecked")
+	protected String getPathOfFolder(String id) {
+		String path = null;
+		try {
+			String filter = PropertyIds.PATH;
+			Properties res = fObjSvc.getProperties(fRepositoryId, id, filter, null);
+			assertNotNull(res);
+			PropertyData<String> pd = (PropertyData<String>) res.getProperties().get(PropertyIds.PATH);
+			assertNotNull(pd);
+			path = pd.getFirstValue();
+			assertNotNull(path);
+		} catch (Exception e) {
+			fail("getProperties() failed with exception: " + e);
+		}
+		return path;
+	}
+
+	@SuppressWarnings("unchecked")
+	protected String getPathOfDocument(String id) {
+		String path = null;
+		String filter = "*";
+		List<ObjectParentData> parentData = fNavSvc.getObjectParents(fRepositoryId, id, filter, false,
+				IncludeRelationships.NONE, null, true, null);
+		String name = parentData.get(0).getRelativePathSegment();
+		PropertyData<String> pd = (PropertyData<String>) parentData.get(0).getObject().getProperties().getProperties()
+				.get(PropertyIds.PATH);
+		assertNotNull(pd);
+		path = pd.getFirstValue() + "/" + name;
+		return path;
+	}
+
+	protected ObjectData getDocumentObjectData(String id) {
+		ObjectData res = null;
+		try {
+			String returnedId = null;
+			res = fObjSvc.getObject(fRepositoryId, id, "*", false, IncludeRelationships.NONE, null, false, false, null);
+			assertNotNull(res);
+			returnedId = res.getId();
+			testReturnedProperties(returnedId, res.getProperties().getProperties());
+			assertEquals(id, returnedId);
+		} catch (Exception e) {
+			fail("getObject() failed with exception: " + e);
+		}
+		return res;
+	}
+
+	protected String getDocument(String id) {
+		ObjectData res = getDocumentObjectData(id);
+		assertNotNull(res);
+		return res.getId();
+	}
+
+	protected void testReturnedProperties(String objectId, Map<String, PropertyData<?>> props) {
+		for (PropertyData<?> pd : props.values()) {
+			LOG.debug("return property id: " + pd.getId() + ", value: " + pd.getValues());
+		}
+
+		PropertyData<?> pd = props.get(PropertyIds.OBJECT_ID);
+		assertNotNull(pd);
+		assertEquals(objectId, pd.getFirstValue());
+	}
+
+	/**
+	 * Instantiates the services by using directly the service implementations.
+	 * 
+	 * @param parameters
+	 *            configuration parameters for client provider interface and
+	 *            in-memory provider
+	 */
+	private void initializeDirect(Map<String, String> parameters) {
+		CmisInMemoryProvider inMemSpi = new CmisInMemoryProvider(parameters);
+		fRepSvc = inMemSpi.getRepositoryService();
+		fObjSvc = inMemSpi.getObjectService();
+		fNavSvc = inMemSpi.getNavigationService();
+		fVerSvc = inMemSpi.getVersioningService();
+		fMultiSvc = inMemSpi.getMultiFilingService();
+	}
+
+	/**
+	 * Instantiates the services by using the client provider interface.
+	 * 
+	 * @param parameters
+	 *            configuration parameters for client provider interface and
+	 *            in-memory provider
+	 */
+	private void initializeUsingClientProvider(Map<String, String> parameters) {
+		CmisBinding provider;
+
+		// get factory and create provider
+		CmisBindingFactory factory = CmisBindingFactory.newInstance();
+		provider = factory.createCmisBinding(parameters);
+		assertNotNull(provider);
+		fFactory = provider.getObjectFactory();
+		fRepSvc = provider.getRepositoryService();
+		fObjSvc = provider.getObjectService();
+		fNavSvc = provider.getNavigationService();
+		fVerSvc = provider.getVersioningService();
+		fMultiSvc = provider.getMultiFilingService();
+	}
+
+	protected String getStringProperty(ObjectData objData, String propertyKey) {
+		PropertyData<? extends Object> pd = (PropertyData<? extends Object>) objData.getProperties().getProperties()
+				.get(PropertyIds.PATH);
+		assertNotNull(pd.getFirstValue());
+		assertTrue(pd.getFirstValue() instanceof String);
+		return (String) pd.getFirstValue();
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/FolderTest.java Fri Apr 16 14:00:23 2010
@@ -36,145 +36,145 @@ import org.junit.Test;
  * @author Jens
  */
 
-/* Some test directly against the in-memory folder object
- * 
+/*
+ * Some test directly against the in-memory folder object
  */
 
-public class FolderTest  extends TestCase {
-  
-  private ObjectStore fStore;
-  private FolderImpl fRoot;
-  private FolderImpl f1;
-  private FolderImpl f2;
-  private FolderImpl f3;
-  private FolderImpl f4;
-  private FolderImpl f11;
-  private static final String TEST_REPOSITORY_ID = "TestRepositoryId";
-
-  @Before
-  protected void setUp() throws Exception {
-    fStore = new ObjectStoreImpl(TEST_REPOSITORY_ID);
-    createFolders();
-  }
-    
-  @Test
-  public void testCreatAndGetFolders() {
-    try {
-      Folder childFolder = fStore.createFolder("Folder 1");
-      fRoot.addChildFolder(childFolder);
-      fail("Should throw exception if folder already exists.");
-    } catch (Exception e) {
-    }
-    assertEquals(f1.getName(), "Folder 1");
-    assertEquals(f11.getName(), "Folder 1.1");
-    assertNull(fRoot.getParent());
-    assertEquals(fRoot, f1.getParent());
-    assertEquals(f1, f11.getParent());
-    assertEquals(Filing.PATH_SEPARATOR, fRoot.getPath());
-    assertEquals("/Folder 1", f1.getPath());
-    assertEquals("/Folder 1/Folder 1.1", f11.getPath());
-    StoredObject fTest = fStore.getObjectByPath("/");
-    assertEquals(fRoot, fTest);
-    fTest = fStore.getObjectByPath("/Folder 1");
-    assertEquals(f1, fTest);
-    fTest = fStore.getObjectByPath("/Folder 1/Folder 1.1");
-    assertEquals(f11, fTest); 
-    List<StoredObject> subFolders = fRoot.getChildren(-1, -1);
-    assertEquals(4, subFolders.size()); 
-    subFolders = f2.getChildren(-1, -1);
-    assertEquals(0, subFolders.size()); 
-    subFolders = f1.getChildren(-1, -1);
-    assertEquals(1, subFolders.size()); 
-  }
-
-  @Test
-  public void testRenameFolder() {
-    // rename top level folder
-    String newName = "Folder B";
-    String oldPath = f2.getPath();
-    f2.rename(newName);
-    assertEquals(f2.getName(), newName);
-    assertEquals(f2.getPath(), Filing.PATH_SEPARATOR + newName);
-    assertNull(fStore.getObjectByPath(oldPath));
-    assertEquals(f2, fStore.getObjectByPath(Filing.PATH_SEPARATOR + newName));
-    try {
-      f2.rename("Folder 3");
-      fail("Should not allow to rename a folder to an existing name");
-    } catch (Exception e) {      
-    }
-    
-    // rename sub folder
-    oldPath = f11.getPath();
-    f11.rename(newName);
-    assertEquals(f11.getName(), newName);
-    assertEquals(f11.getPath(), "/Folder 1/Folder B");
-    assertNull(fStore.getObjectByPath(oldPath));
-    assertEquals(f11, fStore.getObjectByPath("/Folder 1/Folder B"));
-    try {
-      f2.rename(newName);
-      fail("Should not allow to rename a folder to an existing name");
-    } catch (Exception e) {      
-    }
-    try {
-      f2.rename("illegal/name");
-      fail("Should not allow to rename a folder to a name with illegal name");
-    } catch (Exception e) {      
-    }
-    
-    // rename root folder
-    try {
-      fRoot.rename("abc");
-      fail("Should not be possible to rename root folder");
-    } catch (Exception e) {      
-    }    
-  }
-  
-  @Test
-  public void testMoveFolder() {
-    String oldPath = f1.getPath();
-    Folder f1Parent = f1.getParent();
-    f1.move(f1Parent, f3);
-    assertNull(fStore.getObjectByPath(oldPath));
-    assertEquals(f1.getPath(), "/Folder 3/Folder 1");
-    assertEquals(f1, fStore.getObjectByPath("/Folder 3/Folder 1"));
-    
-    f2.rename("Folder 1");
-    try {
-      Folder f2Parent = f2.getParent();
-      f2.move(f2Parent, f3);
-      fail("Should not be possible to move folder to a folder that has a child with same name");
-    } catch (Exception e) {            
-    }
-  }
-  
-  @Test
-  public void testDeleteFolder() {
-    String oldPath = f2.getPath();
-    fStore.deleteObject(f2.getId());
-    assertNull(fStore.getObjectByPath(oldPath));
-
-    try {
-      fStore.deleteObject(f1.getId());
-      fail("Should not be possible to move folder that has children");
-    } catch (Exception e) {            
-    }
-  }
-
-  private void createFolders() {
-    fRoot = (FolderImpl)fStore.getRootFolder();
-    f1 = (FolderImpl) fStore.createFolder("Folder 1");
-    fRoot.addChildFolder(f1);
-    
-    f2 =  (FolderImpl) fStore.createFolder("Folder 2");
-    fRoot.addChildFolder(f2);
-    
-    f3 =  (FolderImpl) fStore.createFolder("Folder 3");
-    fRoot.addChildFolder(f3);
-
-    f4 =  (FolderImpl) fStore.createFolder("Folder 4");
-    fRoot.addChildFolder(f4);
-
-    f11 =  (FolderImpl) fStore.createFolder("Folder 1.1");
-    f1.addChildFolder(f11);
-  }
+public class FolderTest extends TestCase {
+
+	private ObjectStore fStore;
+	private FolderImpl fRoot;
+	private FolderImpl f1;
+	private FolderImpl f2;
+	private FolderImpl f3;
+	private FolderImpl f4;
+	private FolderImpl f11;
+	private static final String TEST_REPOSITORY_ID = "TestRepositoryId";
+
+	@Before
+	protected void setUp() throws Exception {
+		fStore = new ObjectStoreImpl(TEST_REPOSITORY_ID);
+		createFolders();
+	}
+
+	@Test
+	public void testCreatAndGetFolders() {
+		try {
+			Folder childFolder = fStore.createFolder("Folder 1");
+			fRoot.addChildFolder(childFolder);
+			fail("Should throw exception if folder already exists.");
+		} catch (Exception e) {
+		}
+		assertEquals(f1.getName(), "Folder 1");
+		assertEquals(f11.getName(), "Folder 1.1");
+		assertNull(fRoot.getParent());
+		assertEquals(fRoot, f1.getParent());
+		assertEquals(f1, f11.getParent());
+		assertEquals(Filing.PATH_SEPARATOR, fRoot.getPath());
+		assertEquals("/Folder 1", f1.getPath());
+		assertEquals("/Folder 1/Folder 1.1", f11.getPath());
+		StoredObject fTest = fStore.getObjectByPath("/");
+		assertEquals(fRoot, fTest);
+		fTest = fStore.getObjectByPath("/Folder 1");
+		assertEquals(f1, fTest);
+		fTest = fStore.getObjectByPath("/Folder 1/Folder 1.1");
+		assertEquals(f11, fTest);
+		List<StoredObject> subFolders = fRoot.getChildren(-1, -1);
+		assertEquals(4, subFolders.size());
+		subFolders = f2.getChildren(-1, -1);
+		assertEquals(0, subFolders.size());
+		subFolders = f1.getChildren(-1, -1);
+		assertEquals(1, subFolders.size());
+	}
+
+	@Test
+	public void testRenameFolder() {
+		// rename top level folder
+		String newName = "Folder B";
+		String oldPath = f2.getPath();
+		f2.rename(newName);
+		assertEquals(f2.getName(), newName);
+		assertEquals(f2.getPath(), Filing.PATH_SEPARATOR + newName);
+		assertNull(fStore.getObjectByPath(oldPath));
+		assertEquals(f2, fStore.getObjectByPath(Filing.PATH_SEPARATOR + newName));
+		try {
+			f2.rename("Folder 3");
+			fail("Should not allow to rename a folder to an existing name");
+		} catch (Exception e) {
+		}
+
+		// rename sub folder
+		oldPath = f11.getPath();
+		f11.rename(newName);
+		assertEquals(f11.getName(), newName);
+		assertEquals(f11.getPath(), "/Folder 1/Folder B");
+		assertNull(fStore.getObjectByPath(oldPath));
+		assertEquals(f11, fStore.getObjectByPath("/Folder 1/Folder B"));
+		try {
+			f2.rename(newName);
+			fail("Should not allow to rename a folder to an existing name");
+		} catch (Exception e) {
+		}
+		try {
+			f2.rename("illegal/name");
+			fail("Should not allow to rename a folder to a name with illegal name");
+		} catch (Exception e) {
+		}
+
+		// rename root folder
+		try {
+			fRoot.rename("abc");
+			fail("Should not be possible to rename root folder");
+		} catch (Exception e) {
+		}
+	}
+
+	@Test
+	public void testMoveFolder() {
+		String oldPath = f1.getPath();
+		Folder f1Parent = f1.getParent();
+		f1.move(f1Parent, f3);
+		assertNull(fStore.getObjectByPath(oldPath));
+		assertEquals(f1.getPath(), "/Folder 3/Folder 1");
+		assertEquals(f1, fStore.getObjectByPath("/Folder 3/Folder 1"));
+
+		f2.rename("Folder 1");
+		try {
+			Folder f2Parent = f2.getParent();
+			f2.move(f2Parent, f3);
+			fail("Should not be possible to move folder to a folder that has a child with same name");
+		} catch (Exception e) {
+		}
+	}
+
+	@Test
+	public void testDeleteFolder() {
+		String oldPath = f2.getPath();
+		fStore.deleteObject(f2.getId());
+		assertNull(fStore.getObjectByPath(oldPath));
+
+		try {
+			fStore.deleteObject(f1.getId());
+			fail("Should not be possible to move folder that has children");
+		} catch (Exception e) {
+		}
+	}
+
+	private void createFolders() {
+		fRoot = (FolderImpl) fStore.getRootFolder();
+		f1 = (FolderImpl) fStore.createFolder("Folder 1");
+		fRoot.addChildFolder(f1);
+
+		f2 = (FolderImpl) fStore.createFolder("Folder 2");
+		fRoot.addChildFolder(f2);
+
+		f3 = (FolderImpl) fStore.createFolder("Folder 3");
+		fRoot.addChildFolder(f3);
+
+		f4 = (FolderImpl) fStore.createFolder("Folder 4");
+		fRoot.addChildFolder(f4);
+
+		f11 = (FolderImpl) fStore.createFolder("Folder 1.1");
+		f1.addChildFolder(f11);
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.java Fri Apr 16 14:00:23 2010
@@ -50,236 +50,237 @@ import org.junit.Test;
 
 public class MultiFilingTest extends AbstractServiceTst {
 
-  private static Log LOG = LogFactory.getLog(MultiFilingTest.class);
-  private static final String DOCUMENT_TYPE_ID = UnitTestTypeSystemCreator.COMPLEX_TYPE;
-  private static final String FOLDER_TYPE_ID =  InMemoryFolderTypeDefinition.getRootFolderType().getId();
-  private static final String UNFILED_DOC_NAME = "Unfiled document";
-  private static final String RENAMED_DOC_NAME = "My Renamed Document";
-  
-  private String fId1;
-  private String fId2;
-  private String fId11;
-
-  @Before
-  public void setUp() throws Exception {
-    super.setUp();
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    super.tearDown();
-  }
-
-  @Test
-  public void testCreateUnfiledDocument() {
-    LOG.debug("Begin testCreatUnfiledDocument()");
-    String docId = createUnfiledDocument();    
-    String docId2 = getDocument(docId);
-    assertEquals(docId, docId2);
-    
-    // get object parents, must be empty
-    List<ObjectParentData> res = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
-        IncludeRelationships.NONE, null, true, null);
-    
-    assertNotNull(res);
-    assertEquals(res.size(), 0);
-    
-    LOG.debug("End testCreatUnfiledDocument()");    
-  }
-  
-  @Test
-  public void testMakeFiledDocumentUnfiled() {
-    LOG.debug("Begin testMakeFiledDocumentUnfiled()");
-    
-    String docId = createDocument("Filed document", fRootFolderId, DOCUMENT_TYPE_ID, true);
-
-    fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fRootFolderId,  null);
-    List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
-        IncludeRelationships.NONE, null, true, null);
-    assertEquals(0, parents.size());
-
-    LOG.debug("End testMakeFiledDocumentUnfiled()");    
-  }
-
- @Test
- public void testAddDocumentToFolder() {
-   LOG.debug("Begin testAddDocumentToFolder()");
-   String docId = createUnfiledDocument();
-   addDocumentToFolder(docId);
-   LOG.debug("End testAddDocumentToFolder()");    
- }
-   
-  @Test
-  public void testRemoveDocumentFromFolder() {
-    LOG.debug("Begin testRemoveDocumentFromFolder()");
-
-    String docId = createUnfiledDocument();
-    removeDocumentFromFolder(docId);
-    LOG.debug("End testRemoveDocumentFromFolder()");    
-  }
-  
-  @Test 
-  public void testMoveMultiFiledDocument() {
-    LOG.debug("begin testMoveMultiFiledDocument()");    
-    String docId = createUnfiledDocument();
-    prepareMultiFiledDocument(docId);
-    String newFolderId = createFolder("folder2.1", fId2, FOLDER_TYPE_ID);
-    
-    Holder<String> idHolder = new Holder<String>(docId);
-    fObjSvc.moveObject(fRepositoryId, idHolder, newFolderId, fId11, null);
-    List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
-        IncludeRelationships.NONE, null, true, null);
-    assertEquals(3, parents.size());
-    boolean foundNewParent = false;
-    boolean foundOldParent = false;
-    for (ObjectParentData parentData: parents) {
-      if (parentData.getObject().getId().equals(newFolderId))
-        foundNewParent = true;
-      if (parentData.getObject().getId().equals(fId11))
-        foundOldParent = true;
-    }
-    assertTrue("After move new target should be a parent", foundNewParent);
-    assertFalse("After move old source should no longer be a parent", foundOldParent);
-    LOG.debug("End testMoveMultiFiledDocument()");    
-  }
-  
-  @Test 
-  public void testRenameMultiFiledDocument() {
-    LOG.debug("begin testRenameMultiFiledDocument()");    
-    String docId = createUnfiledDocument();
-    prepareMultiFiledDocument(docId);    
-    renameDocumentAndCheckResult(docId);
-    LOG.debug("End testRenameMultiFiledDocument()");        
-  }
-  
-  @Test 
-  public void testRenameMultiFiledDocumentWithNameConflict() {
-    LOG.debug("begin testRenameMultiFiledDocument()");    
-    String docId = createUnfiledDocument();
-    prepareMultiFiledDocument(docId);    
-    // create a document with the new name in one of the folders
-    createDocument(RENAMED_DOC_NAME, fId11, DOCUMENT_TYPE_ID, true);
-    // try to rename which should fail now
-    try {
-      renameDocumentAndCheckResult(docId);
-      fail("A rename to an existing name in one of the filed folders should fail");
-    } catch (Exception e) {
-      assertTrue(e instanceof CmisConstraintException);
-    }
-    LOG.debug("End testRenameMultiFiledDocument()");        
-  }
-  
-  @Test
-  public void testAddVersionedDocumentToFolder() {
-    LOG.debug("Begin testAddVersionedDocumentToFolder()");
-    String docId = createVersionedDocument();
-    addDocumentToFolder(docId);
-    LOG.debug("End testAddVersionedDocumentToFolder()");    
-  }
-    
-   @Test
-   public void testRemoveVersionedDocumentFromFolder() {
-     LOG.debug("Begin testRemoveVersionedDocumentFromFolder()");
-
-     String docId = createVersionedDocument();
-     removeDocumentFromFolder(docId);
-     LOG.debug("End testRemoveVersionedDocumentFromFolder()");    
-   }
-
-   private void createFolders() {
-    fId1 = createFolder("folder1", fRootFolderId, FOLDER_TYPE_ID);
-    fId2 = createFolder("folder2", fRootFolderId, FOLDER_TYPE_ID);
-    fId11 = createFolder("folder1.1", fId1, FOLDER_TYPE_ID);    
-  }
-  
-  private void addDocumentToFolder(String docId) {
-    
-    List<String> folderIds = prepareMultiFiledDocument(docId);
-    
-    // get object parents, must contain all folders
-    List<ObjectParentData> res = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
-        IncludeRelationships.NONE, null, true, null);
-    assertEquals(3, res.size());
-    for (ObjectParentData opd : res) {
-      assertTrue(folderIds.contains(opd.getObject().getId()));
-      assertEquals(BaseTypeId.CMIS_FOLDER, opd.getObject().getBaseTypeId());
-      assertEquals(UNFILED_DOC_NAME, opd.getRelativePathSegment());      
-    }
-    
-    // try version specific filing, should fail
-    try {
-      fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId1, false, null);
-      fail("Adding not all versions to a folder should fail.");
-    } catch (Exception e) {
-      assertTrue(e instanceof CmisNotSupportedException);
-    }
-  }
-  
-  private void removeDocumentFromFolder(String docId) {
-    prepareMultiFiledDocument(docId);
-    
-    fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId1,  null);
-    List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
-        IncludeRelationships.NONE, null, true, null);
-    assertEquals(2, parents.size());
-    for (ObjectParentData opd : parents) {
-      assertFalse(fId1.equals(opd.getObject().getId()));
-    }
-    
-    fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId2,  null);
-    parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
-        IncludeRelationships.NONE, null, true, null);
-    assertEquals(1, parents.size());
-    for (ObjectParentData opd : parents) {
-      assertFalse(fId1.equals(opd.getObject().getId()));
-    }
-
-    fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId11,  null);
-    parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
-        IncludeRelationships.NONE, null, true, null);
-    assertEquals(0, parents.size());
-  }
-  
-  private String createUnfiledDocument() {
-    return createDocument(UNFILED_DOC_NAME , null, DOCUMENT_TYPE_ID, true);
-  }
-  
-  private List<String> prepareMultiFiledDocument(String docId) {
-    createFolders();
-    
-    // add the document to three folders
-    fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId1, true, null);
-    fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId2, true, null);
-    fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId11, true, null);
-    
-    List<String> folderIds = new ArrayList<String>();
-    folderIds.add(fId1);
-    folderIds.add(fId2);
-    folderIds.add(fId11);
-    
-    return folderIds;
-  }
-  
-  private void renameDocumentAndCheckResult(String docId) {
-    Holder<String> idHolder = new Holder<String>(docId);    
-    List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
-    properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, RENAMED_DOC_NAME));      
-    Properties newProps = fFactory.createPropertiesData(properties);
-    Holder<String> changeTokenHolder = new Holder<String>();
-    fObjSvc.updateProperties(fRepositoryId, idHolder, changeTokenHolder, newProps, null);
-    docId = idHolder.getValue(); 
-    ObjectData  res = fObjSvc.getObject(fRepositoryId, docId, "*", false, IncludeRelationships.NONE,
-        null, false, false, null);
-    assertNotNull(res);
-    Map<String, PropertyData<?>> propMap = res.getProperties().getProperties();
-    PropertyData<?> pd = propMap.get(PropertyIds.NAME);
-    assertNotNull(pd);
-    assertEquals(RENAMED_DOC_NAME, pd.getFirstValue());    
-  }
-
-  private String createVersionedDocument() {
-    
-    return createDocument(UNFILED_DOC_NAME , null, UnitTestTypeSystemCreator.VERSION_DOCUMENT_TYPE_ID, VersioningState.MAJOR, true);
+	private static Log LOG = LogFactory.getLog(MultiFilingTest.class);
+	private static final String DOCUMENT_TYPE_ID = UnitTestTypeSystemCreator.COMPLEX_TYPE;
+	private static final String FOLDER_TYPE_ID = InMemoryFolderTypeDefinition.getRootFolderType().getId();
+	private static final String UNFILED_DOC_NAME = "Unfiled document";
+	private static final String RENAMED_DOC_NAME = "My Renamed Document";
+
+	private String fId1;
+	private String fId2;
+	private String fId11;
+
+	@Before
+	public void setUp() throws Exception {
+		super.setUp();
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	@Test
+	public void testCreateUnfiledDocument() {
+		LOG.debug("Begin testCreatUnfiledDocument()");
+		String docId = createUnfiledDocument();
+		String docId2 = getDocument(docId);
+		assertEquals(docId, docId2);
+
+		// get object parents, must be empty
+		List<ObjectParentData> res = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+				IncludeRelationships.NONE, null, true, null);
+
+		assertNotNull(res);
+		assertEquals(res.size(), 0);
+
+		LOG.debug("End testCreatUnfiledDocument()");
+	}
+
+	@Test
+	public void testMakeFiledDocumentUnfiled() {
+		LOG.debug("Begin testMakeFiledDocumentUnfiled()");
+
+		String docId = createDocument("Filed document", fRootFolderId, DOCUMENT_TYPE_ID, true);
+
+		fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fRootFolderId, null);
+		List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+				IncludeRelationships.NONE, null, true, null);
+		assertEquals(0, parents.size());
+
+		LOG.debug("End testMakeFiledDocumentUnfiled()");
+	}
+
+	@Test
+	public void testAddDocumentToFolder() {
+		LOG.debug("Begin testAddDocumentToFolder()");
+		String docId = createUnfiledDocument();
+		addDocumentToFolder(docId);
+		LOG.debug("End testAddDocumentToFolder()");
+	}
+
+	@Test
+	public void testRemoveDocumentFromFolder() {
+		LOG.debug("Begin testRemoveDocumentFromFolder()");
+
+		String docId = createUnfiledDocument();
+		removeDocumentFromFolder(docId);
+		LOG.debug("End testRemoveDocumentFromFolder()");
+	}
+
+	@Test
+	public void testMoveMultiFiledDocument() {
+		LOG.debug("begin testMoveMultiFiledDocument()");
+		String docId = createUnfiledDocument();
+		prepareMultiFiledDocument(docId);
+		String newFolderId = createFolder("folder2.1", fId2, FOLDER_TYPE_ID);
+
+		Holder<String> idHolder = new Holder<String>(docId);
+		fObjSvc.moveObject(fRepositoryId, idHolder, newFolderId, fId11, null);
+		List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+				IncludeRelationships.NONE, null, true, null);
+		assertEquals(3, parents.size());
+		boolean foundNewParent = false;
+		boolean foundOldParent = false;
+		for (ObjectParentData parentData : parents) {
+			if (parentData.getObject().getId().equals(newFolderId))
+				foundNewParent = true;
+			if (parentData.getObject().getId().equals(fId11))
+				foundOldParent = true;
+		}
+		assertTrue("After move new target should be a parent", foundNewParent);
+		assertFalse("After move old source should no longer be a parent", foundOldParent);
+		LOG.debug("End testMoveMultiFiledDocument()");
+	}
+
+	@Test
+	public void testRenameMultiFiledDocument() {
+		LOG.debug("begin testRenameMultiFiledDocument()");
+		String docId = createUnfiledDocument();
+		prepareMultiFiledDocument(docId);
+		renameDocumentAndCheckResult(docId);
+		LOG.debug("End testRenameMultiFiledDocument()");
+	}
+
+	@Test
+	public void testRenameMultiFiledDocumentWithNameConflict() {
+		LOG.debug("begin testRenameMultiFiledDocument()");
+		String docId = createUnfiledDocument();
+		prepareMultiFiledDocument(docId);
+		// create a document with the new name in one of the folders
+		createDocument(RENAMED_DOC_NAME, fId11, DOCUMENT_TYPE_ID, true);
+		// try to rename which should fail now
+		try {
+			renameDocumentAndCheckResult(docId);
+			fail("A rename to an existing name in one of the filed folders should fail");
+		} catch (Exception e) {
+			assertTrue(e instanceof CmisConstraintException);
+		}
+		LOG.debug("End testRenameMultiFiledDocument()");
+	}
+
+	@Test
+	public void testAddVersionedDocumentToFolder() {
+		LOG.debug("Begin testAddVersionedDocumentToFolder()");
+		String docId = createVersionedDocument();
+		addDocumentToFolder(docId);
+		LOG.debug("End testAddVersionedDocumentToFolder()");
+	}
+
+	@Test
+	public void testRemoveVersionedDocumentFromFolder() {
+		LOG.debug("Begin testRemoveVersionedDocumentFromFolder()");
+
+		String docId = createVersionedDocument();
+		removeDocumentFromFolder(docId);
+		LOG.debug("End testRemoveVersionedDocumentFromFolder()");
+	}
+
+	private void createFolders() {
+		fId1 = createFolder("folder1", fRootFolderId, FOLDER_TYPE_ID);
+		fId2 = createFolder("folder2", fRootFolderId, FOLDER_TYPE_ID);
+		fId11 = createFolder("folder1.1", fId1, FOLDER_TYPE_ID);
+	}
+
+	private void addDocumentToFolder(String docId) {
+
+		List<String> folderIds = prepareMultiFiledDocument(docId);
+
+		// get object parents, must contain all folders
+		List<ObjectParentData> res = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+				IncludeRelationships.NONE, null, true, null);
+		assertEquals(3, res.size());
+		for (ObjectParentData opd : res) {
+			assertTrue(folderIds.contains(opd.getObject().getId()));
+			assertEquals(BaseTypeId.CMIS_FOLDER, opd.getObject().getBaseTypeId());
+			assertEquals(UNFILED_DOC_NAME, opd.getRelativePathSegment());
+		}
+
+		// try version specific filing, should fail
+		try {
+			fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId1, false, null);
+			fail("Adding not all versions to a folder should fail.");
+		} catch (Exception e) {
+			assertTrue(e instanceof CmisNotSupportedException);
+		}
+	}
+
+	private void removeDocumentFromFolder(String docId) {
+		prepareMultiFiledDocument(docId);
+
+		fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId1, null);
+		List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+				IncludeRelationships.NONE, null, true, null);
+		assertEquals(2, parents.size());
+		for (ObjectParentData opd : parents) {
+			assertFalse(fId1.equals(opd.getObject().getId()));
+		}
+
+		fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId2, null);
+		parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false, IncludeRelationships.NONE, null, true,
+				null);
+		assertEquals(1, parents.size());
+		for (ObjectParentData opd : parents) {
+			assertFalse(fId1.equals(opd.getObject().getId()));
+		}
+
+		fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId11, null);
+		parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false, IncludeRelationships.NONE, null, true,
+				null);
+		assertEquals(0, parents.size());
+	}
+
+	private String createUnfiledDocument() {
+		return createDocument(UNFILED_DOC_NAME, null, DOCUMENT_TYPE_ID, true);
+	}
+
+	private List<String> prepareMultiFiledDocument(String docId) {
+		createFolders();
+
+		// add the document to three folders
+		fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId1, true, null);
+		fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId2, true, null);
+		fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId11, true, null);
+
+		List<String> folderIds = new ArrayList<String>();
+		folderIds.add(fId1);
+		folderIds.add(fId2);
+		folderIds.add(fId11);
+
+		return folderIds;
+	}
+
+	private void renameDocumentAndCheckResult(String docId) {
+		Holder<String> idHolder = new Holder<String>(docId);
+		List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+		properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, RENAMED_DOC_NAME));
+		Properties newProps = fFactory.createPropertiesData(properties);
+		Holder<String> changeTokenHolder = new Holder<String>();
+		fObjSvc.updateProperties(fRepositoryId, idHolder, changeTokenHolder, newProps, null);
+		docId = idHolder.getValue();
+		ObjectData res = fObjSvc.getObject(fRepositoryId, docId, "*", false, IncludeRelationships.NONE, null, false,
+				false, null);
+		assertNotNull(res);
+		Map<String, PropertyData<?>> propMap = res.getProperties().getProperties();
+		PropertyData<?> pd = propMap.get(PropertyIds.NAME);
+		assertNotNull(pd);
+		assertEquals(RENAMED_DOC_NAME, pd.getFirstValue());
+	}
 
-  }
+	private String createVersionedDocument() {
+
+		return createDocument(UNFILED_DOC_NAME, null, UnitTestTypeSystemCreator.VERSION_DOCUMENT_TYPE_ID,
+				VersioningState.MAJOR, true);
+
+	}
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/NavigationServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/NavigationServiceTest.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/NavigationServiceTest.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/NavigationServiceTest.java Fri Apr 16 14:00:23 2010
@@ -45,189 +45,186 @@ import static org.junit.Assert.*;
  * @author Jens
  */
 public class NavigationServiceTest extends AbstractServiceTst {
-  private static Log log = LogFactory.getLog(NavigationServiceTest.class);
-  private static final int NUM_ROOT_FOLDERS = 10;
-  private String fLevel1FolderId;
-
-  @Before
-  public void setUp() throws Exception {
-    super.setUp();
-  }
-
-  @After
-  public void tearDown() throws Exception {
-    super.tearDown();
-  }
-
-  @Test
-  public void testGetChildren() {
-    log.info("starting testGetChildren() ...");
-    createLevel1Folders();
-
-    log.info("test getting all objects with getChildren");
-    BigInteger maxItems = BigInteger.valueOf(NUM_ROOT_FOLDERS *2);
-    BigInteger skipCount = BigInteger.valueOf(0);
-    ObjectInFolderList result = fNavSvc.getChildren(fRepositoryId, fRootFolderId, "*", null, false,
-        IncludeRelationships.NONE, null, true, maxItems, skipCount, null);
-    List<ObjectInFolderData> folders = result.getObjects();
-    log.info(" found " + folders.size() + " folders in getChildren()");
-    for (ObjectInFolderData folder : folders) {
-      log.info("   found folder id " + folder.getObject().getId() + " path segment "
-          + folder.getPathSegment());
-    }
-    assertEquals(NUM_ROOT_FOLDERS, folders.size());
-    
-    log.info("test paging with getChildren");
-    maxItems = BigInteger.valueOf(3);
-    skipCount = BigInteger.valueOf(3);    
-    result = fNavSvc.getChildren(fRepositoryId, fRootFolderId, "*", null, false,
-        IncludeRelationships.NONE, null, true, maxItems, skipCount, null);
-    folders = result.getObjects();
-    log.info(" found " + folders.size() + " folders in getChildren()");
-    for (ObjectInFolderData folder : folders) {
-      log.info("   found folder id " + folder.getObject().getId() + " path segment "
-          + folder.getPathSegment());
-    }
-    assertEquals(3, folders.size());
-    assertEquals("Folder 3", folders.get(0).getPathSegment());
-    log.info("... testGetChildren() finished.");
-  }
-
-  @Test
-  public void testGetFolderTree() {
-    log.info("starting testGetFolderTree() ...");    
-    createFolderHierachy(3, 5);
-
-    log.info("test getting all objects with getFolderTree");
-    BigInteger depth = BigInteger.valueOf(-1);
-    Boolean includePathSegments = true;
-    String propertyFilter = "*";
-    String renditionFilter = null;
-    Boolean includeAllowableActions = false;
-    String objectId = fRootFolderId;
-    
-    List<ObjectInFolderContainer> tree = fNavSvc.getFolderTree(fRepositoryId, objectId,
-        depth, propertyFilter, includeAllowableActions, IncludeRelationships.NONE, renditionFilter,
-        includePathSegments, null);    
-    
-    log.info("Descendants for object id " + objectId + " are: ");
-    for (ObjectInFolderContainer folder : tree) {
-      logFolderContainer(folder, 0);
-    }
-    
-    log.info("... testGetFolderTree() finished.");
-  }
-
-  private void logFolderContainer(ObjectInFolderContainer folder, int depth) {
-    StringBuilder prefix = new StringBuilder();
-    for (int i=0; i<depth; i++)
-      prefix.append("   ");
-    
-    log.info(prefix + "name: " + folder.getObject().getPathSegment());
-    List<ObjectInFolderContainer> children = folder.getChildren();
-    if (null != children) {
-      for (ObjectInFolderContainer child: children) {
-        logFolderContainer(child, depth+1);
-      } 
-    }
-  }
-
-  @Test
-  public void testGetDescendants() {
-    log.info("starting testGetDescendants() ...");
-    final int numLevels = 3;
-    final int childrenPerLevel = 3;
-    int objCount = createFolderHierachy(numLevels, childrenPerLevel);
-
-    log.info("test getting all objects with getDescendants");
-    List<ObjectInFolderContainer> result = fNavSvc.getDescendants(fRepositoryId, fRootFolderId, BigInteger.valueOf(-1),
-        "*", Boolean.TRUE, IncludeRelationships.NONE, null, Boolean.TRUE, null);
-    
-    for (ObjectInFolderContainer obj: result) {
-      log.info("   found folder id " + obj.getObject().getObject().getId() + " path segment "
-          + obj.getObject().getPathSegment());
-    }
-    int sizeOfDescs = getSizeOfDescendants(result);
-    assertEquals(objCount, sizeOfDescs);
-
-    log.info("test getting one level with getDescendants");
-    result = fNavSvc.getDescendants(fRepositoryId, fRootFolderId, BigInteger.valueOf(1),
-        "*", Boolean.TRUE, IncludeRelationships.NONE, null, Boolean.TRUE, null);
-    
-    for (ObjectInFolderContainer obj: result) {
-      log.info("   found folder id " + obj.getObject().getObject().getId() + " path segment "
-          + obj.getObject().getPathSegment());
-    }
-    sizeOfDescs = getSizeOfDescendants(result);
-    assertEquals(childrenPerLevel, sizeOfDescs);
-    
-    log.info("test getting two levels with getDescendants");
-    result = fNavSvc.getDescendants(fRepositoryId, fRootFolderId, BigInteger.valueOf(2),
-        "*", Boolean.TRUE, IncludeRelationships.NONE, null, Boolean.TRUE, null);
-    
-    for (ObjectInFolderContainer obj: result) {
-      log.info("   found folder id " + obj.getObject().getObject().getId() + " path segment "
-          + obj.getObject().getPathSegment());
-    }
-    sizeOfDescs = getSizeOfDescendants(result);
-    assertEquals(childrenPerLevel*childrenPerLevel+childrenPerLevel, sizeOfDescs);
-
-    log.info("... testGetDescendants() finished.");
-  }
-  
-  @Test
-  public void testGetFolderParent() {
-    log.info("starting testGetFolderParent() ...");
-    createLevel1Folders();
-    String folderId = fLevel1FolderId;
-    
-    ObjectData result = fNavSvc.getFolderParent(fRepositoryId, folderId, null, null);
-    log.info(" found parent for id \'" + folderId + "\' is \'" + result.getId() + "\'");
-    assertEquals(fRootFolderId, result.getId()); // should be root folder 
-    
-    folderId = fRootFolderId;
-    try {
-      result = fNavSvc.getFolderParent(fRepositoryId, folderId, null, null);
-      log.info(" found parent for id " + folderId + " is " + result.getId());
-      fail("Should not be possible to get parent for root folder");
-    } catch (Exception e) {
-      assertEquals(CmisInvalidArgumentException.class, e.getClass());
-      log.info(" getParent() for root folder raised expected exception");      
-    }
-    log.info("... testGetFolderParent() finished.");
-  }
-
-  private int getSizeOfDescendants(List<ObjectInFolderContainer> objs) {
-    int sum = 0; 
-    if (null != objs) {
-      sum = objs.size();
-      for (ObjectInFolderContainer obj: objs) {
-        if (null != obj.getChildren())
-          sum += getSizeOfDescendants(obj.getChildren());
-      }
-    }
-    return sum;
-  }
-  
-  private void createLevel1Folders() {
-    for (int i = 0; i < NUM_ROOT_FOLDERS; i++) {
-      List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
-      properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, "Folder " + i));
-      properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID,
-          InMemoryFolderTypeDefinition.getRootFolderType().getId()));
-      Properties props = fFactory.createPropertiesData(properties);      
-      String id = fObjSvc.createFolder(fRepositoryId, props, fRootFolderId, null, null, null, null);
-      if (i==3) // store one
-        fLevel1FolderId = id;
-    }
-  }
-  
-  private int createFolderHierachy(int levels, int childrenPerLevel) {
-
-    ObjectGenerator gen = new ObjectGenerator(fFactory, fNavSvc, fObjSvc, fRepositoryId);
-    gen.createFolderHierachy(levels, childrenPerLevel, fRootFolderId);
-    int objCount = gen.getObjectsInTotal();
-    return objCount;
-  }
-  
+	private static Log log = LogFactory.getLog(NavigationServiceTest.class);
+	private static final int NUM_ROOT_FOLDERS = 10;
+	private String fLevel1FolderId;
+
+	@Before
+	public void setUp() throws Exception {
+		super.setUp();
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	@Test
+	public void testGetChildren() {
+		log.info("starting testGetChildren() ...");
+		createLevel1Folders();
+
+		log.info("test getting all objects with getChildren");
+		BigInteger maxItems = BigInteger.valueOf(NUM_ROOT_FOLDERS * 2);
+		BigInteger skipCount = BigInteger.valueOf(0);
+		ObjectInFolderList result = fNavSvc.getChildren(fRepositoryId, fRootFolderId, "*", null, false,
+				IncludeRelationships.NONE, null, true, maxItems, skipCount, null);
+		List<ObjectInFolderData> folders = result.getObjects();
+		log.info(" found " + folders.size() + " folders in getChildren()");
+		for (ObjectInFolderData folder : folders) {
+			log.info("   found folder id " + folder.getObject().getId() + " path segment " + folder.getPathSegment());
+		}
+		assertEquals(NUM_ROOT_FOLDERS, folders.size());
+
+		log.info("test paging with getChildren");
+		maxItems = BigInteger.valueOf(3);
+		skipCount = BigInteger.valueOf(3);
+		result = fNavSvc.getChildren(fRepositoryId, fRootFolderId, "*", null, false, IncludeRelationships.NONE, null,
+				true, maxItems, skipCount, null);
+		folders = result.getObjects();
+		log.info(" found " + folders.size() + " folders in getChildren()");
+		for (ObjectInFolderData folder : folders) {
+			log.info("   found folder id " + folder.getObject().getId() + " path segment " + folder.getPathSegment());
+		}
+		assertEquals(3, folders.size());
+		assertEquals("Folder 3", folders.get(0).getPathSegment());
+		log.info("... testGetChildren() finished.");
+	}
+
+	@Test
+	public void testGetFolderTree() {
+		log.info("starting testGetFolderTree() ...");
+		createFolderHierachy(3, 5);
+
+		log.info("test getting all objects with getFolderTree");
+		BigInteger depth = BigInteger.valueOf(-1);
+		Boolean includePathSegments = true;
+		String propertyFilter = "*";
+		String renditionFilter = null;
+		Boolean includeAllowableActions = false;
+		String objectId = fRootFolderId;
+
+		List<ObjectInFolderContainer> tree = fNavSvc.getFolderTree(fRepositoryId, objectId, depth, propertyFilter,
+				includeAllowableActions, IncludeRelationships.NONE, renditionFilter, includePathSegments, null);
+
+		log.info("Descendants for object id " + objectId + " are: ");
+		for (ObjectInFolderContainer folder : tree) {
+			logFolderContainer(folder, 0);
+		}
+
+		log.info("... testGetFolderTree() finished.");
+	}
+
+	private void logFolderContainer(ObjectInFolderContainer folder, int depth) {
+		StringBuilder prefix = new StringBuilder();
+		for (int i = 0; i < depth; i++)
+			prefix.append("   ");
+
+		log.info(prefix + "name: " + folder.getObject().getPathSegment());
+		List<ObjectInFolderContainer> children = folder.getChildren();
+		if (null != children) {
+			for (ObjectInFolderContainer child : children) {
+				logFolderContainer(child, depth + 1);
+			}
+		}
+	}
+
+	@Test
+	public void testGetDescendants() {
+		log.info("starting testGetDescendants() ...");
+		final int numLevels = 3;
+		final int childrenPerLevel = 3;
+		int objCount = createFolderHierachy(numLevels, childrenPerLevel);
+
+		log.info("test getting all objects with getDescendants");
+		List<ObjectInFolderContainer> result = fNavSvc.getDescendants(fRepositoryId, fRootFolderId, BigInteger
+				.valueOf(-1), "*", Boolean.TRUE, IncludeRelationships.NONE, null, Boolean.TRUE, null);
+
+		for (ObjectInFolderContainer obj : result) {
+			log.info("   found folder id " + obj.getObject().getObject().getId() + " path segment "
+					+ obj.getObject().getPathSegment());
+		}
+		int sizeOfDescs = getSizeOfDescendants(result);
+		assertEquals(objCount, sizeOfDescs);
+
+		log.info("test getting one level with getDescendants");
+		result = fNavSvc.getDescendants(fRepositoryId, fRootFolderId, BigInteger.valueOf(1), "*", Boolean.TRUE,
+				IncludeRelationships.NONE, null, Boolean.TRUE, null);
+
+		for (ObjectInFolderContainer obj : result) {
+			log.info("   found folder id " + obj.getObject().getObject().getId() + " path segment "
+					+ obj.getObject().getPathSegment());
+		}
+		sizeOfDescs = getSizeOfDescendants(result);
+		assertEquals(childrenPerLevel, sizeOfDescs);
+
+		log.info("test getting two levels with getDescendants");
+		result = fNavSvc.getDescendants(fRepositoryId, fRootFolderId, BigInteger.valueOf(2), "*", Boolean.TRUE,
+				IncludeRelationships.NONE, null, Boolean.TRUE, null);
+
+		for (ObjectInFolderContainer obj : result) {
+			log.info("   found folder id " + obj.getObject().getObject().getId() + " path segment "
+					+ obj.getObject().getPathSegment());
+		}
+		sizeOfDescs = getSizeOfDescendants(result);
+		assertEquals(childrenPerLevel * childrenPerLevel + childrenPerLevel, sizeOfDescs);
+
+		log.info("... testGetDescendants() finished.");
+	}
+
+	@Test
+	public void testGetFolderParent() {
+		log.info("starting testGetFolderParent() ...");
+		createLevel1Folders();
+		String folderId = fLevel1FolderId;
+
+		ObjectData result = fNavSvc.getFolderParent(fRepositoryId, folderId, null, null);
+		log.info(" found parent for id \'" + folderId + "\' is \'" + result.getId() + "\'");
+		assertEquals(fRootFolderId, result.getId()); // should be root folder
+
+		folderId = fRootFolderId;
+		try {
+			result = fNavSvc.getFolderParent(fRepositoryId, folderId, null, null);
+			log.info(" found parent for id " + folderId + " is " + result.getId());
+			fail("Should not be possible to get parent for root folder");
+		} catch (Exception e) {
+			assertEquals(CmisInvalidArgumentException.class, e.getClass());
+			log.info(" getParent() for root folder raised expected exception");
+		}
+		log.info("... testGetFolderParent() finished.");
+	}
+
+	private int getSizeOfDescendants(List<ObjectInFolderContainer> objs) {
+		int sum = 0;
+		if (null != objs) {
+			sum = objs.size();
+			for (ObjectInFolderContainer obj : objs) {
+				if (null != obj.getChildren())
+					sum += getSizeOfDescendants(obj.getChildren());
+			}
+		}
+		return sum;
+	}
+
+	private void createLevel1Folders() {
+		for (int i = 0; i < NUM_ROOT_FOLDERS; i++) {
+			List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+			properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, "Folder " + i));
+			properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, InMemoryFolderTypeDefinition
+					.getRootFolderType().getId()));
+			Properties props = fFactory.createPropertiesData(properties);
+			String id = fObjSvc.createFolder(fRepositoryId, props, fRootFolderId, null, null, null, null);
+			if (i == 3) // store one
+				fLevel1FolderId = id;
+		}
+	}
+
+	private int createFolderHierachy(int levels, int childrenPerLevel) {
+
+		ObjectGenerator gen = new ObjectGenerator(fFactory, fNavSvc, fObjSvc, fRepositoryId);
+		gen.createFolderHierachy(levels, childrenPerLevel, fRootFolderId);
+		int objCount = gen.getObjectsInTotal();
+		return objCount;
+	}
+
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectCreator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectCreator.java?rev=934878&r1=934877&r2=934878&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectCreator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/ObjectCreator.java Fri Apr 16 14:00:23 2010
@@ -43,143 +43,140 @@ import org.apache.chemistry.opencmis.com
 
 public class ObjectCreator {
 
-  private BindingsObjectFactory fFactory;
-  private ObjectService fObjSvc;
-  private String fRepositoryId;
-
-  public ObjectCreator(BindingsObjectFactory factory, ObjectService objSvc, String repositoryId) {
-    fObjSvc = objSvc;
-    fFactory = factory;
-    fRepositoryId = repositoryId;
-  }
-
-  public String createDocument(String name, String typeId, String folderId, VersioningState versioningState, Map<String, String> propsToSet) {
-    ContentStream contentStream = null;
-    List<String> policies = null;
-    Acl addACEs = null;
-    Acl removeACEs = null;
-    ExtensionsData extension = null;
-
-    Properties props = createStringDocumentProperties(name, typeId, propsToSet);
-
-    contentStream = createContent();
-
-    String id = null;
-    id = fObjSvc.createDocument(fRepositoryId, props, folderId, contentStream, versioningState,
-        policies, addACEs, removeACEs, extension);
-    if (null == id)
-      junit.framework.Assert.fail("createDocument failed.");
-
-    return id;
-  }
-
-  public Properties createStringDocumentProperties(String name, String typeId, Map<String, String> propsToSet) {
-    List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
-    properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, name));
-    properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, typeId));
-    if (null != propsToSet)
-      for (Entry<String, String> propToSet : propsToSet.entrySet()) {
-        properties.add(fFactory.createPropertyStringData(propToSet.getKey(), propToSet.getValue()));
-      }
-    Properties props = fFactory.createPropertiesData(properties);
-    return props;
-  }
-
-  public ContentStream createContent() {
-    ContentStreamImpl content = new ContentStreamImpl();
-    content.setFileName("data.txt");
-    content.setMimeType("text/plain");
-    int len = 32 * 1024;
-    byte[] b = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
-                0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a,
-                0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
-                0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a
-                }; // 32 Bytes
-    ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
-    try {
-      for (int i=0; i<1024; i++)
-        ba.write(b);
-    } catch (IOException e) {
-        throw new RuntimeException("Failed to fill content stream with data", e) ;
-    }
-    content.setStream(new ByteArrayInputStream(ba.toByteArray()));
-    content.setLength(BigInteger.valueOf(len));
-    return content;
-  }
-
-  public ContentStream createAlternateContent() {
-    ContentStreamImpl content = new ContentStreamImpl();
-    content.setFileName("data.txt");
-    content.setMimeType("text/plain");
-    int len = 32 * 1024;
-    byte[] b = {0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
-        0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
-        0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
-        0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61
-    }; // 32 Bytes
-    ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
-    try {
-      for (int i=0; i<1024; i++)
-        ba.write(b);
-    } catch (IOException e) {
-        throw new RuntimeException("Failed to fill content stream with data", e) ;
-    }
-    content.setStream(new ByteArrayInputStream(ba.toByteArray()));
-    content.setLength(BigInteger.valueOf(len));
-    return content;
-  }
-
-  /**
-   * Compare two streams and return true if they are equal
-   * @param csd1
-   * @param csd2
-   * @return
-   */
-  public boolean verifyContent(ContentStream csd1, ContentStream csd2) {
-    if (!csd1.getFileName().equals(csd2.getFileName()))
-        return false;
-    if (!csd1.getBigLength().equals(csd2.getBigLength()))
-        return false;
-    if (!csd1.getMimeType().equals(csd2.getMimeType()))
-        return false;
-    long len = csd1.getBigLength().longValue();
-    InputStream s1 = csd1.getStream();
-    InputStream s2 = csd2.getStream();
-    try {
-      for (int i=0; i<len; i++) {
-        int val1 = s1.read();
-        int val2 = s2.read();
-        if (val1 != val2)
-          return false;
-        }
-    }
-    catch (IOException e) {
-      e.printStackTrace();
-      return false;
-    }
-    return true;
-  }
-
-  public void updateProperty(String id, String propertyId, String propertyValue) {
-    Properties properties = getUpdatePropertyList(propertyId, propertyValue);
-
-    Holder<String> idHolder = new Holder<String>(id);
-    Holder<String> changeTokenHolder = new Holder<String>();
-    fObjSvc.updateProperties(fRepositoryId, idHolder, changeTokenHolder, properties, null);
-  }
-
-  public Properties getUpdatePropertyList(String propertyId, String propertyValue) {
-    List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
-    properties.add(fFactory.createPropertyStringData(propertyId, propertyValue));
-    Properties newProps = fFactory.createPropertiesData(properties);
-    return newProps;
-  }
-
-  public boolean verifyProperty(String id, String propertyId, String propertyValue) {
-      Properties props = fObjSvc.getProperties(fRepositoryId, id, "*", null);
-      Map<String, PropertyData<?>> propsMap = props.getProperties();
-      PropertyString pd = (PropertyString) propsMap.get(propertyId);
-      return propertyValue.equals(pd.getFirstValue());
-  }
+	private BindingsObjectFactory fFactory;
+	private ObjectService fObjSvc;
+	private String fRepositoryId;
+
+	public ObjectCreator(BindingsObjectFactory factory, ObjectService objSvc, String repositoryId) {
+		fObjSvc = objSvc;
+		fFactory = factory;
+		fRepositoryId = repositoryId;
+	}
+
+	public String createDocument(String name, String typeId, String folderId, VersioningState versioningState,
+			Map<String, String> propsToSet) {
+		ContentStream contentStream = null;
+		List<String> policies = null;
+		Acl addACEs = null;
+		Acl removeACEs = null;
+		ExtensionsData extension = null;
+
+		Properties props = createStringDocumentProperties(name, typeId, propsToSet);
+
+		contentStream = createContent();
+
+		String id = null;
+		id = fObjSvc.createDocument(fRepositoryId, props, folderId, contentStream, versioningState, policies, addACEs,
+				removeACEs, extension);
+		if (null == id)
+			junit.framework.Assert.fail("createDocument failed.");
+
+		return id;
+	}
+
+	public Properties createStringDocumentProperties(String name, String typeId, Map<String, String> propsToSet) {
+		List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+		properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, name));
+		properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, typeId));
+		if (null != propsToSet)
+			for (Entry<String, String> propToSet : propsToSet.entrySet()) {
+				properties.add(fFactory.createPropertyStringData(propToSet.getKey(), propToSet.getValue()));
+			}
+		Properties props = fFactory.createPropertiesData(properties);
+		return props;
+	}
+
+	public ContentStream createContent() {
+		ContentStreamImpl content = new ContentStreamImpl();
+		content.setFileName("data.txt");
+		content.setMimeType("text/plain");
+		int len = 32 * 1024;
+		byte[] b = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a,
+				0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x0c, 0x0a }; // 32
+																													// Bytes
+		ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
+		try {
+			for (int i = 0; i < 1024; i++)
+				ba.write(b);
+		} catch (IOException e) {
+			throw new RuntimeException("Failed to fill content stream with data", e);
+		}
+		content.setStream(new ByteArrayInputStream(ba.toByteArray()));
+		content.setLength(BigInteger.valueOf(len));
+		return content;
+	}
+
+	public ContentStream createAlternateContent() {
+		ContentStreamImpl content = new ContentStreamImpl();
+		content.setFileName("data.txt");
+		content.setMimeType("text/plain");
+		int len = 32 * 1024;
+		byte[] b = { 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61,
+				0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61 }; // 32
+																													// Bytes
+		ByteArrayOutputStream ba = new ByteArrayOutputStream(len);
+		try {
+			for (int i = 0; i < 1024; i++)
+				ba.write(b);
+		} catch (IOException e) {
+			throw new RuntimeException("Failed to fill content stream with data", e);
+		}
+		content.setStream(new ByteArrayInputStream(ba.toByteArray()));
+		content.setLength(BigInteger.valueOf(len));
+		return content;
+	}
+
+	/**
+	 * Compare two streams and return true if they are equal
+	 * 
+	 * @param csd1
+	 * @param csd2
+	 * @return
+	 */
+	public boolean verifyContent(ContentStream csd1, ContentStream csd2) {
+		if (!csd1.getFileName().equals(csd2.getFileName()))
+			return false;
+		if (!csd1.getBigLength().equals(csd2.getBigLength()))
+			return false;
+		if (!csd1.getMimeType().equals(csd2.getMimeType()))
+			return false;
+		long len = csd1.getBigLength().longValue();
+		InputStream s1 = csd1.getStream();
+		InputStream s2 = csd2.getStream();
+		try {
+			for (int i = 0; i < len; i++) {
+				int val1 = s1.read();
+				int val2 = s2.read();
+				if (val1 != val2)
+					return false;
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+
+	public void updateProperty(String id, String propertyId, String propertyValue) {
+		Properties properties = getUpdatePropertyList(propertyId, propertyValue);
+
+		Holder<String> idHolder = new Holder<String>(id);
+		Holder<String> changeTokenHolder = new Holder<String>();
+		fObjSvc.updateProperties(fRepositoryId, idHolder, changeTokenHolder, properties, null);
+	}
+
+	public Properties getUpdatePropertyList(String propertyId, String propertyValue) {
+		List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+		properties.add(fFactory.createPropertyStringData(propertyId, propertyValue));
+		Properties newProps = fFactory.createPropertiesData(properties);
+		return newProps;
+	}
+
+	public boolean verifyProperty(String id, String propertyId, String propertyValue) {
+		Properties props = fObjSvc.getProperties(fRepositoryId, id, "*", null);
+		Map<String, PropertyData<?>> propsMap = props.getProperties();
+		PropertyString pd = (PropertyString) propsMap.get(propertyId);
+		return propertyValue.equals(pd.getFirstValue());
+	}
 
 }