Author: fmui
Date: Wed Feb 20 17:26:52 2013
New Revision: 1448311
URL: http://svn.apache.org/r1448311
Log:
CMIS 1.1: more XML unit tests
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.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
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.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/XMLConverter.java?rev=1448311&r1=1448310&r2=1448311&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java
Wed Feb 20 17:26:52 2013
@@ -496,7 +496,7 @@ public class XMLConverter {
PropertyStringDefinition def = (PropertyStringDefinition) source;
if (def.getDefaultValue() != null) {
- writeProperty(writer, new PropertyStringImpl(null,
def.getDefaultValue()));
+ writeProperty(writer, new PropertyStringImpl(null,
def.getDefaultValue()), true);
}
XMLUtils.write(writer, NAMESPACE_CMIS,
TAG_PROPERTY_TYPE_MAX_LENGTH, def.getMaxLength());
@@ -504,13 +504,13 @@ public class XMLConverter {
PropertyIdDefinition def = (PropertyIdDefinition) source;
if (def.getDefaultValue() != null) {
- writeProperty(writer, new PropertyIdImpl(null,
def.getDefaultValue()));
+ writeProperty(writer, new PropertyIdImpl(null,
def.getDefaultValue()), true);
}
} else if (source instanceof PropertyIntegerDefinition) {
PropertyIntegerDefinition def = (PropertyIntegerDefinition) source;
if (def.getDefaultValue() != null) {
- writeProperty(writer, new PropertyIntegerImpl(null,
def.getDefaultValue()));
+ writeProperty(writer, new PropertyIntegerImpl(null,
def.getDefaultValue()), true);
}
XMLUtils.write(writer, NAMESPACE_CMIS,
TAG_PROPERTY_TYPE_MAX_VALUE, def.getMaxValue());
@@ -519,13 +519,13 @@ public class XMLConverter {
PropertyBooleanDefinition def = (PropertyBooleanDefinition) source;
if (def.getDefaultValue() != null) {
- writeProperty(writer, new PropertyBooleanImpl(null,
def.getDefaultValue()));
+ writeProperty(writer, new PropertyBooleanImpl(null,
def.getDefaultValue()), true);
}
} else if (source instanceof PropertyDateTimeDefinition) {
PropertyDateTimeDefinition def = (PropertyDateTimeDefinition)
source;
if (def.getDefaultValue() != null) {
- writeProperty(writer, new PropertyDateTimeImpl(null,
def.getDefaultValue()));
+ writeProperty(writer, new PropertyDateTimeImpl(null,
def.getDefaultValue()), true);
}
XMLUtils.write(writer, NAMESPACE_CMIS,
TAG_PROPERTY_TYPE_RESOLUTION, def.getDateTimeResolution());
@@ -533,7 +533,7 @@ public class XMLConverter {
PropertyDecimalDefinition def = (PropertyDecimalDefinition) source;
if (def.getDefaultValue() != null) {
- writeProperty(writer, new PropertyDecimalImpl(null,
def.getDefaultValue()));
+ writeProperty(writer, new PropertyDecimalImpl(null,
def.getDefaultValue()), true);
}
XMLUtils.write(writer, NAMESPACE_CMIS,
TAG_PROPERTY_TYPE_MAX_VALUE, def.getMaxValue());
@@ -543,13 +543,13 @@ public class XMLConverter {
PropertyHtmlDefinition def = (PropertyHtmlDefinition) source;
if (def.getDefaultValue() != null) {
- writeProperty(writer, new PropertyIdImpl(null,
def.getDefaultValue()));
+ writeProperty(writer, new PropertyIdImpl(null,
def.getDefaultValue()), true);
}
} else if (source instanceof PropertyUriDefinition) {
PropertyUriDefinition def = (PropertyUriDefinition) source;
if (def.getDefaultValue() != null) {
- writeProperty(writer, new PropertyIdImpl(null,
def.getDefaultValue()));
+ writeProperty(writer, new PropertyIdImpl(null,
def.getDefaultValue()), true);
}
}
@@ -642,7 +642,7 @@ public class XMLConverter {
if (properties.getPropertyList() != null) {
for (PropertyData<?> property : properties.getPropertyList()) {
- writeProperty(writer, property);
+ writeProperty(writer, property, false);
}
}
@@ -762,29 +762,34 @@ public class XMLConverter {
}
@SuppressWarnings("unchecked")
- public static void writeProperty(XMLStreamWriter writer, PropertyData<?>
source) throws XMLStreamException {
+ public static void writeProperty(XMLStreamWriter writer, PropertyData<?>
source, boolean isDefaultValue)
+ throws XMLStreamException {
if (source == null) {
return;
}
- if (source instanceof PropertyString) {
- writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_STRING);
- } else if (source instanceof PropertyId) {
- writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_ID);
- } else if (source instanceof PropertyInteger) {
- writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_INTEGER);
- } else if (source instanceof PropertyBoolean) {
- writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_BOOLEAN);
- } else if (source instanceof PropertyDateTime) {
- writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_DATETIME);
- } else if (source instanceof PropertyDecimal) {
- writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_DECIMAL);
- } else if (source instanceof PropertyHtml) {
- writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_HTML);
- } else if (source instanceof PropertyUri) {
- writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_URI);
+ if (isDefaultValue) {
+ writer.writeStartElement(NAMESPACE_CMIS,
TAG_PROPERTY_TYPE_DEAULT_VALUE);
} else {
- throw new CmisRuntimeException("Invalid property!");
+ if (source instanceof PropertyString) {
+ writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_STRING);
+ } else if (source instanceof PropertyId) {
+ writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_ID);
+ } else if (source instanceof PropertyInteger) {
+ writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_INTEGER);
+ } else if (source instanceof PropertyBoolean) {
+ writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_BOOLEAN);
+ } else if (source instanceof PropertyDateTime) {
+ writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_DATETIME);
+ } else if (source instanceof PropertyDecimal) {
+ writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_DECIMAL);
+ } else if (source instanceof PropertyHtml) {
+ writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_HTML);
+ } else if (source instanceof PropertyUri) {
+ writer.writeStartElement(NAMESPACE_CMIS, TAG_PROP_URI);
+ } else {
+ throw new CmisRuntimeException("Invalid property!");
+ }
}
if (source.getId() != null) {
@@ -1799,7 +1804,12 @@ public class XMLConverter {
}
if (isTag(name, TAG_PROPERTY_TYPE_PRECISION)) {
- ((PropertyDecimalDefinitionImpl)
target).setPrecision(readEnum(parser, DecimalPrecision.class));
+ try {
+ ((PropertyDecimalDefinitionImpl)
target).setPrecision(DecimalPrecision
+ .fromValue(readInteger(parser)));
+ } catch (IllegalArgumentException e) {
+ // invalid enum value - ignore
+ }
return true;
}
} else if (target instanceof PropertyHtmlDefinitionImpl) {
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=1448311&r1=1448310&r2=1448311&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
Wed Feb 20 17:26:52 2013
@@ -23,14 +23,20 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
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;
@@ -61,6 +67,8 @@ public abstract class AbstractXMLConvert
private Logger LOG =
LoggerFactory.getLogger(AbstractXMLConverterTest.class);
+ private final static long SEED = 1234567890;
+
protected final static String TEST_SCHEMA = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>"
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"
elementFormDefault=\"qualified\" targetNamespace=\""
+ TEST_NAMESPACE
@@ -84,6 +92,7 @@ public abstract class AbstractXMLConvert
protected static Schema schema10;
protected static Schema schema11;
+ protected static Random rnd;
/**
* Sets up the schema.
@@ -92,16 +101,24 @@ public abstract class AbstractXMLConvert
public static void init() throws SAXException,
UnsupportedEncodingException {
SchemaFactory sf =
SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
- StreamSource core10 = new StreamSource(
-
AbstractXMLConverterTest.class.getResourceAsStream("/schema/cmis10/CMIS-core.xsd"));
+ InputStream schema10stream =
AbstractXMLConverterTest.class.getResourceAsStream("/schema/cmis10/CMIS-core.xsd");
+ if (schema10stream == null) {
+ throw new RuntimeException("Cannot find CMIS 1.0 schema file!");
+ }
+ StreamSource core10 = new StreamSource(schema10stream);
StreamSource test10 = new StreamSource(new
ByteArrayInputStream(TEST_SCHEMA.getBytes("UTF-8")));
- StreamSource core11 = new StreamSource(
-
AbstractXMLConverterTest.class.getResourceAsStream("/schema/cmis11/CMIS-core.xsd"));
+ InputStream schema11stream =
AbstractXMLConverterTest.class.getResourceAsStream("/schema/cmis11/CMIS-core.xsd");
+ if (schema11stream == null) {
+ throw new RuntimeException("Cannot find CMIS 1.1 schema file!");
+ }
+ StreamSource core11 = new StreamSource(schema11stream);
StreamSource test11 = new StreamSource(new
ByteArrayInputStream(TEST_SCHEMA.getBytes("UTF-8")));
-
+
schema10 = sf.newSchema(new Source[] { core10, test10 });
schema11 = sf.newSchema(new Source[] { core11, test11 });
+
+ rnd = new Random(SEED);
}
/**
@@ -207,10 +224,65 @@ public abstract class AbstractXMLConvert
return result.getWriter().toString();
}
+ 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;
+ }
+
+ @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)];
+ }
+
/**
* Compares two data objects.
*/
- protected void assertDataObjectsEquals(String name, Object expected,
Object actual) {
+ protected void assertDataObjectsEquals(String name, Object expected,
Object actual, Set<String> ignoreMethods) {
LOG.debug(name + ": " + expected + " / " + actual);
@@ -228,6 +300,11 @@ public abstract class AbstractXMLConvert
assertEquals(expected, actual);
return;
+ } else if (expected instanceof GregorianCalendar) {
+ assertEquals(((GregorianCalendar) expected).getTimeInMillis(),
+ ((GregorianCalendar) actual).getTimeInMillis());
+
+ return;
} else if (expected instanceof List<?>) {
List<?> expectedList = (List<?>) expected;
List<?> actualList = (List<?>) actual;
@@ -235,7 +312,7 @@ public abstract class AbstractXMLConvert
assertEquals(expectedList.size(), actualList.size());
for (int i = 0; i < expectedList.size(); i++) {
- assertDataObjectsEquals(name + "[" + i + "]",
expectedList.get(i), actualList.get(i));
+ assertDataObjectsEquals(name + "[" + i + "]",
expectedList.get(i), actualList.get(i), ignoreMethods);
}
return;
@@ -248,7 +325,7 @@ public abstract class AbstractXMLConvert
for (Map.Entry<?, ?> entry : expectedMap.entrySet()) {
assertTrue(actualMap.containsKey(entry.getKey()));
assertDataObjectsEquals(name + "[" + entry.getKey() + "]",
entry.getValue(),
- actualMap.get(entry.getKey()));
+ actualMap.get(entry.getKey()), ignoreMethods);
}
return;
@@ -259,6 +336,10 @@ public abstract class AbstractXMLConvert
continue;
}
+ if (ignoreMethods != null && ignoreMethods.contains(m.getName())) {
+ continue;
+ }
+
if (m.getName().equals("getClass")) {
continue;
}
@@ -271,7 +352,7 @@ public abstract class AbstractXMLConvert
Object expectedValue = m.invoke(expected, new Object[0]);
Object actualValue = m.invoke(actual, new Object[0]);
- assertDataObjectsEquals(name + "." + m.getName(),
expectedValue, actualValue);
+ 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=1448311&r1=1448310&r2=1448311&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
Wed Feb 20 17:26:52 2013
@@ -25,13 +25,17 @@ import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.apache.chemistry.opencmis.commons.data.ExtensionFeature;
import org.apache.chemistry.opencmis.commons.data.PermissionMapping;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
@@ -41,12 +45,17 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.CapabilityChanges;
import
org.apache.chemistry.opencmis.commons.enums.CapabilityContentStreamUpdates;
import org.apache.chemistry.opencmis.commons.enums.CapabilityJoin;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityOrderBy;
import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
import org.apache.chemistry.opencmis.commons.enums.CapabilityRenditions;
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.XMLConverter;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.AclCapabilitiesDataImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.CreatablePropertyTypesImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.ExtensionFeatureImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.NewTypeSettableAttributesImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PermissionDefinitionDataImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PermissionMappingDataImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryCapabilitiesImpl;
@@ -55,75 +64,147 @@ import org.junit.Test;
public class RepositoryInfoConverterTest extends AbstractXMLConverterTest {
+ private static Set<String> cmis10ignoreMethods = new HashSet<String>();
+ static {
+ cmis10ignoreMethods.add("getOrderByCapability");
+ cmis10ignoreMethods.add("getCreatablePropertyTypes");
+ cmis10ignoreMethods.add("getNewTypeSettableAttributes");
+ cmis10ignoreMethods.add("getExtensionFeatures");
+ }
+
@Test
public void testRepositoryInfo() throws Exception {
- RepositoryInfoImpl obj1 = new RepositoryInfoImpl();
- assertRepositoryInfo(obj1, false);
+ // run the test a few times with different values
+ for (int i = 0; i < 10; i++) {
+ RepositoryInfoImpl repInfo = new RepositoryInfoImpl();
+
+ assertRepositoryInfo10(repInfo, false);
+
+ // values
+ repInfo = new RepositoryInfoImpl();
+ repInfo.setChangesIncomplete(randomBoolean());
+
repInfo.setChangesOnType(Collections.singletonList(BaseTypeId.CMIS_DOCUMENT));
+ repInfo.setCmisVersionSupported("1.0");
+ repInfo.setLatestChangeLogToken(randomString());
+ repInfo.setPrincipalAnonymous(randomString());
+ repInfo.setPrincipalAnyone(randomString());
+ repInfo.setProductName(randomString());
+ repInfo.setProductVersion(randomString());
+ repInfo.setDescription(randomString());
+ repInfo.setId(randomString());
+ repInfo.setName(randomString());
+ repInfo.setRootFolder(randomString());
+ repInfo.setThinClientUri(randomUri());
+ repInfo.setVendorName(randomString());
+
+ RepositoryCapabilitiesImpl cap1 = new RepositoryCapabilitiesImpl();
+ cap1.setAllVersionsSearchable(randomBoolean());
+ cap1.setCapabilityAcl(randomEnum(CapabilityAcl.class));
+ cap1.setCapabilityChanges(CapabilityChanges.ALL);
+
cap1.setCapabilityContentStreamUpdates(randomEnum(CapabilityContentStreamUpdates.class));
+ cap1.setCapabilityJoin(randomEnum(CapabilityJoin.class));
+ cap1.setCapabilityQuery(randomEnum(CapabilityQuery.class));
+
cap1.setCapabilityRendition(randomEnum(CapabilityRenditions.class));
+ cap1.setIsPwcSearchable(randomBoolean());
+ cap1.setIsPwcUpdatable(randomBoolean());
+ cap1.setSupportsGetDescendants(randomBoolean());
+ cap1.setSupportsGetFolderTree(randomBoolean());
+ cap1.setSupportsMultifiling(randomBoolean());
+ cap1.setOrderByCapability(randomEnum(CapabilityOrderBy.class));
+ cap1.setSupportsUnfiling(randomBoolean());
+ cap1.setSupportsVersionSpecificFiling(randomBoolean());
+
+ CreatablePropertyTypesImpl cpt = new CreatablePropertyTypesImpl();
+ Set<PropertyType> pt = new HashSet<PropertyType>();
+ pt.add(PropertyType.BOOLEAN);
+ pt.add(PropertyType.ID);
+ pt.add(PropertyType.INTEGER);
+ pt.add(PropertyType.DATETIME);
+ pt.add(PropertyType.DECIMAL);
+ pt.add(PropertyType.HTML);
+ pt.add(PropertyType.STRING);
+ pt.add(PropertyType.URI);
+ cpt.setCanCreate(pt);
+ cap1.setCreatablePropertyTypes(cpt);
+
+ NewTypeSettableAttributesImpl newTypeSettableAttributes = new
NewTypeSettableAttributesImpl();
+ newTypeSettableAttributes.setCanSetId(randomBoolean());
+ newTypeSettableAttributes.setCanSetLocalName(randomBoolean());
+ newTypeSettableAttributes.setCanSetLocalNamespace(randomBoolean());
+ newTypeSettableAttributes.setCanSetDisplayName(randomBoolean());
+ newTypeSettableAttributes.setCanSetQueryName(randomBoolean());
+ newTypeSettableAttributes.setCanSetDescription(randomBoolean());
+ newTypeSettableAttributes.setCanSetCreatable(randomBoolean());
+ newTypeSettableAttributes.setCanSetFileable(randomBoolean());
+ newTypeSettableAttributes.setCanSetQueryable(randomBoolean());
+
newTypeSettableAttributes.setCanSetFulltextIndexed(randomBoolean());
+
newTypeSettableAttributes.setCanSetIncludedInSupertypeQuery(randomBoolean());
+
newTypeSettableAttributes.setCanSetControllablePolicy(randomBoolean());
+
newTypeSettableAttributes.setCanSetControllableAcl(randomBoolean());
+ cap1.setNewTypeSettableAttributes(newTypeSettableAttributes);
+
+ repInfo.setCapabilities(cap1);
+
+ AclCapabilitiesDataImpl acl1 = new AclCapabilitiesDataImpl();
+
acl1.setSupportedPermissions(randomEnum(SupportedPermissions.class));
+ acl1.setAclPropagation(randomEnum(AclPropagation.class));
+ List<PermissionDefinition> pddList = new
ArrayList<PermissionDefinition>();
+ PermissionDefinitionDataImpl pdd1 = new
PermissionDefinitionDataImpl();
+ pdd1.setPermission(randomString());
+ pdd1.setDescription(randomString());
+ pddList.add(pdd1);
+ PermissionDefinitionDataImpl pdd2 = new
PermissionDefinitionDataImpl();
+ pdd2.setPermission(randomString());
+ pdd2.setDescription(randomString());
+ pddList.add(pdd2);
+ acl1.setPermissionDefinitionData(pddList);
+ Map<String, PermissionMapping> pmd = new LinkedHashMap<String,
PermissionMapping>();
+ PermissionMappingDataImpl pmd1 = new PermissionMappingDataImpl();
+ pmd1.setKey(PermissionMapping.CAN_CREATE_DOCUMENT_FOLDER);
+ pmd1.setPermissions(Arrays.asList(new String[] { randomString(),
randomString() }));
+ pmd.put(pmd1.getKey(), pmd1);
+ PermissionMappingDataImpl pmd2 = new PermissionMappingDataImpl();
+ pmd2.setKey(PermissionMapping.CAN_DELETE_OBJECT);
+ pmd2.setPermissions(Arrays.asList(new String[] { randomString(),
randomString() }));
+ pmd.put(pmd2.getKey(), pmd2);
+ acl1.setPermissionMappingData(pmd);
+ repInfo.setAclCapabilities(acl1);
+
+ List<ExtensionFeature> extensionFeatures = new
ArrayList<ExtensionFeature>();
+
+ ExtensionFeatureImpl ef1 = new ExtensionFeatureImpl();
+ ef1.setId(randomUri());
+ ef1.setCommonName(randomString());
+ ef1.setDescription(randomString());
+ ef1.setUrl(randomUri());
+ ef1.setVersionLabel(randomString());
+ Map<String, String> efd1 = new HashMap<String, String>();
+ efd1.put(randomString(), randomString());
+ efd1.put(randomString(), randomString());
+ ef1.setFeatureData(efd1);
+ extensionFeatures.add(ef1);
+
+ ExtensionFeatureImpl ef2 = new ExtensionFeatureImpl();
+ ef2.setId(randomUri());
+ ef2.setCommonName(randomString());
+ ef2.setDescription(randomString());
+ ef2.setUrl(randomUri());
+ ef2.setVersionLabel(randomString());
+ Map<String, String> efd2 = new HashMap<String, String>();
+ efd2.put(randomString(), randomString());
+ efd2.put(randomString(), randomString());
+ ef2.setFeatureData(efd2);
+ extensionFeatures.add(ef2);
- // values
- obj1 = new RepositoryInfoImpl();
- obj1.setChangesIncomplete(Boolean.TRUE);
-
obj1.setChangesOnType(Collections.singletonList(BaseTypeId.CMIS_DOCUMENT));
- obj1.setCmisVersionSupported("1.0");
- obj1.setLatestChangeLogToken("changeLogToken");
- obj1.setPrincipalAnonymous("principalAnonymous");
- obj1.setPrincipalAnyone("principalAnyone");
- obj1.setProductName("productName");
- obj1.setProductVersion("productVersion");
- obj1.setDescription("description");
- obj1.setId("id");
- obj1.setName("name");
- obj1.setRootFolder("rootFolderId");
- obj1.setThinClientUri("thinClientUri");
- obj1.setVendorName("vendorName");
-
- RepositoryCapabilitiesImpl cap1 = new RepositoryCapabilitiesImpl();
- cap1.setAllVersionsSearchable(Boolean.TRUE);
- cap1.setCapabilityAcl(CapabilityAcl.DISCOVER);
- cap1.setCapabilityChanges(CapabilityChanges.ALL);
-
cap1.setCapabilityContentStreamUpdates(CapabilityContentStreamUpdates.ANYTIME);
- cap1.setCapabilityJoin(CapabilityJoin.INNERANDOUTER);
- cap1.setCapabilityQuery(CapabilityQuery.BOTHCOMBINED);
- cap1.setCapabilityRendition(CapabilityRenditions.READ);
- cap1.setIsPwcSearchable(Boolean.TRUE);
- cap1.setIsPwcUpdatable(Boolean.TRUE);
- cap1.setSupportsGetDescendants(Boolean.TRUE);
- cap1.setSupportsGetFolderTree(Boolean.TRUE);
- cap1.setSupportsMultifiling(Boolean.TRUE);
- cap1.setSupportsUnfiling(Boolean.TRUE);
- cap1.setSupportsVersionSpecificFiling(Boolean.TRUE);
- obj1.setCapabilities(cap1);
-
- AclCapabilitiesDataImpl acl1 = new AclCapabilitiesDataImpl();
- acl1.setSupportedPermissions(SupportedPermissions.BASIC);
- acl1.setAclPropagation(AclPropagation.PROPAGATE);
- List<PermissionDefinition> pddList = new
ArrayList<PermissionDefinition>();
- PermissionDefinitionDataImpl pdd1 = new PermissionDefinitionDataImpl();
- pdd1.setPermission("test:perm1");
- pdd1.setDescription("Permission1");
- pddList.add(pdd1);
- PermissionDefinitionDataImpl pdd2 = new PermissionDefinitionDataImpl();
- pdd2.setPermission("test:perm2");
- pdd2.setDescription("Permission2");
- pddList.add(pdd2);
- acl1.setPermissionDefinitionData(pddList);
- Map<String, PermissionMapping> pmd = new LinkedHashMap<String,
PermissionMapping>();
- PermissionMappingDataImpl pmd1 = new PermissionMappingDataImpl();
- pmd1.setKey(PermissionMapping.CAN_CREATE_DOCUMENT_FOLDER);
- pmd1.setPermissions(Arrays.asList(new String[] { "p1", "p2" }));
- pmd.put(pmd1.getKey(), pmd1);
- PermissionMappingDataImpl pmd2 = new PermissionMappingDataImpl();
- pmd2.setKey(PermissionMapping.CAN_DELETE_OBJECT);
- pmd2.setPermissions(Arrays.asList(new String[] { "p3", "p4" }));
- pmd.put(pmd2.getKey(), pmd2);
- acl1.setPermissionMappingData(pmd);
- obj1.setAclCapabilities(acl1);
+ repInfo.setExtensionFeature(extensionFeatures);
- assertRepositoryInfo(obj1, true);
+ assertRepositoryInfo10(repInfo, true);
+ assertRepositoryInfo11(repInfo, true);
+ }
}
- protected void assertRepositoryInfo(RepositoryInfo repInfo, boolean
validate) throws Exception {
+ protected void assertRepositoryInfo10(RepositoryInfo repInfo, boolean
validate) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamWriter writer = createWriter(out);
@@ -141,7 +222,29 @@ public class RepositoryInfoConverterTest
closeParser(parser);
assertNotNull(result);
- assertDataObjectsEquals("RepositoryInfo", repInfo, result);
+ assertDataObjectsEquals("RepositoryInfo", repInfo, result,
cmis10ignoreMethods);
+ assertNull(result.getExtensions());
+ }
+
+ protected void assertRepositoryInfo11(RepositoryInfo repInfo, boolean
validate) throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ XMLStreamWriter writer = createWriter(out);
+ XMLConverter.writeRepositoryInfo(writer, CmisVersion.CMIS_1_1,
TEST_NAMESPACE, repInfo);
+ closeWriter(writer);
+
+ byte[] xml = out.toByteArray();
+
+ if (validate) {
+ validate(xml, CmisVersion.CMIS_1_1);
+ }
+
+ XMLStreamReader parser = createParser(xml);
+ RepositoryInfo result = XMLConverter.convertRepositoryInfo(parser);
+ closeParser(parser);
+
+ 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=1448311&r1=1448310&r2=1448311&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
Wed Feb 20 17:26:52 2013
@@ -22,6 +22,9 @@ import static org.junit.Assert.assertNot
import static org.junit.Assert.assertNull;
import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
@@ -31,59 +34,254 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.Cardinality;
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.Updatability;
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;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.FolderTypeDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.ItemTypeDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PolicyTypeDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyBooleanDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDateTimeDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyDecimalDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyHtmlDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIntegerDefinitionImpl;
import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
+import
org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyUriDefinitionImpl;
+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.junit.Test;
public class TypeDefinitionConverterTest extends AbstractXMLConverterTest {
+ private static Set<String> cmis10ignoreMethods = new HashSet<String>();
+ static {
+ cmis10ignoreMethods.add("getTypeMutability");
+ }
+
+ @Test
+ public void testDocumentTypeDefinition() throws Exception {
+ // run the test a few times with different values
+ for (int i = 0; i < 5; i++) {
+ DocumentTypeDefinitionImpl typeDef = new
DocumentTypeDefinitionImpl();
+ fillTypeDefintion(typeDef, BaseTypeId.CMIS_DOCUMENT);
+ typeDef.setIsVersionable(randomBoolean());
+
typeDef.setContentStreamAllowed(randomEnum(ContentStreamAllowed.class));
+
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.BOOLEAN));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DATETIME));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DECIMAL));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.HTML));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.ID));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.INTEGER));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.STRING));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.URI));
+
+ assertTypeDefinition10(typeDef, true);
+ assertTypeDefinition11(typeDef, true);
+ }
+ }
+
@Test
- public void testTypeDefinition() throws Exception {
- DocumentTypeDefinitionImpl typeDef = new DocumentTypeDefinitionImpl();
- typeDef.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT);
- typeDef.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
- typeDef.setDescription("description");
- typeDef.setDisplayName("displayName");
- typeDef.setId("id");
- typeDef.setIsControllableAcl(Boolean.TRUE);
- typeDef.setIsControllablePolicy(Boolean.FALSE);
- typeDef.setIsCreatable(Boolean.TRUE);
- typeDef.setIsFileable(Boolean.TRUE);
- typeDef.setIsIncludedInSupertypeQuery(Boolean.TRUE);
- typeDef.setIsFulltextIndexed(Boolean.FALSE);
- typeDef.setIsQueryable(Boolean.TRUE);
- typeDef.setIsVersionable(Boolean.TRUE);
- typeDef.setLocalName("localName");
- typeDef.setLocalNamespace("localNamespace");
- typeDef.setParentTypeId("parentId");
- typeDef.setQueryName("queryName");
- typeDef.setIsVersionable(Boolean.TRUE);
- typeDef.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
-
- PropertyStringDefinitionImpl propDefString = new
PropertyStringDefinitionImpl();
- propDefString.setId("stringProp");
- propDefString.setDescription("description");
- propDefString.setDisplayName("displayName");
- propDefString.setPropertyType(PropertyType.STRING);
- propDefString.setLocalName("localname");
- propDefString.setLocalNamespace("localnamespace");
- propDefString.setCardinality(Cardinality.SINGLE);
- propDefString.setUpdatability(Updatability.READWRITE);
- propDefString.setIsQueryable(Boolean.TRUE);
- propDefString.setQueryName("queryname");
- propDefString.setIsInherited(Boolean.FALSE);
- propDefString.setIsRequired(Boolean.FALSE);
- propDefString.setIsOrderable(Boolean.TRUE);
+ public void testFolderTypeDefinition() throws Exception {
+ // run the test a few times with different values
+ for (int i = 0; i < 5; i++) {
+ FolderTypeDefinitionImpl typeDef = new FolderTypeDefinitionImpl();
+ fillTypeDefintion(typeDef, BaseTypeId.CMIS_FOLDER);
+
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.BOOLEAN));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DATETIME));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DECIMAL));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.HTML));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.ID));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.INTEGER));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.STRING));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.URI));
- typeDef.addPropertyDefinition(propDefString);
+ assertTypeDefinition10(typeDef, true);
+ assertTypeDefinition11(typeDef, true);
+ }
+ }
+
+ @Test
+ public void testRelationshipTypeDefinition() throws Exception {
+ // run the test a few times with different values
+ for (int i = 0; i < 5; i++) {
+ RelationshipTypeDefinitionImpl typeDef = new
RelationshipTypeDefinitionImpl();
+ fillTypeDefintion(typeDef, BaseTypeId.CMIS_RELATIONSHIP);
+ typeDef.setAllowedSourceTypes(Arrays.asList(randomString(),
randomString(), randomString()));
+ typeDef.setAllowedTargetTypes(Arrays.asList(randomString(),
randomString(), randomString(), randomString()));
+
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.BOOLEAN));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DATETIME));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DECIMAL));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.HTML));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.ID));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.INTEGER));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.STRING));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.URI));
+
+ assertTypeDefinition10(typeDef, true);
+ assertTypeDefinition11(typeDef, true);
+ }
+ }
- assertTypeDefinition(typeDef, true);
+ @Test
+ public void testPolicyTypeDefinition() throws Exception {
+ // run the test a few times with different values
+ for (int i = 0; i < 5; i++) {
+ PolicyTypeDefinitionImpl typeDef = new PolicyTypeDefinitionImpl();
+ fillTypeDefintion(typeDef, BaseTypeId.CMIS_POLICY);
+
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.BOOLEAN));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DATETIME));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DECIMAL));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.HTML));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.ID));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.INTEGER));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.STRING));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.URI));
+
+ assertTypeDefinition10(typeDef, true);
+ assertTypeDefinition11(typeDef, true);
+ }
+ }
+
+ @Test
+ public void testItemTypeDefinition() throws Exception {
+ // run the test a few times with different values
+ for (int i = 0; i < 5; i++) {
+ ItemTypeDefinitionImpl typeDef = new ItemTypeDefinitionImpl();
+ fillTypeDefintion(typeDef, BaseTypeId.CMIS_ITEM);
+
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.BOOLEAN));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DATETIME));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DECIMAL));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.HTML));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.ID));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.INTEGER));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.STRING));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.URI));
+
+ assertTypeDefinition11(typeDef, true);
+ }
+ }
+
+ @Test
+ public void testSecondaryTypeDefinition() throws Exception {
+ // run the test a few times with different values
+ for (int i = 0; i < 5; i++) {
+ SecondaryTypeDefinitionImpl typeDef = new
SecondaryTypeDefinitionImpl();
+ fillTypeDefintion(typeDef, BaseTypeId.CMIS_SECONDARY);
+
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.BOOLEAN));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DATETIME));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.DECIMAL));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.HTML));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.ID));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.INTEGER));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.STRING));
+
typeDef.addPropertyDefinition(createPropertyDefintion(PropertyType.URI));
+
+ assertTypeDefinition11(typeDef, true);
+ }
}
- protected void assertTypeDefinition(TypeDefinition typeDef, boolean
validate) throws Exception {
+ protected void fillTypeDefintion(AbstractTypeDefinition typeDef,
BaseTypeId baseTypeId) {
+ typeDef.setBaseTypeId(baseTypeId);
+ typeDef.setDescription(randomString());
+ typeDef.setDisplayName(randomString());
+ typeDef.setId(randomString());
+ typeDef.setIsControllableAcl(randomBoolean());
+ typeDef.setIsControllablePolicy(randomBoolean());
+ typeDef.setIsCreatable(randomBoolean());
+ typeDef.setIsFileable(randomBoolean());
+ typeDef.setIsIncludedInSupertypeQuery(randomBoolean());
+ typeDef.setIsFulltextIndexed(randomBoolean());
+ typeDef.setIsQueryable(randomBoolean());
+ typeDef.setLocalName(randomString());
+ typeDef.setLocalNamespace(randomUri());
+ typeDef.setParentTypeId(randomString());
+ typeDef.setQueryName(randomString());
+
+ TypeMutabilityImpl tm = new TypeMutabilityImpl();
+ tm.setCanCreate(randomBoolean());
+ tm.setCanDelete(randomBoolean());
+ tm.setCanUpdate(randomBoolean());
+ typeDef.setTypeMutability(tm);
+ }
+
+ protected AbstractPropertyDefinition<?>
createPropertyDefintion(PropertyType propertyType) {
+ AbstractPropertyDefinition<?> result = null;
+
+ switch (propertyType) {
+ case BOOLEAN:
+ result = new PropertyBooleanDefinitionImpl();
+ ((PropertyBooleanDefinitionImpl)
result).setDefaultValue(Arrays.asList(randomBoolean()));
+ break;
+ case DATETIME:
+ result = new PropertyDateTimeDefinitionImpl();
+ ((PropertyDateTimeDefinitionImpl)
result).setDefaultValue(Arrays.asList(randomDateTime()));
+ ((PropertyDateTimeDefinitionImpl)
result).setDateTimeResolution(randomEnum(DateTimeResolution.class));
+ break;
+ case DECIMAL:
+ result = new PropertyDecimalDefinitionImpl();
+ ((PropertyDecimalDefinitionImpl)
result).setDefaultValue(Arrays.asList(randomDecimal()));
+ ((PropertyDecimalDefinitionImpl)
result).setMaxValue(randomDecimal());
+ ((PropertyDecimalDefinitionImpl)
result).setMinValue(randomDecimal());
+ ((PropertyDecimalDefinitionImpl)
result).setPrecision(randomEnum(DecimalPrecision.class));
+ break;
+ case HTML:
+ result = new PropertyHtmlDefinitionImpl();
+ ((PropertyHtmlDefinitionImpl)
result).setDefaultValue(Arrays.asList(randomString()));
+ break;
+ case ID:
+ result = new PropertyIdDefinitionImpl();
+ ((PropertyIdDefinitionImpl)
result).setDefaultValue(Arrays.asList(randomString()));
+ break;
+ case INTEGER:
+ result = new PropertyIntegerDefinitionImpl();
+ ((PropertyIntegerDefinitionImpl)
result).setDefaultValue(Arrays.asList(randomInteger()));
+ ((PropertyIntegerDefinitionImpl)
result).setMaxValue(randomInteger());
+ ((PropertyIntegerDefinitionImpl)
result).setMinValue(randomInteger());
+ break;
+ case STRING:
+ result = new PropertyStringDefinitionImpl();
+ ((PropertyStringDefinitionImpl)
result).setDefaultValue(Arrays.asList(randomString()));
+ ((PropertyStringDefinitionImpl)
result).setMaxLength(randomInteger());
+ break;
+ case URI:
+ result = new PropertyUriDefinitionImpl();
+ ((PropertyUriDefinitionImpl)
result).setDefaultValue(Arrays.asList(randomUri()));
+ break;
+ default:
+ return null;
+ }
+
+ result.setId(randomString());
+ result.setDescription(randomString());
+ result.setDisplayName(randomString());
+ result.setPropertyType(propertyType);
+ result.setLocalName(randomString());
+ result.setLocalNamespace(randomUri());
+ result.setCardinality(randomEnum(Cardinality.class));
+ result.setUpdatability(randomEnum(Updatability.class));
+ result.setIsQueryable(randomBoolean());
+ result.setQueryName(randomString());
+ result.setIsInherited(randomBoolean());
+ result.setIsRequired(randomBoolean());
+ result.setIsOrderable(randomBoolean());
+
+ return result;
+ }
+
+ protected void assertTypeDefinition10(TypeDefinition typeDef, boolean
validate) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamWriter writer = createWriter(out);
@@ -101,7 +299,29 @@ public class TypeDefinitionConverterTest
closeParser(parser);
assertNotNull(result);
- assertDataObjectsEquals("TypeDefinition", typeDef, result);
+ assertDataObjectsEquals("TypeDefinition", typeDef, result,
cmis10ignoreMethods);
+ assertNull(result.getExtensions());
+ }
+
+ protected void assertTypeDefinition11(TypeDefinition typeDef, boolean
validate) throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ XMLStreamWriter writer = createWriter(out);
+ XMLConverter.writeTypeDefinition(writer, CmisVersion.CMIS_1_1,
TEST_NAMESPACE, typeDef);
+ closeWriter(writer);
+
+ byte[] xml = out.toByteArray();
+
+ if (validate) {
+ validate(xml, CmisVersion.CMIS_1_1);
+ }
+
+ XMLStreamReader parser = createParser(xml);
+ TypeDefinition result = XMLConverter.convertTypeDefinition(parser);
+ closeParser(parser);
+
+ assertNotNull(result);
+ assertDataObjectsEquals("TypeDefinition", typeDef, result, null);
assertNull(result.getExtensions());
}
}