You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by dc...@apache.org on 2010/02/16 17:04:07 UTC
svn commit: r910572 [4/36] - in /incubator/chemistry/trunk/opencmis: ./
_dev/ opencmis-client/ opencmis-client/opencmis-client-api/
opencmis-client/opencmis-client-api/src/
opencmis-client/opencmis-client-api/src/main/
opencmis-client/opencmis-client-a...
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyContentStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyContentStreamTest.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyContentStreamTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyContentStreamTest.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.apache.opencmis.client.api.ContentStream;
+import org.apache.opencmis.client.api.Document;
+
+public class ReadOnlyContentStreamTest extends AbstractSessionTest {
+
+ @Test
+ public void readContentStream() throws IOException {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.DOCUMENT1_NAME;
+ Document document = (Document) this.session.getObjectByPath(path);
+ Assert.assertNotNull("document not found: " + path, document);
+
+ ContentStream s = document.getContentStream();
+
+ Assert.assertNotNull(s.getId());
+ Assert.assertNotNull(s.getMimeType());
+ Assert.assertTrue(s.getLength() > 0);
+ Assert.assertNotNull(s.getFileName());
+
+ InputStream is = s.getStream();
+ Assert.assertNotNull(is);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ baos.write(is.read());
+ byte[] b = baos.toByteArray();
+
+ Assert.assertNotNull(b);
+ Assert.assertTrue(b.length > 0);
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyContentStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyCreateSessionTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyCreateSessionTest.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyCreateSessionTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyCreateSessionTest.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test;
+
+import java.util.Hashtable;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.opencmis.client.api.Session;
+import org.apache.opencmis.client.api.SessionFactory;
+import org.apache.opencmis.client.api.TransientSession;
+import org.apache.opencmis.commons.SessionParameter;
+import org.apache.opencmis.commons.enums.SessionType;
+import org.apache.opencmis.commons.exceptions.CmisNotSupportedException;
+
+/**
+ * Independent session creation test (read only)
+ */
+public class ReadOnlyCreateSessionTest {
+
+ protected Log log = LogFactory.getLog(this.getClass());
+
+ @Before
+ public void setup() {
+ }
+
+ @Test
+ public void createDefaultSession() {
+ SessionFactory factory = Fixture.getSessionFactory();
+
+ Hashtable<String, String> parameter = new Hashtable<String, String>(Fixture.getParamter());
+ parameter.remove(SessionParameter.SESSION_TYPE);
+
+ Session s = factory.createSession(parameter);
+ Assert.assertNotNull(s);
+ }
+
+ @Test
+ public void createPersistentSession() {
+ SessionFactory factory = Fixture.getSessionFactory();
+
+ Hashtable<String, String> parameter = new Hashtable<String, String>(Fixture.getParamter());
+ parameter.put(SessionParameter.SESSION_TYPE, SessionType.PERSISTENT.value());
+
+ Session s = factory.createSession(parameter);
+ Assert.assertNotNull(s);
+ }
+
+ @Test
+ public void createTransientSession() {
+ SessionFactory factory = Fixture.getSessionFactory();
+
+ Hashtable<String, String> parameter = new Hashtable<String, String>(Fixture.getParamter());
+ parameter.put(SessionParameter.SESSION_TYPE, SessionType.TRANSIENT.value());
+
+ try {
+ @SuppressWarnings("unused")
+ TransientSession s = factory.createSession(parameter);
+ Assert
+ .fail("CmisNotSupportedException expected, because Transient Session is not supported yet.");
+ }
+ catch (CmisNotSupportedException e) {
+
+ }
+ }
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyCreateSessionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyDiscoverTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyDiscoverTest.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyDiscoverTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyDiscoverTest.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.util.PagingList;
+import org.apache.opencmis.commons.enums.CapabilityChanges;
+import org.apache.opencmis.commons.enums.CapabilityQuery;
+import org.apache.opencmis.commons.enums.TypeOfChanges;
+import org.junit.Test;
+
+public class ReadOnlyDiscoverTest extends AbstractSessionTest {
+
+ private static Log log = LogFactory.getLog(ReadOnlyDiscoverTest.class);
+
+ @Test
+ public void query() {
+ CapabilityQuery query = this.session.getRepositoryInfo().getCapabilities().getQuerySupport();
+
+ switch (query) {
+ case NONE:
+ ReadOnlyDiscoverTest.log.info("queries not supported");
+ break;
+ default:
+ PagingList<CmisObject> resultSet = this.session.query(Fixture.QUERY, false, -1);
+ Assert.assertNotNull(resultSet);
+ Assert.assertFalse(resultSet.isEmpty());
+ for (List<CmisObject> lo : resultSet) {
+ for (CmisObject o : lo) {
+ Assert.assertNotNull(o);
+ }
+ }
+
+ break;
+ }
+
+ }
+
+ @Test
+ public void changes() {
+ CapabilityChanges changes = this.session.getRepositoryInfo().getCapabilities()
+ .getChangesSupport();
+
+ switch (changes) {
+ case NONE:
+ ReadOnlyDiscoverTest.log.info("changes not supported");
+ break;
+ default:
+ PagingList<ChangeEvent> cep = this.session.getContentChanges(null, -1);
+ Assert.assertNotNull(cep);
+ for (List<ChangeEvent> cel : cep)
+ for (ChangeEvent ce : cel) {
+ TypeOfChanges toc = ce.getChangeType();
+ Assert.assertNotNull(toc);
+ switch (toc) {
+ case CREATED:
+ case DELETED:
+ case SECURITY:
+ case UPDATED:
+ break;
+ default:
+ Assert.fail("change type not supported: " + toc);
+ }
+ List<Property<?>> pl = ce.getNewProperties();
+ Assert.assertNotNull(pl);
+ String id = ce.getObjectId();
+ Assert.assertNotNull(id);
+ }
+ break;
+ }
+ }
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyDiscoverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyNavigationTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyNavigationTest.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyNavigationTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyNavigationTest.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test;
+
+import java.util.List;
+import java.util.TreeMap;
+
+import junit.framework.Assert;
+
+import org.apache.opencmis.client.api.CmisObject;
+import org.apache.opencmis.client.api.Folder;
+import org.apache.opencmis.client.api.util.PagingList;
+import org.junit.Test;
+
+public class ReadOnlyNavigationTest extends AbstractSessionTest {
+
+ @Test
+ public void navigateChildren() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME;
+ Folder folder = (Folder) this.session.getObjectByPath(path);
+ Assert.assertNotNull("folder not found: " + path, folder);
+
+ PagingList<CmisObject> pl = folder.getChildren(null, -1);
+ Assert.assertNotNull(pl);
+ Assert.assertFalse(pl.isEmpty());
+
+ for(List<CmisObject> cl : pl) {
+ for (CmisObject o : cl) {
+ Assert.assertNotNull(o);
+ }
+ }
+ }
+
+ @Test
+ public void navigateDescendants() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME;
+ Folder folder = (Folder) this.session.getObjectByPath(path);
+ Assert.assertNotNull("folder not found: " + path, folder);
+
+ TreeMap<String, CmisObject> tree = folder.getDescendants(-1);
+ Assert.assertNotNull(tree);
+ Assert.assertFalse(tree.isEmpty());
+
+ for (CmisObject o : tree.values()) {
+ Assert.assertNotNull(o);
+ }
+ }
+
+ @Test
+ public void navigateTree() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME;
+ Folder folder = (Folder) this.session.getObjectByPath(path);
+ Assert.assertNotNull("folder not found: " + path, folder);
+
+ TreeMap<String, CmisObject> tree = folder.getFolderTree(-1);
+ Assert.assertNotNull(tree);
+ Assert.assertFalse(tree.isEmpty());
+
+ for (CmisObject o : tree.values()) {
+ Assert.assertNotNull(o);
+ }
+ }
+
+ @Test
+ public void navigatePagingRandom() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME;
+ Folder folder = (Folder) this.session.getObjectByPath(path);
+ Assert.assertNotNull("folder not found: " + path, folder);
+
+ PagingList<CmisObject> pl = folder.getChildren(null, -1);
+ Assert.assertNotNull(pl);
+ Assert.assertFalse(pl.isEmpty());
+
+ List<CmisObject> firstPage = pl.get(0);
+ Assert.assertNotNull(firstPage);
+ }
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyNavigationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyObjectTest.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyObjectTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyObjectTest.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,301 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test;
+
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.opencmis.client.api.Document;
+import org.apache.opencmis.client.api.Folder;
+import org.apache.opencmis.client.api.Property;
+import org.apache.opencmis.client.api.objecttype.ObjectType;
+import org.apache.opencmis.commons.SessionParameter;
+import org.apache.opencmis.commons.enums.CmisProperties;
+import org.apache.opencmis.commons.enums.PropertyType;
+import org.junit.Test;
+
+/**
+ * Readonly tests on files and documents
+ */
+public class ReadOnlyObjectTest extends AbstractSessionTest {
+
+ @Test
+ public void verifyRoot() {
+ Folder root = this.session.getRootFolder();
+ Assert.assertNotNull(root);
+
+ Assert.assertEquals("", root.getName());
+ Assert.assertNotNull(root.getId());
+ Assert.assertEquals("/", root.getPath());
+ Assert.assertNull(root.getFolderParent());
+ Assert.assertNotNull(root.getType());
+ Assert.assertEquals(Fixture.FOLDER_TYPE_ID, root.getType().getId());
+
+ Assert.assertEquals("", root.getName());
+ Assert.assertNotNull(root.getId());
+ Assert.assertEquals("/", root.getPath());
+ Assert.assertNull(root.getFolderParent());
+ Assert.assertNotNull(root.getType());
+ Assert.assertEquals(Fixture.FOLDER_TYPE_ID, root.getType().getId());
+ }
+
+ @Test
+ public void readTestFolder() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME;
+ Folder folder = (Folder) this.session.getObjectByPath(path);
+ Assert.assertNotNull("folder not found: " + path, folder);
+
+ Assert.assertEquals(Fixture.TEST_ROOT_FOLDER_NAME, folder.getName());
+ Assert.assertNotNull(folder.getId());
+ Assert.assertEquals("/" + Fixture.TEST_ROOT_FOLDER_NAME, folder.getPath());
+ Assert.assertNotNull(folder.getFolderParent());
+ Assert.assertNotNull(folder.getType());
+ Assert.assertEquals(Fixture.FOLDER_TYPE_ID, folder.getType().getId());
+ Assert.assertNotNull(folder.getBaseType());
+ Assert.assertEquals(ObjectType.FOLDER_BASETYPE_ID, folder.getBaseType().getId());
+
+ Assert.assertNotNull(folder.getCreatedBy());
+ Assert.assertEquals(Fixture.getParamter().get(SessionParameter.USER), folder.getCreatedBy());
+ Assert.assertNotNull(folder.getLastModifiedBy());
+ Assert.assertEquals(Fixture.getParamter().get(SessionParameter.USER), folder
+ .getLastModifiedBy());
+ Assert.assertNotNull(folder.getLastModificationDate());
+ Assert.assertNotNull(folder.getCreationDate());
+
+ }
+
+ @Test
+ public void readTestDocument() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.DOCUMENT1_NAME;
+ Document document = (Document) this.session.getObjectByPath(path);
+ Assert.assertNotNull("document not found: " + path, document);
+
+ Assert.assertNotNull(document.getId());
+ Assert.assertNotNull(document.getBaseType());
+ Assert.assertEquals(ObjectType.DOCUMENT_BASETYPE_ID, document.getBaseType().getId());
+ Assert.assertEquals(Fixture.DOCUMENT1_NAME, document.getName());
+ Assert.assertEquals(path, document.getPath());
+ Assert.assertNotNull(document.getType());
+ Assert.assertEquals(Fixture.DOCUMENT_TYPE_ID, document.getType().getId());
+
+ }
+
+ public void readDocumentDefaultProperties() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.DOCUMENT1_NAME;
+ Document document = (Document) this.session.getObjectByPath(path);
+ Assert.assertNotNull("document not found: " + path, document);
+
+ Assert.assertNotNull(document.getCreatedBy());
+ Assert.assertEquals(Fixture.getParamter().get(SessionParameter.USER), document.getCreatedBy());
+ Assert.assertNotNull(document.getLastModifiedBy());
+ Assert.assertEquals(Fixture.getParamter().get(SessionParameter.USER), document
+ .getLastModifiedBy());
+ Assert.assertNotNull(document.getLastModificationDate());
+ Assert.assertNotNull(document.getCreationDate());
+ }
+
+ @Test
+ public void readDocumentPropertiesWithFilter() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.DOCUMENT1_NAME;
+ Document document = (Document) this.session.getObjectByPath(path);
+ Assert.assertNotNull("document not found: " + path, document);
+
+ List<Property<?>> l = document.getProperties(Fixture.PROPERTY_FILTER);
+ Assert.assertNotNull(l);
+ Assert.assertEquals(false, l.isEmpty());
+ Iterator<Property<?>> i = l.iterator();
+ while (i.hasNext()) {
+ Property<?> p = i.next();
+ Object value = p.getValue();
+ PropertyType t = p.getType();
+
+ Assert.assertNotNull(p);
+ Assert.assertNotNull(t);
+
+ switch (t) {
+ case INTEGER:
+ Integer n = (Integer) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_INTEGER, n);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_INTEGER.toString(), p.getValueAsString());
+ break;
+ case STRING:
+ String s = (String) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_STRING, s);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_STRING.toString(), p.getValueAsString());
+ break;
+ case BOOLEAN:
+ Boolean b = (Boolean) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_BOOLEAN, b);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_BOOLEAN.toString(), p.getValueAsString());
+ break;
+ case DATETIME:
+ Calendar c = (Calendar) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_DATETIME, c);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_DATETIME.toString(), p.getValueAsString());
+ break;
+ case DECIMAL:
+ Number num = (Number) value;
+ if (num instanceof Double) {
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_DOUBLE, num);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_DOUBLE.toString(), p.getValueAsString());
+ }
+ else if (num instanceof Float) {
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_FLOAT, num);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_FLOAT.toString(), p.getValueAsString());
+ }
+ else {
+ Assert.fail("Number not supported: " + num.toString());
+ }
+ break;
+ case HTML:
+ String html = (String) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_HTML, html);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_HTML.toString(), p.getValueAsString());
+ break;
+ case ID:
+ String id = (String) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_ID, id);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_ID.toString(), p.getValueAsString());
+ break;
+ case URI:
+ URI uri = (URI) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_URI, uri);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_URI.toString(), p.getValueAsString());
+ break;
+ default:
+ Assert.fail("PropertyType not supported: " + t);
+ }
+ }
+
+ }
+
+ @Test
+ public void readDocumentProperties() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.DOCUMENT1_NAME;
+ Document document = (Document) this.session.getObjectByPath(path);
+ Assert.assertNotNull("document not found: " + path, document);
+
+ List<Property<?>> l = document.getProperties();
+ Assert.assertNotNull(l);
+ Assert.assertEquals(false, l.isEmpty());
+ Iterator<Property<?>> i = l.iterator();
+ while (i.hasNext()) {
+ Property<?> p = i.next();
+ Object value = p.getValue();
+ PropertyType t = p.getType();
+
+ Assert.assertNotNull(p);
+ Assert.assertNotNull(t);
+
+ switch (t) {
+ case INTEGER:
+ Integer n = (Integer) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_INTEGER, n);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_INTEGER.toString(), p.getValueAsString());
+ break;
+ case STRING:
+ String s = (String) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_STRING, s);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_STRING.toString(), p.getValueAsString());
+ break;
+ case BOOLEAN:
+ Boolean b = (Boolean) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_BOOLEAN, b);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_BOOLEAN.toString(), p.getValueAsString());
+ break;
+ case DATETIME:
+ Calendar c = (Calendar) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_DATETIME, c);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_DATETIME.toString(), p.getValueAsString());
+ break;
+ case DECIMAL:
+ Number num = (Number) value;
+ if (num instanceof Double) {
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_DOUBLE, num);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_DOUBLE.toString(), p.getValueAsString());
+ }
+ else if (num instanceof Float) {
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_FLOAT, num);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_FLOAT.toString(), p.getValueAsString());
+ }
+ else {
+ Assert.fail("Number not supported: " + num.toString());
+ }
+ break;
+ case HTML:
+ String html = (String) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_HTML, html);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_HTML.toString(), p.getValueAsString());
+ break;
+ case ID:
+ String id = (String) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_ID, id);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_ID.toString(), p.getValueAsString());
+ break;
+ case URI:
+ URI uri = (URI) value;
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_URI, uri);
+ Assert.assertEquals(Fixture.PROPERTY_VALUE_URI.toString(), p.getValueAsString());
+ break;
+ default:
+ Assert.fail("PropertyType not supported: " + t);
+ }
+ }
+ }
+
+ @Test
+ public void readSingleProperty() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.DOCUMENT1_NAME;
+ Document document = (Document) this.session.getObjectByPath(path);
+ Assert.assertNotNull("document not found: " + path, document);
+
+ Property<String> p = document.getProperty(CmisProperties.OBJECT_ID.value());
+ Assert.assertNotNull(p);
+ String v1 = p.getValue();
+ Assert.assertNotNull(v1);
+
+ String v2 = document.getPropertyValue(CmisProperties.OBJECT_ID.value());
+ Assert.assertNotNull(v2);
+ Assert.assertEquals(v1, v2);
+
+ }
+
+ @Test
+ public void readMultiValueProperty() {
+ String path = "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/" + Fixture.DOCUMENT1_NAME;
+ Document document = (Document) this.session.getObjectByPath(path);
+ Assert.assertNotNull("document not found: " + path, document);
+
+ Property<String> p = document.getProperty(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED);
+ Assert.assertNotNull(p);
+ Assert.assertTrue(p.isMultiValued());
+ List<String> v1 = p.getValues();
+ Assert.assertNotNull(v1);
+ Assert.assertFalse(v1.isEmpty());
+
+ List<String> v2 = document.getPropertyMultivalue(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED);
+ Assert.assertNotNull(v2);
+ Assert.assertFalse(v2.isEmpty());
+ Assert.assertEquals(v1, v2);
+ }
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyObjectTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyRepositoryInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyRepositoryInfoTest.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyRepositoryInfoTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyRepositoryInfoTest.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test;
+
+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;
+
+/**
+ * Testing folder and files.
+ */
+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);
+ Assert.assertNotNull(r.getThinClientUri());
+ this.log.info("getThinClientUri = " + r.getThinClientUri());
+ }
+
+ @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:
+ PagingList<ChangeEvent> cep = this.session.getContentChanges(null, -1);
+ Assert.assertNotNull(cep);
+ for (List<ChangeEvent> le : cep) {
+ for (ChangeEvent ce : le) {
+ TypeOfChanges toc = ce.getChangeType();
+ Assert.assertNotNull(toc);
+ switch (toc) {
+ case CREATED:
+ case DELETED:
+ case SECURITY:
+ case UPDATED:
+ break;
+ default:
+ Assert.fail("change type not supported: " + toc);
+ }
+ List<Property<?>> pl = ce.getNewProperties();
+ Assert.assertNotNull(pl);
+ String id = ce.getObjectId();
+ Assert.assertNotNull(id);
+ }
+ }
+ break;
+ 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:
+ PagingList<CmisObject> resultSet = this.session.query(Fixture.QUERY, false, -1);
+ Assert.assertNotNull(resultSet);
+ Assert.assertFalse(resultSet.isEmpty());
+ break;
+ case NONE:
+ 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
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyRepositoryInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlySessionTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlySessionTest.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlySessionTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlySessionTest.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.apache.opencmis.client.api.Folder;
+
+/**
+ * Testing session
+ */
+public class ReadOnlySessionTest extends AbstractSessionTest {
+
+ @Test
+ public void testSession() {
+ Assert.assertNotNull(this.session.getContext());
+ Assert.assertNotNull(this.session.getLocale());
+ Assert.assertNotNull(this.session.getObjectFactory());
+ Assert.assertNotNull(this.session.getRepositoryInfo());
+ }
+
+ @Test
+ public void testSessionObjectAccess() {
+ Folder root = this.session.getRootFolder();
+ Assert.assertNotNull(root);
+ String id = root.getId();
+ Assert.assertNotNull(this.session.getObject(id));
+ String path = root.getPath();
+ Assert.assertNotNull(this.session.getObjectByPath(path));
+
+ }
+
+ @Test
+ public void testSessionClear() {
+ this.session.clear();
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlySessionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyTypeTest.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyTypeTest.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyTypeTest.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.opencmis.client.api.objecttype.DocumentType;
+import org.apache.opencmis.client.api.objecttype.FolderType;
+import org.apache.opencmis.client.api.objecttype.ObjectType;
+import org.apache.opencmis.client.api.objecttype.PolicyType;
+import org.apache.opencmis.client.api.objecttype.RelationshipType;
+import org.apache.opencmis.client.api.util.PagingList;
+import org.junit.Test;
+
+public class ReadOnlyTypeTest extends AbstractSessionTest {
+
+ @Test
+ public void readBaseTypePolicy() {
+ ObjectType otd = this.session.getTypeDefinition(ObjectType.POLICY_BASETYPE_ID);
+ Assert.assertNotNull(otd);
+ Assert.assertTrue(otd instanceof PolicyType);
+ Assert.assertEquals(ObjectType.POLICY_BASETYPE_ID, otd.getId());
+ Assert.assertEquals(null, otd.getBaseType());
+ }
+
+ @Test
+ public void readBaseTypeRelation() {
+ ObjectType otd = this.session.getTypeDefinition(ObjectType.RELATIONSHIP_BASETYPE_ID);
+ Assert.assertNotNull(otd);
+ Assert.assertTrue(otd instanceof RelationshipType);
+ Assert.assertEquals(ObjectType.RELATIONSHIP_BASETYPE_ID, otd.getId());
+ Assert.assertEquals(null, otd.getBaseType());
+ }
+
+ @Test
+ public void readBaseTypeDocument() {
+ ObjectType otd = this.session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID);
+ Assert.assertNotNull(otd);
+ Assert.assertTrue(otd instanceof DocumentType);
+ Assert.assertEquals(ObjectType.DOCUMENT_BASETYPE_ID, otd.getId());
+ Assert.assertEquals(null, otd.getBaseType());
+
+ }
+
+ @Test
+ public void readBaseTypeFolder() {
+ ObjectType otf = this.session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID);
+ Assert.assertNotNull(otf);
+ Assert.assertTrue(otf instanceof FolderType);
+ Assert.assertEquals(ObjectType.FOLDER_BASETYPE_ID, otf.getId());
+ Assert.assertEquals(null, otf.getBaseType());
+ }
+
+ @Test
+ public void readTypeChildrenDocument() {
+ ObjectType otd = this.session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID);
+ Assert.assertNotNull(otd);
+ PagingList<ObjectType> pc = this.session.getTypeChildren(otd, true, -1);
+ Assert.assertNotNull(pc);
+
+ for (List<ObjectType> children : pc) {
+ for (ObjectType ot1 : children) {
+ ObjectType ot2 = this.session.getTypeDefinition(ot1.getId());
+ Assert.assertEquals(ot1, ot2);
+ }
+ }
+ }
+
+ @Test
+ public void readTypeChildrenFolder() {
+ ObjectType otd = this.session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID);
+ Assert.assertNotNull(otd);
+ PagingList<ObjectType> pc = this.session.getTypeChildren(otd, true, -1);
+ Assert.assertNotNull(pc);
+
+ for (List<ObjectType> children : pc) {
+ for (ObjectType ot1 : children) {
+ ObjectType ot2 = this.session.getTypeDefinition(ot1.getId());
+ Assert.assertEquals(ot1, ot2);
+ }
+ }
+ }
+
+ @Test
+ public void readTypeDescandantsDocument() {
+ ObjectType otd = this.session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID);
+ Assert.assertNotNull(otd);
+ PagingList<ObjectType> children = this.session.getTypeDescendants(otd, 1, true, -1);
+ Assert.assertNotNull(children);
+ }
+
+ @Test
+ public void readTypeDescandantsFolder() {
+ ObjectType otd = this.session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID);
+ Assert.assertNotNull(otd);
+ PagingList<ObjectType> children = this.session.getTypeDescendants(otd, 1, true, -1);
+ Assert.assertNotNull(children);
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/ReadOnlyTypeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/mock/MockSessionFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/mock/MockSessionFactory.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/mock/MockSessionFactory.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/mock/MockSessionFactory.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,637 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test.mock;
+
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.io.ByteArrayInputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Enumeration;
+import java.util.GregorianCalendar;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.UUID;
+
+import org.apache.opencmis.client.api.ChangeEvent;
+import org.apache.opencmis.client.api.CmisObject;
+import org.apache.opencmis.client.api.ContentStream;
+import org.apache.opencmis.client.api.Document;
+import org.apache.opencmis.client.api.Folder;
+import org.apache.opencmis.client.api.Property;
+import org.apache.opencmis.client.api.Session;
+import org.apache.opencmis.client.api.SessionContext;
+import org.apache.opencmis.client.api.SessionFactory;
+import org.apache.opencmis.client.api.objecttype.DocumentType;
+import org.apache.opencmis.client.api.objecttype.FolderType;
+import org.apache.opencmis.client.api.objecttype.ObjectType;
+import org.apache.opencmis.client.api.objecttype.PolicyType;
+import org.apache.opencmis.client.api.objecttype.RelationshipType;
+import org.apache.opencmis.client.api.repository.ObjectFactory;
+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.PropertyIds;
+import org.apache.opencmis.commons.SessionParameter;
+import org.apache.opencmis.commons.enums.BaseObjectTypeIds;
+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.CmisProperties;
+import org.apache.opencmis.commons.enums.PropertyType;
+import org.apache.opencmis.commons.enums.SessionType;
+import org.apache.opencmis.commons.enums.TypeOfChanges;
+import org.apache.opencmis.commons.exceptions.CmisNotSupportedException;
+import org.apache.opencmis.test.Fixture;
+
+/**
+ * MockSessionFactory based on EasyMock Framework.
+ */
+public class MockSessionFactory implements SessionFactory {
+
+ private Session mockSession;
+
+ {
+ this.idObjectIndex = new Hashtable<String, CmisObject>();
+ this.idTypeIndex = new Hashtable<String, ObjectType>();
+ this.mockSession = this.createMockSession();
+ }
+
+ private Hashtable<String, CmisObject> idObjectIndex = null;
+ private Hashtable<String, ObjectType> idTypeIndex = null;
+
+ @SuppressWarnings("unchecked")
+ public <T extends Session> T createSession(Map<String, String> parameters) {
+ T session = null;
+ SessionType st;
+ String p = parameters.get(SessionParameter.SESSION_TYPE);
+
+ if (p == null) {
+ st = SessionType.PERSISTENT; // default, if type is not set
+ }
+ else {
+ st = SessionType.fromValue(p);
+ }
+
+ switch (st) {
+ case PERSISTENT:
+ session = (T) this.mockSession;
+ break;
+ case TRANSIENT:
+ throw new CmisNotSupportedException("SessionType = " + st);
+ }
+
+ return session;
+ }
+
+ private Session createMockSession() {
+ this.createMockGlobalTypes();
+
+ Session session = createNiceMock(Session.class);
+ Folder rootFolder = this.createMockRepositoryRootFolder();
+ this.createMockTestRootFolder(rootFolder);
+
+ expect(session.getRepositoryInfo()).andReturn(this.createMockRepositoryInfo()).anyTimes();
+ expect(session.getRootFolder()).andReturn(rootFolder).anyTimes();
+
+ expect(session.getContext()).andReturn(this.createMockSessionContext()).anyTimes();
+ expect(session.getLocale()).andReturn(new Locale("EN")).anyTimes();
+ expect(session.getObjectFactory()).andReturn(this.createMockObjectFactory()).anyTimes();
+
+ expect(session.getTypeDefinition(ObjectType.DOCUMENT_BASETYPE_ID)).andReturn(
+ this.idTypeIndex.get(ObjectType.DOCUMENT_BASETYPE_ID)).anyTimes();
+ expect(session.getTypeDefinition(ObjectType.FOLDER_BASETYPE_ID)).andReturn(
+ this.idTypeIndex.get(ObjectType.FOLDER_BASETYPE_ID)).anyTimes();
+ expect(session.getTypeDefinition(ObjectType.POLICY_BASETYPE_ID)).andReturn(
+ this.idTypeIndex.get(ObjectType.POLICY_BASETYPE_ID)).anyTimes();
+ expect(session.getTypeDefinition(ObjectType.RELATIONSHIP_BASETYPE_ID)).andReturn(
+ this.idTypeIndex.get(ObjectType.RELATIONSHIP_BASETYPE_ID)).anyTimes();
+ expect(session.getTypeDefinition(Fixture.DOCUMENT_TYPE_ID)).andReturn(
+ this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID)).anyTimes();
+ expect(session.getTypeDefinition(Fixture.FOLDER_TYPE_ID)).andReturn(
+ this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
+
+ /* document child/descendants types */
+ List<ObjectType> dtl = new ArrayList<ObjectType>();
+ dtl.add(this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID));
+ PagingList<ObjectType> plot = this.createMockPaging(dtl);
+ expect(
+ session.getTypeChildren(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_DOCUMENT.value()),
+ true, -1)).andReturn(plot).anyTimes();
+ expect(
+ session.getTypeDescendants(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_DOCUMENT.value()),
+ 1, true, -1)).andReturn(plot).anyTimes();
+
+ /* folder child/descendants types */
+ List<ObjectType> ftl = new ArrayList<ObjectType>();
+ ftl.add(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID));
+ PagingList<ObjectType> plfot = this.createMockPaging(ftl);
+ expect(
+ session.getTypeChildren(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()), true,
+ -1)).andReturn(plfot).anyTimes();
+ expect(
+ session.getTypeDescendants(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()), 1,
+ true, -1)).andReturn(plfot).anyTimes();
+
+ /* change support */
+ List<ChangeEvent> cel = this.createMockChangeEvents();
+ PagingList<ChangeEvent> plce = this.createMockPaging(cel);
+ expect(session.getContentChanges(null, -1)).andReturn(plce).anyTimes();
+
+ /* query support */
+ List<CmisObject> queryList = new ArrayList<CmisObject>(this.idObjectIndex.values());
+ PagingList<CmisObject> plq = this.createMockPaging(queryList);
+ expect(session.query(Fixture.QUERY, false, -1)).andReturn(plq).anyTimes();
+
+ this.makeObjectsAccessible(session);
+
+ replay(session);
+
+ return session;
+ }
+
+ private List<ChangeEvent> createMockChangeEvents() {
+ List<ChangeEvent> cel = new ArrayList<ChangeEvent>();
+ ChangeEvent ce = createNiceMock(ChangeEvent.class);
+ List<Property<?>> pl = new ArrayList<Property<?>>();
+
+ expect(ce.getObjectId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(ce.getChangeType()).andReturn(TypeOfChanges.CREATED).anyTimes();
+ expect(ce.getNewProperties()).andReturn(pl).anyTimes();
+
+ replay(ce);
+
+ cel.add(ce);
+
+ return cel;
+ }
+
+ private void makeObjectsAccessible(Session s) {
+ Enumeration<String> e = this.idObjectIndex.keys();
+ String id;
+ String path;
+ CmisObject obj;
+
+ while (e.hasMoreElements()) {
+ id = e.nextElement();
+ obj = this.idObjectIndex.get(id);
+ path = obj.getPath();
+
+ expect(s.getObjectByPath(path)).andReturn(obj).anyTimes();
+ expect(s.getObject(id)).andReturn(obj).anyTimes();
+ }
+ }
+
+ private ObjectFactory createMockObjectFactory() {
+ ObjectFactory of = createNiceMock(ObjectFactory.class);
+
+ replay(of);
+
+ return of;
+ }
+
+ private SessionContext createMockSessionContext() {
+ SessionContext sc = createNiceMock(SessionContext.class);
+
+ replay(sc);
+
+ return sc;
+ }
+
+ private Folder createMockTestRootFolder(Folder parent) {
+ Folder f = createNiceMock(Folder.class);
+
+ expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(f.getName()).andReturn(Fixture.TEST_ROOT_FOLDER_NAME).anyTimes();
+ expect(f.getPath()).andReturn("/" + Fixture.TEST_ROOT_FOLDER_NAME).anyTimes();
+ expect(f.getFolderParent()).andReturn(parent).anyTimes();
+ expect(f.getType()).andReturn(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
+ expect(f.getBaseType()).andReturn(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()))
+ .anyTimes();
+ List<CmisObject> children = new ArrayList<CmisObject>();
+ children.add(this.createMockTestFolder(f, "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
+ + Fixture.FOLDER1_NAME, Fixture.FOLDER1_NAME));
+ children.add(this.createMockTestFolder(f, "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
+ + Fixture.FOLDER2_NAME, Fixture.FOLDER2_NAME));
+ children.add(this.createMockTestDocument(f, "/" + Fixture.TEST_ROOT_FOLDER_NAME + "/"
+ + Fixture.DOCUMENT1_NAME, Fixture.DOCUMENT1_NAME));
+
+ PagingList<CmisObject> pl = this.createMockPaging(children);
+ expect(f.getChildren(null, -1)).andReturn(pl).anyTimes();
+
+ TreeMap<String, CmisObject> tree = new TreeMap<String, CmisObject>();
+ Folder f1 = this.createMockTestFolder(f, "/" + Fixture.FOLDER1_NAME, Fixture.FOLDER1_NAME);
+ Folder f2 = this.createMockTestFolder(f, "/" + Fixture.FOLDER2_NAME, Fixture.FOLDER2_NAME);
+ tree.put(f1.getId(), f1);
+ tree.put(f2.getId(), f2);
+ expect(f.getDescendants(-1)).andReturn(tree).anyTimes();
+ expect(f.getFolderTree(-1)).andReturn(tree).anyTimes();
+ this.createMockProperties(f);
+
+ replay(f);
+ this.idObjectIndex.put(f.getId(), f);
+
+ return f;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void createMockProperties(CmisObject o) {
+ GregorianCalendar date = new GregorianCalendar();
+
+ expect(o.getCreatedBy()).andReturn(Fixture.getParamter().get(SessionParameter.USER)).anyTimes();
+ expect(o.getLastModifiedBy()).andReturn(Fixture.getParamter().get(SessionParameter.USER))
+ .anyTimes();
+ expect(o.getLastModificationDate()).andReturn(date).anyTimes();
+ expect(o.getCreationDate()).andReturn(date).anyTimes();
+
+ {
+ ArrayList a = new ArrayList<Property<Property>>();
+
+ // mandatory default properties
+ a.add(this.createMockStringProperty(PropertyIds.CMIS_BASE_TYPE_ID));
+ a.add(this.createMockStringProperty(PropertyIds.CMIS_NAME));
+ a.add(this.createMockIntegerProperty(PropertyIds.CMIS_CONTENT_STREAM_LENGTH));
+
+ // other properties
+ a.add(this.createMockBooleanProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockDateTimeProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockFloatProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockDoubleProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockHtmlProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockIdProperty(UUID.randomUUID().toString()));
+ a.add(this.createMockUriProperty(UUID.randomUUID().toString()));
+
+ expect(o.getProperties()).andReturn(a).anyTimes();
+ expect(o.getProperties(Fixture.PROPERTY_FILTER)).andReturn(a).anyTimes();
+
+ /* single property */
+ Property<Object> p1 = (Property<Object>) createMockStringProperty(CmisProperties.OBJECT_ID
+ .value());
+ expect(o.getProperty(CmisProperties.OBJECT_ID.value())).andReturn(p1).anyTimes();
+ expect(o.getPropertyValue(CmisProperties.OBJECT_ID.value())).andReturn(p1.getValue())
+ .anyTimes();
+
+ /* multi valued property */
+ Property<Object> p2 = (Property<Object>) createMockMultiValuedStringProperty(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED);
+ expect(o.getProperty(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED)).andReturn(p2).anyTimes();
+ expect(o.getPropertyMultivalue(Fixture.PROPERTY_NAME_STRING_MULTI_VALUED)).andReturn(
+ p2.getValues()).anyTimes();
+ }
+
+ }
+
+ private Property<?> createMockMultiValuedStringProperty(String id) {
+ Property<String> p = createNiceMock(StringProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.STRING).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_STRING).anyTimes();
+ expect(p.isMultiValued()).andReturn(true).anyTimes();
+ List<String> v = new ArrayList<String>();
+ v.add(Fixture.PROPERTY_VALUE_STRING);
+ v.add(Fixture.PROPERTY_VALUE_STRING);
+ expect(p.getValues()).andReturn(v).anyTimes();
+ expect(p.getValueAsString()).andReturn(v.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockDateTimeProperty(String id) {
+ Property<Calendar> p = createNiceMock(DateTimeProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.DATETIME).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_DATETIME).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_DATETIME.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockHtmlProperty(String id) {
+ Property<String> p = createNiceMock(StringProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.HTML).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_HTML).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_HTML.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockIdProperty(String id) {
+ Property<String> p = createNiceMock(StringProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.ID).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_ID).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_ID.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockUriProperty(String id) {
+ Property<URI> p = createNiceMock(UriProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.URI).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_URI).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_URI.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockDoubleProperty(String id) {
+ Property<Double> p = createNiceMock(DoubleProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.DECIMAL).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_DOUBLE).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_DOUBLE.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockFloatProperty(String id) {
+ Property<Float> p = createNiceMock(FloatProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.DECIMAL).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_FLOAT).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_FLOAT.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockBooleanProperty(String id) {
+ Property<Boolean> p = createNiceMock(BooleanProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.BOOLEAN).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_BOOLEAN).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_BOOLEAN.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockIntegerProperty(String id) {
+ Property<Integer> p = createNiceMock(IntegerProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.INTEGER).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_INTEGER).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_INTEGER.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private Property<?> createMockStringProperty(String id) {
+ Property<String> p = createNiceMock(StringProperty.class);
+
+ expect(p.getType()).andReturn(PropertyType.STRING).anyTimes();
+ expect(p.getValue()).andReturn(Fixture.PROPERTY_VALUE_STRING).anyTimes();
+ expect(p.getValueAsString()).andReturn(Fixture.PROPERTY_VALUE_STRING.toString()).anyTimes();
+
+ replay(p);
+
+ return p;
+ }
+
+ private CmisObject createMockTestDocument(Folder parent, String path, String name) {
+ Document d = createNiceMock(Document.class);
+
+ expect(d.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(d.getName()).andReturn(name).anyTimes();
+ expect(d.getPath()).andReturn(path).anyTimes();
+ expect(d.getType()).andReturn(this.idTypeIndex.get(Fixture.DOCUMENT_TYPE_ID)).anyTimes();
+ expect(d.getBaseType())
+ .andReturn(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_DOCUMENT.value())).anyTimes();
+ this.createMockProperties(d);
+ expect(d.getContentStream()).andReturn(this.createMockContentStream()).anyTimes();
+
+ replay(d);
+ this.idObjectIndex.put(d.getId(), d);
+
+ return d;
+ }
+
+ private ContentStream createMockContentStream() {
+ ContentStream cs = createNiceMock(ContentStream.class);
+
+ byte[] b = "abc".getBytes();
+ ByteArrayInputStream bais = new ByteArrayInputStream(b);
+
+ expect(cs.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(cs.getFileName()).andReturn("file.txt").anyTimes();
+ expect(cs.getMimeType()).andReturn("text/html").anyTimes();
+ expect(cs.getLength()).andReturn(b.length).anyTimes();
+ expect(cs.getStream()).andReturn(bais).anyTimes();
+
+ replay(cs);
+
+ return cs;
+ }
+
+ private Folder createMockTestFolder(Folder parent, String path, String name) {
+ Folder f = createNiceMock(Folder.class);
+
+ expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(f.getName()).andReturn(name).anyTimes();
+ expect(f.getPath()).andReturn(path).anyTimes();
+ expect(f.getFolderParent()).andReturn(parent).anyTimes();
+ expect(f.getType()).andReturn(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
+ expect(f.getBaseType()).andReturn(this.idTypeIndex.get(BaseObjectTypeIds.CMIS_FOLDER.value()))
+ .anyTimes();
+ List<CmisObject> children = new ArrayList<CmisObject>();
+ children.add(this.createMockTestDocument(f, path + "/" + Fixture.DOCUMENT1_NAME,
+ Fixture.DOCUMENT1_NAME));
+ children.add(this.createMockTestDocument(f, path + "/" + Fixture.DOCUMENT2_NAME,
+ Fixture.DOCUMENT2_NAME));
+
+ PagingList<CmisObject> pl = this.createMockPaging(children);
+ expect(f.getChildren(null, -1)).andReturn(pl).anyTimes();
+
+ TreeMap<String, CmisObject> tree = new TreeMap<String, CmisObject>();
+ expect(f.getDescendants(-1)).andReturn(tree).anyTimes();
+ expect(f.getFolderTree(-1)).andReturn(tree).anyTimes();
+ this.createMockProperties(f);
+
+ replay(f);
+ this.idObjectIndex.put(f.getId(), f);
+
+ return f;
+ }
+
+ @SuppressWarnings( { "unchecked" })
+ private <T> PagingList<T> createMockPaging(List<T> items) {
+ PagingList<T> pl = createNiceMock(PagingList.class);
+
+ ArrayList<List<T>> a = new ArrayList<List<T>>();
+ a.add(items);
+ Iterator<List<T>> i = a.iterator();
+
+ expect(pl.get(0)).andReturn(items).anyTimes();
+ expect(pl.isEmpty()).andReturn(false).anyTimes();
+ expect(pl.iterator()).andReturn(i).anyTimes();
+
+ replay(pl);
+
+ return pl;
+ }
+
+ private void createMockGlobalTypes() {
+ FolderType bft = createNiceMock(FolderType.class);
+ expect(bft.getId()).andReturn(ObjectType.FOLDER_BASETYPE_ID).anyTimes();
+ expect(bft.isBase()).andReturn(true);
+ expect(bft.getBaseType()).andReturn(null).anyTimes();
+
+ FolderType ft = createNiceMock(FolderType.class);
+ expect(ft.getId()).andReturn(Fixture.FOLDER_TYPE_ID).anyTimes();
+ expect(ft.isBase()).andReturn(false);
+ expect(ft.getBaseType()).andReturn(bft).anyTimes();
+
+ PolicyType bpt = createNiceMock(PolicyType.class);
+ expect(bpt.getId()).andReturn(ObjectType.POLICY_BASETYPE_ID).anyTimes();
+ expect(bpt.isBase()).andReturn(true);
+ expect(bpt.getBaseType()).andReturn(null).anyTimes();
+
+ RelationshipType brt = createNiceMock(RelationshipType.class);
+ expect(brt.getId()).andReturn(ObjectType.RELATIONSHIP_BASETYPE_ID).anyTimes();
+ expect(brt.isBase()).andReturn(true);
+ expect(brt.getBaseType()).andReturn(null).anyTimes();
+
+ DocumentType bdt = createNiceMock(DocumentType.class);
+ expect(bdt.getId()).andReturn(ObjectType.DOCUMENT_BASETYPE_ID).anyTimes();
+ expect(bdt.isBase()).andReturn(true);
+ expect(bdt.getBaseType()).andReturn(null).anyTimes();
+
+ DocumentType dt = createNiceMock(DocumentType.class);
+ expect(dt.getId()).andReturn(Fixture.DOCUMENT_TYPE_ID).anyTimes();
+ expect(dt.isBase()).andReturn(false);
+ expect(dt.getBaseType()).andReturn(bft).anyTimes();
+
+ replay(bft);
+ replay(ft);
+ replay(bdt);
+ replay(dt);
+ replay(bpt);
+ replay(brt);
+
+ this.idTypeIndex.put(bft.getId(), bft);
+ this.idTypeIndex.put(ft.getId(), ft);
+ this.idTypeIndex.put(bdt.getId(), bdt);
+ this.idTypeIndex.put(dt.getId(), dt);
+ this.idTypeIndex.put(bpt.getId(), bpt);
+ this.idTypeIndex.put(brt.getId(), brt);
+
+ }
+
+ private Folder createMockRepositoryRootFolder() {
+ Folder f = createNiceMock(Folder.class);
+
+ expect(f.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(f.getName()).andReturn("").anyTimes(); // or "root" ?
+ expect(f.getPath()).andReturn("/").anyTimes();
+ expect(f.getFolderParent()).andReturn(null).anyTimes();
+ expect(f.getType()).andReturn(this.idTypeIndex.get(Fixture.FOLDER_TYPE_ID)).anyTimes();
+ this.createMockProperties(f);
+
+ replay(f);
+ this.idObjectIndex.put(f.getId(), f);
+
+ return f;
+ }
+
+ private RepositoryInfo createMockRepositoryInfo() {
+ RepositoryInfo ri = createNiceMock(RepositoryInfo.class);
+
+ expect(ri.getName()).andReturn("MockRepository").anyTimes();
+ expect(ri.getId()).andReturn(UUID.randomUUID().toString()).anyTimes();
+ expect(ri.getDescription()).andReturn("description").anyTimes();
+ expect(ri.getCmisVersionSupported()).andReturn("1.0").anyTimes();
+ expect(ri.getVendorName()).andReturn("Apache").anyTimes();
+ expect(ri.getProductName()).andReturn("OpenCMIS").anyTimes();
+ expect(ri.getPrincipalIdAnonymous()).andReturn("anonymous").anyTimes();
+ expect(ri.getPrincipalIdAnyone()).andReturn("anyone").anyTimes();
+ expect(ri.getThinClientUri()).andReturn("http://foo.com").anyTimes();
+ expect(ri.getChangesOnType()).andReturn(new ArrayList<BaseObjectTypeIds>()).anyTimes();
+
+ expect(ri.getCapabilities()).andReturn(this.createMockRepositoryCapabilities()).anyTimes();
+
+ replay(ri);
+
+ return ri;
+ }
+
+ private RepositoryCapabilities createMockRepositoryCapabilities() {
+ RepositoryCapabilities rc = createNiceMock(RepositoryCapabilities.class);
+
+ expect(rc.getAclSupport()).andReturn(CapabilityAcl.NONE).anyTimes();
+ expect(rc.getChangesSupport()).andReturn(CapabilityChanges.ALL).anyTimes();
+ expect(rc.getContentStreamUpdatabilitySupport()).andReturn(CapabilityContentStreamUpdates.NONE)
+ .anyTimes();
+ expect(rc.getJoinSupport()).andReturn(CapabilityJoin.NONE).anyTimes();
+ expect(rc.getQuerySupport()).andReturn(CapabilityQuery.BOTHCOMBINED).anyTimes();
+ expect(rc.getRenditionsSupport()).andReturn(CapabilityRendition.NONE).anyTimes();
+
+ replay(rc);
+
+ return rc;
+ }
+
+ private interface StringProperty extends Property<String> {
+ }
+
+ private interface IntegerProperty extends Property<Integer> {
+ }
+
+ private interface DoubleProperty extends Property<Double> {
+ }
+
+ private interface FloatProperty extends Property<Float> {
+ }
+
+ private interface DateTimeProperty extends Property<Calendar> {
+ }
+
+ private interface UriProperty extends Property<URI> {
+ }
+
+ private interface BooleanProperty extends Property<Boolean> {
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/mock/MockSessionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/AbstractCmisTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/AbstractCmisTestSuite.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/AbstractCmisTestSuite.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/AbstractCmisTestSuite.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test.suite;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.PropertyConfigurator;
+import org.junit.runners.Suite;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+import org.apache.opencmis.test.Fixture;
+
+/**
+ * Abstract test suite for initialization of
+ * <ul>
+ * <li>logging
+ * <li>abstract fixture initialization
+ * </ul>
+ *
+ */
+public abstract class AbstractCmisTestSuite extends Suite {
+
+ protected Log log = LogFactory.getLog(this.getClass());
+
+ /**
+ * Standard suite constructor for initialization.
+ *
+ * @param klass
+ * @param r
+ * @throws InitializationError
+ */
+ public AbstractCmisTestSuite(Class<?> klass, RunnerBuilder r) throws InitializationError {
+ super(klass, r);
+
+ this.initializeLogging();
+ this.initializeFixture();
+ this.writeLogEntry();
+ }
+
+ private void writeLogEntry() {
+ this.log.info("---------------------------------------------------------------");
+ this.log.info("--- CMIS Test Suite Setup -------------------------------------");
+ this.log.info("---------------------------------------------------------------");
+ this.log.info("test suite: " + this.getClass());
+ this.log.info("session factory: " + Fixture.getSessionFactory().getClass());
+ this.log.info("session parameter: " + Fixture.getParamter());
+ this.log.info("---------------------------------------------------------------");
+ }
+
+ /**
+ * Abstract fixture initialization.
+ */
+ protected abstract void initializeFixture();
+
+ /**
+ * Initialize logging support.
+ */
+ private void initializeLogging() {
+ Properties p = new Properties();
+ try {
+ p.load(AbstractCmisTestSuite.class.getResourceAsStream("/log4j.properties"));
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ PropertyConfigurator.configure(p);
+
+ }
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/AbstractCmisTestSuite.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/mock/MockTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/mock/MockTestSuite.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/mock/MockTestSuite.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/mock/MockTestSuite.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test.suite.mock;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.opencmis.commons.SessionParameter;
+import org.apache.opencmis.test.Fixture;
+import org.apache.opencmis.test.ReadOnlyAclCapabilityTest;
+import org.apache.opencmis.test.ReadOnlyContentStreamTest;
+import org.apache.opencmis.test.ReadOnlyCreateSessionTest;
+import org.apache.opencmis.test.ReadOnlyDiscoverTest;
+import org.apache.opencmis.test.ReadOnlyNavigationTest;
+import org.apache.opencmis.test.ReadOnlyObjectTest;
+import org.apache.opencmis.test.ReadOnlyRepositoryInfoTest;
+import org.apache.opencmis.test.ReadOnlySessionTest;
+import org.apache.opencmis.test.ReadOnlyTypeTest;
+import org.apache.opencmis.test.mock.MockSessionFactory;
+import org.apache.opencmis.test.suite.AbstractCmisTestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+
+/**
+ * Test suite to run API Mock
+ */
+@RunWith(MockTestSuite.class)
+@SuiteClasses( { ReadOnlyCreateSessionTest.class, ReadOnlySessionTest.class,
+ ReadOnlyRepositoryInfoTest.class, ReadOnlyAclCapabilityTest.class, ReadOnlyObjectTest.class,
+ ReadOnlyTypeTest.class, ReadOnlyNavigationTest.class, ReadOnlyContentStreamTest.class,
+ ReadOnlyDiscoverTest.class })
+public class MockTestSuite extends AbstractCmisTestSuite {
+
+ public MockTestSuite(Class<?> klass, RunnerBuilder r) throws InitializationError {
+ super(klass, r);
+ }
+
+ @Override
+ protected void initializeFixture() {
+ Map<String, String> parameter = new HashMap<String, String>();
+
+ parameter.put(SessionParameter.USER, "Mr. Mock");
+ parameter.put(SessionParameter.PASSWORD, "*mock#");
+ parameter.put(SessionParameter.LOCALE_ISO639_LANGUAGE, "EN");
+
+ Fixture.setSessionFactory(new MockSessionFactory());
+ Fixture.setParamter(parameter);
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/mock/MockTestSuite.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxAtomPubCmisTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxAtomPubCmisTestSuite.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxAtomPubCmisTestSuite.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxAtomPubCmisTestSuite.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test.suite.otx;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+import org.apache.opencmis.test.Fixture;
+import org.apache.opencmis.test.ReadOnlyAclCapabilityTest;
+import org.apache.opencmis.test.ReadOnlyCreateSessionTest;
+import org.apache.opencmis.test.ReadOnlyObjectTest;
+import org.apache.opencmis.test.ReadOnlyRepositoryInfoTest;
+import org.apache.opencmis.test.suite.AbstractCmisTestSuite;
+
+/**
+ * Test suite to run OTX AtomPub binding.
+ */
+@RunWith(OtxAtomPubCmisTestSuite.class)
+@SuiteClasses( { ReadOnlyCreateSessionTest.class, ReadOnlyRepositoryInfoTest.class,
+ ReadOnlyObjectTest.class, ReadOnlyAclCapabilityTest.class })
+public class OtxAtomPubCmisTestSuite extends AbstractCmisTestSuite {
+
+ public OtxAtomPubCmisTestSuite(Class<?> klass, RunnerBuilder r) throws InitializationError {
+ super(klass, r);
+ }
+
+ @Override
+ protected void initializeFixture() {
+ Map<String, String> parameter = new HashMap<String, String>();
+ // parameter.put(Session.URL, "http://pwdf6227:8080/cmis/atom");
+ // parameter.put(Session.USER, "test");
+ // parameter.put(Session.PASSWORD, "test");
+ // parameter.put(Session.BINDING, "atompub");
+ // parameter.put(Session.PROVIDER, "otx");
+ // parameter.put(Session.REPOSITORY_ID, "myRepository");
+
+ Fixture.setParamter(parameter);
+ Fixture.setSessionFactory(null);
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxAtomPubCmisTestSuite.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxInMemoryCmisTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxInMemoryCmisTestSuite.java?rev=910572&view=auto
==============================================================================
--- incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxInMemoryCmisTestSuite.java (added)
+++ incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxInMemoryCmisTestSuite.java Tue Feb 16 16:03:38 2010
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.opencmis.test.suite.otx;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+import org.apache.opencmis.test.Fixture;
+import org.apache.opencmis.test.ReadOnlyAclCapabilityTest;
+import org.apache.opencmis.test.ReadOnlyCreateSessionTest;
+import org.apache.opencmis.test.ReadOnlyObjectTest;
+import org.apache.opencmis.test.ReadOnlyRepositoryInfoTest;
+import org.apache.opencmis.test.suite.AbstractCmisTestSuite;
+
+/**
+ * Test suite to run InMemory binding.
+ */
+@RunWith(OtxInMemoryCmisTestSuite.class)
+@SuiteClasses( { ReadOnlyCreateSessionTest.class, ReadOnlyRepositoryInfoTest.class,
+ ReadOnlyAclCapabilityTest.class, ReadOnlyObjectTest.class })
+public class OtxInMemoryCmisTestSuite extends AbstractCmisTestSuite {
+
+ public OtxInMemoryCmisTestSuite(Class<?> klass, RunnerBuilder r) throws InitializationError {
+ super(klass, r);
+ }
+
+ @Override
+ protected void initializeFixture() {
+ Map<String, String> parameter = new HashMap<String, String>();
+ // parameter.put(Session.USER, "test");
+ // parameter.put(Session.BINDING, "inmemory");
+ // parameter.put(Session.PROVIDER, "otx");
+ // parameter.put(Session.REPOSITORY_ID, "InMemory");
+
+ Fixture.setParamter(parameter);
+ Fixture.setSessionFactory(null);
+ }
+
+}
Propchange: incubator/chemistry/trunk/opencmis/opencmis-client/opencmis-client-impl/src/test/java/org/apache/opencmis/test/suite/otx/OtxInMemoryCmisTestSuite.java
------------------------------------------------------------------------------
svn:eol-style = native