You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2010/04/15 12:33:51 UTC
svn commit: r934361 [7/9] - in /incubator/chemistry/opencmis/trunk:
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/
chemistry-opencmis-client/chemistry-opencmis-client-bindings/s...
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java?rev=934361&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java Thu Apr 15 10:33:49 2010
@@ -0,0 +1,149 @@
+/*
+ * 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.chemistry.opencmis.client.bindings.atompub;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl;
+import org.apache.chemistry.opencmis.commons.provider.AccessControlEntry;
+import org.apache.chemistry.opencmis.commons.provider.AccessControlList;
+
+/**
+ * Test for the ACL merging that is necessary in the AtomPub binding implementation.
+ *
+ * @author <a href="mailto:fmueller@opentext.com">Florian Müller</a>
+ *
+ */
+public class AclMergeTest extends TestCase {
+
+ public void testIsACLMergeRequired() throws Exception {
+ AtomPubService service = new AtomPubService();
+
+ assertFalse(service.publicIsACLMergeRequired(null, null));
+ assertFalse(service.publicIsACLMergeRequired(new AccessControlListImpl(), null));
+ assertFalse(service.publicIsACLMergeRequired(null, new AccessControlListImpl()));
+ assertFalse(service.publicIsACLMergeRequired(new AccessControlListImpl(),
+ new AccessControlListImpl()));
+ }
+
+ public void testAclMerge() throws Exception {
+ AtomPubService service = new AtomPubService();
+
+ // original
+ Map<String, String[]> originalAceData = new HashMap<String, String[]>();
+
+ originalAceData.put("p1", new String[] { "perm:read", "perm:write", "perm:delete" });
+ originalAceData.put("p2", new String[] { "perm:read" });
+ originalAceData.put("p3", new String[] { "perm:all" });
+
+ AccessControlList originalACEs = createACL(originalAceData);
+
+ // add
+ Map<String, String[]> addAceData = new HashMap<String, String[]>();
+
+ addAceData.put("p2", new String[] { "perm:write" });
+ addAceData.put("p4", new String[] { "perm:all" });
+
+ AccessControlList addACEs = createACL(addAceData);
+
+ // remove
+ Map<String, String[]> removeAceData = new HashMap<String, String[]>();
+
+ removeAceData.put("p1", new String[] { "perm:write" });
+ removeAceData.put("p3", new String[] { "perm:all" });
+
+ AccessControlList removeACEs = createACL(removeAceData);
+
+ AccessControlList newACL = service.publicMergeACLs(originalACEs, addACEs, removeACEs);
+
+ assertEquals(3, newACL.getAces().size());
+
+ for (AccessControlEntry ace : newACL.getAces()) {
+ String principal = ace.getPrincipal().getPrincipalId();
+ assertNotNull(principal);
+
+ if (principal.equals("p1")) {
+ assertEquals(2, ace.getPermissions().size());
+ assertTrue(ace.getPermissions().contains("perm:read"));
+ assertTrue(ace.getPermissions().contains("perm:delete"));
+ assertFalse(ace.getPermissions().contains("perm:write"));
+ }
+ else if (principal.equals("p2")) {
+ assertEquals(2, ace.getPermissions().size());
+ assertTrue(ace.getPermissions().contains("perm:read"));
+ assertTrue(ace.getPermissions().contains("perm:write"));
+ }
+ else if (principal.equals("p3")) {
+ fail("Principal should be deleted!");
+ }
+ else if (principal.equals("p4")) {
+ assertEquals(1, ace.getPermissions().size());
+ assertTrue(ace.getPermissions().contains("perm:all"));
+ }
+ }
+ }
+
+ /**
+ * Creates an ACL structure from a Map.
+ */
+ private AccessControlList createACL(Map<String, String[]> aceData) {
+ AccessControlListImpl result = new AccessControlListImpl();
+
+ List<AccessControlEntry> aces = new ArrayList<AccessControlEntry>();
+
+ for (Map.Entry<String, String[]> e : aceData.entrySet()) {
+ ArrayList<String> permissions = new ArrayList<String>();
+
+ for (String s : e.getValue()) {
+ permissions.add(s);
+ }
+
+ AccessControlEntryImpl ace = new AccessControlEntryImpl(new AccessControlPrincipalDataImpl(e
+ .getKey()), permissions);
+
+ aces.add(ace);
+ }
+
+ result.setAces(aces);
+
+ return result;
+ }
+
+ /**
+ * A class to make a few protected methods publicly available.
+ */
+ private static class AtomPubService extends AbstractAtomPubService {
+ public AccessControlList publicMergeACLs(AccessControlList originalACEs,
+ AccessControlList addACEs, AccessControlList removeACEs) {
+ return mergeAcls(originalACEs, addACEs, removeACEs);
+ }
+
+ public boolean publicIsACLMergeRequired(AccessControlList addACEs, AccessControlList removeACEs) {
+ return isAclMergeRequired(addACEs, removeACEs);
+ }
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AclMergeTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java?rev=934361&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java Thu Apr 15 10:33:49 2010
@@ -0,0 +1,161 @@
+/*
+ * 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.chemistry.opencmis.client.bindings.atompub;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.chemistry.opencmis.client.bindings.spi.atompub.AtomEntryWriter;
+import org.apache.chemistry.opencmis.client.bindings.spi.atompub.AtomPubParser;
+import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomBase;
+import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomElement;
+import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomEntry;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertiesType;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisProperty;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertyDecimal;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertyInteger;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertyString;
+
+/**
+ * Minimal test for AtomEntryWriter and AtomPubParser.
+ *
+ * @author <a href="mailto:fmueller@opentext.com">Florian Müller</a>
+ *
+ */
+public class AtomParserTest extends TestCase {
+
+ private static final byte[] CONTENT = "This is my test content!".getBytes();
+ private static final String CONTENT_TYPE = "text/plain";
+
+ public void testParser() throws Exception {
+ ByteArrayOutputStream bao = new ByteArrayOutputStream();
+
+ // set up an object
+ CmisPropertiesType properties = new CmisPropertiesType();
+
+ CmisPropertyString propName = new CmisPropertyString();
+ propName.setPropertyDefinitionId(PropertyIds.CMIS_NAME);
+ propName.getValue().add("TestName");
+ properties.getProperty().add(propName);
+
+ CmisPropertyInteger propInt = new CmisPropertyInteger();
+ propInt.setPropertyDefinitionId("IntProp");
+ propInt.getValue().add(BigInteger.valueOf(1));
+ propInt.getValue().add(BigInteger.valueOf(2));
+ propInt.getValue().add(BigInteger.valueOf(3));
+ properties.getProperty().add(propInt);
+
+ CmisPropertyDecimal propDec = new CmisPropertyDecimal();
+ propDec.setPropertyDefinitionId("DecProp");
+ propDec.getValue().add(
+ new BigDecimal("3.14159253589793238462643383279502884197"
+ + "169399375105820974944592307816406286208998628034825342117067982148086513"));
+ properties.getProperty().add(propDec);
+
+ CmisObjectType object1 = new CmisObjectType();
+ object1.setProperties(properties);
+
+ // write the entry
+ AtomEntryWriter aew = new AtomEntryWriter(object1, CONTENT_TYPE, new ByteArrayInputStream(
+ CONTENT));
+ aew.write(bao);
+
+ byte[] entryContent = bao.toByteArray();
+ assertTrue(entryContent.length > 0);
+
+ String entryContentStr = new String(entryContent, "UTF-8");
+ System.out.println(entryContentStr);
+
+ // parse it
+ AtomPubParser parser = new AtomPubParser(new ByteArrayInputStream(entryContent));
+ parser.parse();
+ AtomBase parseResult = parser.getResults();
+
+ assertTrue(parseResult instanceof AtomEntry);
+ AtomEntry entry = (AtomEntry) parseResult;
+
+ assertNotNull(entry);
+ assertTrue(entry.getElements().size() > 0);
+
+ // find the object
+ CmisObjectType object2 = null;
+ for (AtomElement element : entry.getElements()) {
+ if (element.getObject() instanceof CmisObjectType) {
+ assertNull(object2);
+ object2 = (CmisObjectType) element.getObject();
+ }
+ }
+
+ assertNotNull(object2);
+ assertNotNull(object2.getProperties());
+
+ // compare properteis
+ for (CmisProperty property1 : object1.getProperties().getProperty()) {
+ boolean found = false;
+
+ for (CmisProperty property2 : object2.getProperties().getProperty()) {
+ if (property1.getPropertyDefinitionId().equals(property2.getPropertyDefinitionId())) {
+ found = true;
+
+ assertEquals(property1, property2);
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+
+ protected void assertEquals(CmisProperty expected, CmisProperty actual) throws Exception {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if ((expected == null) || (actual == null)) {
+ fail("Property is null!");
+ }
+
+ assertEquals(expected.getPropertyDefinitionId(), actual.getPropertyDefinitionId());
+ assertEquals(expected.getClass(), actual.getClass());
+
+ Method m1 = expected.getClass().getMethod("getValue", new Class<?>[0]);
+ List<?> values1 = (List<?>) m1.invoke(expected, new Object[0]);
+ assertNotNull(values1);
+ assertFalse(values1.isEmpty());
+
+ Method m2 = actual.getClass().getMethod("getValue", new Class<?>[0]);
+ List<?> values2 = (List<?>) m2.invoke(actual, new Object[0]);
+ assertNotNull(values2);
+ assertFalse(values2.isEmpty());
+
+ assertEquals(values1.size(), values2.size());
+
+ for (int i = 0; i < values1.size(); i++) {
+ assertEquals(values1.get(i), values2.get(i));
+ }
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java?rev=934361&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java Thu Apr 15 10:33:49 2010
@@ -0,0 +1,48 @@
+/*
+ * 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.chemistry.opencmis.client.bindings.atompub;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.client.bindings.factory.CmisBindingFactory;
+import org.apache.chemistry.opencmis.commons.SessionParameter;
+import org.apache.chemistry.opencmis.commons.provider.CmisBinding;
+
+/**
+ * @author <a href="mailto:fmueller@opentext.com">Florian Müller</a>
+ *
+ */
+public class AtomPubTestBindingFactory {
+
+ public static CmisBinding createBinding(String atomPubUrl, String user, String password) {
+ // gather parameters
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put(SessionParameter.USER, user);
+ parameters.put(SessionParameter.PASSWORD, password);
+
+ parameters.put(SessionParameter.ATOMPUB_URL, atomPubUrl);
+
+ // get factory and create provider
+ CmisBindingFactory factory = CmisBindingFactory.newInstance();
+ CmisBinding binding = factory.createCmisAtomPubBinding(parameters);
+
+ return binding;
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomPubTestBindingFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java?rev=934361&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java Thu Apr 15 10:33:49 2010
@@ -0,0 +1,62 @@
+/*
+ * 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.chemistry.opencmis.client.bindings.atompub;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.chemistry.opencmis.client.bindings.framework.AbstractSimpleReadOnlyTests;
+import org.apache.chemistry.opencmis.commons.provider.CmisBinding;
+
+/**
+ * @author <a href="mailto:fmueller@opentext.com">Florian Müller</a>
+ *
+ */
+public class SimpleReadOnlyTests extends AbstractSimpleReadOnlyTests {
+
+ private Set<String> fTests;
+
+ public SimpleReadOnlyTests() {
+ fTests = new HashSet<String>();
+ fTests.add(TEST_REPOSITORY_INFO);
+ fTests.add(TEST_TYPES);
+ fTests.add(TEST_NAVIGATION);
+ fTests.add(TEST_CONTENT_STREAM);
+ fTests.add(TEST_QUERY);
+ fTests.add(TEST_CHECKEDOUT);
+ fTests.add(TEST_CONTENT_CHANGES);
+ }
+
+ @Override
+ protected CmisBinding createBinding() {
+ // Add the default Java cookie manager from Java 1.6 to optimize authentication
+ // by reusing the common case where a token is stored in a cookie.
+ // Note: Enable cookie management requires Java 1.6, uncomment the following two lines to
+ // enable cookie management for the tests.
+ // java.net.CookieManager cm = new java.net.CookieManager(null, CookiePolicy.ACCEPT_ALL);
+ // java.net.CookieHandler.setDefault(cm);
+
+ return AtomPubTestBindingFactory.createBinding(getAtomPubURL(), getUsername(), getPassword());
+ }
+
+ @Override
+ protected Set<String> getEnabledTests() {
+ return fTests;
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadOnlyTests.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java?rev=934361&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java Thu Apr 15 10:33:49 2010
@@ -0,0 +1,62 @@
+/*
+ * 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.chemistry.opencmis.client.bindings.atompub;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.chemistry.opencmis.client.bindings.framework.AbstractSimpleReadWriteTests;
+import org.apache.chemistry.opencmis.commons.provider.CmisBinding;
+
+/**
+ * @author <a href="mailto:fmueller@opentext.com">Florian Müller</a>
+ *
+ */
+public class SimpleReadWriteTests extends AbstractSimpleReadWriteTests {
+
+ private Set<String> fTests;
+
+ public SimpleReadWriteTests() {
+ fTests = new HashSet<String>();
+ fTests.add(TEST_CREATE_FOLDER);
+ fTests.add(TEST_CREATE_DOCUMENT);
+ fTests.add(TEST_SET_AND_DELETE_CONTENT);
+ fTests.add(TEST_UPDATE_PROPERTIES);
+ fTests.add(TEST_DELETE_TREE);
+ fTests.add(TEST_MOVE_OBJECT);
+ fTests.add(TEST_VERSIONING);
+ }
+
+ @Override
+ protected CmisBinding createBinding() {
+ // Add the default Java cookie manager from Java 1.6 to optimize authentication
+ // by reusing the common case where a token is stored in a cookie.
+ // Note: Enable cookie management requires Java 1.6, uncomment the following two lines to
+ // enable cookie management for the tests.
+ // java.net.CookieManager cm = new java.net.CookieManager(null, CookiePolicy.ACCEPT_ALL);
+ // java.net.CookieHandler.setDefault(cm);
+
+ return AtomPubTestBindingFactory.createBinding(getAtomPubURL(), getUsername(), getPassword());
+ }
+
+ @Override
+ protected Set<String> getEnabledTests() {
+ return fTests;
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/SimpleReadWriteTests.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java?rev=934361&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java Thu Apr 15 10:33:49 2010
@@ -0,0 +1,222 @@
+/*
+ * 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.chemistry.opencmis.client.bindings.cache;
+
+import junit.framework.TestCase;
+
+import org.apache.chemistry.opencmis.client.bindings.cache.Cache;
+import org.apache.chemistry.opencmis.client.bindings.cache.impl.CacheImpl;
+import org.apache.chemistry.opencmis.client.bindings.cache.impl.ContentTypeCacheLevelImpl;
+import org.apache.chemistry.opencmis.client.bindings.cache.impl.LruCacheLevelImpl;
+import org.apache.chemistry.opencmis.client.bindings.cache.impl.MapCacheLevelImpl;
+
+/**
+ * Tests the cache implementation.
+ *
+ * @author <a href="mailto:fmueller@opentext.com">Florian Müller</a>
+ *
+ */
+public class CacheTest extends TestCase {
+
+ public final static String MAP_CACHE_LEVEL = "org.apache.chemistry.opencmis.client.bindings.cache.impl.MapCacheLevelImpl";
+ public final static String LRU_CACHE_LEVEL = "org.apache.chemistry.opencmis.client.bindings.cache.impl.LruCacheLevelImpl";
+
+ public void testCache() throws Exception {
+ Cache cache;
+
+ cache = new CacheImpl();
+ cache.initialize(new String[] { MAP_CACHE_LEVEL, LRU_CACHE_LEVEL, MAP_CACHE_LEVEL,
+ MAP_CACHE_LEVEL });
+
+ String value1 = "value1";
+ String value2 = "value2";
+ String value3 = "value3";
+ Object valueObj;
+
+ // put and get
+ cache.put(value1, "l1", "l2a", "l3", "l4");
+ cache.put(value2, "l1", "l2b", "l3", "l4");
+ cache.put(value3, "l1", "l2c", "l3", "l4");
+
+ valueObj = cache.get("l1", "l2a", "l3", "l4");
+ assertTrue(valueObj instanceof String);
+ assertTrue(value1 == valueObj);
+
+ valueObj = cache.get("l1", "l2b", "l3", "l4");
+ assertTrue(valueObj instanceof String);
+ assertTrue(value2 == valueObj);
+
+ valueObj = cache.get("l1", "l2c", "l3", "l4");
+ assertTrue(valueObj instanceof String);
+ assertTrue(value3 == valueObj);
+
+ // remove leaf
+ cache.remove("l1", "l2", "l3", "l4");
+ valueObj = cache.get("l1", "l2", "l3", "l4");
+ assertNull(valueObj);
+
+ // put and get
+ cache.put(value1, "l1", "l2", "l3", "l4");
+ valueObj = cache.get("l1", "l2", "l3", "l4");
+ assertTrue(valueObj instanceof String);
+ assertTrue(value1 == valueObj);
+
+ // remove branch
+ cache.remove("l1", "l2");
+ valueObj = cache.get("l1", "l2", "l3", "l4");
+ assertNull(valueObj);
+ }
+
+ public void testCacheBadUsage() throws Exception {
+ Cache cache;
+
+ cache = new CacheImpl();
+ cache.initialize(new String[] { MAP_CACHE_LEVEL, LRU_CACHE_LEVEL, MAP_CACHE_LEVEL,
+ MAP_CACHE_LEVEL });
+
+ // insufficient number of keys
+ try {
+ cache.put("value", "l1", "l2", "l3");
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ // too many number of keys
+ try {
+ cache.put("value", "l1", "l2", "l3", "l4", "l5");
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ // no keys
+ assertNull(cache.get((String[]) null));
+ }
+
+ public void testCacheConfig() throws Exception {
+ Cache cache;
+
+ // empty config
+ try {
+ cache = new CacheImpl();
+ cache.initialize(new String[] {});
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ // null config
+ try {
+ cache = new CacheImpl();
+ cache.initialize(null);
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ // unknown class
+ try {
+ cache = new CacheImpl();
+ cache.initialize(new String[] { "this.is.not.a.valid.class" });
+ }
+ catch (IllegalArgumentException e) {
+ }
+
+ // not a CacheLevel class
+ try {
+ cache = new CacheImpl();
+ cache.initialize(new String[] { "org.apache.chemistry.opencmis.client.provider.cache.CacheTest" });
+ }
+ catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testMapCache() throws Exception {
+ Cache cache;
+
+ cache = new CacheImpl();
+ cache.initialize(new String[] { MAP_CACHE_LEVEL + " " + MapCacheLevelImpl.CAPACITY + "=10,"
+ + MapCacheLevelImpl.LOAD_FACTOR + "=0.5" });
+
+ for (int i = 0; i < 100; i++) {
+ cache.put("value" + i, "key" + i);
+ }
+
+ for (int i = 0; i < 100; i++) {
+ Object valueObj = cache.get("key" + i);
+ assertTrue(valueObj instanceof String);
+ assertEquals("value" + i, valueObj);
+ }
+ }
+
+ public void testURLCache() throws Exception {
+ Cache cache;
+
+ cache = new CacheImpl();
+ cache
+ .initialize(new String[] { LRU_CACHE_LEVEL + " " + LruCacheLevelImpl.MAX_ENTRIES + "=10" });
+
+ for (int i = 0; i < 100; i++) {
+ cache.put("value" + i, "key" + i);
+ }
+
+ for (int i = 0; i < 90; i++) {
+ Object valueObj = cache.get("key" + i);
+ assertNull(valueObj);
+ }
+
+ for (int i = 90; i < 100; i++) {
+ Object valueObj = cache.get("key" + i);
+ assertTrue(valueObj instanceof String);
+ assertEquals("value" + i, valueObj);
+ }
+ }
+
+ public void XtestFallback() throws Exception {
+ Cache cache;
+
+ cache = new CacheImpl();
+ cache.initialize(new String[] { MAP_CACHE_LEVEL + " " + MapCacheLevelImpl.CAPACITY + "=10,"
+ + MapCacheLevelImpl.LOAD_FACTOR + "=0.5" });
+
+ cache.put("value1", new String[] { null });
+ cache.put("value2", "key2");
+
+ assertEquals("value1", cache.get(new String[] { null }));
+ assertEquals("value2", cache.get("key2"));
+ assertEquals("value1", cache.get("key3"));
+ }
+
+ public void testContentTypeCache() throws Exception {
+ ContentTypeCacheLevelImpl cl = new ContentTypeCacheLevelImpl();
+ cl.initialize(null);
+
+ String type1 = "type1";
+
+ cl.put(type1, "text/plain; param1=test; charset=UTF-8");
+
+ assertEquals(type1, cl.get("text/plain; param1=test; charset=UTF-8"));
+ assertEquals(type1, cl.get("text/plain; param1=test; charset=utf-8"));
+ assertEquals(type1, cl.get("text/plain; charset=utf-8; param1=test"));
+ assertEquals(type1, cl.get("text/plain; charset=utf-8; param1=test;"));
+ assertEquals(type1, cl.get("text/plain;charset=utf-8;param1=test"));
+ assertEquals(type1, cl.get("text/plain;\tcharset=utf-8; param1=test"));
+ assertEquals(type1, cl.get("text/plain; charset=\"utf-8\"; param1=test;"));
+
+ assertNull(cl.get("text/plain; param1=blah; charset=UTF-8"));
+ assertNull(cl.get("text/plain; param1=test; charset=us-ascii"));
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/cache/CacheTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/framework/AbstractCmisTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/framework/AbstractCmisTestCase.java?rev=934361&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/framework/AbstractCmisTestCase.java (added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/framework/AbstractCmisTestCase.java Thu Apr 15 10:33:49 2010
@@ -0,0 +1,1252 @@
+/*
+ * 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.chemistry.opencmis.client.bindings.framework;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.api.DocumentTypeDefinition;
+import org.apache.chemistry.opencmis.commons.api.ExtensionsData;
+import org.apache.chemistry.opencmis.commons.api.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.api.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityAcl;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityChanges;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityRendition;
+import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+import org.apache.chemistry.opencmis.commons.enums.UnfileObjects;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
+import org.apache.chemistry.opencmis.commons.provider.AccessControlEntry;
+import org.apache.chemistry.opencmis.commons.provider.AccessControlList;
+import org.apache.chemistry.opencmis.commons.provider.AllowableActionsData;
+import org.apache.chemistry.opencmis.commons.provider.BindingsObjectFactory;
+import org.apache.chemistry.opencmis.commons.provider.CmisBinding;
+import org.apache.chemistry.opencmis.commons.provider.ContentStreamData;
+import org.apache.chemistry.opencmis.commons.provider.ObjectData;
+import org.apache.chemistry.opencmis.commons.provider.ObjectInFolderData;
+import org.apache.chemistry.opencmis.commons.provider.ObjectInFolderList;
+import org.apache.chemistry.opencmis.commons.provider.ObjectParentData;
+import org.apache.chemistry.opencmis.commons.provider.PropertiesData;
+import org.apache.chemistry.opencmis.commons.provider.PropertyData;
+import org.apache.chemistry.opencmis.commons.provider.PropertyDateTimeData;
+import org.apache.chemistry.opencmis.commons.provider.PropertyIdData;
+import org.apache.chemistry.opencmis.commons.provider.PropertyStringData;
+import org.apache.chemistry.opencmis.commons.provider.RenditionData;
+import org.apache.chemistry.opencmis.commons.provider.RepositoryInfoData;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Base test case for CMIS tests.
+ *
+ * @author <a href="mailto:fmueller@opentext.com">Florian Müller</a>
+ *
+ */
+public abstract class AbstractCmisTestCase extends TestCase {
+
+ public static final String DEFAULT_TESTS_ENABLED = "false";
+ public static final String DEFAULT_USERNAME = "test";
+ public static final String DEFAULT_PASSWORD = "test";
+ public static final String DEFAULT_ATOMPUB_URL = "http://localhost:8080/cmis/atom";
+ public static final String DEFAULT_WEBSERVICES_URLPREFIX = "http://localhost:8080/cmis/services/";
+ public static final String DEFAULT_DOCTYPE = "cmis:document";
+ public static final String DEFAULT_FOLDERTYPE = "cmis:folder";
+
+ public static final String PROP_TESTS_ENABLED = "opencmis.test";
+ public static final String PROP_USERNAME = "opencmis.test.username";
+ public static final String PROP_PASSWORD = "opencmis.test.password";
+ public static final String PROP_REPOSITORY = "opencmis.test.repository";
+ public static final String PROP_TESTFOLDER = "opencmis.test.testfolder";
+ public static final String PROP_DOCTYPE = "opencmis.test.documenttype";
+ public static final String PROP_FOLDERTYPE = "opencmis.test.foldertype";
+ public static final String PROP_CONFIG_FILE = "opencmis.test.config";
+
+ public static final String PROP_ATOMPUB_URL = "opencmis.test.atompub.url";
+ public static final String PROP_WEBSERVICES_URLPREFIX = "opencmis.test.webservices.url";
+
+ private CmisBinding binding;
+ private String fTestRepositoryId;
+ private String fTestFolderId;
+
+ private static Log log = LogFactory.getLog(AbstractCmisTestCase.class);
+
+ /**
+ * Read configuration file.
+ */
+ static {
+ String configFileName = System.getProperty(PROP_CONFIG_FILE);
+ if (configFileName != null) {
+
+ try {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(configFileName));
+
+ for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ String value = properties.getProperty(key);
+ System.setProperty(key, value);
+ }
+ }
+ catch (Exception e) {
+ System.err.println("Could not load test properties: " + e.toString());
+ }
+ }
+ }
+
+ /**
+ * Returns the binding object or creates one if does not exist.
+ */
+ protected CmisBinding getBinding() {
+ if (binding == null) {
+ log.info("Creating binding...");
+ binding = createBinding();
+ }
+
+ return binding;
+ }
+
+ /**
+ * Creates a binding object.
+ */
+ protected abstract CmisBinding createBinding();
+
+ /**
+ * Returns a set of test names that enabled.
+ */
+ protected abstract Set<String> getEnabledTests();
+
+ /**
+ * Returns the test repository id.
+ */
+ protected String getTestRepositoryId() {
+ if (fTestRepositoryId != null) {
+ return fTestRepositoryId;
+ }
+
+ fTestRepositoryId = System.getProperty(PROP_REPOSITORY);
+ if (fTestRepositoryId != null) {
+ log.info("Test repository: " + fTestRepositoryId);
+ return fTestRepositoryId;
+ }
+
+ fTestRepositoryId = getFirstRepositoryId();
+ log.info("Test repository: " + fTestRepositoryId);
+
+ return fTestRepositoryId;
+ }
+
+ /**
+ * Returns the test root folder id.
+ */
+ protected String getTestRootFolder() {
+ if (fTestFolderId != null) {
+ return fTestFolderId;
+ }
+
+ fTestFolderId = System.getProperty(PROP_TESTFOLDER);
+ if (fTestFolderId != null) {
+ log.info("Test root folder: " + fTestFolderId);
+ return fTestFolderId;
+ }
+
+ fTestFolderId = getRootFolderId();
+ log.info("Test root folder: " + fTestFolderId);
+
+ return fTestFolderId;
+ }
+
+ /**
+ * Returns if the test is enabled.
+ */
+ protected boolean isEnabled(String name) {
+ boolean testsEnabled = Boolean.parseBoolean(System.getProperty(PROP_TESTS_ENABLED,
+ DEFAULT_TESTS_ENABLED));
+
+ if (testsEnabled && getEnabledTests().contains(name)) {
+ return true;
+ }
+
+ log.info("Skipping test '" + name + "'!");
+
+ return false;
+ }
+
+ /**
+ * Returns the test username.
+ */
+ protected String getUsername() {
+ return System.getProperty(PROP_USERNAME, DEFAULT_USERNAME);
+ }
+
+ /**
+ * Returns the test password.
+ */
+ protected String getPassword() {
+ return System.getProperty(PROP_PASSWORD, DEFAULT_PASSWORD);
+ }
+
+ /**
+ * Returns the default document type.
+ */
+ protected String getDefaultDocumentType() {
+ return System.getProperty(PROP_DOCTYPE, DEFAULT_DOCTYPE);
+ }
+
+ /**
+ * Returns the default folder type.
+ */
+ protected String getDefaultFolderType() {
+ return System.getProperty(PROP_FOLDERTYPE, DEFAULT_FOLDERTYPE);
+ }
+
+ /**
+ * Returns the AtomPub URL.
+ */
+ protected String getAtomPubURL() {
+ return System.getProperty(PROP_ATOMPUB_URL, DEFAULT_ATOMPUB_URL);
+ }
+
+ /**
+ * Returns the Web Services URL prefix.
+ */
+ protected String getWebServicesURL() {
+ return System.getProperty(PROP_WEBSERVICES_URLPREFIX, DEFAULT_WEBSERVICES_URLPREFIX);
+ }
+
+ /**
+ * Returns the object factory.
+ */
+ protected BindingsObjectFactory getObjectFactory() {
+ return getBinding().getObjectFactory();
+ }
+
+ /**
+ * Returns the id of the first repository.
+ */
+ protected String getFirstRepositoryId() {
+ List<RepositoryInfoData> repositories = getBinding().getRepositoryService().getRepositoryInfos(
+ null);
+
+ assertNotNull(repositories);
+ assertFalse(repositories.isEmpty());
+ assertNotNull(repositories.get(0).getRepositoryId());
+
+ return repositories.get(0).getRepositoryId();
+ }
+
+ /**
+ * Returns the info object of the test repository.
+ */
+ protected RepositoryInfoData getRepositoryInfo() {
+ RepositoryInfoData repositoryInfo = getBinding().getRepositoryService().getRepositoryInfo(
+ getTestRepositoryId(), null);
+
+ assertNotNull(repositoryInfo);
+ assertNotNull(repositoryInfo.getRepositoryId());
+ assertEquals(getTestRepositoryId(), repositoryInfo.getRepositoryId());
+
+ return repositoryInfo;
+ }
+
+ /**
+ * Returns the root folder of the test repository.
+ */
+ protected String getRootFolderId() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRootFolderId());
+
+ return repository.getRootFolderId();
+ }
+
+ /**
+ * Returns if the test repository supports reading ACLs.
+ */
+ protected boolean supportsDiscoverACLs() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRepositoryCapabilities());
+
+ return (repository.getRepositoryCapabilities().getCapabilityAcl() != CapabilityAcl.NONE);
+ }
+
+ /**
+ * Returns if the test repository supports setting ACLs.
+ */
+ protected boolean supportsManageACLs() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRepositoryCapabilities());
+
+ return (repository.getRepositoryCapabilities().getCapabilityAcl() == CapabilityAcl.MANAGE);
+ }
+
+ /**
+ * Returns if the test repository supports renditions.
+ */
+ protected boolean supportsRenditions() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRepositoryCapabilities());
+
+ if (repository.getRepositoryCapabilities().getCapabilityRenditions() == null) {
+ return false;
+ }
+
+ return (repository.getRepositoryCapabilities().getCapabilityRenditions() != CapabilityRendition.NONE);
+ }
+
+ /**
+ * Returns if the test repository supports descendants.
+ */
+ protected boolean supportsDescendants() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRepositoryCapabilities());
+
+ if (repository.getRepositoryCapabilities().supportsGetDescendants() == null) {
+ return false;
+ }
+
+ return repository.getRepositoryCapabilities().supportsGetDescendants().booleanValue();
+ }
+
+ /**
+ * Returns if the test repository supports descendants.
+ */
+ protected boolean supportsFolderTree() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRepositoryCapabilities());
+
+ if (repository.getRepositoryCapabilities().supportsGetFolderTree() == null) {
+ return false;
+ }
+
+ return repository.getRepositoryCapabilities().supportsGetFolderTree().booleanValue();
+ }
+
+ /**
+ * Returns if the test repository supports content changes.
+ */
+ protected boolean supportsContentChanges() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRepositoryCapabilities());
+
+ if (repository.getRepositoryCapabilities().getCapabilityChanges() == null) {
+ return false;
+ }
+
+ return (repository.getRepositoryCapabilities().getCapabilityChanges() != CapabilityChanges.NONE);
+ }
+
+ /**
+ * Returns if the test repository supports query.
+ */
+ protected boolean supportsQuery() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRepositoryCapabilities());
+
+ if (repository.getRepositoryCapabilities().getCapabilityQuery() == null) {
+ return false;
+ }
+
+ return (repository.getRepositoryCapabilities().getCapabilityQuery() != CapabilityQuery.NONE);
+ }
+
+ /**
+ * Returns if the test repository supports relationships.
+ */
+ protected boolean supportsRelationships() {
+ TypeDefinition relType = null;
+
+ try {
+ relType = getBinding().getRepositoryService().getTypeDefinition(getTestRepositoryId(),
+ "cmis:relationship", null);
+ }
+ catch (CmisObjectNotFoundException e) {
+ return false;
+ }
+
+ return (relType != null);
+ }
+
+ /**
+ * Returns if the test repository supports policies.
+ */
+ protected boolean supportsPolicies() {
+ TypeDefinition relType = null;
+
+ try {
+ relType = getBinding().getRepositoryService().getTypeDefinition(getTestRepositoryId(),
+ "cmis:policy", null);
+ }
+ catch (CmisObjectNotFoundException e) {
+ return false;
+ }
+
+ return (relType != null);
+ }
+
+ /**
+ * Returns the AclPropagation from the ACL capabilities.
+ */
+ protected AclPropagation getAclPropagation() {
+ RepositoryInfoData repository = getRepositoryInfo();
+
+ assertNotNull(repository.getRepositoryCapabilities());
+
+ if (repository.getAclCapabilities().getAclPropagation() == null) {
+ return AclPropagation.REPOSITORYDETERMINED;
+ }
+
+ return repository.getAclCapabilities().getAclPropagation();
+ }
+
+ // ---- helpers ----
+
+ /**
+ * Prints a warning.
+ */
+ protected void warning(String message) {
+ System.out.println("**** " + message);
+ }
+
+ /**
+ * Creates a ContentStreamData object from a byte array.
+ */
+ protected ContentStreamData createContentStreamData(String mimeType, byte[] content) {
+ assertNotNull(content);
+
+ return getObjectFactory().createContentStream(BigInteger.valueOf(content.length), mimeType,
+ "test", new ByteArrayInputStream(content));
+ }
+
+ /**
+ * Extracts the path from a folder object.
+ */
+ protected String getPath(ObjectData folderObject) {
+ assertNotNull(folderObject);
+ assertNotNull(folderObject.getProperties());
+ assertNotNull(folderObject.getProperties().getProperties());
+ assertTrue(folderObject.getProperties().getProperties().get(PropertyIds.CMIS_PATH) instanceof PropertyStringData);
+
+ PropertyStringData pathProperty = (PropertyStringData) folderObject.getProperties()
+ .getProperties().get(PropertyIds.CMIS_PATH);
+
+ assertNotNull(pathProperty.getValues());
+ assertEquals(1, pathProperty.getValues().size());
+ assertNotNull(pathProperty.getValues().get(0));
+
+ return pathProperty.getValues().get(0);
+ }
+
+ // ---- short cuts ----
+
+ /**
+ * Retrieves an object.
+ */
+ protected ObjectData getObject(String objectId, String filter, Boolean includeAllowableActions,
+ IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds,
+ Boolean includeACL, ExtensionsData extension) {
+ ObjectData object = getBinding().getObjectService().getObject(getTestRepositoryId(), objectId,
+ filter, includeAllowableActions, includeRelationships, renditionFilter, includePolicyIds,
+ includeACL, extension);
+
+ assertNotNull(object);
+
+ return object;
+ }
+
+ /**
+ * Retrieves a full blown object.
+ */
+ protected ObjectData getObject(String objectId) {
+ ObjectData object = getObject(objectId, "*", Boolean.TRUE, IncludeRelationships.BOTH, null,
+ Boolean.TRUE, Boolean.TRUE, null);
+
+ assertBasicProperties(object.getProperties());
+
+ return object;
+ }
+
+ /**
+ * Retrieves an object by path.
+ */
+ protected ObjectData getObjectByPath(String path, String filter, Boolean includeAllowableActions,
+ IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds,
+ Boolean includeACL, ExtensionsData extension) {
+ ObjectData object = getBinding().getObjectService().getObjectByPath(getTestRepositoryId(),
+ path, filter, includeAllowableActions, includeRelationships, renditionFilter,
+ includePolicyIds, includeACL, extension);
+
+ assertNotNull(object);
+
+ return object;
+ }
+
+ /**
+ * Retrieves a full blown object by path.
+ */
+ protected ObjectData getObjectByPath(String path) {
+ ObjectData object = getObjectByPath(path, "*", Boolean.TRUE, IncludeRelationships.BOTH, null,
+ Boolean.TRUE, Boolean.TRUE, null);
+
+ assertBasicProperties(object.getProperties());
+
+ return object;
+ }
+
+ /**
+ * Returns <code>true</code> if the object with the given id exists, <code>false</code> otherwise.
+ */
+ protected boolean existsObject(String objectId) {
+ try {
+ ObjectData object = getObject(objectId, PropertyIds.CMIS_OBJECT_ID, Boolean.FALSE,
+ IncludeRelationships.NONE, null, Boolean.FALSE, Boolean.FALSE, null);
+
+ assertNotNull(object);
+ assertNotNull(object.getId());
+ }
+ catch (CmisObjectNotFoundException e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns the child of a folder.
+ */
+ protected ObjectInFolderData getChild(String folderId, String objectId) {
+ boolean hasMore = true;
+
+ while (hasMore) {
+ ObjectInFolderList children = getBinding().getNavigationService().getChildren(
+ getTestRepositoryId(), folderId, "*", null, Boolean.TRUE, IncludeRelationships.BOTH,
+ null, Boolean.TRUE, null, null, null);
+
+ assertNotNull(children);
+ assertTrue(children.getObjects().size() > 0);
+
+ hasMore = (children.hasMoreItems() == null ? false : children.hasMoreItems().booleanValue());
+
+ for (ObjectInFolderData object : children.getObjects()) {
+ assertNotNull(object);
+ assertNotNull(object.getPathSegment());
+ assertNotNull(object.getObject());
+ assertNotNull(object.getObject().getId());
+
+ assertBasicProperties(object.getObject().getProperties());
+
+ if (object.getObject().getId().equals(objectId)) {
+ return object;
+ }
+ }
+ }
+
+ fail("Child not found!");
+
+ return null;
+ }
+
+ /**
+ * Gets the version series id of an object.
+ */
+ protected String getVersionSeriesId(ObjectData object) {
+ PropertyData<?> versionSeriesId = object.getProperties().getProperties().get(
+ PropertyIds.CMIS_VERSION_SERIES_ID);
+ assertNotNull(versionSeriesId);
+ assertTrue(versionSeriesId instanceof PropertyIdData);
+
+ return ((PropertyIdData) versionSeriesId).getFirstValue();
+ }
+
+ /**
+ * Gets the version series id of an object.
+ */
+ protected String getVersionSeriesId(String docId) {
+ return getVersionSeriesId(getObject(docId));
+ }
+
+ /**
+ * Creates a folder.
+ */
+ protected String createFolder(PropertiesData properties, String folderId, List<String> policies,
+ AccessControlList addACEs, AccessControlList removeACEs) {
+ String objectId = getBinding().getObjectService().createFolder(getTestRepositoryId(),
+ properties, folderId, policies, addACEs, removeACEs, null);
+ assertNotNull(objectId);
+ assertTrue(existsObject(objectId));
+
+ ObjectInFolderData folderChild = getChild(folderId, objectId);
+
+ // check canGetProperties
+ assertAllowableAction(folderChild.getObject().getAllowableActions(),
+ AllowableActionsData.ACTION_CAN_GET_PROPERTIES, true);
+
+ // check name
+ PropertyData<?> nameProp = properties.getProperties().get(PropertyIds.CMIS_NAME);
+ if (nameProp != null) {
+ assertPropertyValue(folderChild.getObject().getProperties(), PropertyIds.CMIS_NAME,
+ PropertyStringData.class, nameProp.getFirstValue());
+ }
+
+ // check object type
+ PropertyData<?> typeProp = properties.getProperties().get(PropertyIds.CMIS_OBJECT_TYPE_ID);
+ assertNotNull(typeProp);
+ assertPropertyValue(folderChild.getObject().getProperties(), PropertyIds.CMIS_OBJECT_TYPE_ID,
+ PropertyIdData.class, typeProp.getFirstValue());
+
+ // check parent
+ ObjectData parent = getBinding().getNavigationService().getFolderParent(getTestRepositoryId(),
+ objectId, null, null);
+ assertNotNull(parent);
+ assertNotNull(parent.getProperties());
+ assertNotNull(parent.getProperties().getProperties());
+ assertNotNull(parent.getProperties().getProperties().get(PropertyIds.CMIS_OBJECT_ID));
+ assertEquals(folderId, parent.getProperties().getProperties().get(PropertyIds.CMIS_OBJECT_ID)
+ .getFirstValue());
+
+ return objectId;
+ }
+
+ /**
+ * Creates a folder with the default type.
+ */
+ protected String createDefaultFolder(String folderId, String name) {
+ List<PropertyData<?>> propList = new ArrayList<PropertyData<?>>();
+ propList.add(getObjectFactory().createPropertyStringData(PropertyIds.CMIS_NAME, name));
+ propList.add(getObjectFactory().createPropertyIdData(PropertyIds.CMIS_OBJECT_TYPE_ID,
+ getDefaultFolderType()));
+
+ PropertiesData properties = getObjectFactory().createPropertiesData(propList);
+
+ return createFolder(properties, folderId, null, null, null);
+ }
+
+ /**
+ * Creates a document.
+ */
+ protected String createDocument(PropertiesData properties, String folderId,
+ ContentStreamData contentStream, VersioningState versioningState, List<String> policies,
+ AccessControlList addACEs, AccessControlList removeACEs) {
+ String objectId = getBinding().getObjectService().createDocument(getTestRepositoryId(),
+ properties, folderId, contentStream, versioningState, policies, addACEs, removeACEs, null);
+ assertNotNull(objectId);
+ assertTrue(existsObject(objectId));
+
+ if (folderId != null) {
+ ObjectInFolderData folderChild = getChild(folderId, objectId);
+
+ // check canGetProperties
+ assertAllowableAction(folderChild.getObject().getAllowableActions(),
+ AllowableActionsData.ACTION_CAN_GET_PROPERTIES, true);
+
+ // check canGetContentStream
+ if (contentStream != null) {
+ assertAllowableAction(folderChild.getObject().getAllowableActions(),
+ AllowableActionsData.ACTION_CAN_GET_CONTENT_STREAM, true);
+ }
+
+ // check name
+ PropertyData<?> nameProp = properties.getProperties().get(PropertyIds.CMIS_NAME);
+ if (nameProp != null) {
+ assertPropertyValue(folderChild.getObject().getProperties(), PropertyIds.CMIS_NAME,
+ PropertyStringData.class, nameProp.getFirstValue());
+ }
+
+ // check object type
+ PropertyData<?> typeProp = properties.getProperties().get(PropertyIds.CMIS_OBJECT_TYPE_ID);
+ assertNotNull(typeProp);
+ assertPropertyValue(folderChild.getObject().getProperties(), PropertyIds.CMIS_OBJECT_TYPE_ID,
+ PropertyIdData.class, typeProp.getFirstValue());
+
+ // check parent
+ List<ObjectParentData> parents = getBinding().getNavigationService().getObjectParents(
+ getTestRepositoryId(), objectId, "*", Boolean.TRUE, IncludeRelationships.BOTH, null,
+ Boolean.TRUE, null);
+ assertNotNull(parents);
+ assertEquals(1, parents.size());
+
+ ObjectParentData parent = parents.get(0);
+ assertNotNull(parent);
+ assertNotNull(parent.getRelativePathSegment());
+ assertNotNull(parent.getObject());
+ assertNotNull(parent.getObject().getProperties().getProperties());
+ assertNotNull(parent.getObject().getProperties().getProperties().get(
+ PropertyIds.CMIS_OBJECT_ID));
+ assertEquals(folderId, parent.getObject().getProperties().getProperties().get(
+ PropertyIds.CMIS_OBJECT_ID).getFirstValue());
+
+ // get document by path (check relative path segment)
+ assertNotNull(parent.getObject().getProperties().getProperties().get(PropertyIds.CMIS_PATH));
+ String parentPath = parent.getObject().getProperties().getProperties().get(
+ PropertyIds.CMIS_PATH).getFirstValue().toString();
+
+ ObjectData docByPath = getObjectByPath((parentPath.equals("/") ? "" : parentPath) + "/"
+ + parent.getRelativePathSegment());
+
+ PropertyData<?> idProp = docByPath.getProperties().getProperties().get(
+ PropertyIds.CMIS_OBJECT_ID);
+ assertNotNull(idProp);
+ assertEquals(objectId, idProp.getFirstValue());
+ }
+ else {
+ List<ObjectParentData> parents = getBinding().getNavigationService().getObjectParents(
+ getTestRepositoryId(), objectId, null, Boolean.TRUE, IncludeRelationships.BOTH, null,
+ Boolean.TRUE, null);
+ assertNotNull(parents);
+ assertEquals(0, parents.size());
+ }
+
+ return objectId;
+ }
+
+ /**
+ * Creates a document with the default type.
+ */
+ protected String createDefaultDocument(String folderId, String name, String contentType,
+ byte[] content) {
+ VersioningState vs = (isVersionable(getDefaultDocumentType()) ? VersioningState.MAJOR
+ : VersioningState.NONE);
+
+ List<PropertyData<?>> propList = new ArrayList<PropertyData<?>>();
+ propList.add(getObjectFactory().createPropertyStringData(PropertyIds.CMIS_NAME, name));
+ propList.add(getObjectFactory().createPropertyIdData(PropertyIds.CMIS_OBJECT_TYPE_ID,
+ getDefaultDocumentType()));
+
+ PropertiesData properties = getObjectFactory().createPropertiesData(propList);
+
+ ContentStreamData contentStream = createContentStreamData(contentType, content);
+
+ return createDocument(properties, folderId, contentStream, vs, null, null, null);
+ }
+
+ /**
+ * Creates a document from source.
+ */
+ protected String createDocumentFromSource(String sourceId, PropertiesData properties,
+ String folderId, VersioningState versioningState, List<String> policies,
+ AccessControlList addACEs, AccessControlList removeACEs) {
+ String objectId = getBinding().getObjectService().createDocumentFromSource(
+ getTestRepositoryId(), sourceId, properties, folderId, versioningState, policies, addACEs,
+ removeACEs, null);
+ assertNotNull(objectId);
+ assertTrue(existsObject(objectId));
+
+ if (folderId != null) {
+ ObjectInFolderData folderChild = getChild(folderId, objectId);
+
+ // check name
+ PropertyData<?> nameProp = properties.getProperties().get(PropertyIds.CMIS_NAME);
+ if (nameProp != null) {
+ assertPropertyValue(folderChild.getObject().getProperties(), PropertyIds.CMIS_NAME,
+ PropertyStringData.class, nameProp.getValues().get(0));
+ }
+
+ // check parent
+ List<ObjectParentData> parents = getBinding().getNavigationService().getObjectParents(
+ getTestRepositoryId(), objectId, null, Boolean.TRUE, IncludeRelationships.BOTH, null,
+ Boolean.TRUE, null);
+ assertNotNull(parents);
+ assertEquals(1, parents.size());
+
+ ObjectParentData parent = parents.get(0);
+ assertNotNull(parent);
+ assertNotNull(parent.getRelativePathSegment());
+ assertNotNull(parent.getObject());
+ assertNotNull(parent.getObject().getProperties().getProperties());
+ assertNotNull(parent.getObject().getProperties().getProperties().get(
+ PropertyIds.CMIS_OBJECT_ID));
+ assertEquals(folderId, parent.getObject().getProperties().getProperties().get(
+ PropertyIds.CMIS_OBJECT_ID).getFirstValue());
+ }
+
+ return objectId;
+ }
+
+ /**
+ * Deletes an object.
+ */
+ protected void delete(String objectId, boolean allVersions) {
+ getBinding().getObjectService()
+ .deleteObject(getTestRepositoryId(), objectId, allVersions, null);
+ assertFalse(existsObject(objectId));
+ }
+
+ /**
+ * Deletes a tree.
+ */
+ protected void deleteTree(String folderId) {
+ getBinding().getObjectService().deleteTree(getTestRepositoryId(), folderId, Boolean.TRUE,
+ UnfileObjects.DELETE, Boolean.TRUE, null);
+ assertFalse(existsObject(folderId));
+ }
+
+ /**
+ * Gets a content stream.
+ */
+ protected ContentStreamData getContent(String objectId, String streamId) {
+ ContentStreamData contentStream = getBinding().getObjectService().getContentStream(
+ getTestRepositoryId(), objectId, streamId, null, null, null);
+ assertNotNull(contentStream);
+ assertNotNull(contentStream.getMimeType());
+ assertNotNull(contentStream.getStream());
+
+ return contentStream;
+ }
+
+ /**
+ * Reads the content from a content stream into a byte array.
+ */
+ protected byte[] readContent(ContentStreamData contentStream) throws Exception {
+ assertNotNull(contentStream);
+ assertNotNull(contentStream.getStream());
+
+ InputStream stream = contentStream.getStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ byte[] buffer = new byte[4096];
+ int b;
+ while ((b = stream.read(buffer)) > -1) {
+ baos.write(buffer, 0, b);
+ }
+
+ return baos.toByteArray();
+ }
+
+ /**
+ * Returns a type definition.
+ */
+ protected TypeDefinition getTypeDefinition(String typeName) {
+ TypeDefinition typeDef = getBinding().getRepositoryService().getTypeDefinition(
+ getTestRepositoryId(), typeName, null);
+
+ assertNotNull(typeDef);
+ assertNotNull(typeDef.getId());
+
+ return typeDef;
+ }
+
+ /**
+ * Returns if the type is versionable.
+ */
+ protected boolean isVersionable(String typeName) {
+ TypeDefinition type = getTypeDefinition(typeName);
+
+ assertTrue(type instanceof DocumentTypeDefinition);
+
+ Boolean isVersionable = ((DocumentTypeDefinition) type).isVersionable();
+ assertNotNull(isVersionable);
+
+ return isVersionable.booleanValue();
+ }
+
+ // ---- asserts ----
+
+ protected void assertEquals(TypeDefinition expected, TypeDefinition actual,
+ boolean checkPropertyDefintions) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if (expected == null) {
+ fail("Expected type definition is null!");
+ }
+
+ if (actual == null) {
+ fail("Actual type definition is null!");
+ }
+
+ assertEquals("TypeDefinition id:", expected.getId(), actual.getId());
+ assertEquals("TypeDefinition local name:", expected.getLocalName(), actual.getLocalName());
+ assertEquals("TypeDefinition local namespace:", expected.getLocalNamespace(), actual
+ .getLocalNamespace());
+ assertEquals("TypeDefinition display name:", expected.getDisplayName(), actual.getDisplayName());
+ assertEquals("TypeDefinition description:", expected.getDescription(), actual.getDescription());
+ assertEquals("TypeDefinition query name:", expected.getQueryName(), actual.getQueryName());
+ assertEquals("TypeDefinition parent id:", expected.getParentId(), actual.getParentId());
+ assertEquals("TypeDefinition base id:", expected.getBaseId(), actual.getBaseId());
+
+ if (!checkPropertyDefintions) {
+ return;
+ }
+
+ if ((expected.getPropertyDefinitions() == null) && (actual.getPropertyDefinitions() == null)) {
+ return;
+ }
+
+ if (expected.getPropertyDefinitions() == null) {
+ fail("Expected property definition list is null!");
+ }
+
+ if (actual.getPropertyDefinitions() == null) {
+ fail("Actual property definition list is null!");
+ }
+
+ assertEquals(expected.getPropertyDefinitions().size(), actual.getPropertyDefinitions().size());
+
+ for (PropertyDefinition<?> expectedPropDef : expected.getPropertyDefinitions().values()) {
+ PropertyDefinition<?> actualPropDef = actual.getPropertyDefinitions().get(
+ expectedPropDef.getId());
+
+ assertEquals(expectedPropDef, actualPropDef);
+ }
+ }
+
+ protected void assertEquals(PropertyDefinition<?> expected, PropertyDefinition<?> actual) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if (expected == null) {
+ fail("Expected property definition is null!");
+ }
+
+ if (actual == null) {
+ fail("Actual property definition is null!");
+ }
+
+ assertNotNull(expected.getId());
+ assertNotNull(actual.getId());
+
+ String id = expected.getId();
+
+ assertEquals("PropertyDefinition " + id + " id:", expected.getId(), actual.getId());
+ assertEquals("PropertyDefinition " + id + " local name:", expected.getLocalName(), actual
+ .getLocalName());
+ assertEquals("PropertyDefinition " + id + " local namespace:", expected.getLocalNamespace(),
+ actual.getLocalNamespace());
+ assertEquals("PropertyDefinition " + id + " query name:", expected.getQueryName(), actual
+ .getQueryName());
+ assertEquals("PropertyDefinition " + id + " display name:", expected.getDisplayName(), actual
+ .getDisplayName());
+ assertEquals("PropertyDefinition " + id + " description:", expected.getDescription(), actual
+ .getDescription());
+ assertEquals("PropertyDefinition " + id + " property type:", expected.getPropertyType(), actual
+ .getPropertyType());
+ assertEquals("PropertyDefinition " + id + " cardinality:", expected.getCardinality(), actual
+ .getCardinality());
+ assertEquals("PropertyDefinition " + id + " updatability:", expected.getUpdatability(), actual
+ .getUpdatability());
+ }
+
+ protected void assertEquals(PropertiesData expected, PropertiesData actual) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if (expected == null) {
+ fail("Expected properties data is null!");
+ }
+
+ if (actual == null) {
+ fail("Actual properties data is null!");
+ }
+
+ if ((expected.getProperties() == null) && (actual.getProperties() == null)) {
+ return;
+ }
+
+ if ((expected.getProperties() == null) || (actual.getProperties() == null)) {
+ fail("Properties are null!");
+ }
+
+ if (expected.getProperties() == null) {
+ fail("Expected properties are null!");
+ }
+
+ if (actual.getProperties() == null) {
+ fail("Actual properties are null!");
+ }
+
+ assertEquals(expected.getProperties().size(), actual.getProperties().size());
+
+ for (String id : expected.getProperties().keySet()) {
+ PropertyData<?> expectedProperty = expected.getProperties().get(id);
+ assertNotNull(expectedProperty);
+ assertEquals(id, expectedProperty.getId());
+
+ PropertyData<?> actualProperty = actual.getProperties().get(id);
+ assertNotNull(actualProperty);
+ assertEquals(id, actualProperty.getId());
+
+ assertEquals(expectedProperty, actualProperty);
+ }
+ }
+
+ protected void assertEquals(PropertyData<?> expected, PropertyData<?> actual) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if ((expected == null) || (actual == null)) {
+ fail("Properties data is null!");
+ }
+
+ String id = expected.getId();
+
+ assertEquals("PropertyData " + id + " id:", expected.getId(), actual.getId());
+ assertEquals("PropertyData " + id + " display name:", expected.getDisplayName(), actual
+ .getDisplayName());
+ assertEquals("PropertyData " + id + " local name:", expected.getLocalName(), actual
+ .getLocalName());
+ assertEquals("PropertyData " + id + " query name:", expected.getQueryName(), actual
+ .getQueryName());
+
+ assertEquals("PropertyData " + id + " values:", expected.getValues().size(), actual.getValues()
+ .size());
+
+ for (int i = 0; i < expected.getValues().size(); i++) {
+ assertEquals("PropertyData " + id + " value[" + i + "]:", expected.getValues().get(i), actual
+ .getValues().get(i));
+ }
+ }
+
+ protected void assertBasicProperties(PropertiesData properties) {
+ assertNotNull(properties);
+ assertNotNull(properties.getProperties());
+
+ assertProperty(properties.getProperties().get(PropertyIds.CMIS_OBJECT_ID),
+ PropertyIds.CMIS_OBJECT_ID, PropertyIdData.class);
+ assertProperty(properties.getProperties().get(PropertyIds.CMIS_OBJECT_TYPE_ID),
+ PropertyIds.CMIS_OBJECT_TYPE_ID, PropertyIdData.class);
+ assertProperty(properties.getProperties().get(PropertyIds.CMIS_BASE_TYPE_ID),
+ PropertyIds.CMIS_BASE_TYPE_ID, PropertyIdData.class);
+ assertProperty(properties.getProperties().get(PropertyIds.CMIS_NAME), PropertyIds.CMIS_NAME,
+ PropertyStringData.class);
+ assertProperty(properties.getProperties().get(PropertyIds.CMIS_CREATED_BY),
+ PropertyIds.CMIS_CREATED_BY, PropertyStringData.class);
+ assertProperty(properties.getProperties().get(PropertyIds.CMIS_CREATION_DATE),
+ PropertyIds.CMIS_CREATION_DATE, PropertyDateTimeData.class);
+ assertProperty(properties.getProperties().get(PropertyIds.CMIS_LAST_MODIFIED_BY),
+ PropertyIds.CMIS_LAST_MODIFIED_BY, PropertyStringData.class);
+ assertProperty(properties.getProperties().get(PropertyIds.CMIS_LAST_MODIFICATION_DATE),
+ PropertyIds.CMIS_LAST_MODIFICATION_DATE, PropertyDateTimeData.class);
+ }
+
+ protected void assertProperty(PropertyData<?> property, String id, Class<?> clazz) {
+ assertNotNull(property);
+ assertNotNull(property.getId());
+ assertEquals("PropertyData " + id + " id:", id, property.getId());
+ assertTrue(clazz.isAssignableFrom(property.getClass()));
+ assertNotNull(property.getValues());
+ assertFalse(property.getValues().isEmpty());
+ }
+
+ protected void assertPropertyValue(PropertyData<?> property, String id, Class<?> clazz,
+ Object... values) {
+ assertProperty(property, id, clazz);
+
+ assertEquals("Property " + id + " values:", values.length, property.getValues().size());
+
+ int i = 0;
+ for (Object value : property.getValues()) {
+ assertEquals("Property " + id + " value[" + i + "]:", values[i], value);
+ i++;
+ }
+ }
+
+ protected void assertPropertyValue(PropertiesData properties, String id, Class<?> clazz,
+ Object... values) {
+ assertNotNull(properties);
+ assertNotNull(properties.getProperties());
+
+ PropertyData<?> property = properties.getProperties().get(id);
+ assertNotNull(property);
+
+ assertPropertyValue(property, id, clazz, values);
+ }
+
+ protected void assertEquals(AllowableActionsData expected, AllowableActionsData actual) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if (expected == null) {
+ fail("Expected allowable action data is null!");
+ }
+
+ if (actual == null) {
+ fail("Actual allowable action data is null!");
+ }
+
+ assertNotNull(expected.getAllowableActions());
+ assertNotNull(actual.getAllowableActions());
+
+ assertEquals("Allowable action size:", expected.getAllowableActions().size(), actual
+ .getAllowableActions().size());
+
+ for (String action : expected.getAllowableActions().keySet()) {
+ Boolean expectedBoolean = expected.getAllowableActions().get(action);
+ Boolean actualBoolean = actual.getAllowableActions().get(action);
+
+ assertEquals("AllowableAction " + action + ":", expectedBoolean, actualBoolean);
+ }
+ }
+
+ protected void assertAllowableAction(AllowableActionsData allowableActions, String action,
+ Boolean expected) {
+ assertNotNull(allowableActions);
+ assertNotNull(allowableActions.getAllowableActions());
+ assertNotNull(action);
+
+ assertEquals("Allowable action \"" + action + "\":", expected, allowableActions
+ .getAllowableActions().get(action));
+ }
+
+ protected void assertEquals(AccessControlList expected, AccessControlList actual) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if (expected == null) {
+ fail("Expected ACL data is null!");
+ }
+
+ if (actual == null) {
+ fail("Actual ACL data is null!");
+ }
+
+ if ((expected.getAces() == null) && (actual.getAces() == null)) {
+ return;
+ }
+
+ if (expected.getAces() == null) {
+ fail("Expected ACE data is null!");
+ }
+
+ if (actual.getAces() == null) {
+ fail("Actual ACE data is null!");
+ }
+
+ // assertEquals(expected.isExact(), actual.isExact());
+ assertEquals(expected.getAces().size(), actual.getAces().size());
+
+ for (int i = 0; i < expected.getAces().size(); i++) {
+ assertEquals(expected.getAces().get(i), actual.getAces().get(i));
+ }
+ }
+
+ protected void assertEquals(AccessControlEntry expected, AccessControlEntry actual) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if (expected == null) {
+ fail("Expected ACE data is null!");
+ }
+
+ if (actual == null) {
+ fail("Actual ACE data is null!");
+ }
+
+ assertNotNull(expected.getPrincipal());
+ assertNotNull(expected.getPrincipal().getPrincipalId());
+ assertNotNull(actual.getPrincipal());
+ assertNotNull(actual.getPrincipal().getPrincipalId());
+ assertEquals("ACE Principal:", expected.getPrincipal().getPrincipalId(), actual.getPrincipal()
+ .getPrincipalId());
+
+ assertEqualLists(expected.getPermissions(), actual.getPermissions());
+ }
+
+ protected void assertEquals(RenditionData expected, RenditionData actual) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if (expected == null) {
+ fail("Expected rendition is null!");
+ }
+
+ if (actual == null) {
+ fail("Actual rendition is null!");
+ }
+
+ assertEquals("Rendition kind:", expected.getKind(), actual.getKind());
+ assertEquals("Rendition MIME type:", expected.getMimeType(), actual.getMimeType());
+ assertEquals("Rendition length:", expected.getLength(), actual.getLength());
+ assertEquals("Rendition stream id:", expected.getStreamId(), actual.getStreamId());
+ assertEquals("Rendition title:", expected.getTitle(), actual.getTitle());
+ assertEquals("Rendition height:", expected.getHeight(), actual.getHeight());
+ assertEquals("Rendition width:", expected.getWidth(), actual.getWidth());
+ assertEquals("Rendition document id:", expected.getRenditionDocumentId(), actual
+ .getRenditionDocumentId());
+ }
+
+ protected void assertContent(byte[] expected, byte[] actual) {
+ assertNotNull(expected);
+ assertNotNull(actual);
+
+ assertEquals("Content size:", expected.length, actual.length);
+
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals("Content not equal.", expected[i], actual[i]);
+ }
+ }
+
+ protected void assertMimeType(String expected, String actual) {
+ assertNotNull(expected);
+ assertNotNull(actual);
+
+ int paramIdx = actual.indexOf(';');
+ if (paramIdx != -1) {
+ actual = actual.substring(0, paramIdx);
+ }
+
+ assertEquals(expected, actual);
+ }
+
+ protected void assertEqualLists(List<?> expected, List<?> actual) {
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if (expected == null) {
+ fail("Expected list is null!");
+ }
+
+ if (actual == null) {
+ fail("Actual list is null!");
+ }
+
+ assertEquals("List size:", expected.size(), actual.size());
+
+ for (int i = 0; i < expected.size(); i++) {
+ assertEquals("List element " + i + ":", expected.get(i), actual.get(i));
+ }
+ }
+}
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/framework/AbstractCmisTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/framework/AbstractCmisTestCase.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/framework/AbstractCmisTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/framework/AbstractCmisTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain