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/28 14:11:33 UTC

svn commit: r1518174 - 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: Wed Aug 28 12:11:33 2013
New Revision: 1518174

URL: http://svn.apache.org/r1518174
Log:
more unit test + fixes

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.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/ChoiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ObjectDataImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.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/test/java/org/apache/chemistry/opencmis/inmemory/RelationshipServiceTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.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/JSONConverter.java?rev=1518174&r1=1518173&r2=1518174&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/JSONConverter.java Wed Aug 28 12:11:33 2013
@@ -1110,8 +1110,8 @@ public final class JSONConverter {
         // ACL
         if ((object.getAcl() != null) && (object.getAcl().getAces() != null) && propertyMode != PropertyMode.QUERY) {
             result.put(JSON_OBJECT_ACL, convert(object.getAcl()));
-            result.put(JSON_OBJECT_EXACT_ACL, object.isExactAcl());
         }
+        setIfNotNull(JSON_OBJECT_EXACT_ACL, object.isExactAcl(), result);
 
         // policy ids
         if ((object.getPolicyIds() != null) && (object.getPolicyIds().getPolicyIds() != null)
@@ -1819,7 +1819,7 @@ public final class JSONConverter {
 
         ObjectDataImpl result = new ObjectDataImpl();
 
-        result.setAcl(convertAcl(getMap(json.get(JSON_OBJECT_ACL)), getBoolean(json, JSON_OBJECT_EXACT_ACL)));
+        result.setAcl(convertAcl(getMap(json.get(JSON_OBJECT_ACL)), null));
         result.setAllowableActions(convertAllowableActions(getMap(json.get(JSON_OBJECT_ALLOWABLE_ACTIONS))));
         Map<String, Object> jsonChangeEventInfo = getMap(json.get(JSON_OBJECT_CHANGE_EVENT_INFO));
         if (jsonChangeEventInfo != null) {

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=1518174&r1=1518173&r2=1518174&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 Wed Aug 28 12:11:33 2013
@@ -1599,7 +1599,7 @@ public final class WSConverter {
 
         ObjectDataImpl result = new ObjectDataImpl();
 
-        result.setAcl(convert(object.getAcl(), object.isExactACL()));
+        result.setAcl(convert(object.getAcl(), null));
         result.setAllowableActions(convert(object.getAllowableActions()));
         if (object.getChangeEventInfo() != null) {
             ChangeEventInfoDataImpl changeEventInfo = new ChangeEventInfoDataImpl();
@@ -1838,7 +1838,7 @@ public final class WSConverter {
 
             result.setChangeEventInfo(changeEventInfo);
         }
-        result.setExactACL(object.getAcl() == null ? null : object.getAcl().isExact());
+        result.setExactACL(object.isExactAcl());
         result.setPolicyIds(convert(object.getPolicyIds()));
         result.setProperties(convert(object.getProperties()));
         if (object.getRelationships() != null) {

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=1518174&r1=1518173&r2=1518174&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 Wed Aug 28 12:11:33 2013
@@ -58,11 +58,16 @@ public class ChoiceImpl<T> implements Ch
         if (choice == null) {
             choice = new ArrayList<Choice<T>>();
         }
-        
+
         return choice;
     }
 
     public void setChoice(List<Choice<T>> choice) {
         this.choice = choice;
     }
+
+    @Override
+    public String toString() {
+        return "Choice [displayName=" + displayName + ", value=" + value + ", choice=" + choice + "]";
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ObjectDataImpl.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/ObjectDataImpl.java?rev=1518174&r1=1518173&r2=1518174&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ObjectDataImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/ObjectDataImpl.java Wed Aug 28 12:11:33 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.PropertyIds;
@@ -86,6 +87,10 @@ public class ObjectDataImpl extends Abst
     }
 
     public List<ObjectData> getRelationships() {
+        if (relationships == null) {
+            relationships = new ArrayList<ObjectData>();
+        }
+
         return relationships;
     }
 
@@ -94,6 +99,10 @@ public class ObjectDataImpl extends Abst
     }
 
     public List<RenditionData> getRenditions() {
+        if (renditions == null) {
+            renditions = new ArrayList<RenditionData>();
+        }
+
         return renditions;
     }
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.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/ObjectConvertTest.java?rev=1518174&r1=1518173&r2=1518174&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/test/java/org/apache/chemistry/opencmis/commons/impl/xml/ObjectConvertTest.java Wed Aug 28 12:11:33 2013
@@ -18,12 +18,17 @@
  */
 package org.apache.chemistry.opencmis.commons.impl.xml;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
+import java.io.StringWriter;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.xml.stream.XMLStreamReader;
@@ -32,12 +37,18 @@ import javax.xml.stream.XMLStreamWriter;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.Ace;
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.data.ObjectInFolderData;
+import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
+import org.apache.chemistry.opencmis.commons.data.ObjectList;
 import org.apache.chemistry.opencmis.commons.data.RenditionData;
 import org.apache.chemistry.opencmis.commons.enums.Action;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.ChangeType;
 import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
 import org.apache.chemistry.opencmis.commons.enums.PropertyType;
+import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
+import org.apache.chemistry.opencmis.commons.impl.TypeCache;
+import org.apache.chemistry.opencmis.commons.impl.WSConverter;
 import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
@@ -45,9 +56,17 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.AllowableActionsImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ChangeEventInfoDataImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderDataImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderListImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PolicyIdListImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RenditionDataImpl;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectInFolderListType;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectListType;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
+import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
+import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser;
 import org.junit.Test;
 
 public class ObjectConvertTest extends AbstractXMLConverterTest {
@@ -56,15 +75,58 @@ public class ObjectConvertTest extends A
     public void testObjectData() throws Exception {
         // run the test a few times with different values
         for (int i = 0; i < 10; i++) {
-            ObjectDataImpl data10 = createObjectData(true, CmisVersion.CMIS_1_0);
+            ObjectDataImpl data10 = createObjectData(true, CmisVersion.CMIS_1_0, true, true);
             assertObjectData10(data10, true);
 
-            ObjectDataImpl data11 = createObjectData(true, CmisVersion.CMIS_1_1);
+            ObjectDataImpl data11 = createObjectData(true, CmisVersion.CMIS_1_1, true, true);
             assertObjectData11(data11, true);
+
+            ObjectDataImpl data11j = createObjectData(true, CmisVersion.CMIS_1_1, true, false);
+            assertJsonObjectData11(data11j);
+        }
+    }
+
+    @Test
+    public void testChildren() throws Exception {
+        // run the test a few times with different values
+        for (int i = 0; i < 5; i++) {
+            List<ObjectData> list1 = new ArrayList<ObjectData>();
+            List<ObjectInFolderData> list2 = new ArrayList<ObjectInFolderData>();
+
+            for (int j = 0; j < randomInt(10) + 10; j++) {
+                ObjectData data = createObjectData(true, CmisVersion.CMIS_1_1, false, false);
+
+                list1.add(data);
+
+                ObjectInFolderDataImpl dataInFolder = new ObjectInFolderDataImpl(data);
+                dataInFolder.setPathSegment(randomString());
+                list2.add(dataInFolder);
+            }
+
+            ObjectListImpl children1 = new ObjectListImpl();
+            children1.setObjects(list1);
+
+            ObjectInFolderListImpl children2 = new ObjectInFolderListImpl();
+            children2.setObjects(list2);
+
+            if (randomBoolean()) {
+                children1.setNumItems(BigInteger.valueOf(list1.size()));
+                children1.setHasMoreItems(false);
+                children2.setNumItems(BigInteger.valueOf(list2.size()));
+                children2.setHasMoreItems(false);
+            } else {
+                children1.setNumItems(BigInteger.valueOf(list1.size() + 1 + randomInt(99)));
+                children1.setHasMoreItems(true);
+                children2.setNumItems(BigInteger.valueOf(list2.size() + 1 + randomInt(99)));
+                children2.setHasMoreItems(true);
+            }
+
+            assertObjectList(children1, children2);
         }
     }
 
-    protected ObjectDataImpl createObjectData(boolean addRelationships, CmisVersion cmisVersion) {
+    protected ObjectDataImpl createObjectData(boolean addRelationships, CmisVersion cmisVersion, boolean withChanges,
+            boolean withExtensions) {
         ObjectDataImpl result = new ObjectDataImpl();
 
         // properties
@@ -96,7 +158,9 @@ public class ObjectConvertTest extends A
         properties.addProperty(createPropertyData(PropertyType.URI, 0));
         properties.addProperty(createPropertyData(PropertyType.URI, 1));
         properties.addProperty(createPropertyData(PropertyType.URI, randomInt(8) + 2));
-        properties.setExtensions(createExtensions(3));
+        if (withExtensions) {
+            properties.setExtensions(createExtensions(3));
+        }
         result.setProperties(properties);
 
         // allowable actions
@@ -115,16 +179,18 @@ public class ObjectConvertTest extends A
         if (addRelationships) {
             List<ObjectData> relationships = new ArrayList<ObjectData>();
             for (int i = 0; i < randomInt(4) + 1; i++) {
-                relationships.add(createObjectData(false, cmisVersion));
+                relationships.add(createObjectData(false, cmisVersion, withChanges, withExtensions));
             }
             result.setRelationships(relationships);
         }
 
         // change event info
-        ChangeEventInfoDataImpl changeEventInfo = new ChangeEventInfoDataImpl();
-        changeEventInfo.setChangeTime(randomDateTime());
-        changeEventInfo.setChangeType(randomEnum(ChangeType.class));
-        result.setChangeEventInfo(changeEventInfo);
+        if (withChanges) {
+            ChangeEventInfoDataImpl changeEventInfo = new ChangeEventInfoDataImpl();
+            changeEventInfo.setChangeTime(randomDateTime());
+            changeEventInfo.setChangeType(randomEnum(ChangeType.class));
+            result.setChangeEventInfo(changeEventInfo);
+        }
 
         // ACL
         AccessControlListImpl acl = new AccessControlListImpl();
@@ -172,12 +238,21 @@ public class ObjectConvertTest extends A
         result.setRenditions(renditions);
 
         // extensions
-        result.setExtensions(createExtensions(5));
+        if (withExtensions) {
+            result.setExtensions(createExtensions(5));
+        }
 
         return result;
     }
 
+    // --- asserts ---
+
     protected void assertObjectData10(ObjectData data, boolean validate) throws Exception {
+        assertXmlObjectData10(data, validate);
+        assertWsObjectData10(data);
+    }
+
+    protected void assertXmlObjectData10(ObjectData data, boolean validate) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
 
         XMLStreamWriter writer = createWriter(out);
@@ -199,7 +274,22 @@ public class ObjectConvertTest extends A
         assertNotNull(result.getExtensions());
     }
 
+    protected void assertWsObjectData10(ObjectData data) throws Exception {
+        CmisObjectType ws = WSConverter.convert(data, CmisVersion.CMIS_1_0);
+
+        ObjectData result = WSConverter.convert(ws);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("ObjectData", data, result, null);
+        assertNotNull(result.getExtensions());
+    }
+
     protected void assertObjectData11(ObjectData data, boolean validate) throws Exception {
+        assertXmlObjectData11(data, validate);
+        assertWsObjectData11(data);
+    }
+
+    protected void assertXmlObjectData11(ObjectData data, boolean validate) throws Exception {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
 
         XMLStreamWriter writer = createWriter(out);
@@ -220,4 +310,91 @@ public class ObjectConvertTest extends A
         assertDataObjectsEquals("ObjectData", data, result, null);
         assertNotNull(result.getExtensions());
     }
+
+    protected void assertWsObjectData11(ObjectData data) throws Exception {
+        CmisObjectType ws = WSConverter.convert(data, CmisVersion.CMIS_1_1);
+
+        ObjectData result = WSConverter.convert(ws);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("ObjectData", data, result, null);
+        assertNotNull(result.getExtensions());
+    }
+
+    protected void assertJsonObjectData11(ObjectData data) throws Exception {
+        TypeCache typeCache = null;
+
+        StringWriter sw = new StringWriter();
+
+        JSONObject jsonObject = JSONConverter.convert(data, typeCache, JSONConverter.PropertyMode.CHANGE, false);
+        jsonObject.writeJSONString(sw);
+
+        // test toJSONString()
+        assertEquals(sw.toString(), jsonObject.toJSONString());
+
+        Object json = (new JSONParser()).parse(sw.toString());
+        assertTrue(json instanceof Map<?, ?>);
+        @SuppressWarnings("unchecked")
+        ObjectData result = JSONConverter.convertObject((Map<String, Object>) json, typeCache);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("ObjectData", data, result, null);
+    }
+
+    protected void assertObjectList(ObjectList children1, ObjectInFolderList children2) throws Exception {
+        assertWsObjectList(children1);
+        assertJsonObjectList(children1);
+        assertWsObjectInFolderList(children2);
+        assertJsonObjectInFolderList(children2);
+    }
+
+    protected void assertWsObjectList(ObjectList children) throws Exception {
+        CmisObjectListType ws = WSConverter.convert(children, CmisVersion.CMIS_1_1);
+
+        ObjectList result = WSConverter.convert(ws);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("ObjectList", children, result, null);
+    }
+
+    protected void assertJsonObjectList(ObjectList children) throws Exception {
+        TypeCache typeCache = null;
+
+        StringWriter sw = new StringWriter();
+
+        JSONConverter.convert(children, typeCache, JSONConverter.PropertyMode.CHANGE, false).writeJSONString(sw);
+
+        Object json = (new JSONParser()).parse(sw.toString());
+        assertTrue(json instanceof Map<?, ?>);
+        @SuppressWarnings("unchecked")
+        ObjectList result = JSONConverter.convertObjectList((Map<String, Object>) json, typeCache, false);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("ObjectList", children, result, null);
+    }
+
+    protected void assertWsObjectInFolderList(ObjectInFolderList children) throws Exception {
+        CmisObjectInFolderListType ws = WSConverter.convert(children, CmisVersion.CMIS_1_1);
+
+        ObjectInFolderList result = WSConverter.convert(ws);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("ObjectInFolderList", children, result, null);
+    }
+
+    protected void assertJsonObjectInFolderList(ObjectInFolderList children) throws Exception {
+        TypeCache typeCache = null;
+
+        StringWriter sw = new StringWriter();
+
+        JSONConverter.convert(children, typeCache, false).writeJSONString(sw);
+
+        Object json = (new JSONParser()).parse(sw.toString());
+        assertTrue(json instanceof Map<?, ?>);
+        @SuppressWarnings("unchecked")
+        ObjectInFolderList result = JSONConverter.convertObjectInFolderList((Map<String, Object>) json, typeCache);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("ObjectInFolderList", children, result, null);
+    }
 }

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=1518174&r1=1518173&r2=1518174&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 Aug 28 12:11:33 2013
@@ -18,21 +18,31 @@
  */
 package org.apache.chemistry.opencmis.commons.impl.xml;
 
+import static org.junit.Assert.assertEquals;
 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.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.GregorianCalendar;
 import java.util.HashSet;
+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.definitions.Choice;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
 import org.apache.chemistry.opencmis.commons.enums.Cardinality;
 import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
@@ -46,6 +56,7 @@ import org.apache.chemistry.opencmis.com
 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.ChoiceImpl;
 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;
@@ -60,7 +71,11 @@ import org.apache.chemistry.opencmis.com
 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.TypeDefinitionContainerImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionListImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeMutabilityImpl;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeContainer;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionListType;
 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionType;
 import org.apache.chemistry.opencmis.commons.impl.json.parser.JSONParser;
 import org.junit.Test;
@@ -200,6 +215,84 @@ public class TypeDefinitionConverterTest
         }
     }
 
+    @Test
+    public void testTypeDefinitionList() throws Exception {
+        // run the test a few times with different values
+        for (int i = 0; i < 5; i++) {
+            List<TypeDefinition> list = new ArrayList<TypeDefinition>();
+
+            for (int j = 0; j < randomInt(5); j++) {
+                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));
+
+                list.add(typeDef);
+            }
+
+            // type definition list
+            TypeDefinitionListImpl typeDefList = new TypeDefinitionListImpl();
+            typeDefList.setList(list);
+            if (randomBoolean()) {
+                typeDefList.setNumItems(BigInteger.valueOf(list.size()));
+                typeDefList.setHasMoreItems(false);
+            } else {
+                typeDefList.setNumItems(BigInteger.valueOf(list.size() + 1 + randomInt(99)));
+                typeDefList.setHasMoreItems(true);
+            }
+
+            assertTypeDefinitionList(typeDefList);
+        }
+    }
+
+    @Test
+    public void testTypeDefinitionContainer() throws Exception {
+        // run the test a few times with different values
+        for (int i = 0; i < 5; i++) {
+            TypeDefinitionContainer typeDefContainter = createTypeDefinitionContainer(randomInt(7) + 2);
+            assertTypeDefinitionContainer(typeDefContainter);
+        }
+    }
+
+    private TypeDefinitionContainer createTypeDefinitionContainer(int level) {
+        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));
+
+        TypeDefinitionContainerImpl result = new TypeDefinitionContainerImpl();
+        result.setTypeDefinition(typeDef);
+
+        if (level > 0) {
+            List<TypeDefinitionContainer> children = new ArrayList<TypeDefinitionContainer>();
+            for (int i = 0; i < randomInt(3); i++) {
+                children.add(createTypeDefinitionContainer(level - 1));
+            }
+
+            result.setChildren(children);
+        }
+
+        return result;
+    }
+
     protected void fillTypeDefintion(AbstractTypeDefinition typeDef, BaseTypeId baseTypeId) {
         typeDef.setBaseTypeId(baseTypeId);
         typeDef.setDescription(randomString());
@@ -226,20 +319,25 @@ public class TypeDefinitionConverterTest
 
     protected AbstractPropertyDefinition<?> createPropertyDefintion(PropertyType propertyType) {
         AbstractPropertyDefinition<?> result = null;
+        Cardinality cardinality = randomEnum(Cardinality.class);
 
         switch (propertyType) {
         case BOOLEAN:
             result = new PropertyBooleanDefinitionImpl();
             ((PropertyBooleanDefinitionImpl) result).setDefaultValue(Arrays.asList(randomBoolean()));
+            ((PropertyBooleanDefinitionImpl) result).setChoices(createChoiceList(Boolean.class, cardinality));
             break;
         case DATETIME:
             result = new PropertyDateTimeDefinitionImpl();
             ((PropertyDateTimeDefinitionImpl) result).setDefaultValue(Arrays.asList(randomDateTime()));
+            ((PropertyDateTimeDefinitionImpl) result)
+                    .setChoices(createChoiceList(GregorianCalendar.class, cardinality));
             ((PropertyDateTimeDefinitionImpl) result).setDateTimeResolution(randomEnum(DateTimeResolution.class));
             break;
         case DECIMAL:
             result = new PropertyDecimalDefinitionImpl();
             ((PropertyDecimalDefinitionImpl) result).setDefaultValue(Arrays.asList(randomDecimal()));
+            ((PropertyDecimalDefinitionImpl) result).setChoices(createChoiceList(BigDecimal.class, cardinality));
             ((PropertyDecimalDefinitionImpl) result).setMaxValue(randomDecimal());
             ((PropertyDecimalDefinitionImpl) result).setMinValue(randomDecimal());
             ((PropertyDecimalDefinitionImpl) result).setPrecision(randomEnum(DecimalPrecision.class));
@@ -247,25 +345,30 @@ public class TypeDefinitionConverterTest
         case HTML:
             result = new PropertyHtmlDefinitionImpl();
             ((PropertyHtmlDefinitionImpl) result).setDefaultValue(Arrays.asList(randomString()));
+            ((PropertyHtmlDefinitionImpl) result).setChoices(createChoiceList(String.class, cardinality));
             break;
         case ID:
             result = new PropertyIdDefinitionImpl();
             ((PropertyIdDefinitionImpl) result).setDefaultValue(Arrays.asList(randomString()));
+            ((PropertyIdDefinitionImpl) result).setChoices(createChoiceList(String.class, cardinality));
             break;
         case INTEGER:
             result = new PropertyIntegerDefinitionImpl();
             ((PropertyIntegerDefinitionImpl) result).setDefaultValue(Arrays.asList(randomInteger()));
+            ((PropertyIntegerDefinitionImpl) result).setChoices(createChoiceList(BigInteger.class, cardinality));
             ((PropertyIntegerDefinitionImpl) result).setMaxValue(randomInteger());
             ((PropertyIntegerDefinitionImpl) result).setMinValue(randomInteger());
             break;
         case STRING:
             result = new PropertyStringDefinitionImpl();
             ((PropertyStringDefinitionImpl) result).setDefaultValue(Arrays.asList(randomString()));
+            ((PropertyStringDefinitionImpl) result).setChoices(createChoiceList(String.class, cardinality));
             ((PropertyStringDefinitionImpl) result).setMaxLength(randomInteger());
             break;
         case URI:
             result = new PropertyUriDefinitionImpl();
             ((PropertyUriDefinitionImpl) result).setDefaultValue(Arrays.asList(randomUri()));
+            ((PropertyUriDefinitionImpl) result).setChoices(createChoiceList(String.class, cardinality));
             break;
         default:
             return null;
@@ -277,7 +380,7 @@ public class TypeDefinitionConverterTest
         result.setPropertyType(propertyType);
         result.setLocalName(randomString());
         result.setLocalNamespace(randomUri());
-        result.setCardinality(randomEnum(Cardinality.class));
+        result.setCardinality(cardinality);
         result.setUpdatability(randomEnum(Updatability.class));
         result.setIsQueryable(randomBoolean());
         result.setQueryName(randomString());
@@ -288,6 +391,42 @@ public class TypeDefinitionConverterTest
         return result;
     }
 
+    @SuppressWarnings("unchecked")
+    protected <T> List<Choice<T>> createChoiceList(Class<T> clazz, Cardinality cardinality) {
+        List<Choice<T>> result = new ArrayList<Choice<T>>();
+
+        for (int i = 0; i < randomInt(10); i++) {
+            ChoiceImpl<T> choice = new ChoiceImpl<T>();
+            choice.setDisplayName(randomString());
+
+            List<T> values = new ArrayList<T>();
+            choice.setValue(values);
+
+            int valueCount = (cardinality == Cardinality.SINGLE ? 1 : randomInt(5));
+            for (int j = 0; j < valueCount; j++) {
+                if (clazz == Boolean.class) {
+                    values.add((T) randomBoolean());
+                } else if (clazz == String.class) {
+                    values.add((T) randomUri());
+                } else if (clazz == BigInteger.class) {
+                    values.add((T) randomInteger());
+                } else if (clazz == BigDecimal.class) {
+                    values.add((T) randomDecimal());
+                } else if (clazz == GregorianCalendar.class) {
+                    values.add((T) randomDateTime());
+                } else {
+                    assert false;
+                }
+            }
+
+            result.add(choice);
+        }
+
+        return result;
+    }
+
+    // --- asserts ---
+
     protected void assertTypeDefinition10(TypeDefinition typeDef, boolean validate) throws Exception {
         assertXmlTypeDefinition10(typeDef, validate);
         assertWsTypeDefinition10(typeDef);
@@ -377,4 +516,67 @@ public class TypeDefinitionConverterTest
         assertDataObjectsEquals("TypeDefinition", typeDef, result, null);
         assertNull(result.getExtensions());
     }
+
+    protected void assertTypeDefinitionList(TypeDefinitionList typeDefList) throws Exception {
+        assertWsTypeDefinitionList(typeDefList);
+        assertJsonTypeDefinitionList(typeDefList);
+    }
+
+    protected void assertWsTypeDefinitionList(TypeDefinitionList typeDefList) throws Exception {
+        CmisTypeDefinitionListType ws = WSConverter.convert(typeDefList);
+
+        TypeDefinitionList result = WSConverter.convert(ws);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("TypeDefinitionList", typeDefList, result, null);
+        assertNull(result.getExtensions());
+    }
+
+    protected void assertJsonTypeDefinitionList(TypeDefinitionList typeDefList) throws Exception {
+        StringWriter sw = new StringWriter();
+
+        JSONConverter.convert(typeDefList).writeJSONString(sw);
+
+        Object json = (new JSONParser()).parse(sw.toString());
+        assertTrue(json instanceof Map<?, ?>);
+        @SuppressWarnings("unchecked")
+        TypeDefinitionList result = JSONConverter.convertTypeChildren((Map<String, Object>) json);
+
+        assertNotNull(result);
+        assertDataObjectsEquals("TypeDefinitionList", typeDefList, result, null);
+        assertNull(result.getExtensions());
+    }
+
+    protected void assertTypeDefinitionContainer(TypeDefinitionContainer typeDefContainer) throws Exception {
+        assertWsTypeDefinitionContainer(typeDefContainer);
+        assertJsonTypeDefinitionContainer(typeDefContainer);
+    }
+
+    protected void assertWsTypeDefinitionContainer(TypeDefinitionContainer typeDefContainer) throws Exception {
+        List<CmisTypeContainer> target = new ArrayList<CmisTypeContainer>();
+        WSConverter.convertTypeContainerList(Collections.singletonList(typeDefContainer), target);
+
+        assertEquals(1, target.size());
+
+        List<TypeDefinitionContainer> result = WSConverter.convertTypeContainerList(target);
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        assertDataObjectsEquals("TypeDefinitionContainer", typeDefContainer, result.get(0), null);
+    }
+
+    protected void assertJsonTypeDefinitionContainer(TypeDefinitionContainer typeDefContainer) throws Exception {
+        StringWriter sw = new StringWriter();
+
+        JSONConverter.convert(typeDefContainer).writeJSONString(sw);
+
+        Object json = (new JSONParser()).parse(sw.toString());
+        assertTrue(json instanceof Map<?, ?>);
+
+        List<TypeDefinitionContainer> result = JSONConverter.convertTypeDescendants(Collections.singletonList(json));
+
+        assertNotNull(result);
+        assertEquals(1, result.size());
+        assertDataObjectsEquals("TypeDefinitionContainer", typeDefContainer, result.get(0), null);
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RelationshipServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RelationshipServiceTest.java?rev=1518174&r1=1518173&r2=1518174&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RelationshipServiceTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/RelationshipServiceTest.java Wed Aug 28 12:11:33 2013
@@ -337,7 +337,7 @@ public class RelationshipServiceTest ext
         // get document object, none
         objectData = fObjSvc.getObject(fRepositoryId, targetId, null, false, IncludeRelationships.NONE, null, false,
                 false, null);
-        assertNull(objectData.getRelationships());
+        assertTrue(objectData.getRelationships().isEmpty());
 
         // Folder
         String folderId = createFolder("folder1", fRootFolderId, BaseTypeId.CMIS_FOLDER.value());