You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/08/27 18:03:00 UTC
svn commit: r1517855 - in /chemistry/opencmis/trunk:
chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/
chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apach...
Author: fmui
Date: Tue Aug 27 16:03:00 2013
New Revision: 1517855
URL: http://svn.apache.org/r1517855
Log:
more unit tests + fixes
Added:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractConverterTest.java (with props)
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConstants.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyDefinition.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ChoiceImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/RepositoryCapabilitiesImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConstants.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConstants.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConstants.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConstants.java Tue Aug 27 16:03:00 2013
@@ -145,6 +145,7 @@ public final class JSONConstants {
CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_KEYS.add(JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_QUERYNAME);
CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_KEYS.add(JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_DESCRIPTION);
CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_KEYS.add(JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_CREATEABLE);
+ CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_KEYS.add(JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_QUERYABLE);
CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_KEYS.add(JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_FILEABLE);
CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_KEYS.add(JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_FULLTEXTINDEXED);
CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_KEYS.add(JSON_CAP_NEW_TYPE_SETTABLE_ATTRIBUTES_INCLUDEDINSUPERTYTPEQUERY);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/WSConverter.java Tue Aug 27 16:03:00 2013
@@ -112,6 +112,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
import org.apache.chemistry.opencmis.commons.enums.DateTimeResolution;
+import org.apache.chemistry.opencmis.commons.enums.DecimalPrecision;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.enums.SupportedPermissions;
import org.apache.chemistry.opencmis.commons.enums.Updatability;
@@ -273,6 +274,9 @@ public final class WSConverter {
private static final Logger LOG = LoggerFactory.getLogger(WSConverter.class);
+ private static final BigInteger BIG_INT_32 = BigInteger.valueOf(32);
+ private static final BigInteger BIG_INT_64 = BigInteger.valueOf(64);
+
private static Class<?> streamDataHandlerClass1;
private static Method streamDataHandlerReadMethod1;
private static Class<?> streamDataHandlerClass2;
@@ -844,6 +848,14 @@ public final class WSConverter {
((PropertyDecimalDefinitionImpl) result)
.setMaxValue(((CmisPropertyDecimalDefinitionType) propertyDefinition).getMaxValue());
+ BigInteger precision = ((CmisPropertyDecimalDefinitionType) propertyDefinition).getPrecision();
+ if (precision != null) {
+ if (BIG_INT_32.equals(precision)) {
+ ((PropertyDecimalDefinitionImpl) result).setPrecision(DecimalPrecision.BITS32);
+ } else if (BIG_INT_64.equals(precision)) {
+ ((PropertyDecimalDefinitionImpl) result).setPrecision(DecimalPrecision.BITS64);
+ }
+ }
} else if (propertyDefinition instanceof CmisPropertyBooleanDefinitionType) {
result = new PropertyBooleanDefinitionImpl();
@@ -2614,8 +2626,7 @@ public final class WSConverter {
if (streamDataHandlerClass1 != null && streamDataHandlerClass1.isInstance(streamDataHandler)) {
result.setStream((InputStream) streamDataHandlerReadMethod1.invoke(streamDataHandler,
(Object[]) null));
- } else if (streamDataHandlerClass2 != null
- && streamDataHandlerClass2.isInstance(streamDataHandler)) {
+ } else if (streamDataHandlerClass2 != null && streamDataHandlerClass2.isInstance(streamDataHandler)) {
result.setStream((InputStream) streamDataHandlerReadMethod2.invoke(streamDataHandler,
(Object[]) null));
} else {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyDefinition.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyDefinition.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyDefinition.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/AbstractPropertyDefinition.java Tue Aug 27 16:03:00 2013
@@ -18,6 +18,7 @@
*/
package org.apache.chemistry.opencmis.commons.impl.dataobjects;
+import java.util.ArrayList;
import java.util.List;
import org.apache.chemistry.opencmis.commons.definitions.Choice;
@@ -116,6 +117,10 @@ public abstract class AbstractPropertyDe
}
public List<Choice<T>> getChoices() {
+ if (choiceList == null) {
+ choiceList = new ArrayList<Choice<T>>();
+ }
+
return choiceList;
}
@@ -124,6 +129,10 @@ public abstract class AbstractPropertyDe
}
public List<T> getDefaultValue() {
+ if (defaultValue == null) {
+ defaultValue = new ArrayList<T>();
+ }
+
return defaultValue;
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ChoiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ChoiceImpl.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ChoiceImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ChoiceImpl.java Tue Aug 27 16:03:00 2013
@@ -18,6 +18,7 @@
*/
package org.apache.chemistry.opencmis.commons.impl.dataobjects;
+import java.util.ArrayList;
import java.util.List;
import org.apache.chemistry.opencmis.commons.definitions.Choice;
@@ -42,6 +43,10 @@ public class ChoiceImpl<T> implements Ch
}
public List<T> getValue() {
+ if (value == null) {
+ value = new ArrayList<T>();
+ }
+
return value;
}
@@ -50,6 +55,10 @@ public class ChoiceImpl<T> implements Ch
}
public List<Choice<T>> getChoice() {
+ if (choice == null) {
+ choice = new ArrayList<Choice<T>>();
+ }
+
return choice;
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/RepositoryCapabilitiesImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/RepositoryCapabilitiesImpl.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/RepositoryCapabilitiesImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/RepositoryCapabilitiesImpl.java Tue Aug 27 16:03:00 2013
@@ -60,6 +60,27 @@ public class RepositoryCapabilitiesImpl
public RepositoryCapabilitiesImpl() {
}
+ public RepositoryCapabilitiesImpl(RepositoryCapabilities data) {
+ allVersionsSearchable = data.isAllVersionsSearchableSupported();
+ capabilityAcl = data.getAclCapability();
+ capabilityChanges = data.getChangesCapability();
+ capabilityContentStreamUpdates = data.getContentStreamUpdatesCapability();
+ capabilityJoin = data.getJoinCapability();
+ capabilityQuery = data.getQueryCapability();
+ capabilityRendition = data.getRenditionsCapability();
+ isPwcSearchable = data.isPwcSearchableSupported();
+ isPwcUpdatable = data.isPwcUpdatableSupported();
+ supportsGetDescendants = data.isGetDescendantsSupported();
+ supportsGetFolderTree = data.isGetFolderTreeSupported();
+ capabilityOrderBy = data.getOrderByCapability();
+ supportsMultifiling = data.isMultifilingSupported();
+ supportsUnfiling = data.isUnfilingSupported();
+ supportsVersionSpecificFiling = data.isVersionSpecificFilingSupported();
+ creatablePropertyTypes = data.getCreatablePropertyTypes();
+ newTypeSettableAttributes = data.getNewTypeSettableAttributes();
+ setExtensions(data.getExtensions());
+ }
+
public Boolean isAllVersionsSearchableSupported() {
return allVersionsSearchable;
}
Added: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractConverterTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractConverterTest.java?rev=1517855&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractConverterTest.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractConverterTest.java Tue Aug 27 16:03:00 2013
@@ -0,0 +1,368 @@
+/*
+ * 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.commons.impl.xml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.TimeZone;
+
+import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
+import org.apache.chemistry.opencmis.commons.data.PropertyData;
+import org.apache.chemistry.opencmis.commons.data.PropertyId;
+import org.apache.chemistry.opencmis.commons.enums.PropertyType;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyData;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriImpl;
+import org.junit.Before;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Base test class for converter tests.
+ */
+public abstract class AbstractConverterTest {
+
+ private final static Logger LOG = LoggerFactory.getLogger(AbstractConverterTest.class);
+
+ private final static long SEED = 1234567890;
+
+ protected Random rnd;
+
+ @Before
+ public void init() throws Exception {
+ rnd = new Random(SEED);
+ }
+
+ protected PropertyData<?> createPropertyData(PropertyType propertyType, int numValues) {
+ AbstractPropertyData<?> result = null;
+
+ switch (propertyType) {
+ case BOOLEAN:
+ result = new PropertyBooleanImpl();
+ if (numValues > 0) {
+ List<Boolean> values = new ArrayList<Boolean>();
+ for (int i = 0; i < numValues; i++) {
+ values.add(randomBoolean());
+ }
+ ((PropertyBooleanImpl) result).setValues(values);
+ }
+ break;
+ case DATETIME:
+ result = new PropertyDateTimeImpl();
+ if (numValues > 0) {
+ List<GregorianCalendar> values = new ArrayList<GregorianCalendar>();
+ for (int i = 0; i < numValues; i++) {
+ values.add(randomDateTime());
+ }
+ ((PropertyDateTimeImpl) result).setValues(values);
+ }
+ break;
+ case DECIMAL:
+ result = new PropertyDecimalImpl();
+ if (numValues > 0) {
+ List<BigDecimal> values = new ArrayList<BigDecimal>();
+ for (int i = 0; i < numValues; i++) {
+ values.add(randomDecimal());
+ }
+ ((PropertyDecimalImpl) result).setValues(values);
+ }
+ break;
+ case HTML:
+ result = new PropertyHtmlImpl();
+ if (numValues > 0) {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i < numValues; i++) {
+ values.add(randomString());
+ }
+ ((PropertyHtmlImpl) result).setValues(values);
+ }
+ break;
+ case ID:
+ result = new PropertyIdImpl();
+ if (numValues > 0) {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i < numValues; i++) {
+ values.add(randomString());
+ }
+ ((PropertyIdImpl) result).setValues(values);
+ }
+ break;
+ case INTEGER:
+ result = new PropertyIntegerImpl();
+ if (numValues > 0) {
+ List<BigInteger> values = new ArrayList<BigInteger>();
+ for (int i = 0; i < numValues; i++) {
+ values.add(randomInteger());
+ }
+ ((PropertyIntegerImpl) result).setValues(values);
+ }
+ break;
+ case STRING:
+ result = new PropertyStringImpl();
+ if (numValues > 0) {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i < numValues; i++) {
+ values.add(randomString());
+ }
+ ((PropertyStringImpl) result).setValues(values);
+ }
+ break;
+ case URI:
+ result = new PropertyUriImpl();
+ if (numValues > 0) {
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i < numValues; i++) {
+ values.add(randomUri());
+ }
+ ((PropertyUriImpl) result).setValues(values);
+ }
+ break;
+ default:
+ assert false;
+ }
+
+ result.setId(randomString());
+ result.setDisplayName(randomString());
+ result.setLocalName(randomString());
+ result.setQueryName(randomString());
+
+ return result;
+ }
+
+ protected PropertyId createIdPropertyData(String id, String value) {
+ PropertyIdImpl result = new PropertyIdImpl();
+
+ result.setId(id);
+ result.setDisplayName(id);
+ result.setLocalName(id);
+ result.setQueryName(id);
+ result.setValue(value);
+
+ return result;
+ }
+
+ protected List<CmisExtensionElement> createExtensions(int depth) {
+ List<CmisExtensionElement> result = new ArrayList<CmisExtensionElement>();
+
+ String[] namespaces = new String[] { "http://ext1.com", "http://ext2.org", "http://ext3.net" };
+
+ for (int i = 0; i < randomInt(4) + 1; i++) {
+ String ns = namespaces[randomInt(namespaces.length)];
+
+ Map<String, String> attr = new HashMap<String, String>();
+ for (int j = 0; j < randomInt(3); j++) {
+ attr.put(randomTag(), randomString());
+ }
+
+ CmisExtensionElementImpl element;
+ if (randomBoolean() || depth < 1) {
+ element = new CmisExtensionElementImpl(ns, randomTag(), attr, randomString());
+ } else {
+ element = new CmisExtensionElementImpl(ns, randomTag(), attr, createExtensions(depth - 1));
+ }
+
+ result.add(element);
+ }
+
+ return result;
+ }
+
+ protected String randomString() {
+ StringBuilder sb = new StringBuilder();
+
+ int length = rnd.nextInt(21) + 3;
+ for (int i = 0; i < length; i++) {
+ sb.append((char) (rnd.nextInt(94) + 32));
+ }
+
+ return sb.toString();
+ }
+
+ protected String randomUri() {
+ StringBuilder sb = new StringBuilder("urn:test:");
+
+ int length = rnd.nextInt(21) + 3;
+ for (int i = 0; i < length; i++) {
+ sb.append((char) (rnd.nextInt(26) + 97));
+ }
+
+ return sb.toString();
+ }
+
+ protected Boolean randomBoolean() {
+ return Boolean.valueOf(rnd.nextBoolean());
+ }
+
+ protected BigInteger randomInteger() {
+ return BigInteger.valueOf(rnd.nextInt());
+ }
+
+ protected BigDecimal randomDecimal() {
+ return BigDecimal.valueOf(rnd.nextDouble() * rnd.nextInt());
+ }
+
+ protected GregorianCalendar randomDateTime() {
+ GregorianCalendar cal = new GregorianCalendar();
+ cal.setTimeZone(TimeZone.getTimeZone("GMT" + (rnd.nextBoolean() ? "+" : "-") + (rnd.nextInt(23) - 12) + ":00"));
+ cal.set(1583 + rnd.nextInt(8416), rnd.nextInt(12), rnd.nextInt(31) + 1, rnd.nextInt(23), rnd.nextInt(60),
+ rnd.nextInt(60));
+ cal.set(Calendar.MILLISECOND, 0);
+
+ return cal;
+ }
+
+ protected int randomInt(int n) {
+ return rnd.nextInt(n);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T extends Enum<?>> T randomEnum(Class<T> enumClass) {
+ T[] values = null;
+ try {
+ values = (T[]) enumClass.getMethod("values", new Class<?>[0]).invoke(null, new Object[0]);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return values[rnd.nextInt(values.length)];
+ }
+
+ protected String randomTag() {
+ StringBuilder sb = new StringBuilder();
+
+ int length = rnd.nextInt(7) + 3;
+ for (int i = 0; i < length; i++) {
+ sb.append((char) (rnd.nextInt(26) + 'a'));
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Compares two data objects.
+ */
+ protected void assertDataObjectsEquals(String name, Object expected, Object actual, Set<String> ignoreMethods) {
+
+ LOG.debug(name + ": " + expected + " / " + actual);
+
+ if ((expected == null) && (actual == null)) {
+ return;
+ }
+
+ if ((expected == null) || (actual == null)) {
+ fail("Data object is null! name: " + name + " / expected: " + expected + " / actual: " + actual);
+ }
+
+ // handle simple types
+ if ((expected instanceof String) || (expected instanceof Boolean) || (expected instanceof BigInteger)
+ || (expected instanceof BigDecimal) || (expected instanceof Enum<?>)) {
+ assertEquals(name, expected, actual);
+
+ return;
+ } else if (expected instanceof GregorianCalendar) {
+ long expectedMillis = ((GregorianCalendar) expected).getTimeInMillis();
+ long actualMillis = ((GregorianCalendar) actual).getTimeInMillis();
+
+ assertEquals(name, expectedMillis, actualMillis);
+
+ return;
+ } else if (expected instanceof List<?>) {
+ List<?> expectedList = (List<?>) expected;
+ List<?> actualList = (List<?>) actual;
+
+ assertEquals(name + ".length", expectedList.size(), actualList.size());
+
+ for (int i = 0; i < expectedList.size(); i++) {
+ assertDataObjectsEquals(name + "[" + i + "]", expectedList.get(i), actualList.get(i), ignoreMethods);
+ }
+
+ return;
+ } else if (expected instanceof Map<?, ?>) {
+ Map<?, ?> expectedMap = (Map<?, ?>) expected;
+ Map<?, ?> actualMap = (Map<?, ?>) actual;
+
+ assertEquals(name + ".length", expectedMap.size(), actualMap.size());
+
+ for (Map.Entry<?, ?> entry : expectedMap.entrySet()) {
+ assertTrue(name + ".contains[" + entry.getKey() + "]", actualMap.containsKey(entry.getKey()));
+ assertDataObjectsEquals(name + "[" + entry.getKey() + "]", entry.getValue(),
+ actualMap.get(entry.getKey()), ignoreMethods);
+ }
+
+ return;
+ } else if (expected instanceof Set<?>) {
+ Set<?> expectedSet = (Set<?>) expected;
+ Set<?> actualSet = (Set<?>) actual;
+
+ assertEquals(name + ".length", expectedSet.size(), actualSet.size());
+
+ for (Object item : expectedSet) {
+ assertTrue(name + ".contains[" + item + "]", actualSet.contains(item));
+ }
+
+ return;
+ }
+
+ for (Method m : expected.getClass().getMethods()) {
+ if (!m.getName().startsWith("get") && !m.getName().startsWith("is") && !m.getName().startsWith("supports")) {
+ continue;
+ }
+
+ if (ignoreMethods != null && ignoreMethods.contains(m.getName())) {
+ continue;
+ }
+
+ if (m.getName().equals("getClass")) {
+ continue;
+ }
+
+ if (m.getParameterTypes().length != 0) {
+ continue;
+ }
+
+ try {
+ Object expectedValue = m.invoke(expected, new Object[0]);
+ Object actualValue = m.invoke(actual, new Object[0]);
+
+ assertDataObjectsEquals(name + "." + m.getName(), expectedValue, actualValue, ignoreMethods);
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+ }
+ }
+}
Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractConverterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java Tue Aug 27 16:03:00 2013
@@ -18,27 +18,12 @@
*/
package org.apache.chemistry.opencmis.commons.impl.xml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-import java.util.TimeZone;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@@ -54,38 +39,21 @@ import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
-import org.apache.chemistry.opencmis.commons.data.CmisExtensionElement;
-import org.apache.chemistry.opencmis.commons.data.PropertyData;
-import org.apache.chemistry.opencmis.commons.data.PropertyId;
import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
-import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.impl.IOUtils;
import org.apache.chemistry.opencmis.commons.impl.XMLConstants;
import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyData;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.CmisExtensionElementImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriImpl;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.xml.sax.SAXException;
-public abstract class AbstractXMLConverterTest {
+public abstract class AbstractXMLConverterTest extends AbstractConverterTest {
protected final static String TEST_NAMESPACE = "http://chemistry.apache.org/test/schema";
protected final static String TEST_PREFIX = "test";
private final static Logger LOG = LoggerFactory.getLogger(AbstractXMLConverterTest.class);
- private final static long SEED = 1234567890;
-
protected final static String TEST_SCHEMA10 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" targetNamespace=\""
+ TEST_NAMESPACE
@@ -133,13 +101,14 @@ public abstract class AbstractXMLConvert
protected Schema schema10;
protected Schema schema11;
- protected Random rnd;
/**
* Sets up the schema.
*/
@Before
- public void init() throws SAXException, IOException {
+ public void init() throws Exception {
+ super.init();
+
SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
InputStream schema10stream = AbstractXMLConverterTest.class.getResourceAsStream("/schema/cmis10/CMIS-core.xsd");
@@ -155,8 +124,6 @@ public abstract class AbstractXMLConvert
StreamSource test11 = new StreamSource(new ByteArrayInputStream(IOUtils.getUTF8Bytes(TEST_SCHEMA11)));
schema11 = sf.newSchema(new Source[] { core11, test11 });
}
-
- rnd = new Random(SEED);
}
/**
@@ -271,299 +238,4 @@ public abstract class AbstractXMLConvert
return result.getWriter().toString();
}
-
- protected PropertyData<?> createPropertyData(PropertyType propertyType, int numValues) {
- AbstractPropertyData<?> result;
-
- switch (propertyType) {
- case BOOLEAN:
- result = new PropertyBooleanImpl();
- if (numValues > 0) {
- List<Boolean> values = new ArrayList<Boolean>();
- for (int i = 0; i < numValues; i++) {
- values.add(randomBoolean());
- }
- ((PropertyBooleanImpl) result).setValues(values);
- }
- break;
- case DATETIME:
- result = new PropertyDateTimeImpl();
- if (numValues > 0) {
- List<GregorianCalendar> values = new ArrayList<GregorianCalendar>();
- for (int i = 0; i < numValues; i++) {
- values.add(randomDateTime());
- }
- ((PropertyDateTimeImpl) result).setValues(values);
- }
- break;
- case DECIMAL:
- result = new PropertyDecimalImpl();
- if (numValues > 0) {
- List<BigDecimal> values = new ArrayList<BigDecimal>();
- for (int i = 0; i < numValues; i++) {
- values.add(randomDecimal());
- }
- ((PropertyDecimalImpl) result).setValues(values);
- }
- break;
- case HTML:
- result = new PropertyHtmlImpl();
- if (numValues > 0) {
- List<String> values = new ArrayList<String>();
- for (int i = 0; i < numValues; i++) {
- values.add(randomString());
- }
- ((PropertyHtmlImpl) result).setValues(values);
- }
- break;
- case ID:
- result = new PropertyIdImpl();
- if (numValues > 0) {
- List<String> values = new ArrayList<String>();
- for (int i = 0; i < numValues; i++) {
- values.add(randomString());
- }
- ((PropertyIdImpl) result).setValues(values);
- }
- break;
- case INTEGER:
- result = new PropertyIntegerImpl();
- if (numValues > 0) {
- List<BigInteger> values = new ArrayList<BigInteger>();
- for (int i = 0; i < numValues; i++) {
- values.add(randomInteger());
- }
- ((PropertyIntegerImpl) result).setValues(values);
- }
- break;
- case STRING:
- result = new PropertyStringImpl();
- if (numValues > 0) {
- List<String> values = new ArrayList<String>();
- for (int i = 0; i < numValues; i++) {
- values.add(randomString());
- }
- ((PropertyStringImpl) result).setValues(values);
- }
- break;
- case URI:
- result = new PropertyUriImpl();
- if (numValues > 0) {
- List<String> values = new ArrayList<String>();
- for (int i = 0; i < numValues; i++) {
- values.add(randomUri());
- }
- ((PropertyUriImpl) result).setValues(values);
- }
- break;
- default:
- return null;
- }
-
- result.setId(randomString());
- result.setDisplayName(randomString());
- result.setLocalName(randomString());
- result.setQueryName(randomString());
-
- return result;
- }
-
- protected PropertyId createIdPropertyData(String id, String value) {
- PropertyIdImpl result = new PropertyIdImpl();
-
- result.setId(id);
- result.setDisplayName(id);
- result.setLocalName(id);
- result.setQueryName(id);
- result.setValue(value);
-
- return result;
- }
-
- protected List<CmisExtensionElement> createExtensions(int depth) {
- List<CmisExtensionElement> result = new ArrayList<CmisExtensionElement>();
-
- String[] namespaces = new String[] { "http://ext1.com", "http://ext2.org", "http://ext3.net" };
-
- for (int i = 0; i < randomInt(4) + 1; i++) {
- String ns = namespaces[randomInt(namespaces.length)];
-
- Map<String, String> attr = new HashMap<String, String>();
- for (int j = 0; j < randomInt(3); j++) {
- attr.put(randomTag(), randomString());
- }
-
- CmisExtensionElementImpl element;
- if (randomBoolean() || depth < 1) {
- element = new CmisExtensionElementImpl(ns, randomTag(), attr, randomString());
- } else {
- element = new CmisExtensionElementImpl(ns, randomTag(), attr, createExtensions(depth - 1));
- }
-
- result.add(element);
- }
-
- return result;
- }
-
- protected String randomString() {
- StringBuilder sb = new StringBuilder();
-
- int length = rnd.nextInt(21) + 3;
- for (int i = 0; i < length; i++) {
- sb.append((char) (rnd.nextInt(94) + 32));
- }
-
- return sb.toString();
- }
-
- protected String randomUri() {
- StringBuilder sb = new StringBuilder("urn:test:");
-
- int length = rnd.nextInt(21) + 3;
- for (int i = 0; i < length; i++) {
- sb.append((char) (rnd.nextInt(26) + 97));
- }
-
- return sb.toString();
- }
-
- protected Boolean randomBoolean() {
- return Boolean.valueOf(rnd.nextBoolean());
- }
-
- protected BigInteger randomInteger() {
- return BigInteger.valueOf(rnd.nextInt());
- }
-
- protected BigDecimal randomDecimal() {
- return BigDecimal.valueOf(rnd.nextDouble() * rnd.nextInt());
- }
-
- protected GregorianCalendar randomDateTime() {
- GregorianCalendar cal = new GregorianCalendar();
- cal.setTimeZone(TimeZone.getTimeZone("GMT" + (rnd.nextBoolean() ? "+" : "-") + (rnd.nextInt(23) - 12) + ":00"));
- cal.set(rnd.nextInt(9998) + 1, rnd.nextInt(12), rnd.nextInt(31) + 1, rnd.nextInt(23), rnd.nextInt(60),
- rnd.nextInt(60));
- cal.set(Calendar.MILLISECOND, 0);
-
- return cal;
- }
-
- protected int randomInt(int n) {
- return rnd.nextInt(n);
- }
-
- @SuppressWarnings("unchecked")
- protected <T extends Enum<?>> T randomEnum(Class<T> enumClass) {
- T[] values = null;
- try {
- values = (T[]) enumClass.getMethod("values", new Class<?>[0]).invoke(null, new Object[0]);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return values[rnd.nextInt(values.length)];
- }
-
- protected String randomTag() {
- StringBuilder sb = new StringBuilder();
-
- int length = rnd.nextInt(7) + 3;
- for (int i = 0; i < length; i++) {
- sb.append((char) (rnd.nextInt(26) + 'a'));
- }
-
- return sb.toString();
- }
-
- /**
- * Compares two data objects.
- */
- protected void assertDataObjectsEquals(String name, Object expected, Object actual, Set<String> ignoreMethods) {
-
- LOG.debug(name + ": " + expected + " / " + actual);
-
- if ((expected == null) && (actual == null)) {
- return;
- }
-
- if ((expected == null) || (actual == null)) {
- fail("Data object is null! name: " + name + " / expected: " + expected + " / actual: " + actual);
- }
-
- // handle simple types
- if ((expected instanceof String) || (expected instanceof Boolean) || (expected instanceof BigInteger)
- || (expected instanceof BigDecimal) || (expected instanceof Enum<?>)) {
- assertEquals(name, expected, actual);
-
- return;
- } else if (expected instanceof GregorianCalendar) {
- assertEquals(name, ((GregorianCalendar) expected).getTimeInMillis(),
- ((GregorianCalendar) actual).getTimeInMillis());
-
- return;
- } else if (expected instanceof List<?>) {
- List<?> expectedList = (List<?>) expected;
- List<?> actualList = (List<?>) actual;
-
- assertEquals(name + ".length", expectedList.size(), actualList.size());
-
- for (int i = 0; i < expectedList.size(); i++) {
- assertDataObjectsEquals(name + "[" + i + "]", expectedList.get(i), actualList.get(i), ignoreMethods);
- }
-
- return;
- } else if (expected instanceof Map<?, ?>) {
- Map<?, ?> expectedMap = (Map<?, ?>) expected;
- Map<?, ?> actualMap = (Map<?, ?>) actual;
-
- assertEquals(name + ".length", expectedMap.size(), actualMap.size());
-
- for (Map.Entry<?, ?> entry : expectedMap.entrySet()) {
- assertTrue(name + ".contains[" + entry.getKey() + "]", actualMap.containsKey(entry.getKey()));
- assertDataObjectsEquals(name + "[" + entry.getKey() + "]", entry.getValue(),
- actualMap.get(entry.getKey()), ignoreMethods);
- }
-
- return;
- } else if (expected instanceof Set<?>) {
- Set<?> expectedSet = (Set<?>) expected;
- Set<?> actualSet = (Set<?>) actual;
-
- assertEquals(name + ".length", expectedSet.size(), actualSet.size());
-
- for (Object item : expectedSet) {
- assertTrue(name + ".contains[" + item + "]", actualSet.contains(item));
- }
-
- return;
- }
-
- for (Method m : expected.getClass().getMethods()) {
- if (!m.getName().startsWith("get") && !m.getName().startsWith("is") && !m.getName().startsWith("supports")) {
- continue;
- }
-
- if (ignoreMethods != null && ignoreMethods.contains(m.getName())) {
- continue;
- }
-
- if (m.getName().equals("getClass")) {
- continue;
- }
-
- if (m.getParameterTypes().length != 0) {
- continue;
- }
-
- try {
- Object expectedValue = m.invoke(expected, new Object[0]);
- Object actualValue = m.invoke(actual, new Object[0]);
-
- assertDataObjectsEquals(name + "." + m.getName(), expectedValue, actualValue, ignoreMethods);
- } catch (Exception e) {
- fail(e.toString());
- }
- }
- }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java Tue Aug 27 16:03:00 2013
@@ -20,8 +20,10 @@ package org.apache.chemistry.opencmis.co
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
+import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -51,6 +53,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.enums.SupportedPermissions;
+import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
+import org.apache.chemistry.opencmis.commons.impl.WSConverter;
import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.AclCapabilitiesDataImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.CreatablePropertyTypesImpl;
@@ -60,6 +64,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PermissionMappingDataImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryCapabilitiesImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryInfoImpl;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRepositoryInfoType;
+import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser;
import org.junit.Test;
public class RepositoryInfoConverterTest extends AbstractXMLConverterTest {
@@ -205,6 +211,11 @@ public class RepositoryInfoConverterTest
}
protected void assertRepositoryInfo10(RepositoryInfo repInfo, boolean validate) throws Exception {
+ assertXmlRepositoryInfo10(repInfo, validate);
+ assertWsRepositoryInfo10(repInfo);
+ }
+
+ protected void assertXmlRepositoryInfo10(RepositoryInfo repInfo, boolean validate) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamWriter writer = createWriter(out);
@@ -226,7 +237,34 @@ public class RepositoryInfoConverterTest
assertNull(result.getExtensions());
}
+ protected void assertWsRepositoryInfo10(RepositoryInfo repInfo) throws Exception {
+ CmisRepositoryInfoType ws = WSConverter.convert(repInfo, CmisVersion.CMIS_1_0);
+
+ RepositoryInfo result = WSConverter.convert(ws);
+
+ // remove CMIS 1.1 features
+ RepositoryInfoImpl repInfo2 = new RepositoryInfoImpl(repInfo);
+ repInfo2.setExtensionFeature(null);
+ if (repInfo.getCapabilities() != null) {
+ RepositoryCapabilitiesImpl capabilities = new RepositoryCapabilitiesImpl(repInfo.getCapabilities());
+ capabilities.setOrderByCapability(null);
+ capabilities.setCreatablePropertyTypes(null);
+ capabilities.setNewTypeSettableAttributes(null);
+ repInfo2.setCapabilities(capabilities);
+ }
+
+ assertNotNull(result);
+ assertDataObjectsEquals("RepositoryInfo", repInfo2, result, null);
+ assertNull(result.getExtensions());
+ }
+
protected void assertRepositoryInfo11(RepositoryInfo repInfo, boolean validate) throws Exception {
+ assertXmlRepositoryInfo11(repInfo, validate);
+ assertWsRepositoryInfo11(repInfo);
+ assertJsonRepositoryInfo11(repInfo);
+ }
+
+ protected void assertXmlRepositoryInfo11(RepositoryInfo repInfo, boolean validate) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamWriter writer = createWriter(out);
@@ -247,4 +285,29 @@ public class RepositoryInfoConverterTest
assertDataObjectsEquals("RepositoryInfo", repInfo, result, null);
assertNull(result.getExtensions());
}
+
+ protected void assertWsRepositoryInfo11(RepositoryInfo repInfo) throws Exception {
+ CmisRepositoryInfoType ws = WSConverter.convert(repInfo, CmisVersion.CMIS_1_1);
+
+ RepositoryInfo result = WSConverter.convert(ws);
+
+ assertNotNull(result);
+ assertDataObjectsEquals("RepositoryInfo", repInfo, result, null);
+ assertNull(result.getExtensions());
+ }
+
+ protected void assertJsonRepositoryInfo11(RepositoryInfo repInfo) throws Exception {
+ StringWriter sw = new StringWriter();
+
+ JSONConverter.convert(repInfo, null, null).writeJSONString(sw);
+
+ Object json = (new JSONParser()).parse(sw.toString());
+ assertTrue(json instanceof Map<?, ?>);
+ @SuppressWarnings("unchecked")
+ RepositoryInfo result = JSONConverter.convertRepositoryInfo((Map<String, Object>) json);
+
+ assertNotNull(result);
+ assertDataObjectsEquals("RepositoryInfo", repInfo, result, null);
+ assertNull(result.getExtensions());
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java Tue Aug 27 16:03:00 2013
@@ -20,10 +20,13 @@ package org.apache.chemistry.opencmis.co
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
+import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import javax.xml.stream.XMLStreamReader;
@@ -38,6 +41,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.DecimalPrecision;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.enums.Updatability;
+import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
+import org.apache.chemistry.opencmis.commons.impl.WSConverter;
import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractTypeDefinition;
@@ -56,6 +61,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.dataobjects.RelationshipTypeDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.SecondaryTypeDefinitionImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeMutabilityImpl;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionType;
+import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser;
import org.junit.Test;
public class TypeDefinitionConverterTest extends AbstractXMLConverterTest {
@@ -282,6 +289,11 @@ public class TypeDefinitionConverterTest
}
protected void assertTypeDefinition10(TypeDefinition typeDef, boolean validate) throws Exception {
+ assertXmlTypeDefinition10(typeDef, validate);
+ assertWsTypeDefinition10(typeDef);
+ }
+
+ protected void assertXmlTypeDefinition10(TypeDefinition typeDef, boolean validate) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamWriter writer = createWriter(out);
@@ -303,7 +315,23 @@ public class TypeDefinitionConverterTest
assertNull(result.getExtensions());
}
+ protected void assertWsTypeDefinition10(TypeDefinition typeDef) throws Exception {
+ CmisTypeDefinitionType ws = WSConverter.convert(typeDef);
+
+ TypeDefinition result = WSConverter.convert(ws);
+
+ assertNotNull(result);
+ assertDataObjectsEquals("TypeDefinition", typeDef, result, null);
+ assertNull(result.getExtensions());
+ }
+
protected void assertTypeDefinition11(TypeDefinition typeDef, boolean validate) throws Exception {
+ assertXmlTypeDefinition11(typeDef, validate);
+ assertWsTypeDefinition11(typeDef);
+ assertJsonTypeDefinition11(typeDef);
+ }
+
+ protected void assertXmlTypeDefinition11(TypeDefinition typeDef, boolean validate) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamWriter writer = createWriter(out);
@@ -324,4 +352,29 @@ public class TypeDefinitionConverterTest
assertDataObjectsEquals("TypeDefinition", typeDef, result, null);
assertNull(result.getExtensions());
}
+
+ protected void assertWsTypeDefinition11(TypeDefinition typeDef) throws Exception {
+ CmisTypeDefinitionType ws = WSConverter.convert(typeDef);
+
+ TypeDefinition result = WSConverter.convert(ws);
+
+ assertNotNull(result);
+ assertDataObjectsEquals("TypeDefinition", typeDef, result, null);
+ assertNull(result.getExtensions());
+ }
+
+ protected void assertJsonTypeDefinition11(TypeDefinition typeDef) throws Exception {
+ StringWriter sw = new StringWriter();
+
+ JSONConverter.convert(typeDef).writeJSONString(sw);
+
+ Object json = (new JSONParser()).parse(sw.toString());
+ assertTrue(json instanceof Map<?, ?>);
+ @SuppressWarnings("unchecked")
+ TypeDefinition result = JSONConverter.convertTypeDefinition((Map<String, Object>) json);
+
+ assertNotNull(result);
+ assertDataObjectsEquals("TypeDefinition", typeDef, result, null);
+ assertNull(result.getExtensions());
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryObjectServiceImpl.java Tue Aug 27 16:03:00 2013
@@ -1269,7 +1269,7 @@ public class InMemoryObjectServiceImpl e
for (PropertyDefinition<?> propDef : propDefs.values()) {
String propId = propDef.getId();
List<?> defaultVal = propDef.getDefaultValue();
- if (defaultVal != null && null == properties.get(propId)) {
+ if (defaultVal != null && !defaultVal.isEmpty() && null == properties.get(propId)) {
if (!hasCopied) {
// copy because it is an unmodified collection
propertiesReturn = new HashMap<String, PropertyData<?>>(properties);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java?rev=1517855&r1=1517854&r2=1517855&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java Tue Aug 27 16:03:00 2013
@@ -167,10 +167,10 @@ public final class TypeValidator {
private List<T> getAllowedValues(List<Choice<T>> choices) {
List<T> allowedValues = new ArrayList<T>(choices.size());
for (Choice<T> choice : choices) {
- if (choice.getValue() != null) {
+ if (choice.getValue() != null && !choice.getValue().isEmpty()) {
allowedValues.add(choice.getValue().get(0));
}
- if (choice.getChoice() != null) {
+ if (choice.getChoice() != null && !choice.getChoice().isEmpty()) {
List<Choice<T>> x = choice.getChoice();
allowedValues.addAll(getAllowedValues(x));
}