You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by sk...@apache.org on 2010/03/22 17:59:27 UTC
svn commit: r926185 - in
/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime:
ReadOnlyRepositoryInfoTest.java WriteObjectTest.java
Author: sklevenz
Date: Mon Mar 22 16:59:27 2010
New Revision: 926185
URL: http://svn.apache.org/viewvc?rev=926185&view=rev
Log:
Unit test cases for r/w extended
- change and delete content
- update properties
Modified:
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyRepositoryInfoTest.java
incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/WriteObjectTest.java
Modified: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyRepositoryInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyRepositoryInfoTest.java?rev=926185&r1=926184&r2=926185&view=diff
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyRepositoryInfoTest.java (original)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/client/runtime/ReadOnlyRepositoryInfoTest.java Mon Mar 22 16:59:27 2010
@@ -18,23 +18,16 @@
*/
package org.apache.opencmis.client.runtime;
-import java.util.List;
-
import junit.framework.Assert;
-import org.apache.opencmis.client.api.ChangeEvent;
-import org.apache.opencmis.client.api.CmisObject;
-import org.apache.opencmis.client.api.Property;
import org.apache.opencmis.client.api.repository.RepositoryCapabilities;
import org.apache.opencmis.client.api.repository.RepositoryInfo;
-import org.apache.opencmis.client.api.util.PagingList;
import org.apache.opencmis.commons.enums.CapabilityAcl;
import org.apache.opencmis.commons.enums.CapabilityChanges;
import org.apache.opencmis.commons.enums.CapabilityContentStreamUpdates;
import org.apache.opencmis.commons.enums.CapabilityJoin;
import org.apache.opencmis.commons.enums.CapabilityQuery;
import org.apache.opencmis.commons.enums.CapabilityRendition;
-import org.apache.opencmis.commons.enums.TypeOfChanges;
import org.junit.Test;
/**
@@ -42,223 +35,226 @@ import org.junit.Test;
*/
public class ReadOnlyRepositoryInfoTest extends AbstractSessionTest {
- @Test
- public void changesIncomplete() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.changesIncomplete());
- }
-
- @Test
- public void changesOnType() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getChangesOnType());
- }
-
- @Test
- public void cmisVersionSupported() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getCmisVersionSupported());
- this.log.info("getCmisVersionSupported = " + r.getCmisVersionSupported());
- }
-
- @Test
- public void description() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getDescription());
- this.log.info("getDescription = " + r.getDescription());
- }
-
- @Test
- public void id() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getId());
- this.log.info("getId = " + r.getId());
- }
-
- @Test
- public void name() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getName());
- this.log.info("getName = " + r.getName());
- }
-
- @Test
- public void principalIdAnonymous() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getPrincipalIdAnonymous());
- this.log.info("getPrincipalIdAnonymous = " + r.getPrincipalIdAnonymous());
- }
-
- @Test
- public void principalIdAnyone() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getPrincipalIdAnyone());
- this.log.info("getPrincipalIdAnyone = " + r.getPrincipalIdAnyone());
- }
-
- @Test
- public void productName() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getProductName());
- this.log.info("getProductName = " + r.getProductName());
- }
-
- @Test
- public void thinClientUri() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- String uri = r.getThinClientUri();
- this.log.info("getThinClientUri = " + uri);
- }
-
- @Test
- public void vendorName() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
- Assert.assertNotNull(r.getVendorName());
- this.log.info("getVendorName = " + r.getVendorName());
- }
-
- @Test
- public void repositoryCapabilitiesAclSupport() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
-
- // capabilities
- RepositoryCapabilities repcap = r.getCapabilities();
- Assert.assertNotNull(repcap);
-
- CapabilityAcl capacl = repcap.getAclSupport();
- Assert.assertNotNull(capacl);
- switch (capacl) {
- case DISCOVER:
- case MANAGE:
- case NONE:
- break;
- default:
- Assert.fail("enumeration not supported: " + capacl);
- }
- this.log.info("CapabilityAcl = " + capacl);
- }
-
- @Test
- public void repositoryCapabilitiesChangesSupport() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
-
- // capabilities
- RepositoryCapabilities repcap = r.getCapabilities();
- Assert.assertNotNull(repcap);
- CapabilityChanges capch = repcap.getChangesSupport();
- Assert.assertNotNull(capch);
- switch (capch) {
- case ALL:
- case OBJECTIDSONLY:
- case PROPERTIES:
- case NONE:
- break;
- default:
- Assert.fail("enumeration not supported: " + capch);
- }
- this.log.info("CapabilityChanges = " + capch);
- }
-
- @Test
- public void repositoryCapabilitiesContentStreamUpdateabilitySupport() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
-
- // capabilities
- RepositoryCapabilities repcap = r.getCapabilities();
- Assert.assertNotNull(repcap);
- CapabilityContentStreamUpdates ccsu = repcap.getContentStreamUpdatabilitySupport();
- Assert.assertNotNull(ccsu);
- switch (ccsu) {
- case ANYTIME:
- case NONE:
- case PWCONLY:
- break;
- default:
- Assert.fail("enumeration not supported: " + ccsu);
- }
- this.log.info("CapabilityContentStreamUpdates = " + ccsu);
- }
-
- @Test
- public void repositoryCapabilitiesJointSupport() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
-
- // capabilities
- RepositoryCapabilities repcap = r.getCapabilities();
- Assert.assertNotNull(repcap);
-
- CapabilityJoin capj = repcap.getJoinSupport();
- Assert.assertNotNull(capj);
-
- switch (capj) {
- case INNERANDOUTER:
- case INNERONLY:
- case NONE:
- break;
- default:
- Assert.fail("enumeration not supported: " + capj);
- }
- this.log.info("CapabilityJoin = " + capj);
- }
-
- @Test
- public void repositoryCapabilitiesQuerySupport() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
-
- // capabilities
- RepositoryCapabilities repcap = r.getCapabilities();
- Assert.assertNotNull(repcap);
-
- CapabilityQuery capq = repcap.getQuerySupport();
- Assert.assertNotNull(capq);
- switch (capq) {
- case BOTHCOMBINED:
- case BOTHSEPARATE:
- case FULLTEXTONLY:
- case METADATAONLY:
- case NONE:
- break;
- default:
- Assert.fail("enumeration not supported: " + capq);
- }
- this.log.info("CapabilityQuery = " + capq);
- }
-
- @Test
- public void repositoryCapabilitiesRenditionSupport() {
- RepositoryInfo r = this.session.getRepositoryInfo();
- Assert.assertNotNull(r);
-
- // capabilities
- RepositoryCapabilities repcap = r.getCapabilities();
- Assert.assertNotNull(repcap);
-
- CapabilityRendition caprend = repcap.getRenditionsSupport();
- Assert.assertNotNull(caprend);
- switch (caprend) {
- case NONE:
- case READ:
- break;
- default:
- Assert.fail("enumeration not supported: " + caprend);
- }
- this.log.info("CapabilityRendition = " + caprend);
- }
+ @Test
+ public void changesIncomplete() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.changesIncomplete());
+ }
+
+ @Test
+ public void changesOnType() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getChangesOnType());
+ }
+
+ @Test
+ public void cmisVersionSupported() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getCmisVersionSupported());
+ this.log.info("getCmisVersionSupported = "
+ + r.getCmisVersionSupported());
+ }
+
+ @Test
+ public void description() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getDescription());
+ this.log.info("getDescription = " + r.getDescription());
+ }
+
+ @Test
+ public void id() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getId());
+ this.log.info("getId = " + r.getId());
+ }
+
+ @Test
+ public void name() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getName());
+ this.log.info("getName = " + r.getName());
+ }
+
+ @Test
+ public void principalIdAnonymous() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getPrincipalIdAnonymous());
+ this.log.info("getPrincipalIdAnonymous = "
+ + r.getPrincipalIdAnonymous());
+ }
+
+ @Test
+ public void principalIdAnyone() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getPrincipalIdAnyone());
+ this.log.info("getPrincipalIdAnyone = " + r.getPrincipalIdAnyone());
+ }
+
+ @Test
+ public void productName() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getProductName());
+ this.log.info("getProductName = " + r.getProductName());
+ }
+
+ @Test
+ public void thinClientUri() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ String uri = r.getThinClientUri();
+ this.log.info("getThinClientUri = " + uri);
+ }
+
+ @Test
+ public void vendorName() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+ Assert.assertNotNull(r.getVendorName());
+ this.log.info("getVendorName = " + r.getVendorName());
+ }
+
+ @Test
+ public void repositoryCapabilitiesAclSupport() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+
+ // capabilities
+ RepositoryCapabilities repcap = r.getCapabilities();
+ Assert.assertNotNull(repcap);
+
+ CapabilityAcl capacl = repcap.getAclSupport();
+ Assert.assertNotNull(capacl);
+ switch (capacl) {
+ case DISCOVER:
+ case MANAGE:
+ case NONE:
+ break;
+ default:
+ Assert.fail("enumeration not supported: " + capacl);
+ }
+ this.log.info("CapabilityAcl = " + capacl);
+ }
+
+ @Test
+ public void repositoryCapabilitiesChangesSupport() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+
+ // capabilities
+ RepositoryCapabilities repcap = r.getCapabilities();
+ Assert.assertNotNull(repcap);
+ CapabilityChanges capch = repcap.getChangesSupport();
+ Assert.assertNotNull(capch);
+ switch (capch) {
+ case ALL:
+ case OBJECTIDSONLY:
+ case PROPERTIES:
+ case NONE:
+ break;
+ default:
+ Assert.fail("enumeration not supported: " + capch);
+ }
+ this.log.info("CapabilityChanges = " + capch);
+ }
+
+ @Test
+ public void repositoryCapabilitiesContentStreamUpdateabilitySupport() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+
+ // capabilities
+ RepositoryCapabilities repcap = r.getCapabilities();
+ Assert.assertNotNull(repcap);
+ CapabilityContentStreamUpdates ccsu = repcap
+ .getContentStreamUpdatabilitySupport();
+ Assert.assertNotNull(ccsu);
+ switch (ccsu) {
+ case ANYTIME:
+ case NONE:
+ case PWCONLY:
+ break;
+ default:
+ Assert.fail("enumeration not supported: " + ccsu);
+ }
+ this.log.info("CapabilityContentStreamUpdates = " + ccsu);
+ }
+
+ @Test
+ public void repositoryCapabilitiesJointSupport() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+
+ // capabilities
+ RepositoryCapabilities repcap = r.getCapabilities();
+ Assert.assertNotNull(repcap);
+
+ CapabilityJoin capj = repcap.getJoinSupport();
+ Assert.assertNotNull(capj);
+
+ switch (capj) {
+ case INNERANDOUTER:
+ case INNERONLY:
+ case NONE:
+ break;
+ default:
+ Assert.fail("enumeration not supported: " + capj);
+ }
+ this.log.info("CapabilityJoin = " + capj);
+ }
+
+ @Test
+ public void repositoryCapabilitiesQuerySupport() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+
+ // capabilities
+ RepositoryCapabilities repcap = r.getCapabilities();
+ Assert.assertNotNull(repcap);
+
+ CapabilityQuery capq = repcap.getQuerySupport();
+ Assert.assertNotNull(capq);
+ switch (capq) {
+ case BOTHCOMBINED:
+ case BOTHSEPARATE:
+ case FULLTEXTONLY:
+ case METADATAONLY:
+ case NONE:
+ break;
+ default:
+ Assert.fail("enumeration not supported: " + capq);
+ }
+ this.log.info("CapabilityQuery = " + capq);
+ }
+
+ @Test
+ public void repositoryCapabilitiesRenditionSupport() {
+ RepositoryInfo r = this.session.getRepositoryInfo();
+ Assert.assertNotNull(r);
+
+ // capabilities
+ RepositoryCapabilities repcap = r.getCapabilities();
+ Assert.assertNotNull(repcap);
+
+ CapabilityRendition caprend = repcap.getRenditionsSupport();
+ Assert.assertNotNull(caprend);
+ switch (caprend) {
+ case NONE:
+ case READ:
+ break;
+ default:
+ Assert.fail("enumeration not supported: " + caprend);
+ }
+ this.log.info("CapabilityRendition = " + caprend);
+ }
}
\ No newline at end of file
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=926185&r1=926184&r2=926185&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 Mon Mar 22 16:59:27 2010
@@ -18,6 +18,9 @@
*/
package org.apache.opencmis.client.runtime;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -26,8 +29,6 @@ import java.util.Collection;
import java.util.List;
import java.util.UUID;
-import junit.framework.Assert;
-
import org.apache.opencmis.client.api.ContentStream;
import org.apache.opencmis.client.api.Document;
import org.apache.opencmis.client.api.ObjectId;
@@ -36,118 +37,228 @@ import org.apache.opencmis.client.api.ob
import org.apache.opencmis.commons.api.PropertyDefinition;
import org.apache.opencmis.commons.enums.CmisProperties;
import org.apache.opencmis.commons.enums.VersioningState;
-import org.junit.Ignore;
+import org.apache.opencmis.commons.exceptions.CmisNotSupportedException;
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);
- 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);
- }
+ @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);
+ 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)
+ */
+ this.log
+ .info(
+ "Custom property found but not supported in test case!",
+ e);
+ }
+ }
+
+ 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);
+ assertNotNull(contentStream);
+
+ ObjectId id = this.session.createDocument(properties, parentId,
+ contentStream, VersioningState.NONE, null, null, null);
+ assertNotNull(id);
+
+ // verify content (which is not supported by mock)
+ if (this.isMock()) {
+ return;
+ }
+ Document doc = (Document) this.session.getObject(id);
+ assertNotNull(doc);
+ // Assert.assertEquals(buf1.length, doc.getContentStreamLength());
+ // Assert.assertEquals(mimetype, doc.getContentStreamMimeType());
+ // Assert.assertEquals(filename, doc.getContentStreamFileName());
+ String content2 = this.getContentAsString(doc.getContentStream());
+ assertEquals(content1, content2);
+ }
+
+ @Test
+ public void createDocumentFromSource() throws IOException {
+ try {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
+ + FixtureData.DOCUMENT1_NAME;
+ Document srcDocument = (Document) this.session
+ .getObjectByPath(path);
+ assertNotNull("Document not found: " + path, srcDocument);
+ String srcContent = this.getContentAsString(srcDocument
+ .getContentStream());
+
+ ObjectId parentFolder = session.createObjectId(Fixture
+ .getTestRootId());
+ List<Property<?>> srcProperties = srcDocument.getProperties();
+ assertNotNull(srcProperties);
+ List<Property<?>> dstProperties = new ArrayList<Property<?>>();
+
+ for (Property<?> p : srcProperties) {
+ if (p.getId().equalsIgnoreCase(CmisProperties.NAME.value())) {
+ // change the name
+ String name = UUID.randomUUID().toString();
+ Property<String> pn = this.session.getObjectFactory()
+ .createProperty(p.getDefinition(), name);
+ dstProperties.add(pn);
+ } else {
+ dstProperties.add(p);
+ }
+ }
+
+ ObjectId dstDocumentId = this.session.createDocumentFromSource(
+ srcDocument, dstProperties, parentFolder,
+ VersioningState.NONE, null, null, null);
+ assertNotNull(dstDocumentId);
+ Document dstDocument = (Document) this.session
+ .getObject(dstDocumentId);
+ String dstContent = this.getContentAsString(dstDocument
+ .getContentStream());
+ assertEquals(srcContent, dstContent);
+
+ } catch (CmisNotSupportedException e) {
+ // not an error
+ this.log.info(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void deleteAndCreateContent() throws IOException {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
+ + FixtureData.DOCUMENT1_NAME;
+ Document document = (Document) this.session.getObjectByPath(path);
+ assertNotNull("Document not found: " + path, document);
+
+ // check default content
+ ContentStream contentStream = document.getContentStream();
+ assertNotNull(contentStream);
+ String contentString = this.getContentAsString(contentStream);
+ assertNotNull(contentString);
+
+ // delete and set new content
+ ObjectId id = document.deleteContentStream();
+ // assertNotNull(id);
+
+ 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 = this.session.getObjectFactory().createContentStream(
+ filename, buf1.length, mimetype, in1);
+ assertNotNull(contentStream);
+
+ document.setContentStream(true, contentStream);
+
+ // check default content
+ ContentStream contentStream2 = document.getContentStream();
+ assertNotNull(contentStream2);
+ String contentString2 = this.getContentAsString(contentStream2);
+ assertNotNull(contentString2);
+
+ assertEquals(content1, contentString2);
+ }
+
+ @Test
+ public void updateProperties() {
+// String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
+// + FixtureData.DOCUMENT1_NAME;
+// Document document = (Document) this.session.getObjectByPath(path);
+// assertNotNull("Document not found: " + path, document);
+//
+// document.updateProperties();
+ }
+
+ private String getContentAsString(ContentStream stream) throws IOException {
+ assertNotNull(stream);
+ InputStream in2 = stream.getStream();
+ assertNotNull(in2);
+ 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();
+ return sbuf.toString();
+ }
}