Author: fguillaume
Date: Tue Dec 22 17:58:45 2009
New Revision: 893247
URL: http://svn.apache.org/viewvc?rev=893247&view=rev
Log:
Test AtomPub media PUT
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java?rev=893247&r1=893246&r2=893247&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
Tue Dec 22 17:58:45 2009
@@ -33,6 +33,7 @@
import org.apache.abdera.protocol.server.RequestContext;
import org.apache.abdera.protocol.server.ResponseContext;
import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.context.EmptyResponseContext;
import org.apache.abdera.protocol.server.context.ResponseContextException;
import org.apache.axiom.om.OMElement;
import org.apache.chemistry.ContentAlreadyExistsException;
@@ -197,6 +198,22 @@
}
@Override
+ public ResponseContext putMedia(RequestContext request) {
+ try {
+ String id = getResourceName(request);
+ ObjectEntry object = getEntry(id, request);
+ putMedia(object, request.getContentType(), request.getSlug(),
+ request.getInputStream(), request);
+ return buildCreateMediaResponse(getMediaLink(object.getId(),
+ request));
+ } catch (IOException e) {
+ return new EmptyResponseContext(500);
+ } catch (ResponseContextException e) {
+ return createErrorResponse(e);
+ }
+ }
+
+ @Override
public void putMedia(ObjectEntry entry, MimeType contentType, String slug,
InputStream in, RequestContext request)
throws ResponseContextException {
@@ -217,6 +234,14 @@
}
}
+ protected ResponseContext buildCreateMediaResponse(String mediaLink) {
+ EmptyResponseContext rc = new EmptyResponseContext(200);
+ rc.setLocation(mediaLink);
+ rc.setContentLocation(mediaLink);
+ rc.setStatus(201);
+ return rc;
+ }
+
@Override
public void deleteMedia(String resourceName, RequestContext request)
throws ResponseContextException {
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=893247&r1=893246&r2=893247&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
Tue Dec 22 17:58:45 2009
@@ -121,15 +121,6 @@
return rc;
}
- protected ResponseContext buildCreateMediaResponse(String mediaLink,
- Entry entry) {
- BaseResponseContext<Entry> rc = new BaseResponseContext<Entry>(entry);
- rc.setLocation(mediaLink);
- rc.setContentLocation(mediaLink);
- rc.setStatus(201);
- return rc;
- }
-
/*
* ----- CollectionInfo -----
*/
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java?rev=893247&r1=893246&r2=893247&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
Tue Dec 22 17:58:45 2009
@@ -18,6 +18,7 @@
*/
package org.apache.chemistry.atompub.server;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
@@ -66,6 +67,8 @@
public static final String TEST_FILE_CONTENT = "This is a test
file.\nTesting, testing...\n";
+ public static final String TEST_FILE_CONTENT2 =
"<html><head><title>foo</title></head><body>bar</body></html>";
+
protected static final AbderaClient client = new AbderaClient();
protected static String rootFolderId;
@@ -187,6 +190,7 @@
Element tmpl = uritmpl.getFirstChild(AtomPubCMIS.TEMPLATE);
assertNotNull(tmpl);
assertEquals(base + "/object/{id}", tmpl.getText());
+ resp.release();
}
public void testTypes() throws Exception {
@@ -194,6 +198,7 @@
assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element el = resp.getDocument().getRoot();
assertNotNull(el);
+ resp.release();
}
public void testChildren() throws Exception {
@@ -201,6 +206,7 @@
assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element ch = resp.getDocument().getRoot();
assertNotNull(ch);
+ resp.release();
resp = client.get(base + "/children/"
+ repository.getInfo().getRootFolderId().getId() + "?"
@@ -208,6 +214,7 @@
assertEquals(HttpStatus.SC_OK, resp.getStatus());
ch = resp.getDocument().getRoot();
assertNotNull(ch);
+ resp.release();
// post of new document
PostMethod postMethod = new PostMethod(base + "/children/"
@@ -219,7 +226,7 @@
assertEquals(HttpStatus.SC_CREATED, status);
assertNotNull(postMethod.getResponseHeader(HttpHeaders.LOCATION));
assertNotNull(postMethod.getResponseHeader(HttpHeaders.CONTENT_LOCATION));
-
+ postMethod.releaseConnection();
}
public void testObject() throws Exception {
@@ -227,12 +234,14 @@
assertEquals(HttpStatus.SC_OK, resp.getStatus());
Element ob = resp.getDocument().getRoot();
assertNotNull(ob);
+ resp.release();
resp = client.get(base + "/object/" + doc3id + '?'
+ AtomPubCMIS.PARAM_FILTER + "=cmis:name");
assertEquals(HttpStatus.SC_OK, resp.getStatus());
ob = resp.getDocument().getRoot();
assertNotNull(ob);
+ resp.release();
// update
RequestOptions options = new RequestOptions();
@@ -242,6 +251,7 @@
assertEquals(HttpStatus.SC_OK, resp.getStatus());
ob = resp.getDocument().getRoot();
assertNotNull(ob);
+ resp.release();
}
public void testFile() throws Exception {
@@ -261,6 +271,28 @@
status = new HttpClient().executeMethod(method);
assertEquals(HttpStatus.SC_CONFLICT, status);
method.releaseConnection();
+
+ // put file (
+ RequestOptions options = new RequestOptions();
+ options.setContentType("text/html");
+ InputStream is = new
ByteArrayInputStream(TEST_FILE_CONTENT2.getBytes());
+ ClientResponse resp = client.put(base + "/file/" + doc2id, is,
options);
+ assertEquals(HttpStatus.SC_CREATED, resp.getStatus());
+ assertNotNull(resp.getLocation());
+ assertNotNull(resp.getContentLocation());
+ resp.release();
+
+ // get it again
+ method = new GetMethod(base + "/file/" + doc2id);
+ status = new HttpClient().executeMethod(method);
+ assertEquals(HttpStatus.SC_OK, status);
+ assertEquals("text/html",
+ method.getResponseHeader("Content-Type").getValue());
+ assertEquals(String.valueOf(TEST_FILE_CONTENT2.getBytes().length),
+ method.getResponseHeader("Content-Length").getValue());
+ body = method.getResponseBody();
+ assertEquals(TEST_FILE_CONTENT2, new String(body, "UTF-8"));
+ method.releaseConnection();
}
public void testQuery() throws Exception {
@@ -270,6 +302,7 @@
assertEquals(HttpStatus.SC_CREATED, resp.getStatus());
Element res = resp.getDocument().getRoot();
assertNotNull(res);
+ resp.release();
}
protected InputStream load(String resource) throws Exception {