chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcaru...@apache.org
Subject svn commit: r824848 - in /incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry: abdera/ext/ tck/atompub/client/ tck/atompub/fixture/ tck/atompub/test/ tck/atompub/test/spec/
Date Tue, 13 Oct 2009 17:23:02 GMT
Author: dcaruana
Date: Tue Oct 13 17:23:02 2009
New Revision: 824848

URL: http://svn.apache.org/viewvc?rev=824848&view=rev
Log:
Addition of Move tests to AtomPub TCK (CMIS-88)

Fix validation of responses - validator now based on returned content type rather than explicitly
defined.

Added:
    incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/spec/MoveTest.java
  (with props)
Modified:
    incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/abdera/ext/CMISConstants.java
    incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/client/CMISClient.java
    incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/fixture/CMISTestFixture.java
    incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/TCKTestSuite.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/abdera/ext/CMISConstants.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/abdera/ext/CMISConstants.java?rev=824848&r1=824847&r2=824848&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/abdera/ext/CMISConstants.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/abdera/ext/CMISConstants.java
Tue Oct 13 17:23:02 2009
@@ -30,6 +30,8 @@
     public static final String CMISLINK_NS = "http://docs.oasis-open.org/ns/cmis/link/200908/";
 
     // Mimetypes
+    public static final String MIMETYPE_APP = "application/atomsvc+xml";
+    public static final String MIMETYPE_ATOM = "application/atom+xml";
     public static final String MIMETYPE_ENTRY = "application/atom+xml;type=entry";
     public static final String MIMETYPE_FEED = "application/atom+xml;type=feed";
     public static final String MIMETYPE_TEXT = "text/plain";

Modified: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/client/CMISClient.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/client/CMISClient.java?rev=824848&r1=824847&r2=824848&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/client/CMISClient.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/client/CMISClient.java
Tue Oct 13 17:23:02 2009
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.StringReader;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -99,7 +100,7 @@
     public Service getRepository() throws Exception {
         if (cmisService == null) {
             Request req = new GetRequest(serviceUrl);
-            Response res = executeRequest(req, 200, cmisValidator.getAppValidator());
+            Response res = executeRequest(req, 200);
             String xml = res.getContentAsString();
             Assert.assertNotNull(xml);
             Assert.assertTrue(xml.length() > 0);
@@ -237,7 +238,7 @@
 
     public Entry getEntry(IRI href, Map<String, String> args) throws Exception {
         Request get = new GetRequest(href.toString()).setArgs(args);
-        Response res = executeRequest(get, 200, cmisValidator.getCMISAtomValidator());
+        Response res = executeRequest(get, 200);
         String xml = res.getContentAsString();
         Entry entry = appModel.parseEntry(new StringReader(xml), null);
         Assert.assertNotNull(entry);
@@ -254,7 +255,7 @@
 
     public Feed getFeed(IRI href, Map<String, String> args) throws Exception {
         Request get = new GetRequest(href.toString()).setArgs(args);
-        Response res = executeRequest(get, 200, cmisValidator.getCMISAtomValidator());
+        Response res = executeRequest(get, 200);
         Assert.assertNotNull(res);
         String xml = res.getContentAsString();
         Feed feed = appModel.parseFeed(new StringReader(xml), null);
@@ -271,7 +272,7 @@
         String createFolder = templates.load(atomEntryFile == null ? "createfolder.atomentry.xml"
: atomEntryFile);
         createFolder = createFolder.replace("${NAME}", name);
         Request req = new PostRequest(parent.toString(), createFolder, CMISConstants.MIMETYPE_ENTRY);
-        Response res = executeRequest(req, 201, cmisValidator.getCMISAtomValidator());
+        Response res = executeRequest(req, 201);
         Assert.assertNotNull(res);
         String xml = res.getContentAsString();
         Entry entry = appModel.parseEntry(new StringReader(xml), null);
@@ -299,7 +300,7 @@
         createFile = createFile.replace("${CMISCONTENT}", new String(Base64.encodeBase64(name.getBytes())));
         createFile = createFile.replace("${CONTENT}", mediaType ? new String(Base64.encodeBase64(name.getBytes()))
: name);
         Request req = new PostRequest(parent.toString(), createFile, CMISConstants.MIMETYPE_ENTRY);
-        Response res = executeRequest(req, 201, cmisValidator.getCMISAtomValidator());
+        Response res = executeRequest(req, 201);
         Assert.assertNotNull(res);
         String xml = res.getContentAsString();
         Entry entry = appModel.parseEntry(new StringReader(xml), null);
@@ -323,7 +324,7 @@
         createFile = createFile.replace("${RELTYPE}", type);
         createFile = createFile.replace("${TARGETID}", targetId);
         Request req = new PostRequest(parent.toString(), createFile, CMISConstants.MIMETYPE_ENTRY);
-        Response res = executeRequest(req, 201, cmisValidator.getCMISAtomValidator());
+        Response res = executeRequest(req, 201);
         Assert.assertNotNull(res);
         String xml = res.getContentAsString();
         Entry entry = appModel.parseEntry(new StringReader(xml), null);
@@ -336,10 +337,22 @@
         return entry;
     }
 
-    public Response executeRequest(Request req, int expectedStatus) throws IOException {
-        return executeRequest(req, expectedStatus, null);
+    public Entry moveObject(IRI destFolder, Entry atomEntry, String sourceFolderId) throws
Exception {
+        Response res = moveObjectRequest(destFolder, atomEntry, sourceFolderId, 201);
+        Assert.assertNotNull(res);
+        String xml = res.getContentAsString();
+        Entry entry = appModel.parseEntry(new StringReader(xml), null);
+        return entry;
     }
-
+    
+    public Response moveObjectRequest(IRI destFolder, Entry atomEntry, String sourceFolderId,
int expectedStatus) throws Exception {
+        Map<String, String> args = new HashMap<String, String>();
+        args.put("sourceFolderId", sourceFolderId);
+        Request req = new PostRequest(destFolder.toString(), atomEntry.toString(), CMISConstants.MIMETYPE_ENTRY).setArgs(args);
+        Response res = executeRequest(req, expectedStatus);
+        return res;
+    }
+    
     /**
      * Execute Request
      *
@@ -349,7 +362,7 @@
      * @return response
      * @throws IOException
      */
-    public Response executeRequest(Request req, int expectedStatus, Validator validator)
throws IOException {
+    public Response executeRequest(Request req, int expectedStatus) throws IOException {
         if (traceConnection) {
             messageWriter.trace("Request: " + req.getMethod() + " " + req.getFullUri()
                     + (req.getBody() == null ? "" : "\n" + new String(req.getBody(), req.getEncoding())));
@@ -365,15 +378,34 @@
         if (expectedStatus > -1)
             Assert.assertEquals("Request status for " + req.getFullUri(), expectedStatus,
res.getStatus());
 
-        if (validator != null && validate) {
-            try {
-                String resXML = res.getContentAsString();
-                assertValid(resXML, validator);
-            } catch (ParserConfigurationException e) {
-                // @TODO: Maybe make a Chemistry specific exception
-                throw new RuntimeException("Failed to validate", e);
+        if (validate) {
+            Validator mimetypeValidator = null;
+            String contentType = res.getContentType();
+            if (contentType != null) {
+                try {
+                    // @TODO: register of mappings
+                    if (contentType.startsWith(CMISConstants.MIMETYPE_ATOM)) {
+                        mimetypeValidator = getAtomValidator();
+                    }
+                    else if (contentType.startsWith(CMISConstants.MIMETYPE_APP)) {
+                        mimetypeValidator = getAppValidator();
+                    }
+                } catch(SAXException e) {}
+                
+                if (mimetypeValidator != null) {
+                    try {
+                        messageWriter.trace("Validating Response of content type " + contentType);
+                        
+                        String resXML = res.getContentAsString();
+                        assertValid(resXML, mimetypeValidator);
+                    } catch (ParserConfigurationException e) {
+                        // @TODO: Maybe make a Chemistry specific exception
+                        throw new RuntimeException("Failed to validate", e);
+                    }
+                }
             }
         }
+        
         return res;
     }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/fixture/CMISTestFixture.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/fixture/CMISTestFixture.java?rev=824848&r1=824847&r2=824848&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/fixture/CMISTestFixture.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/fixture/CMISTestFixture.java
Tue Oct 13 17:23:02 2009
@@ -112,7 +112,8 @@
 
         // do deeper, if required
         if (depth > 0) {
-            Entry subFolder = client.createFolder(childrenLink.getHref(), name, folderTemplate);
+            String folderName = name + " (depth " + (0 - depth) + ")";
+            Entry subFolder = client.createFolder(childrenLink.getHref(), folderName, folderTemplate);
             folderEntry.children.add(createTree(entry, subFolder, depth - 1, docCount, folderTemplate,
docTemplate));
         }
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/TCKTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/TCKTestSuite.java?rev=824848&r1=824847&r2=824848&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/TCKTestSuite.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/TCKTestSuite.java
Tue Oct 13 17:23:02 2009
@@ -27,6 +27,7 @@
 import org.apache.chemistry.tck.atompub.test.spec.FolderChildrenTest;
 import org.apache.chemistry.tck.atompub.test.spec.FolderHierarchyTest;
 import org.apache.chemistry.tck.atompub.test.spec.GetTest;
+import org.apache.chemistry.tck.atompub.test.spec.MoveTest;
 import org.apache.chemistry.tck.atompub.test.spec.QueryPagingTest;
 import org.apache.chemistry.tck.atompub.test.spec.QueryTest;
 import org.apache.chemistry.tck.atompub.test.spec.RepositoryServiceTest;
@@ -53,6 +54,7 @@
         suite.addTestSuite(FolderHierarchyTest.class);
         suite.addTestSuite(ContentStreamTest.class);
         suite.addTestSuite(UpdateTest.class);
+        suite.addTestSuite(MoveTest.class);
         suite.addTestSuite(QueryTest.class);
         suite.addTestSuite(QueryPagingTest.class);
         suite.addTestSuite(AllowableActionsTest.class);

Added: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/spec/MoveTest.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/spec/MoveTest.java?rev=824848&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/spec/MoveTest.java
(added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/spec/MoveTest.java
Tue Oct 13 17:23:02 2009
@@ -0,0 +1,123 @@
+/*
+ * 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.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.CMISTree;
+import org.apache.chemistry.tck.atompub.fixture.EntryTree;
+import org.junit.Assert;
+
+
+/**
+ * CMIS Move Tests
+ */
+public class MoveTest extends TCKTest {
+    
+    public void testMoveDocument() throws Exception {
+        EntryTree sourceFolder = fixture.createTestTree("sourceTree", 1, 1, null, null);
+        EntryTree destFolder = fixture.createTestTree("destTree", 1, 0, null, null);
+        
+        // assert one child in source folder
+        Link sourceChildrenLink = client.getChildrenLink(sourceFolder.entry);
+        Feed sourceChildren = client.getFeed(sourceChildrenLink.getHref());
+        Assert.assertEquals(1, sourceChildren.getEntries().size());
+        sourceFolder.walkChildren(new AssertEntryInFeedVisitor(sourceChildren));
+
+        // assert no children in dest folder
+        Link destChildrenLink = client.getChildrenLink(destFolder.entry);
+        Feed destChildren = client.getFeed(destChildrenLink.getHref());
+        Assert.assertEquals(0, destChildren.getEntries().size());
+        
+        // move document
+        CMISObject sourceFolderObject = sourceFolder.entry.getExtension(CMISConstants.OBJECT);
+        String sourceFolderId = sourceFolderObject.getObjectId().getStringValue();
+        Entry document = sourceFolder.children.get(0).entry;
+        client.moveObject(destChildrenLink.getHref(), document, sourceFolderId);
+        
+        // assert one source child in dest folder
+        Feed destChildrenAfter = client.getFeed(destChildrenLink.getHref());
+        EntryTree destFolderAfter = new CMISTree(destFolder, destChildrenAfter);
+        Assert.assertEquals(1, destChildrenAfter.getEntries().size());
+        destFolderAfter.walkChildren(new AssertEntryInFeedVisitor(sourceChildren));
+
+        // assert no children in source folder
+        Feed sourceChildrenAfter = client.getFeed(sourceChildrenLink.getHref());
+        Assert.assertEquals(0, sourceChildrenAfter.getEntries().size());
+    }
+    
+    public void testMoveFolder() throws Exception {
+        EntryTree sourceFolder = fixture.createTestTree("sourceTree", 2, 0, null, null);
+        EntryTree destFolder = fixture.createTestTree("destTree", 1, 0, null, null);
+        
+        // assert one child in source folder
+        Link sourceChildrenLink = client.getChildrenLink(sourceFolder.entry);
+        Feed sourceChildren = client.getFeed(sourceChildrenLink.getHref());
+        Assert.assertEquals(1, sourceChildren.getEntries().size());
+        sourceFolder.walkChildren(new AssertEntryInFeedVisitor(sourceChildren));
+
+        // assert no children in dest folder
+        Link destChildrenLink = client.getChildrenLink(destFolder.entry);
+        Feed destChildren = client.getFeed(destChildrenLink.getHref());
+        Assert.assertEquals(0, destChildren.getEntries().size());
+        
+        // move folder
+        CMISObject sourceFolderObject = sourceFolder.entry.getExtension(CMISConstants.OBJECT);
+        String sourceFolderId = sourceFolderObject.getObjectId().getStringValue();
+        Entry folder = sourceFolder.children.get(0).entry;
+        client.moveObject(destChildrenLink.getHref(), folder, sourceFolderId);
+        
+        // assert one source child in dest folder
+        Feed destChildrenAfter = client.getFeed(destChildrenLink.getHref());
+        EntryTree destFolderAfter = new CMISTree(destFolder, destChildrenAfter);
+        Assert.assertEquals(1, destChildrenAfter.getEntries().size());
+        destFolderAfter.walkChildren(new AssertEntryInFeedVisitor(sourceChildren));
+
+        // assert no children in source folder
+        Feed sourceChildrenAfter = client.getFeed(sourceChildrenLink.getHref());
+        Assert.assertEquals(0, sourceChildrenAfter.getEntries().size());
+    }
+
+    public void testInvalidSourceFolderId() throws Exception {
+        EntryTree sourceFolder = fixture.createTestTree("sourceTree", 1, 1, null, null);
+        EntryTree destFolder = fixture.createTestTree("destTree", 1, 0, null, null);
+        
+        // assert one child in source folder
+        Link sourceChildrenLink = client.getChildrenLink(sourceFolder.entry);
+        Feed sourceChildren = client.getFeed(sourceChildrenLink.getHref());
+        Assert.assertEquals(1, sourceChildren.getEntries().size());
+        sourceFolder.walkChildren(new AssertEntryInFeedVisitor(sourceChildren));
+
+        // assert no children in dest folder
+        Link destChildrenLink = client.getChildrenLink(destFolder.entry);
+        Feed destChildren = client.getFeed(destChildrenLink.getHref());
+        Assert.assertEquals(0, destChildren.getEntries().size());
+        
+        // move document
+        CMISObject sourceFolderObject = sourceFolder.entry.getExtension(CMISConstants.OBJECT);
+        String sourceFolderId = "invalid" + sourceFolderObject.getObjectId().getStringValue();
+        Entry document = sourceFolder.children.get(0).entry;
+        client.moveObjectRequest(destChildrenLink.getHref(), document, sourceFolderId, 400);
+    }
+
+}

Propchange: incubator/chemistry/trunk/chemistry/chemistry-tck-atompub/src/main/java/org/apache/chemistry/tck/atompub/test/spec/MoveTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message