]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3598: Media and Blob tests needed to create example media data in the "Nightly...
authorRichard Millet <richard.millet@berkeley.edu>
Thu, 24 Feb 2011 00:37:33 +0000 (00:37 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Thu, 24 Feb 2011 00:37:33 +0000 (00:37 +0000)
services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java
services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java
services/media/client/src/main/java/org/collectionspace/services/client/MediaClient.java
services/media/client/src/main/java/org/collectionspace/services/client/MediaProxy.java
services/media/client/src/test/java/org/collectionspace/services/client/test/MediaServiceTest.java
services/media/client/src/test/resources/blobs/03-31-09_1404.jpg [new file with mode: 0644]
services/media/service/src/main/java/org/collectionspace/services/media/MediaResource.java

index 8867531fc36abf162d374caf6f1b76386cdb4c22..d766f4549109bdc6ed3d4048edb7e69a08cb689e 100644 (file)
@@ -57,7 +57,6 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
     private final String CLASS_NAME = BlobServiceTest.class.getName();
     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
     private String knownResourceId = null;
-    private static final String BLOBS_DIR = "blobs";
     
     private boolean blobCleanup = true;
 
@@ -96,7 +95,7 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
        }
     }
     
-    private boolean blobCleanup() {
+    private boolean isBlobCleanup() {
        return blobCleanup;
     }
     
@@ -129,14 +128,16 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
                File[] children = blobsDir.listFiles();
                if (children != null && children.length > 0) {
                        for (File child : children) {
-                               String mimeType = this.getMimeType(child);
-                               logger.debug("Processing file URI: " + child.getAbsolutePath());
-                               logger.debug("MIME type is: " + mimeType);
-                           ClientResponse<Response> res = client.createBlobFromURI(child.getAbsolutePath());
-                           assertStatusCode(res, testName);
-                           if (blobCleanup == true) {
-                               allResourceIdsCreated.add(extractId(res));
-                           }
+                               if (child.isHidden() == false) {
+                                       String mimeType = this.getMimeType(child);
+                                       logger.debug("Processing file URI: " + child.getAbsolutePath());
+                                       logger.debug("MIME type is: " + mimeType);
+                                   ClientResponse<Response> res = client.createBlobFromURI(child.getAbsolutePath());
+                                   assertStatusCode(res, testName);
+                                   if (isBlobCleanup() == true) {
+                                       allResourceIdsCreated.add(extractId(res));
+                                   }
+                               }
                        }
                } else {
                        logger.debug("Directory: " + blobsDirPath + " is empty or cannot be read.");
@@ -160,16 +161,18 @@ public class BlobServiceTest extends AbstractServiceTestImpl {
                File[] children = blobsDir.listFiles();
                if (children != null && children.length > 0) {
                        for (File child : children) {
-                               String mimeType = this.getMimeType(child);
-                               logger.debug("Posting file: " + child.getAbsolutePath());
-                               logger.debug("MIME type is: " + mimeType);
-                           MultipartFormDataOutput form = new MultipartFormDataOutput();
-                           OutputPart outputPart = form.addFormData("file", child, MediaType.valueOf(mimeType));
-                           ClientResponse<Response> res = client.createBlobFromFormData(form);
-                           assertStatusCode(res, testName);
-                           if (blobCleanup == true) {
-                               allResourceIdsCreated.add(extractId(res));
-                           }
+                               if (child.isHidden() == false) {
+                                       String mimeType = this.getMimeType(child);
+                                       logger.debug("Posting file: " + child.getAbsolutePath());
+                                       logger.debug("MIME type is: " + mimeType);
+                                   MultipartFormDataOutput form = new MultipartFormDataOutput();
+                                   OutputPart outputPart = form.addFormData("file", child, MediaType.valueOf(mimeType));
+                                   ClientResponse<Response> res = client.createBlobFromFormData(form);
+                                   assertStatusCode(res, testName);
+                                   if (blobCleanup == true) {
+                                       allResourceIdsCreated.add(extractId(res));
+                                   }
+                               }
                        }
                } else {
                        logger.debug("Directory: " + blobsDirPath + " is empty or cannot be read.");
index acd7dae5afca02a2828746abbff40076196fcbee..42be818d19486f586be582a9bf14ad9217751489 100644 (file)
@@ -69,9 +69,12 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements
     static protected final String RESOURCE_PATH = "src" + File.separator +
        "test" + File.separator +
        "resources";
+    protected static final String BLOBS_DIR = "blobs";
+
     static protected final String DEFAULT_MIME = "application/octet-stream; charset=ISO-8859-1";
     static private final String NO_TEST_CLEANUP = "noTestCleanup";
     static protected final String NO_BLOB_CLEANUP = "noBlobCleanup";
+    static protected final String NO_MEDIA_CLEANUP = "noMediaCleanup";
 
     protected String getMimeType(File theFile) {
        String result = null;
index a10b346693a74dcbb2615ebfabd6e241c473a889..6516d2f06a3b8fb5092973eb3fd8fff123667b64 100644 (file)
@@ -24,6 +24,7 @@ import org.collectionspace.services.jaxb.AbstractCommonList;
 
 import org.jboss.resteasy.client.ProxyFactory;
 import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput;
 import org.jboss.resteasy.client.ClientResponse;
 import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor;
 //import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
@@ -128,10 +129,20 @@ public class MediaClient extends AbstractServiceClientImpl {
      * @return
      *
      */
-    public ClientResponse<Response> createBlob(String csid, String blobUri) {
-        return mediaProxy.createBlob(csid, blobUri);
+    public ClientResponse<Response> createBlobFromFormData(String csid,
+               MultipartFormDataOutput formDataOutput) {
+        return mediaProxy.createBlobFromFormData(csid, formDataOutput);
     }    
 
+    /**
+     * @param media
+     * @return
+     *
+     */
+    public ClientResponse<Response> createBlobFromUri(String csid, String blobUri) {
+        return mediaProxy.createBlobFromUri(csid, blobUri);
+    }    
+    
     /**
      * @param csid
      * @param media
index 28d97631e1372b2ca20a364a2cf18e2b1bc1c611..89bd4580b243c32adeaa1714bfa4f8da0076c865 100644 (file)
@@ -17,13 +17,14 @@ import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
 import org.collectionspace.services.client.BlobClient;
 import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput;
 
 /**
  * @version $Revision: 2108 $
  */
 @Path(MediaClient.SERVICE_PATH + "/")
-@Produces({"application/xml", "multipart/mixed"})
-@Consumes({"application/xml", "multipart/mixed"})
+@Produces("application/xml")
+@Consumes("application/xml")
 public interface MediaProxy extends CollectionSpaceProxy {
 
     //(C)reate
@@ -31,9 +32,14 @@ public interface MediaProxy extends CollectionSpaceProxy {
     ClientResponse<Response> create(byte[] xmlPayload);
     
     @POST
-    @Path("{csid}")
-    @Produces("multipart/form-data")    
-    ClientResponse<Response>createBlob(@PathParam("csid") String csid,
+    @Path("/{csid}")
+    @Consumes("multipart/form-data")
+    ClientResponse<Response> createBlobFromFormData(String csid,
+               MultipartFormDataOutput formDataOutput);
+    
+    @POST
+    @Path("/{csid}")
+    ClientResponse<Response>createBlobFromUri(@PathParam("csid") String csid,
                @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri);
 
     //(R)ead
index 84fe26d9ac42da5b43040d37539d63258fb0b72c..ca8c9779438425fe30ac2ba48d40a71da25c8e03 100644 (file)
@@ -22,6 +22,7 @@
  */
 package org.collectionspace.services.client.test;
 
+import java.io.File;
 import java.util.List;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
@@ -53,6 +54,28 @@ public class MediaServiceTest extends AbstractServiceTestImpl {
     private final Logger logger = LoggerFactory.getLogger(MediaServiceTest.class);
     private String knownResourceId = null;
 
+    private boolean mediaCleanup = true;
+    
+    /**
+     * Sets up create tests.
+     */
+    @Override
+       protected void setupCreate() {
+        super.setupCreate();
+        String noMediaCleanup = System.getProperty(NO_MEDIA_CLEANUP);
+       if(Boolean.TRUE.toString().equalsIgnoreCase(noMediaCleanup)) {
+               //
+               // Don't delete the blobs that we created during the test cycle
+               //
+            this.mediaCleanup = false;
+       }
+    }
+    
+    private boolean isMediaCleanup() {
+       return mediaCleanup;
+    }
+
+    
     @Override
        public String getServicePathComponent() {
                return MediaClient.SERVICE_PATH_COMPONENT;
@@ -88,6 +111,51 @@ public class MediaServiceTest extends AbstractServiceTestImpl {
         }
         allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run.
     }
+
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
+    public void createWithBlobUri(String testName) throws Exception {
+        logger.debug(testBanner(testName, CLASS_NAME));
+        
+        setupCreate();
+        MediaClient client = new MediaClient();
+        PoxPayloadOut multipart = createMediaInstance(createIdentifier());
+        ClientResponse<Response> mediaRes = client.create(multipart);
+        assertStatusCode(mediaRes, testName);
+        String mediaCsid = extractId(mediaRes);
+        
+        String currentDir = this.getResourceDir();
+        String blobsDirPath = currentDir + File.separator + BLOBS_DIR;
+        File blobsDir = new File(blobsDirPath);
+        if (blobsDir != null && blobsDir.exists()) {
+               File[] children = blobsDir.listFiles();
+               if (children != null && children.length > 0) {
+                       File blobFile = null;
+                       for (File child : children) {
+                               if (child.isHidden() == false) {
+                                       blobFile = child;
+                                       break;
+                               }
+                       }
+                       if (blobFile != null) {
+                               String mimeType = this.getMimeType(blobFile);
+                               logger.debug("Processing file URI: " + blobFile.getAbsolutePath());
+                               logger.debug("MIME type is: " + mimeType);
+                           ClientResponse<Response> res = client.createBlobFromUri(mediaCsid, blobFile.getAbsolutePath());
+                           assertStatusCode(res, testName);
+                           if (isMediaCleanup() == true) {
+                               allResourceIdsCreated.add(extractId(res));
+                               allResourceIdsCreated.add(mediaCsid);
+                           }
+                       } else {
+                               logger.debug("Directory: " + blobsDirPath + " contains no readable files.");
+                       }
+               } else {
+                       logger.debug("Directory: " + blobsDirPath + " is empty or cannot be read.");
+               }
+        } else {
+               logger.debug("Directory: " + blobsDirPath + " is missing or cannot be read.");
+        }        
+    }
     
 //    String noTest = System.getProperty("noTestCleanup");
 //     if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
diff --git a/services/media/client/src/test/resources/blobs/03-31-09_1404.jpg b/services/media/client/src/test/resources/blobs/03-31-09_1404.jpg
new file mode 100644 (file)
index 0000000..f245278
Binary files /dev/null and b/services/media/client/src/test/resources/blobs/03-31-09_1404.jpg differ
index 068b1e66c80fd58c69824d0fb407b3444137112c..24a14ff7ec500ca394c0e2898df8cccbeaed8cf6 100644 (file)
@@ -114,39 +114,38 @@ public class MediaResource extends ResourceBase {
     public Class<MediaCommon> getCommonPartClass() {
        return MediaCommon.class;
     }
-
+    
     @POST
-    @Override
-    public Response create(@Context UriInfo ui,
-               String xmlPayload) {
+    @Path("{csid}")
+    public Response createBlobWithUri(@PathParam("csid") String csid,
+               @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri) {
        Response response = null;
        PoxPayloadIn input = null;
-       MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-       String blobUri = queryParams.getFirst(BlobClient.BLOB_URI_PARAM);
        
        try {
-               if (blobUri != null) {
-                       ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(BlobUtil.BLOB_RESOURCE_NAME, input);
-                       BlobInput blobInput = BlobUtil.getBlobInput(ctx);
-                       blobInput.createBlobFile(blobUri);
-                       response = this.create(input, ctx);
-               } else {
-                       response = super.create(ui, xmlPayload);
-               }
+               ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(BlobUtil.BLOB_RESOURCE_NAME, input);
+               BlobInput blobInput = BlobUtil.getBlobInput(ctx);
+               blobInput.createBlobFile(blobUri);
+               response = this.create(input, ctx);
+               //
+               // Next, update the Media record to be linked to the blob
+               //
+               ServiceContext<PoxPayloadIn, PoxPayloadOut> mediaContext = createServiceContext();
+               BlobUtil.setBlobInput(mediaContext, blobInput); //and put the blobInput into the Media context
+               response = this.update(csid, input, mediaContext);
        } catch (Exception e) {
                throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
        }
-                       
+
                return response;
     }    
-    
+        
     @POST
     @Path("{csid}")
     @Consumes("multipart/form-data")
-    @Produces("application/xml")
     public Response createBlob(@Context HttpServletRequest req,
-               @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri,
-               @PathParam("csid") String csid) {
+               @PathParam("csid") String csid,
+               @QueryParam(BlobClient.BLOB_URI_PARAM) String blobUri) { //FIXME: REM - Do we really need the blobUri query param here?
        PoxPayloadIn input = null;
        Response response = null;       
        try {
@@ -163,7 +162,6 @@ public class MediaResource extends ResourceBase {
                ServiceContext<PoxPayloadIn, PoxPayloadOut> mediaContext = createServiceContext();
                BlobUtil.setBlobInput(mediaContext, blobInput); //and put the blobInput into the Media context
                this.update(csid, input, mediaContext);
-
        } catch (Exception e) {
                throw bigReThrow(e, ServiceMessages.CREATE_FAILED);
        }