You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by dc...@apache.org on 2009/08/18 16:27:59 UTC
svn commit: r805426 [8/9] - in /incubator/chemistry/trunk/chemistry: ./
chemistry-tck-atompub/ chemistry-tck-atompub/src/
chemistry-tck-atompub/src/main/ chemistry-tck-atompub/src/main/java/
chemistry-tck-atompub/src/main/java/org/ chemistry-tck-atompu...
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/CMISCustomTypeTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/CMISCustomTypeTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/CMISCustomTypeTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/CMISCustomTypeTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,427 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.custom;
+
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.chemistry.abdera.ext.CMISConstants;
+import org.apache.chemistry.abdera.ext.CMISObject;
+import org.apache.chemistry.abdera.ext.CMISProperties;
+import org.apache.chemistry.abdera.ext.CMISProperty;
+import org.apache.chemistry.tck.atompub.http.DeleteRequest;
+import org.apache.chemistry.tck.atompub.http.GetRequest;
+import org.apache.chemistry.tck.atompub.http.PatchRequest;
+import org.apache.chemistry.tck.atompub.http.PostRequest;
+import org.apache.chemistry.tck.atompub.http.PutRequest;
+import org.apache.chemistry.tck.atompub.http.Response;
+
+
+//
+// TODO: Determine mechanism for repo specific registration of custom types
+//
+
+
+public class CMISCustomTypeTest extends TCKCustomTest {
+
+ public static final String ARG_INCLUDE_SUB_RELATIONSHIP_TYPES = "includeSubRelationshipTypes";
+
+ public void testCreateFolder() throws Exception {
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ assertNotNull(childrenLink);
+ Feed children = client.getFeed(childrenLink.getHref());
+ assertNotNull(children);
+ int entriesBefore = children.getEntries().size();
+ Entry folder = client.createFolder(children.getSelfLink().getHref(), "testCreateCustomFolder",
+ "/org/apache/chemistry/tck/atompub/test/createcustomfolder.atomentry.xml");
+ Feed feedFolderAfter = client.getFeed(childrenLink.getHref());
+ int entriesAfter = feedFolderAfter.getEntries().size();
+ assertEquals(entriesBefore + 1, entriesAfter);
+ Entry entry = feedFolderAfter.getEntry(folder.getId().toString());
+ CMISObject object = entry.getExtension(CMISConstants.OBJECT);
+ assertEquals("F/cmiscustom:folder", object.getObjectTypeId().getStringValue());
+ CMISProperty customProp = object.getProperties().find("cmiscustom:folderprop_string");
+ assertNotNull(customProp);
+ assertEquals("custom string", customProp.getStringValue());
+ }
+
+ public void testCreateDocument() throws Exception {
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ assertNotNull(childrenLink);
+ Feed children = client.getFeed(childrenLink.getHref());
+ assertNotNull(children);
+ int entriesBefore = children.getEntries().size();
+ Entry document = client.createDocument(children.getSelfLink().getHref(), "testCreateCustomDocument",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ Feed feedFolderAfter = client.getFeed(childrenLink.getHref());
+ int entriesAfter = feedFolderAfter.getEntries().size();
+ assertEquals(entriesBefore + 1, entriesAfter);
+ Entry entry = feedFolderAfter.getEntry(document.getId().toString());
+ CMISObject object = entry.getExtension(CMISConstants.OBJECT);
+ assertEquals("D/cmiscustom:document", object.getObjectTypeId().getStringValue());
+ CMISProperty customProp = object.getProperties().find("cmiscustom:docprop_string");
+ assertNotNull(customProp);
+ assertEquals("custom string", customProp.getStringValue());
+ CMISProperty multiProp = object.getProperties().find("cmiscustom:docprop_boolean_multi");
+ assertNotNull(multiProp);
+ List<Object> multiValues = multiProp.getNativeValues();
+ assertNotNull(multiValues);
+ assertEquals(2, multiValues.size());
+ assertEquals(true, multiValues.get(0));
+ assertEquals(false, multiValues.get(1));
+ }
+
+ public void testUpdatePatch() throws Exception {
+ // retrieve test folder for update
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+
+ // create document for update
+ Entry document = client.createDocument(childrenLink.getHref(), "testUpdatePatchCustomDocument",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(document);
+
+ // update
+ String updateFile = customTemplates.load("updatecustomdocument.atomentry.xml");
+ // FIXME: Add a decent UID generation policy
+ // String guid = GUID.generate();
+ String guid = System.currentTimeMillis() + "";
+ updateFile = updateFile.replace("${NAME}", guid);
+ Response res = client.executeRequest(new PatchRequest(document.getSelfLink().getHref().toString(), updateFile,
+ CMISConstants.MIMETYPE_ENTRY), 200, client.getAtomValidator());
+ assertNotNull(res);
+ Entry updated = model.parseEntry(new StringReader(res.getContentAsString()), null);
+
+ // ensure update occurred
+ assertEquals(document.getId(), updated.getId());
+ assertEquals(document.getPublished(), updated.getPublished());
+ assertEquals("Updated Title " + guid, updated.getTitle());
+ CMISObject object = updated.getExtension(CMISConstants.OBJECT);
+ assertEquals("D/cmiscustom:document", object.getObjectTypeId().getStringValue());
+ CMISProperty customProp = object.getProperties().find("cmiscustom:docprop_string");
+ assertNotNull(customProp);
+ assertEquals("custom " + guid, customProp.getStringValue());
+ CMISProperty multiProp = object.getProperties().find("cmiscustom:docprop_boolean_multi");
+ assertNotNull(multiProp);
+ List<Object> multiValues = multiProp.getNativeValues();
+ assertNotNull(multiValues);
+ assertEquals(2, multiValues.size());
+ assertEquals(false, multiValues.get(0));
+ assertEquals(true, multiValues.get(1));
+ }
+
+ public void testUpdatePut() throws Exception {
+ // retrieve test folder for update
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+
+ // create document for update
+ Entry document = client.createDocument(childrenLink.getHref(), "testUpdatePutCustomDocument",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(document);
+
+ // update
+ String updateFile = customTemplates.load("updatecustomdocument.atomentry.xml");
+ // FIXME: Add a decent UID generation policy
+ // String guid = GUID.generate();
+ String guid = System.currentTimeMillis() + "";
+ updateFile = updateFile.replace("${NAME}", guid);
+ Response res = client.executeRequest(new PutRequest(document.getSelfLink().getHref().toString(), updateFile,
+ CMISConstants.MIMETYPE_ENTRY), 200, client.getAtomValidator());
+ assertNotNull(res);
+ Entry updated = model.parseEntry(new StringReader(res.getContentAsString()), null);
+
+ // ensure update occurred
+ assertEquals(document.getId(), updated.getId());
+ assertEquals(document.getPublished(), updated.getPublished());
+ assertEquals("Updated Title " + guid, updated.getTitle());
+ CMISObject object = updated.getExtension(CMISConstants.OBJECT);
+ assertEquals("D/cmiscustom:document", object.getObjectTypeId().getStringValue());
+ CMISProperty customProp = object.getProperties().find("cmiscustom:docprop_string");
+ assertNotNull(customProp);
+ assertEquals("custom " + guid, customProp.getStringValue());
+ CMISProperty multiProp = object.getProperties().find("cmiscustom:docprop_boolean_multi");
+ assertNotNull(multiProp);
+ List<Object> multiValues = multiProp.getNativeValues();
+ assertNotNull(multiValues);
+ assertEquals(2, multiValues.size());
+ assertEquals(false, multiValues.get(0));
+ assertEquals(true, multiValues.get(1));
+ }
+
+ public void testDelete() throws Exception {
+ // retrieve test folder for deletes
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ Feed children = client.getFeed(childrenLink.getHref());
+ int entriesBefore = children.getEntries().size();
+
+ // create document for delete
+ Entry document = client.createDocument(childrenLink.getHref(), "testDeleteCustomDocument",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ Response documentRes = client.executeRequest(new GetRequest(document.getSelfLink().getHref().toString()), 200,
+ client.getAtomValidator());
+ assertNotNull(documentRes);
+
+ // ensure document has been created
+ Feed children2 = client.getFeed(childrenLink.getHref());
+ assertNotNull(children2);
+ int entriesAfterCreate = children2.getEntries().size();
+ assertEquals(entriesAfterCreate, entriesBefore + 1);
+
+ // delete
+ Response deleteRes = client.executeRequest(new DeleteRequest(document.getSelfLink().getHref().toString()), 204);
+ assertNotNull(deleteRes);
+
+ // ensure document has been deleted
+ Feed children3 = client.getFeed(childrenLink.getHref());
+ assertNotNull(children3);
+ int entriesAfterDelete = children3.getEntries().size();
+ assertEquals(entriesBefore, entriesAfterDelete);
+ }
+
+ public void testQuery() throws Exception {
+ // retrieve query collection
+ IRI queryHREF = client.getQueryCollection(client.getWorkspace());
+
+ // retrieve test folder for query
+ Entry testFolder = fixture.getTestCaseFolder();
+ CMISObject testFolderObject = testFolder.getExtension(CMISConstants.OBJECT);
+ Link childrenLink = client.getChildrenLink(testFolder);
+
+ // create documents to query
+ // Standard root document
+ Entry document1 = client.createDocument(childrenLink.getHref(), "apple1");
+ assertNotNull(document1);
+ CMISObject document1Object = document1.getExtension(CMISConstants.OBJECT);
+ assertNotNull(document1Object);
+ String doc2name = "name" + System.currentTimeMillis();
+ // Custom documents
+ Entry document2 = client.createDocument(childrenLink.getHref(), doc2name,
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(document2);
+ CMISObject document2Object = document2.getExtension(CMISConstants.OBJECT);
+ assertNotNull(document2Object);
+ Entry document3 = client.createDocument(childrenLink.getHref(), "banana1",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(document3);
+ CMISObject document3Object = document3.getExtension(CMISConstants.OBJECT);
+ assertNotNull(document3Object);
+
+ // retrieve query request document
+ String queryDoc = customTemplates.load("query.cmisquery.xml");
+
+ {
+ // construct structured query
+ String query = "SELECT ObjectId, Name, ObjectTypeId, cmiscustom_docprop_string, cmiscustom_docprop_boolean_multi FROM cmiscustom_document "
+ + "WHERE IN_FOLDER('"
+ + testFolderObject.getObjectId().getStringValue()
+ + "') "
+ + "AND cmiscustom_docprop_string = 'custom string' ";
+ String queryReq = queryDoc.replace("${STATEMENT}", query);
+ queryReq = queryReq.replace("${SKIPCOUNT}", "0");
+ queryReq = queryReq.replace("${PAGESIZE}", "5");
+
+ // issue structured query
+ Response queryRes = client.executeRequest(new PostRequest(queryHREF.toString(), queryReq,
+ CMISConstants.MIMETYPE_CMIS_QUERY), 200);
+ assertNotNull(queryRes);
+ Feed queryFeed = model.parseFeed(new StringReader(queryRes.getContentAsString()), null);
+ assertNotNull(queryFeed);
+ assertEquals(2, queryFeed.getEntries().size());
+
+ assertNotNull(queryFeed.getEntry(document2.getId().toString()));
+ CMISObject result1 = queryFeed.getEntry(document2.getId().toString()).getExtension(CMISConstants.OBJECT);
+ assertNotNull(result1);
+ assertEquals(document2Object.getName().getStringValue(), result1.getName().getStringValue());
+ assertEquals(document2Object.getObjectId().getStringValue(), result1.getObjectId().getStringValue());
+ assertEquals(document2Object.getObjectTypeId().getStringValue(), result1.getObjectTypeId().getStringValue());
+ CMISProperties result1properties = result1.getProperties();
+ assertNotNull(result1properties);
+ CMISProperty result1property = result1properties.find("cmiscustom:docprop_string");
+ assertNotNull(result1property);
+ assertEquals("custom string", result1property.getStringValue());
+ CMISProperty result1multiproperty = result1properties.find("cmiscustom:docprop_boolean_multi");
+ assertNotNull(result1multiproperty);
+ List<Object> result1multiValues = result1multiproperty.getNativeValues();
+ assertNotNull(result1multiValues);
+ assertEquals(2, result1multiValues.size());
+ assertEquals(true, result1multiValues.get(0));
+ assertEquals(false, result1multiValues.get(1));
+
+ assertNotNull(queryFeed.getEntry(document3.getId().toString()));
+ CMISObject result2 = queryFeed.getEntry(document3.getId().toString()).getExtension(CMISConstants.OBJECT);
+ assertNotNull(result2);
+ assertEquals(document3Object.getName().getStringValue(), result2.getName().getStringValue());
+ assertEquals(document3Object.getObjectId().getStringValue(), result2.getObjectId().getStringValue());
+ assertEquals(document3Object.getObjectTypeId().getStringValue(), result2.getObjectTypeId().getStringValue());
+ CMISProperties result2properties = result2.getProperties();
+ assertNotNull(result2properties);
+ CMISProperty result2property = result2properties.find("cmiscustom:docprop_string");
+ assertNotNull(result2property);
+ assertEquals("custom string", result2property.getStringValue());
+ CMISProperty result2multiproperty = result1properties.find("cmiscustom:docprop_boolean_multi");
+ assertNotNull(result2multiproperty);
+ List<Object> result2multiValues = result2multiproperty.getNativeValues();
+ assertNotNull(result2multiValues);
+ assertEquals(2, result2multiValues.size());
+ assertEquals(true, result2multiValues.get(0));
+ assertEquals(false, result2multiValues.get(1));
+ }
+ }
+
+ public void testCreateRelationship() throws Exception {
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ assertNotNull(childrenLink);
+ Feed children = client.getFeed(childrenLink.getHref());
+ assertNotNull(children);
+ Entry source = client.createDocument(children.getSelfLink().getHref(), "testSource",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(source);
+ Entry target = client.createDocument(children.getSelfLink().getHref(), "testTarget",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(target);
+
+ // retrieve relationships feed on source
+ Link relsLink = source.getLink(CMISConstants.REL_RELATIONSHIPS);
+ assertNotNull(relsLink);
+ Feed relsBefore = client.getFeed(relsLink.getHref());
+ assertNotNull(relsBefore);
+ assertEquals(0, relsBefore.getEntries().size());
+
+ // create relationship between source and target documents
+ CMISObject targetObject = target.getExtension(CMISConstants.OBJECT);
+ assertNotNull(targetObject);
+ String targetId = targetObject.getObjectId().getStringValue();
+ assertNotNull(targetId);
+ Entry rel = client.createRelationship(relsLink.getHref(), "R/cmiscustom:assoc", targetId);
+ assertNotNull(rel);
+
+ // check created relationship
+ CMISObject sourceObject = source.getExtension(CMISConstants.OBJECT);
+ assertNotNull(sourceObject);
+ String sourceId = sourceObject.getObjectId().getStringValue();
+ assertNotNull(sourceId);
+ CMISObject relObject = rel.getExtension(CMISConstants.OBJECT);
+ assertNotNull(relObject);
+ assertEquals("R/cmiscustom:assoc", relObject.getObjectTypeId().getStringValue());
+ assertEquals(sourceId, relObject.getSourceId().getStringValue());
+ assertEquals(targetId, relObject.getTargetId().getStringValue());
+ assertEquals(source.getSelfLink().getHref(), rel.getLink(CMISConstants.REL_ASSOC_SOURCE).getHref());
+ assertEquals(target.getSelfLink().getHref(), rel.getLink(CMISConstants.REL_ASSOC_TARGET).getHref());
+
+ // check relationships for created item
+ Map<String, String> args = new HashMap<String, String>();
+ args.put(ARG_INCLUDE_SUB_RELATIONSHIP_TYPES, "true");
+ Feed relsAfter = client.getFeed(relsLink.getHref(), args);
+ assertNotNull(relsAfter);
+ assertEquals(1, relsAfter.getEntries().size());
+ }
+
+ public void testGetRelationship() throws Exception {
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ assertNotNull(childrenLink);
+ Feed children = client.getFeed(childrenLink.getHref());
+ assertNotNull(children);
+ Entry source = client.createDocument(children.getSelfLink().getHref(), "testSource",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(source);
+ Entry target = client.createDocument(children.getSelfLink().getHref(), "testTarget",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(target);
+
+ // retrieve relationships feed on source
+ Link relsLink = source.getLink(CMISConstants.REL_RELATIONSHIPS);
+ assertNotNull(relsLink);
+
+ // create relationship between source and target documents
+ CMISObject targetObject = target.getExtension(CMISConstants.OBJECT);
+ assertNotNull(targetObject);
+ String targetId = targetObject.getObjectId().getStringValue();
+ assertNotNull(targetId);
+ Entry rel = client.createRelationship(relsLink.getHref(), "R/cmiscustom:assoc", targetId);
+ assertNotNull(rel);
+
+ // get created relationship
+ Entry relEntry = client.getEntry(rel.getSelfLink().getHref());
+ CMISObject relEntryObject = rel.getExtension(CMISConstants.OBJECT);
+ CMISObject relObject = rel.getExtension(CMISConstants.OBJECT);
+ assertNotNull(relObject);
+ assertEquals(relObject.getObjectTypeId().getStringValue(), relEntryObject.getObjectTypeId().getStringValue());
+ assertEquals(relObject.getSourceId().getStringValue(), relEntryObject.getSourceId().getStringValue());
+ assertEquals(relObject.getTargetId().getStringValue(), relEntryObject.getTargetId().getStringValue());
+ assertEquals(source.getSelfLink().getHref(), relEntry.getLink(CMISConstants.REL_ASSOC_SOURCE).getHref());
+ assertEquals(target.getSelfLink().getHref(), relEntry.getLink(CMISConstants.REL_ASSOC_TARGET).getHref());
+ }
+
+ public void testDeleteRelationship() throws Exception {
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ assertNotNull(childrenLink);
+ Feed children = client.getFeed(childrenLink.getHref());
+ assertNotNull(children);
+ Entry source = client.createDocument(children.getSelfLink().getHref(), "testSource",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(source);
+ Entry target = client.createDocument(children.getSelfLink().getHref(), "testTarget",
+ "/org/apache/chemistry/tck/atompub/test/createcustomdocument.atomentry.xml");
+ assertNotNull(target);
+
+ // retrieve relationships feed on source
+ Link relsLink = source.getLink(CMISConstants.REL_RELATIONSHIPS);
+ assertNotNull(relsLink);
+ Feed relsBefore = client.getFeed(relsLink.getHref());
+ assertNotNull(relsBefore);
+ assertEquals(0, relsBefore.getEntries().size());
+
+ // create relationship between source and target documents
+ CMISObject targetObject = target.getExtension(CMISConstants.OBJECT);
+ assertNotNull(targetObject);
+ String targetId = targetObject.getObjectId().getStringValue();
+ assertNotNull(targetId);
+ Entry rel = client.createRelationship(relsLink.getHref(), "R/cmiscustom:assoc", targetId);
+ assertNotNull(rel);
+
+ // check relationships for created item
+ Map<String, String> args = new HashMap<String, String>();
+ args.put(ARG_INCLUDE_SUB_RELATIONSHIP_TYPES, "true");
+ Feed relsAfterCreate = client.getFeed(relsLink.getHref(), args);
+ assertNotNull(relsAfterCreate);
+ assertEquals(1, relsAfterCreate.getEntries().size());
+
+ // delete relationship
+ Response deleteRes = client.executeRequest(new DeleteRequest(rel.getSelfLink().getHref().toString()), 204);
+ assertNotNull(deleteRes);
+
+ // check relationships for deleted item
+ Feed relsAfterDelete = client.getFeed(relsLink.getHref(), args);
+ assertNotNull(relsAfterDelete);
+ assertEquals(0, relsAfterDelete.getEntries().size());
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/CMISCustomTypeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/TCKCustomTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/TCKCustomTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/TCKCustomTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/TCKCustomTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,34 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.custom;
+
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.utils.ResourceLoader;
+
+public class TCKCustomTest extends TCKTest {
+
+ protected ResourceLoader customTemplates;
+
+ @Override
+ public void setUp() {
+ super.setUp();
+
+ // construct test custom templates
+ customTemplates = new ResourceLoader("/org/apache/chemistry/tck/atompub/templates/custom/");
+ }
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/custom/TCKCustomTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/schema/CMISSchemaTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/schema/CMISSchemaTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/schema/CMISSchemaTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/schema/CMISSchemaTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,157 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.schema;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.validation.Validator;
+
+import junit.framework.TestCase;
+
+import org.apache.chemistry.tck.atompub.client.CMISValidator;
+import org.apache.chemistry.tck.atompub.utils.ResourceLoader;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Test CMIS Examples against CMIS XSDs
+ */
+public class CMISSchemaTest extends TestCase {
+ private CMISValidator cmisValidator;
+ private ResourceLoader examples;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ cmisValidator = new CMISValidator();
+ examples = new ResourceLoader("/org/apache/chemistry/tck/atompub/examples/");
+ }
+
+ public void testAllowableActions() throws Exception {
+ String xml = examples.load("AllowableActions.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testChangeLog() throws Exception {
+ String xml = examples.load("ChangeLog.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testDocumentEntry() throws Exception {
+ String xml = examples.load("DocumentEntry.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testDocumentEntryPWC() throws Exception {
+ String xml = examples.load("DocumentEntryPWC.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testDocumentEntryWithChanges() throws Exception {
+ String xml = examples.load("DocumentEntryWithChanges.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testFolderChildren() throws Exception {
+ String xml = examples.load("FolderChildren.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testFolderDescendants() throws Exception {
+ String xml = examples.load("FolderDescendants.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testFolderEntry() throws Exception {
+ String xml = examples.load("FolderEntry.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testPolicyEntry() throws Exception {
+ String xml = examples.load("PolicyEntry.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testQuery() throws Exception {
+ String xml = examples.load("Query.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testRelationshipEntry() throws Exception {
+ String xml = examples.load("RelationshipEntry.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testService() throws Exception {
+ String xml = examples.load("Service.xml");
+ assertValidXML(xml, cmisValidator.getAppValidator());
+ }
+
+ public void testTypeDocumentWith() throws Exception {
+ String xml = examples.load("TypeDocumentWith.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testTypeDocumentWithout() throws Exception {
+ String xml = examples.load("TypeDocumentWithout.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testTypeFolderWith() throws Exception {
+ String xml = examples.load("TypeFolderWith.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testTypeFolderWithOut() throws Exception {
+ String xml = examples.load("TypeFolderWithOut.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testTypeRelationshipWith() throws Exception {
+ String xml = examples.load("TypeRelationshipWith.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ public void testTypeRelationshipWithOut() throws Exception {
+ String xml = examples.load("TypeRelationshipWithout.xml");
+ assertValidXML(xml, cmisValidator.getCMISAtomValidator());
+ }
+
+ /**
+ * Assert XML is valid according to specified validator
+ *
+ * @param xml
+ * document to test
+ * @param validator
+ * validator to test with
+ * @throws IOException
+ * @throws ParserConfigurationException
+ */
+ private void assertValidXML(String xml, Validator validator) throws IOException, ParserConfigurationException {
+ try {
+ Document document = cmisValidator.getDocumentBuilder().parse(new InputSource(new StringReader(xml)));
+ validator.validate(new DOMSource(document));
+ } catch (SAXException e) {
+ fail(cmisValidator.toString(e, xml));
+ }
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/schema/CMISSchemaTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/AllowableActionsTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/AllowableActionsTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/AllowableActionsTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/AllowableActionsTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,150 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.spec;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.chemistry.abdera.ext.CMISAllowableAction;
+import org.apache.chemistry.abdera.ext.CMISAllowableActions;
+import org.apache.chemistry.abdera.ext.CMISConstants;
+import org.apache.chemistry.abdera.ext.CMISObject;
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.http.GetRequest;
+import org.apache.chemistry.tck.atompub.http.Request;
+import org.apache.chemistry.tck.atompub.http.Response;
+import org.junit.Assert;
+
+/**
+ * CMIS Allowable Actions Tests
+ */
+public class AllowableActionsTest extends TCKTest {
+
+ public void testFolderAllowableActions() throws Exception {
+ Entry folder = fixture.createTestFolder("testAllowableActions");
+
+ Link allowableActionsLink = folder.getLink(CMISConstants.REL_ALLOWABLE_ACTIONS);
+ Request req = new GetRequest(allowableActionsLink.getHref().toString());
+ Response allowableActionsRes = client.executeRequest(req, 200, client.getAtomValidator());
+ Assert.assertNotNull(allowableActionsRes);
+ Element allowableActions = model.parse(new StringReader(allowableActionsRes.getContentAsString()), null);
+ Assert.assertNotNull(allowableActions);
+ Assert.assertTrue(allowableActions instanceof CMISAllowableActions);
+ CMISObject childObject = folder.getExtension(CMISConstants.OBJECT);
+ Assert.assertNotNull(childObject);
+ CMISAllowableActions objectAllowableActions = childObject.getExtension(CMISConstants.ALLOWABLE_ACTIONS);
+ Assert.assertNotNull(objectAllowableActions);
+ compareAllowableActions((CMISAllowableActions) allowableActions, objectAllowableActions);
+
+ // retrieve getProperties() with includeAllowableActions flag
+ Map<String, String> args = new HashMap<String, String>();
+ args.put("includeAllowableActions", "true");
+ Entry properties = client.getEntry(folder.getSelfLink().getHref(), args);
+ Assert.assertNotNull(properties);
+ CMISObject propObject = properties.getExtension(CMISConstants.OBJECT);
+ Assert.assertNotNull(propObject);
+ CMISAllowableActions propAllowableActions = propObject.getExtension(CMISConstants.ALLOWABLE_ACTIONS);
+ Assert.assertNotNull(propAllowableActions);
+ compareAllowableActions((CMISAllowableActions) allowableActions, propAllowableActions);
+ }
+
+ public void testDocumentAllowableActions() throws Exception {
+ Entry document = fixture.createTestDocument("testDocumentAllowableActions");
+
+ Link allowableActionsLink = document.getLink(CMISConstants.REL_ALLOWABLE_ACTIONS);
+ Request req = new GetRequest(allowableActionsLink.getHref().toString());
+ Response allowableActionsRes = client.executeRequest(req, 200, client.getAtomValidator());
+ Assert.assertNotNull(allowableActionsRes);
+ Element allowableActions = model.parse(new StringReader(allowableActionsRes.getContentAsString()), null);
+ Assert.assertNotNull(allowableActions);
+ Assert.assertTrue(allowableActions instanceof CMISAllowableActions);
+ CMISObject childObject = document.getExtension(CMISConstants.OBJECT);
+ Assert.assertNotNull(childObject);
+ CMISAllowableActions objectAllowableActions = childObject.getExtension(CMISConstants.ALLOWABLE_ACTIONS);
+ Assert.assertNotNull(objectAllowableActions);
+ compareAllowableActions((CMISAllowableActions) allowableActions, objectAllowableActions);
+
+ // retrieve getProperties() with includeAllowableActions flag
+ Map<String, String> args = new HashMap<String, String>();
+ args.put("includeAllowableActions", "true");
+ Entry properties = client.getEntry(document.getSelfLink().getHref(), args);
+ Assert.assertNotNull(properties);
+ CMISObject propObject = properties.getExtension(CMISConstants.OBJECT);
+ Assert.assertNotNull(propObject);
+ CMISAllowableActions propAllowableActions = propObject.getExtension(CMISConstants.ALLOWABLE_ACTIONS);
+ Assert.assertNotNull(propAllowableActions);
+ compareAllowableActions((CMISAllowableActions) allowableActions, propAllowableActions);
+ }
+
+ public void testGetChildrenAllowableActions() throws Exception {
+ fixture.createTestFolder("testAllowableActions");
+ fixture.createTestDocument("testDocumentAllowableActions");
+ Entry testCase = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testCase);
+
+ // test allowable actions for children
+ Map<String, String> args = new HashMap<String, String>();
+ args.put("includeAllowableActions", "true");
+ Feed children = client.getFeed(childrenLink.getHref(), args);
+ Assert.assertNotNull(children);
+ for (Entry child : children.getEntries()) {
+ // extract allowable actions from child
+ CMISObject childObject = child.getExtension(CMISConstants.OBJECT);
+ Assert.assertNotNull(childObject);
+ CMISAllowableActions objectAllowableActions = childObject.getExtension(CMISConstants.ALLOWABLE_ACTIONS);
+ Assert.assertNotNull(objectAllowableActions);
+
+ // retrieve allowable actions from link
+ Link allowableActionsLink = child.getLink(CMISConstants.REL_ALLOWABLE_ACTIONS);
+ Request req = new GetRequest(allowableActionsLink.getHref().toString());
+ Response allowableActionsRes = client.executeRequest(req, 200, client.getAtomValidator());
+ Assert.assertNotNull(allowableActionsRes);
+ Element allowableActions = model.parse(new StringReader(allowableActionsRes.getContentAsString()), null);
+ Assert.assertNotNull(allowableActions);
+ Assert.assertTrue(allowableActions instanceof CMISAllowableActions);
+
+ // compare the two
+ compareAllowableActions((CMISAllowableActions) allowableActions, objectAllowableActions);
+ }
+ }
+
+ /**
+ * Compare two sets of allowable actions
+ */
+ public static void compareAllowableActions(CMISAllowableActions left, CMISAllowableActions right) {
+ List<String> rightactions = new ArrayList<String>(right.getNames());
+ for (String action : left.getNames()) {
+ Assert.assertTrue(rightactions.contains(action));
+ CMISAllowableAction leftAction = left.find(action);
+ Assert.assertNotNull(leftAction);
+ CMISAllowableAction rightAction = right.find(action);
+ Assert.assertNotNull(rightAction);
+ Assert.assertEquals(leftAction.isAllowed(), rightAction.isAllowed());
+ rightactions.remove(action);
+ }
+ Assert.assertTrue(rightactions.size() == 0);
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/AllowableActionsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/ContentStreamTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/ContentStreamTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/ContentStreamTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/ContentStreamTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,87 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.spec;
+
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Link;
+import org.apache.chemistry.abdera.ext.CMISConstants;
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.http.DeleteRequest;
+import org.apache.chemistry.tck.atompub.http.GetRequest;
+import org.apache.chemistry.tck.atompub.http.PutRequest;
+import org.apache.chemistry.tck.atompub.http.Request;
+import org.apache.chemistry.tck.atompub.http.Response;
+import org.junit.Assert;
+
+/**
+ * CMIS Content Stream Tests
+ */
+public class ContentStreamTest extends TCKTest {
+
+ public void testContentStreamEmpty() throws Exception {
+ // create document for setting / getting content
+ Entry document = fixture.createTestDocument("testContent", "createDocumentNoContent.atomentry.xml");
+
+ // retrieve content
+ client.executeRequest(new GetRequest(document.getContentSrc().toString()), 404);
+ }
+
+ public void testUpdateContentStream() throws Exception {
+ // create document for setting / getting content
+ Entry document = fixture.createTestDocument("testContent");
+
+ // retrieve content
+ Response documentContentRes = client.executeRequest(new GetRequest(document.getContentSrc().toString()), 200);
+ String resContent = documentContentRes.getContentAsString();
+ Assert.assertEquals(document.getTitle(), resContent);
+
+ // set content
+ String UPDATED_CONTENT = "Updated via SetContentStream()";
+ Link editMediaLink = document.getEditMediaLink();
+ Assert.assertNotNull(editMediaLink);
+ Request putReq = new PutRequest(editMediaLink.getHref().toString(), UPDATED_CONTENT, CMISConstants.MIMETYPE_TEXT);
+ Response res = client.executeRequest(putReq, 200);
+ Assert.assertNotNull(res);
+
+ // retrieve updated content
+ Request getReq = new GetRequest(document.getContentSrc().toString());
+ Response documentUpdatedContentRes = client.executeRequest(getReq, 200);
+ String resUpdatedContent = documentUpdatedContentRes.getContentAsString();
+ Assert.assertEquals(UPDATED_CONTENT, resUpdatedContent);
+ }
+
+ public void testDeleteContentStream() throws Exception {
+ // create document for setting / getting content
+ Entry document = fixture.createTestDocument("testContent");
+
+ // retrieve content
+ Response documentContentRes = client.executeRequest(new GetRequest(document.getContentSrc().toString()), 200);
+ String resContent = documentContentRes.getContentAsString();
+ Assert.assertEquals(document.getTitle(), resContent);
+
+ // delete content
+ Link editMediaLink = document.getEditMediaLink();
+ Assert.assertNotNull(editMediaLink);
+ Response res = client.executeRequest(new DeleteRequest(editMediaLink.getHref().toString()), 204);
+ Assert.assertNotNull(res);
+
+ // retrieve deleted content
+ client.executeRequest(new GetRequest(document.getContentSrc().toString()), 404);
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/ContentStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/CreateTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/CreateTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/CreateTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/CreateTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,91 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.spec;
+
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.http.GetRequest;
+import org.apache.chemistry.tck.atompub.http.Response;
+import org.junit.Assert;
+
+/**
+ * CMIS Create Tests
+ */
+public class CreateTest extends TCKTest
+{
+
+ public void testCreateFolder()
+ throws Exception
+ {
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ Assert.assertNotNull(childrenLink);
+ Feed children = client.getFeed(childrenLink.getHref());
+ Assert.assertNotNull(children);
+ int entriesBefore = children.getEntries().size();
+ Entry folder = client.createFolder(children.getSelfLink().getHref(), "testCreateFolder");
+ Feed feedFolderAfter = client.getFeed(childrenLink.getHref());
+ int entriesAfter = feedFolderAfter.getEntries().size();
+ Assert.assertEquals(entriesBefore +1, entriesAfter);
+ Entry entry = feedFolderAfter.getEntry(folder.getId().toString());
+ Assert.assertNotNull(entry);
+ }
+
+ public void testCreateDocument()
+ throws Exception
+ {
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ Assert.assertNotNull(childrenLink);
+ Feed children = client.getFeed(childrenLink.getHref());
+ Assert.assertNotNull(children);
+ int entriesBefore = children.getEntries().size();
+ Entry document = client.createDocument(children.getSelfLink().getHref(), "testCreateDocument");
+ Response documentContentRes = client.executeRequest(new GetRequest(document.getContentSrc().toString()), 200);
+ String resContent = documentContentRes.getContentAsString();
+ Assert.assertEquals(document.getTitle(), resContent);
+ Feed feedFolderAfter = client.getFeed(childrenLink.getHref());
+ int entriesAfter = feedFolderAfter.getEntries().size();
+ Assert.assertEquals(entriesBefore +1, entriesAfter);
+ Entry entry = feedFolderAfter.getEntry(document.getId().toString());
+ Assert.assertNotNull(entry);
+ }
+
+ public void testCreateAtomEntry()
+ throws Exception
+ {
+ Entry testFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testFolder);
+ Assert.assertNotNull(childrenLink);
+ Feed children = client.getFeed(childrenLink.getHref());
+ Assert.assertNotNull(children);
+ int entriesBefore = children.getEntries().size();
+ Entry document = client.createDocument(children.getSelfLink().getHref(), "Iñtërnâtiônà lizætiøn - 1.html", "createatomentry.atomentry.xml");
+ Response documentContentRes = client.executeRequest(new GetRequest(document.getContentSrc().toString()), 200);
+ String resContent = documentContentRes.getContentAsString();
+ Assert.assertEquals(document.getTitle(), resContent);
+ Feed feedFolderAfter = client.getFeed(childrenLink.getHref());
+ int entriesAfter = feedFolderAfter.getEntries().size();
+ Assert.assertEquals(entriesBefore +1, entriesAfter);
+ Entry entry = feedFolderAfter.getEntry(document.getId().toString());
+ Assert.assertNotNull(entry);
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/CreateTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/DeleteTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/DeleteTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/DeleteTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/DeleteTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,99 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.spec;
+
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.fixture.AssertNotExistVisitor;
+import org.apache.chemistry.tck.atompub.fixture.EntryTree;
+import org.apache.chemistry.tck.atompub.http.DeleteRequest;
+import org.apache.chemistry.tck.atompub.http.GetRequest;
+import org.junit.Assert;
+
+/**
+ * CMIS Delete Tests
+ */
+public class DeleteTest extends TCKTest {
+
+ public void testDeleteFolder() throws Exception {
+ Entry folder = fixture.createTestFolder("testFolder");
+
+ // delete
+ client.executeRequest(new DeleteRequest(folder.getSelfLink().getHref().toString()), 204);
+
+ // ensure removed
+ client.executeRequest(new GetRequest(folder.getSelfLink().getHref().toString()), 404);
+ Entry testCaseFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testCaseFolder);
+ Feed children = client.getFeed(childrenLink.getHref());
+ Assert.assertEquals(0, children.getEntries().size());
+ }
+
+ public void testDeleteDocument() throws Exception {
+ Entry document = fixture.createTestDocument("testDocument");
+
+ // delete
+ client.executeRequest(new DeleteRequest(document.getSelfLink().getHref().toString()), 204);
+
+ // ensure removed
+ client.executeRequest(new GetRequest(document.getSelfLink().getHref().toString()), 404);
+ Entry testCaseFolder = fixture.getTestCaseFolder();
+ Link childrenLink = client.getChildrenLink(testCaseFolder);
+ Feed children = client.getFeed(childrenLink.getHref());
+ Assert.assertEquals(0, children.getEntries().size());
+ }
+
+ public void testDeleteDescendants() throws Exception {
+ EntryTree descendants = fixture.createTestTree("descendants", 3, 2, null, null);
+
+ // delete
+ Link descendantsLink = client.getDescendantsLink(descendants.entry);
+ Assert.assertNotNull(descendantsLink);
+ client.executeRequest(new DeleteRequest(descendantsLink.getHref().toString()), 204);
+
+ // ensure all have been deleted
+ descendants.walkTree(new AssertNotExistVisitor(client));
+ }
+
+ public void testDeleteFolderTree() throws Exception {
+ EntryTree descendants = fixture.createTestTree("descendants", 3, 0, null, null);
+
+ // delete
+ Link folderTreeLink = client.getFolderTreeLink(descendants.entry);
+ Assert.assertNotNull(folderTreeLink);
+ client.executeRequest(new DeleteRequest(folderTreeLink.getHref().toString()), 204);
+
+ // ensure all have been deleted
+ descendants.walkTree(new AssertNotExistVisitor(client));
+ }
+
+ public void testDeleteFolderTreeWithDocuments() throws Exception {
+ EntryTree descendants = fixture.createTestTree("descendants", 3, 2, null, null);
+
+ // delete
+ Link folderTreeLink = client.getFolderTreeLink(descendants.entry);
+ Assert.assertNotNull(folderTreeLink);
+ client.executeRequest(new DeleteRequest(folderTreeLink.getHref().toString()), 204);
+
+ // ensure all have been deleted
+ descendants.walkTree(new AssertNotExistVisitor(client));
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/DeleteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderChildrenTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderChildrenTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderChildrenTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderChildrenTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,131 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.spec;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.chemistry.abdera.ext.CMISConstants;
+import org.apache.chemistry.abdera.ext.CMISObject;
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.fixture.AssertEntryInFeedVisitor;
+import org.apache.chemistry.tck.atompub.fixture.AssertValidFolderParentVisitor;
+import org.apache.chemistry.tck.atompub.fixture.EntryTree;
+import org.junit.Assert;
+
+/**
+ * CMIS Folder Children Tests
+ */
+public class FolderChildrenTest extends TCKTest {
+
+ public void testGetChildren() throws Exception {
+ EntryTree folder = fixture.createTestTree("children", 1, 3, null, null);
+
+ // get children
+ Link childrenLink = client.getChildrenLink(folder.entry);
+ Feed children = client.getFeed(childrenLink.getHref());
+
+ // ensure they all exist
+ Assert.assertEquals(3, children.getEntries().size());
+ folder.walkChildren(new AssertEntryInFeedVisitor(children));
+ }
+
+ public void testGetChildrenPaging() throws Exception {
+ EntryTree folder = fixture.createTestTree("children", 1, 15, null, null);
+
+ // record child ids
+ Set<IRI> unread = new HashSet<IRI>();
+ for (EntryTree child : folder.children) {
+ unread.add(child.entry.getId());
+ }
+ Assert.assertEquals(15, unread.size());
+
+ // page thru children
+ Link nextLink = client.getChildrenLink(folder.entry);
+ Map<String, String> args = new HashMap<String, String>();
+ args.put("maxItems", "4");
+
+ int pageCount = 0;
+ while (nextLink != null) {
+ pageCount++;
+ Feed children = client.getFeed(nextLink.getHref(), args);
+ Assert.assertNotNull(children);
+ Assert.assertEquals(pageCount < 4 ? 4 : 3, children.getEntries().size());
+
+ // mark children as read
+ for (Entry entry : children.getEntries()) {
+ unread.remove(entry.getId());
+ }
+
+ // next page
+ nextLink = children.getLink("next");
+ if (pageCount < 4) {
+ Assert.assertNotNull(nextLink);
+ }
+ args = null;
+ }
+ ;
+ Assert.assertEquals(4, pageCount);
+ Assert.assertEquals(0, unread.size());
+ }
+
+ public void testGetChildrenAllPropertyFilter() throws Exception {
+ EntryTree folder = fixture.createTestTree("children", 1, 1, null, null);
+
+ // get children (with all properties)
+ Link childrenLink = client.getChildrenLink(folder.entry);
+ Map<String, String> args = new HashMap<String, String>();
+ args.put("filter", "*");
+ Feed children = client.getFeed(childrenLink.getHref(), args);
+
+ for (Entry entry : children.getEntries()) {
+ CMISObject object = entry.getExtension(CMISConstants.OBJECT);
+ Assert.assertNotNull(object.getObjectId().getStringValue());
+ Assert.assertNotNull(object.getObjectTypeId().getStringValue());
+ }
+ }
+
+ public void testGetChildrenNamedPropertyFilter() throws Exception {
+ EntryTree folder = fixture.createTestTree("children", 1, 1, null, null);
+
+ // get children with object_id only
+ Link childrenLink = client.getChildrenLink(folder.entry);
+ Map<String, String> args = new HashMap<String, String>();
+ args.put("filter", CMISConstants.PROP_OBJECT_ID);
+ Feed children = client.getFeed(childrenLink.getHref(), args);
+
+ for (Entry entry : children.getEntries()) {
+ CMISObject object = entry.getExtension(CMISConstants.OBJECT);
+ Assert.assertNotNull(object.getObjectId().getStringValue());
+ Assert.assertNull(object.getObjectTypeId());
+ }
+ }
+
+ public void testGetParents() throws Exception {
+ EntryTree folder = fixture.createTestTree("children", 3, 0, null, null);
+
+ folder.walkTree(new AssertValidFolderParentVisitor(client));
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderChildrenTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderHierarchyTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderHierarchyTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderHierarchyTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderHierarchyTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,131 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.spec;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.chemistry.abdera.ext.CMISCapabilities;
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.fixture.AssertValidObjectParentsVisitor;
+import org.apache.chemistry.tck.atompub.fixture.CMISTree;
+import org.apache.chemistry.tck.atompub.fixture.EntryTree;
+import org.junit.Assert;
+
+
+/**
+ * CMIS Folder Hierarchy Tests
+ */
+public class FolderHierarchyTest extends TCKTest {
+
+ public void testGetFolderTreeMinusOne() throws Exception {
+ getFolderTreeDepthN(3, -1);
+ }
+
+ public void testGetFolderTreeOne() throws Exception {
+ getFolderTreeDepthN(3, 1);
+ }
+
+ public void testGetFolderTreeExactDepth() throws Exception {
+ getFolderTreeDepthN(3, 3);
+ }
+
+ public void testGetFolderTreeOverDepth() throws Exception {
+ getFolderTreeDepthN(3, 4);
+ }
+
+ private void getFolderTreeDepthN(int depth, int getDepth) throws Exception {
+ // construct hierarchy of folders and docs
+ EntryTree folderTree = fixture.createTestTree("foldertree", depth, 2, null, null);
+
+ // retrieve folder tree
+ Link treeLink = client.getFolderTreeLink(folderTree.entry);
+ Assert.assertNotNull(treeLink);
+ Map<String, String> args = new HashMap<String, String>();
+ args.put("depth", "" + getDepth);
+ Feed tree = client.getFeed(treeLink.getHref(), args);
+
+ // compare constructed folder tree with retrieved one
+ EntryTree constructedFoldersOnly = new EntryTree(folderTree, getDepth, false);
+ EntryTree retrievedFoldersOnly = new CMISTree(folderTree, tree);
+ Assert.assertTrue(constructedFoldersOnly.equalsTree(retrievedFoldersOnly));
+ Assert.assertFalse(folderTree.equalsTree(retrievedFoldersOnly));
+ }
+
+ public void testGetDescendantsMinusOne() throws Exception {
+ CMISCapabilities capabilities = client.getCapabilities();
+ if (!capabilities.getDescendants()) {
+ skipTest("Capabilities Get Descendants: false");
+ return;
+ }
+ getDescendantsDepthN(3, -1);
+ }
+
+ public void testGetDescendantsOne() throws Exception {
+ CMISCapabilities capabilities = client.getCapabilities();
+ if (!capabilities.getDescendants()) {
+ skipTest("Capabilities Get Descendants: false");
+ return;
+ }
+ getDescendantsDepthN(3, 1);
+ }
+
+ public void testGetDescendantsExactDepth() throws Exception {
+ CMISCapabilities capabilities = client.getCapabilities();
+ if (!capabilities.getDescendants()) {
+ skipTest("Capabilities Get Descendants: false");
+ return;
+ }
+ getDescendantsDepthN(3, 3);
+ }
+
+ public void testGetDescendantsOverDepth() throws Exception {
+ CMISCapabilities capabilities = client.getCapabilities();
+ if (!capabilities.getDescendants()) {
+ skipTest("Capabilities Get Descendants: false");
+ return;
+ }
+ getDescendantsDepthN(3, 4);
+ }
+
+ private void getDescendantsDepthN(int depth, int getDepth) throws Exception {
+ // construct hierarchy of folders and docs
+ EntryTree descendantsTree = fixture.createTestTree("descendants", depth, 2, null, null);
+
+ // retrieve folder tree
+ Link descendantsLink = client.getDescendantsLink(descendantsTree.entry);
+ Assert.assertNotNull(descendantsLink);
+ Map<String, String> args = new HashMap<String, String>();
+ args.put("depth", "" + getDepth);
+ Feed descendants = client.getFeed(descendantsLink.getHref(), args);
+
+ // compare constructed folder tree with retrieved one
+ EntryTree constructedDescendantsOnly = new EntryTree(descendantsTree, getDepth);
+ EntryTree retrievedDescendantsOnly = new CMISTree(descendantsTree, descendants);
+ Assert.assertTrue(constructedDescendantsOnly.equalsTree(retrievedDescendantsOnly));
+ }
+
+ public void testGetObjectParents() throws Exception {
+ EntryTree folder = fixture.createTestTree("children", 3, 2, null, null);
+
+ folder.walkTree(new AssertValidObjectParentsVisitor(client));
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/FolderHierarchyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/GetTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/GetTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/GetTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/GetTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,57 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.spec;
+
+import org.apache.abdera.model.Entry;
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.http.GetRequest;
+import org.junit.Assert;
+
+
+/**
+ * CMIS Get Tests
+ */
+public class GetTest extends TCKTest {
+
+ public void testGetFolder() throws Exception {
+ // get folder
+ Entry folder = fixture.getTestCaseFolder();
+ Assert.assertNotNull(folder);
+ Entry getFolder = client.getEntry(folder.getSelfLink().getHref());
+ Assert.assertEquals(folder.getId(), getFolder.getId());
+ Assert.assertEquals(folder.getTitle(), getFolder.getTitle());
+ Assert.assertEquals(folder.getSummary(), getFolder.getSummary());
+ }
+
+ public void testGetDocument() throws Exception {
+ Entry document = fixture.createTestDocument("testDocument");
+ Entry getDocument = client.getEntry(document.getSelfLink().getHref());
+ Assert.assertEquals(document.getId(), getDocument.getId());
+ Assert.assertEquals(document.getTitle(), getDocument.getTitle());
+ // Assert.assertEquals(document(), getDocument());
+ }
+
+ public void testGetDocumentNotExist() throws Exception {
+ Entry folder = fixture.getTestCaseFolder();
+ // get something that doesn't exist
+ // FIXME: Add a decent UID generation policy
+ String guid = System.currentTimeMillis() + "";
+ client.executeRequest(new GetRequest(folder.getSelfLink().getHref().toString() + guid), 404);
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/GetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/QueryPagingTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/QueryPagingTest.java?rev=805426&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/QueryPagingTest.java (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/QueryPagingTest.java Tue Aug 18 14:27:55 2009
@@ -0,0 +1,119 @@
+/*
+ * Licensed 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.
+ *
+ * Authors:
+ * David Caruana, Alfresco
+ * Gabriele Columbro, Alfresco
+ */
+package org.apache.chemistry.tck.atompub.test.spec;
+
+import java.io.StringReader;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Link;
+import org.apache.chemistry.abdera.ext.CMISCapabilities;
+import org.apache.chemistry.abdera.ext.CMISConstants;
+import org.apache.chemistry.abdera.ext.CMISObject;
+import org.apache.chemistry.tck.atompub.TCKTest;
+import org.apache.chemistry.tck.atompub.fixture.EntryTree;
+import org.apache.chemistry.tck.atompub.http.PostRequest;
+import org.apache.chemistry.tck.atompub.http.Response;
+import org.junit.Assert;
+
+
+/**
+ * CMIS Query Paging Tests
+ */
+public class QueryPagingTest extends TCKTest {
+ private EntryTree searchFolder;
+
+ @Override
+ public void setUp() {
+ super.setUp();
+
+ try {
+ searchFolder = fixture.createTestTree("paging", 1, 15, null, null);
+ } catch (Exception e) {
+ // TODO: appropriate exception handling
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void testQueryPaging() throws Exception {
+ CMISCapabilities capabilities = client.getCapabilities();
+ String capability = capabilities.getQuery();
+ if (capability.equals("none")) {
+ skipTest("Query capability: " + capability);
+ return;
+ }
+
+ // create folder and children to page through
+ Set<IRI> unread = new HashSet<IRI>();
+ for (EntryTree child : searchFolder.children) {
+ unread.add(child.entry.getId());
+ }
+ Assert.assertEquals(15, unread.size());
+
+ // query children
+ // TODO: use property query name
+ IRI queryHREF = client.getQueryCollection(client.getWorkspace());
+ String queryDoc = templates.load("query.cmisquery.xml");
+ CMISObject testFolderObject = searchFolder.entry.getExtension(CMISConstants.OBJECT);
+ String query =
+ "SELECT cmis:ObjectId, cmis:ObjectTypeId, cmis:Name FROM cmis:document " +
+ "WHERE IN_FOLDER('" + testFolderObject.getObjectId().getStringValue() + "')";
+ String queryReq = queryDoc.replace("${STATEMENT}", query);
+ queryReq = queryReq.replace("${SKIPCOUNT}", "0");
+ queryReq = queryReq.replace("${MAXITEMS}", "4");
+ Response queryRes = client.executeRequest(new PostRequest(queryHREF.toString(), queryReq,
+ CMISConstants.MIMETYPE_CMIS_QUERY), 200);
+ Assert.assertNotNull(queryRes);
+
+ // retrieve entries for first page
+ Feed queryFeed = model.parseFeed(new StringReader(queryRes.getContentAsString()), null);
+ Assert.assertNotNull(queryFeed);
+
+ // page through results
+ int page = 0;
+ Link nextLink = null;
+ do {
+ page++;
+ Assert.assertEquals(page < 4 ? 4 : 3, queryFeed.getEntries().size());
+
+ // mark entries as read
+ for (Entry entry : queryFeed.getEntries()) {
+ unread.remove(entry.getId());
+ }
+
+ // next page
+ nextLink = queryFeed.getLink("next");
+ if (page == 4) {
+ Assert.assertNull(nextLink);
+ } else {
+ Assert.assertNotNull(nextLink);
+ }
+
+ if (nextLink != null) {
+ queryFeed = client.getFeed(nextLink.getHref());
+ }
+ } while (nextLink != null);
+
+ Assert.assertEquals(4, page);
+ Assert.assertEquals(0, unread.size());
+ }
+
+}
Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/test/java/org/apache/chemistry/tck/atompub/test/spec/QueryPagingTest.java
------------------------------------------------------------------------------
svn:eol-style = native