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;
}
}
- private boolean blobCleanup() {
+ private boolean isBlobCleanup() {
return blobCleanup;
}
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.");
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.");
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;
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;
* @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
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
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
*/
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;
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;
}
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)) {
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 {
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);
}