chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1447804 - in /chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src: main/java/org/apache/chemistry/opencmis/commons/impl/ test/java/org/apache/chemistry/opencmis/commons/impl/xml/
Date Tue, 19 Feb 2013 16:41:35 GMT
Author: fmui
Date: Tue Feb 19 16:41:34 2013
New Revision: 1447804

URL: http://svn.apache.org/r1447804
Log:
CMIS 1.1: new XML code, first set of unit tests

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java
  (with props)
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java
  (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConstants.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConverter.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConstants.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/XMLConstants.java?rev=1447804&r1=1447803&r2=1447804&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConstants.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/XMLConstants.java
Tue Feb 19 16:41:34 2013
@@ -42,7 +42,7 @@ public class XMLConstants {
     public static final String TAG_REPINFO_PRODUCT_VERSION = "productVersion";
     public static final String TAG_REPINFO_ROOT_FOLDER_ID = "rootFolderId";
     public static final String TAG_REPINFO_CAPABILITIES = "capabilities";
-    public static final String TAG_REPINFO_ACL_CAPABILITIES = "aclCapabilities";
+    public static final String TAG_REPINFO_ACL_CAPABILITIES = "aclCapability";
     public static final String TAG_REPINFO_CHANGE_LOG_TOKEN = "latestChangeLogToken";
     public static final String TAG_REPINFO_CMIS_VERSION_SUPPORTED = "cmisVersionSupported";
     public static final String TAG_REPINFO_THIN_CLIENT_URI = "thinClientURI";

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=1447804&r1=1447803&r2=1447804&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
Tue Feb 19 16:41:34 2013
@@ -62,6 +62,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities;
 import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
 import org.apache.chemistry.opencmis.commons.definitions.Choice;
+import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyBooleanDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyDateTimeDefinition;
@@ -72,6 +73,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.definitions.PropertyIntegerDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyStringDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.PropertyUriDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.TypeMutability;
 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
@@ -363,17 +365,18 @@ public class XMLConverter {
         writer.writeStartElement(namespace, TAG_TYPE);
 
         if (source.getBaseTypeId() == BaseTypeId.CMIS_DOCUMENT) {
-            writer.writeAttribute(NAMESPACE_XSI, "type", ATTR_DOCUMENT_TYPE);
+            writer.writeAttribute(NAMESPACE_XSI, "type", writer.getPrefix(NAMESPACE_CMIS)
+ ":" + ATTR_DOCUMENT_TYPE);
         } else if (source.getBaseTypeId() == BaseTypeId.CMIS_FOLDER) {
-            writer.writeAttribute(NAMESPACE_XSI, "type", ATTR_FOLDER_TYPE);
+            writer.writeAttribute(NAMESPACE_XSI, "type", writer.getPrefix(NAMESPACE_CMIS)
+ ":" + ATTR_FOLDER_TYPE);
         } else if (source.getBaseTypeId() == BaseTypeId.CMIS_RELATIONSHIP) {
-            writer.writeAttribute(NAMESPACE_XSI, "type", ATTR_RELATIONSHIP_TYPE);
+            writer.writeAttribute(NAMESPACE_XSI, "type", writer.getPrefix(NAMESPACE_CMIS)
+ ":"
+                    + ATTR_RELATIONSHIP_TYPE);
         } else if (source.getBaseTypeId() == BaseTypeId.CMIS_POLICY) {
-            writer.writeAttribute(NAMESPACE_XSI, "type", ATTR_POLICY_TYPE);
+            writer.writeAttribute(NAMESPACE_XSI, "type", writer.getPrefix(NAMESPACE_CMIS)
+ ":" + ATTR_POLICY_TYPE);
         } else if (source.getBaseTypeId() == BaseTypeId.CMIS_ITEM) {
-            writer.writeAttribute(NAMESPACE_XSI, "type", ATTR_ITEM_TYPE);
+            writer.writeAttribute(NAMESPACE_XSI, "type", writer.getPrefix(NAMESPACE_CMIS)
+ ":" + ATTR_ITEM_TYPE);
         } else if (source.getBaseTypeId() == BaseTypeId.CMIS_SECONDARY) {
-            writer.writeAttribute(NAMESPACE_XSI, "type", ATTR_SECONDARY_TYPE);
+            writer.writeAttribute(NAMESPACE_XSI, "type", writer.getPrefix(NAMESPACE_CMIS)
+ ":" + ATTR_SECONDARY_TYPE);
         } else {
             throw new CmisRuntimeException("Type definition has no base type id!");
         }
@@ -411,6 +414,30 @@ public class XMLConverter {
             }
         }
 
+        if (source instanceof DocumentTypeDefinition) {
+            DocumentTypeDefinition docDef = (DocumentTypeDefinition) source;
+            XMLUtils.write(writer, NAMESPACE_CMIS, TAG_TYPE_VERSIONABLE, docDef.isVersionable());
+            XMLUtils.write(writer, NAMESPACE_CMIS, TAG_TYPE_CONTENTSTREAM_ALLOWED, docDef.getContentStreamAllowed());
+        }
+
+        if (source instanceof RelationshipTypeDefinition) {
+            RelationshipTypeDefinition relDef = (RelationshipTypeDefinition) source;
+            if (relDef.getAllowedSourceTypeIds() != null) {
+                for (String id : relDef.getAllowedSourceTypeIds()) {
+                    if (id != null) {
+                        XMLUtils.write(writer, NAMESPACE_CMIS, TAG_TYPE_ALLOWED_SOURCE_TYPES,
id);
+                    }
+                }
+            }
+            if (relDef.getAllowedTargetTypeIds() != null) {
+                for (String id : relDef.getAllowedTargetTypeIds()) {
+                    if (id != null) {
+                        XMLUtils.write(writer, NAMESPACE_CMIS, TAG_TYPE_ALLOWED_TARGET_TYPES,
id);
+                    }
+                }
+            }
+        }
+
         writeExtensions(writer, source);
         writer.writeEndElement();
     }
@@ -923,7 +950,7 @@ public class XMLConverter {
                 }
 
                 if (isTag(name, TAG_REPINFO_CHANGE_LOG_TOKEN)) {
-                    target.setRootFolder(readText(parser));
+                    target.setLatestChangeLogToken(readText(parser));
                     return true;
                 }
 

Added: 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=1447804&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/AbstractXMLConverterTest.java
Tue Feb 19 16:41:34 2013
@@ -0,0 +1,265 @@
+/*
+ * 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.io.ByteArrayInputStream;
+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.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.apache.chemistry.opencmis.commons.impl.XMLConstants;
+import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
+import org.junit.BeforeClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
+
+public abstract class AbstractXMLConverterTest {
+
+    protected final static String TEST_NAMESPACE = "http://chemistry.apache.org/test/schema";
+    protected final static String TEST_PREFIX = "test";
+
+    private Logger LOG = LoggerFactory.getLogger(AbstractXMLConverterTest.class);
+
+    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
+            + "\" xmlns:test=\""
+            + TEST_NAMESPACE
+            + "\" xmlns:cmis=\""
+            + XMLConstants.NAMESPACE_CMIS
+            + "\" version=\"1.0\">"
+            + "<xs:import namespace=\""
+            + XMLConstants.NAMESPACE_CMIS
+            + "\"/>"
+            + "<xs:complexType name=\"testType\">"
+            + "<xs:sequence>"
+            + "<xs:element name=\"repositoryInfo\" type=\"cmis:cmisRepositoryInfoType\"
minOccurs=\"0\" maxOccurs=\"1\" />"
+            + "<xs:element name=\"type\" type=\"cmis:cmisTypeDefinitionType\" minOccurs=\"0\"
maxOccurs=\"1\" />"
+            + "<xs:element name=\"object\" type=\"cmis:cmisObjectType\" minOccurs=\"0\"
maxOccurs=\"1\" />"
+            + "</xs:sequence>" //
+            + "</xs:complexType>" //
+            + "<xs:element name=\"test\" type=\"test:testType\"/>" //
+            + "</xs:schema>";
+
+    protected static Schema schema;
+
+    /**
+     * Sets up the schema.
+     */
+    @BeforeClass
+    public static void init() throws SAXException, UnsupportedEncodingException {
+        SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
+        StreamSource core = new StreamSource(AbstractXMLConverterTest.class.getResourceAsStream("/wsdl/CMIS-core.xsd"));
+        StreamSource test = new StreamSource(new ByteArrayInputStream(TEST_SCHEMA.getBytes("UTF-8")));
+
+        schema = sf.newSchema(new Source[] { core, test });
+    }
+
+    /**
+     * Writes root tag of the test XML.
+     */
+    protected void writeRootTag(XMLStreamWriter writer) throws XMLStreamException {
+        writer.setPrefix(TEST_PREFIX, TEST_NAMESPACE);
+        writer.writeStartElement(TEST_NAMESPACE, TEST_PREFIX);
+        writer.writeNamespace(XMLUtils.PREFIX_XSI, XMLConstants.NAMESPACE_XSI);
+        writer.writeNamespace(XMLUtils.PREFIX_CMIS, XMLConstants.NAMESPACE_CMIS);
+        writer.writeNamespace(TEST_PREFIX, TEST_NAMESPACE);
+    }
+
+    /**
+     * Creates a test XML writer.
+     */
+    protected XMLStreamWriter createWriter(OutputStream out) throws XMLStreamException {
+        XMLStreamWriter writer = XMLUtils.createWriter(out);
+
+        XMLUtils.startXmlDocument(writer);
+        writeRootTag(writer);
+
+        return writer;
+    }
+
+    /**
+     * Closes the test XML writer.
+     */
+    protected void closeWriter(XMLStreamWriter writer) throws XMLStreamException {
+        XMLUtils.endXmlDocument(writer);
+        writer.close();
+    }
+
+    /**
+     * Creates a parser and moves it to the tag that should be tested.
+     */
+    protected XMLStreamReader createParser(byte[] xmlDocument) throws XMLStreamException
{
+        XMLStreamReader parser = XMLUtils.createParser(new ByteArrayInputStream(xmlDocument));
+        moveToTestTag(parser);
+
+        return parser;
+    }
+
+    /**
+     * Closes the parser.
+     */
+    protected void closeParser(XMLStreamReader parser) throws XMLStreamException {
+        parser.close();
+    }
+
+    /**
+     * Moves the parser to tag that should be tested.
+     */
+    protected void moveToTestTag(XMLStreamReader parser) throws XMLStreamException {
+        while (XMLUtils.findNextStartElemenet(parser)) {
+            if (parser.getName().getLocalPart().equals("test")) {
+                XMLUtils.next(parser);
+                XMLUtils.findNextStartElemenet(parser);
+                break;
+            }
+        }
+    }
+
+    /**
+     * Validates the given XML.
+     */
+    protected void validate(byte[] xmlDocument) {
+        Validator validator = schema.newValidator();
+        Source source = new StreamSource(new ByteArrayInputStream(xmlDocument));
+
+        try {
+            validator.validate(source);
+        } catch (Exception e) {
+            try {
+                LOG.error("Schema validation failed:\n" + format(xmlDocument));
+                System.out.println(format(xmlDocument));
+            } catch (TransformerException e1) {
+            }
+            fail("Schema validation failed: " + e);
+        }
+    }
+
+    /**
+     * Formats an XML document.
+     */
+    protected String format(byte[] xmlDocument) throws TransformerException {
+        TransformerFactory tf = TransformerFactory.newInstance();
+        tf.setAttribute("indent-number", new Integer(2));
+
+        Transformer transformer = tf.newTransformer();
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+        StreamResult result = new StreamResult(new StringWriter());
+        Source source = new StreamSource(new ByteArrayInputStream(xmlDocument));
+        transformer.transform(source, result);
+
+        return result.getWriter().toString();
+    }
+
+    /**
+     * Compares two data objects.
+     */
+    protected void assertDataObjectsEquals(String name, Object expected, Object actual) {
+
+        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(expected, actual);
+
+            return;
+        } else if (expected instanceof List<?>) {
+            List<?> expectedList = (List<?>) expected;
+            List<?> actualList = (List<?>) actual;
+
+            assertEquals(expectedList.size(), actualList.size());
+
+            for (int i = 0; i < expectedList.size(); i++) {
+                assertDataObjectsEquals(name + "[" + i + "]", expectedList.get(i), actualList.get(i));
+            }
+
+            return;
+        } else if (expected instanceof Map<?, ?>) {
+            Map<?, ?> expectedMap = (Map<?, ?>) expected;
+            Map<?, ?> actualMap = (Map<?, ?>) actual;
+
+            assertEquals(expectedMap.size(), actualMap.size());
+
+            for (Map.Entry<?, ?> entry : expectedMap.entrySet()) {
+                assertTrue(actualMap.containsKey(entry.getKey()));
+                assertDataObjectsEquals(name + "[" + entry.getKey() + "]", entry.getValue(),
+                        actualMap.get(entry.getKey()));
+            }
+
+            return;
+        }
+
+        for (Method m : expected.getClass().getMethods()) {
+            if (!m.getName().startsWith("get") && !m.getName().startsWith("is") &&
!m.getName().startsWith("supports")) {
+                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);
+            } 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/AbstractXMLConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=1447804&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java
Tue Feb 19 16:41:34 2013
@@ -0,0 +1,147 @@
+/*
+ * 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.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.chemistry.opencmis.commons.data.PermissionMapping;
+import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.definitions.PermissionDefinition;
+import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityAcl;
+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.CapabilityQuery;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityRenditions;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
+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.PermissionDefinitionDataImpl;
+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.junit.Test;
+
+public class RepositoryInfoConverterTest extends AbstractXMLConverterTest {
+
+    @Test
+    public void testRepositoryInfo() throws Exception {
+        RepositoryInfoImpl obj1 = new RepositoryInfoImpl();
+
+        assertRepositoryInfo(obj1, false);
+
+        // 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);
+
+        assertRepositoryInfo(obj1, true);
+    }
+
+    protected void assertRepositoryInfo(RepositoryInfo repInfo, boolean validate) throws
Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        XMLStreamWriter writer = createWriter(out);
+        XMLConverter.writeRepositoryInfo(writer, CmisVersion.CMIS_1_0, TEST_NAMESPACE, repInfo);
+        closeWriter(writer);
+
+        byte[] xml = out.toByteArray();
+
+        if (validate) {
+            validate(xml);
+        }
+
+        XMLStreamReader parser = createParser(xml);
+        RepositoryInfo result = XMLConverter.convertRepositoryInfo(parser);
+        closeParser(parser);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("RepositoryInfo", repInfo, result);
+        assertNull(result.getExtensions());
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/RepositoryInfoConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=1447804&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java
Tue Feb 19 16:41:34 2013
@@ -0,0 +1,107 @@
+/*
+ * 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.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+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.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.DocumentTypeDefinitionImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
+import org.junit.Test;
+
+public class TypeDefinitionConverterTest extends AbstractXMLConverterTest {
+
+    @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);
+
+        typeDef.addPropertyDefinition(propDefString);
+
+        assertTypeDefinition(typeDef, true);
+    }
+
+    protected void assertTypeDefinition(TypeDefinition typeDef, boolean validate) throws
Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+        XMLStreamWriter writer = createWriter(out);
+        XMLConverter.writeTypeDefinition(writer, CmisVersion.CMIS_1_0, TEST_NAMESPACE, typeDef);
+        closeWriter(writer);
+
+        byte[] xml = out.toByteArray();
+
+        if (validate) {
+            validate(xml);
+        }
+
+        XMLStreamReader parser = createParser(xml);
+        TypeDefinition result = XMLConverter.convertTypeDefinition(parser);
+        closeParser(parser);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("TypeDefinition", typeDef, result);
+        assertNull(result.getExtensions());
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/TypeDefinitionConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message