From 91fdd2225892480fa09acf21744d111f5b948535 Mon Sep 17 00:00:00 2001 From: Chris Tavares Date: Thu, 13 Dec 2012 09:46:04 -0800 Subject: [PATCH] Can now list input and output assets for jobs --- .../media/implementation/ODataEntity.java | 11 ++++ .../media/implementation/content/JobType.java | 47 ---------------- .../services/media/models/Asset.java | 12 +++++ .../services/media/models/Job.java | 2 +- .../services/media/models/JobInfo.java | 25 +++++---- .../services/media/JobIntegrationTest.java | 49 ++++++++++------- .../media/models/AssetEntityTest.java | 54 +++++++++++++++++++ .../scenarios/MediaServiceWrapper.java | 10 +--- 8 files changed, 122 insertions(+), 88 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java index fa1a382f7211..fac9d627b782 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java @@ -99,6 +99,17 @@ public LinkInfo getLink(String rel) { return null; } + /** + * Get the link to navigate an OData relationship + * + * @param relationName + * name of the OData relationship + * @return the link if found, null if not. + */ + public LinkInfo getRelationLink(String relationName) { + return getLink(Constants.ODATA_DATA_NS + "/related/" + relationName); + } + /** * Return the links from this entry * diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java index eb274041985f..6ae248b7e5db 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/JobType.java @@ -16,7 +16,6 @@ package com.microsoft.windowsazure.services.media.implementation.content; import java.util.Date; -import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -70,12 +69,6 @@ public class JobType implements MediaServiceDTO { @XmlElement(name = "TemplateId", namespace = Constants.ODATA_DATA_NS) protected String templateId; - /** The output media assets. */ - protected List outputMediaAssets; - - /** The input media assets. */ - protected List inputMediaAssets; - /** The tasks. */ @XmlElement(name = "TaskBody", namespace = Constants.ODATA_DATA_NS) protected String taskBody; @@ -280,46 +273,6 @@ public JobType setTemplateId(String templateId) { return this; } - /** - * Gets the output media assets. - * - * @return the output media assets - */ - public List getOutputMediaAssets() { - return outputMediaAssets; - } - - /** - * Sets the output media assets. - * - * @param uriList - * the new output media assets - */ - public JobType setOutputMediaAssets(List outputMediaAssets) { - this.outputMediaAssets = outputMediaAssets; - return this; - } - - /** - * Gets the input media assets. - * - * @return the input media assets - */ - public List getInputMediaAssets() { - return inputMediaAssets; - } - - /** - * Sets the input media assets. - * - * @param uriList - * the new input media assets - */ - public JobType setInputMediaAssets(List inputMediaAssets) { - this.inputMediaAssets = inputMediaAssets; - return this; - } - /** * Gets the tasks. * diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java index e736b536d9e0..a82eb3edd1d1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java @@ -183,6 +183,18 @@ public static EntityListOperation list(MultivaluedMap }, queryParameters); } + /** + * Create an operation that will list all the assets at the given link. + * + * @param link + * Link to request assets from. + * @return The list operation. + */ + public static EntityListOperation list(LinkInfo link) { + return new DefaultListOperation(link.getHref(), new GenericType>() { + }); + } + /** * Create an operation that will update the given asset. * diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java index 9bc5d0519cd8..fb6d50b632ba 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Job.java @@ -62,7 +62,7 @@ private Job() { } /** - * Creates the. + * Creates an operation to create a new job. * * @param serviceUri * the service uri diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java index 23f9c36de43e..f4c6c97f2711 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java @@ -16,7 +16,6 @@ package com.microsoft.windowsazure.services.media.models; import java.util.Date; -import java.util.List; import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; @@ -130,29 +129,29 @@ public String getTemplateId() { } /** - * Gets the input media assets. + * Gets the task body. * - * @return the input media assets + * @return the task body */ - public List getInputMediaAssets() { - return getContent().getInputMediaAssets(); + public String getTaskBody() { + return getContent().getTaskBody(); } /** - * Gets the output media assets. + * Get a link which, when listed, will return the input assets for the job * - * @return the output media assets + * @return Link if found, null if not. */ - public List getOutputMediaAssets() { - return getContent().getOutputMediaAssets(); + public LinkInfo getInputAssetsLink() { + return getRelationLink("InputMediaAssets"); } /** - * Gets the task body. + * Get a link which, when listed, will return the output assets for the job * - * @return the task body + * @return Link if found, null if not. */ - public String getTaskBody() { - return getContent().getTaskBody(); + public LinkInfo getOutputAssetsLink() { + return getRelationLink("OutputMediaAssets"); } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index bfa003d0cc98..96f4fe07a3d8 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -55,13 +55,12 @@ public class JobIntegrationTest extends IntegrationTestBase { private void verifyJobInfoEqual(String message, JobInfo expected, JobInfo actual) { verifyJobProperties(message, expected.getName(), expected.getPriority(), expected.getRunningDuration(), expected.getState(), expected.getTemplateId(), expected.getCreated(), expected.getLastModified(), - expected.getStartTime(), expected.getEndTime(), expected.getInputMediaAssets(), - expected.getOutputMediaAssets(), actual); + expected.getStartTime(), expected.getEndTime(), actual); } private void verifyJobProperties(String message, String testName, Integer priority, Double runningDuration, JobState state, String templateId, Date created, Date lastModified, Date startTime, Date endTime, - List inputMediaAssets, List outputMediaAssets, JobInfo actualJob) { + JobInfo actualJob) { assertNotNull(message, actualJob); assertNotNull(message + "Id", actualJob.getId()); @@ -78,11 +77,6 @@ private void verifyJobProperties(String message, String testName, Integer priori assertDateApproxEquals(message + " StartTime", startTime, actualJob.getStartTime()); assertDateApproxEquals(message + " EndTime", endTime, actualJob.getEndTime()); - // TODO: Add test for accessing the input and output media assets when fixed: - // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/508 - assertEquals(message + " InputMediaAssets", inputMediaAssets, actualJob.getInputMediaAssets()); - assertEquals(message + " OutputMediaAssets", outputMediaAssets, actualJob.getOutputMediaAssets()); - // TODO: Add test for accessing the tasks when fixed: // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/531 } @@ -139,8 +133,6 @@ public void createJobSuccess() throws Exception { double duration = 0.0; JobState state = JobState.Queued; String templateId = null; - List inputMediaAssets = null; - List outputMediaAssets = null; Date created = new Date(); Date lastModified = new Date(); Date stateTime = null; @@ -152,7 +144,7 @@ public void createJobSuccess() throws Exception { // Assert verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, - endTime, inputMediaAssets, outputMediaAssets, actualJob); + endTime, actualJob); } @Test @@ -163,8 +155,6 @@ public void createJobTwoTasksSuccess() throws Exception { double duration = 0.0; JobState state = JobState.Queued; String templateId = null; - List inputMediaAssets = null; - List outputMediaAssets = null; Date created = new Date(); Date lastModified = new Date(); Date stateTime = null; @@ -179,7 +169,7 @@ public void createJobTwoTasksSuccess() throws Exception { // Assert verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, - endTime, inputMediaAssets, outputMediaAssets, actualJob); + endTime, actualJob); } @Test @@ -190,8 +180,6 @@ public void getJobSuccess() throws Exception { double duration = 0.0; JobState state = JobState.Queued; String templateId = null; - List inputMediaAssets = null; - List outputMediaAssets = null; String jobId = createJob(name).getId(); Date created = new Date(); Date lastModified = new Date(); @@ -203,7 +191,7 @@ public void getJobSuccess() throws Exception { // Assert verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, - endTime, inputMediaAssets, outputMediaAssets, actualJob); + endTime, actualJob); } @Test @@ -296,7 +284,7 @@ public void deleteJobSuccess() throws ServiceException { } @Test - public void deleteJobIvalidIdFail() throws ServiceException { + public void deleteJobInvalidIdFail() throws ServiceException { // Arrange expectedException.expect(ServiceException.class); expectedException.expect(new ServiceExceptionMatcher(400)); @@ -306,4 +294,29 @@ public void deleteJobIvalidIdFail() throws ServiceException { // Assert } + + @Test + public void canGetInputOutputAssetsFromJob() throws Exception { + String name = testJobPrefix + "canGetInputOutputAssetsFromJob"; + int priority = 3; + double duration = 0.0; + JobState state = JobState.Queued; + String templateId = null; + Date created = new Date(); + Date lastModified = new Date(); + Date stateTime = null; + Date endTime = null; + + JobInfo actualJob = service.create(Job.create(service.getRestServiceUri()).setName(name).setPriority(priority) + .addInputMediaAsset(assetInfo.getId()).addTaskCreator(getTaskCreator(0))); + + ListResult inputs = service.list(Asset.list(actualJob.getInputAssetsLink())); + ListResult outputs = service.list(Asset.list(actualJob.getOutputAssetsLink())); + + assertEquals(1, inputs.size()); + assertEquals(assetInfo.getId(), inputs.get(0).getId()); + + assertEquals(1, outputs.size()); + assertTrue(outputs.get(0).getName().contains(name)); + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java index 5ec15ac69f1a..9c5fcc892eeb 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java @@ -20,10 +20,17 @@ import java.net.URLEncoder; import javax.ws.rs.core.MultivaluedMap; +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; import org.junit.Test; +import com.microsoft.windowsazure.services.media.implementation.atom.ContentType; +import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; +import com.microsoft.windowsazure.services.media.implementation.atom.LinkType; import com.microsoft.windowsazure.services.media.implementation.content.AssetType; +import com.microsoft.windowsazure.services.media.implementation.content.Constants; +import com.microsoft.windowsazure.services.media.implementation.content.JobType; import com.microsoft.windowsazure.services.media.implementation.entities.EntityDeleteOperation; import com.microsoft.windowsazure.services.media.implementation.entities.EntityGetOperation; import com.microsoft.windowsazure.services.media.implementation.entities.EntityListOperation; @@ -130,4 +137,51 @@ public void assetDeleteReturnsExpectedUri() throws Exception { assertEquals(expectedUri, deleter.getUri()); } + private static final String expectedOutputAsset = "Job(someJobId)/OutputAssets"; + private static final String expectedInputAsset = "Job(someJobId)/InputAssets"; + + @Test + public void listForLinkReturnsExpectedUri() throws Exception { + JobInfo fakeJob = createJob(); + + EntityListOperation lister = Asset.list(fakeJob.getInputAssetsLink()); + + assertEquals(lister.getUri(), expectedInputAsset); + } + + private JobInfo createJob() { + EntryType fakeJobEntry = new EntryType(); + addEntryLink(fakeJobEntry, Constants.ODATA_DATA_NS + "/related/OutputMediaAssets", expectedOutputAsset, + "application/atom+xml;type=feed", "OutputAssets"); + addEntryLink(fakeJobEntry, Constants.ODATA_DATA_NS + "/related/InputMediaAssets", expectedInputAsset, + "application/atom+xml;type=feed", "InputAssets"); + + JobType payload = new JobType().setId("SomeId").setName("FakeJob"); + addEntryContent(fakeJobEntry, payload); + + return new JobInfo(fakeJobEntry, payload); + } + + private void addEntryLink(EntryType entry, String rel, String href, String type, String title) { + LinkType link = new LinkType(); + link.setRel(rel); + link.setHref(href); + link.setType(type); + link.setTitle(title); + + JAXBElement linkElement = new JAXBElement(new QName("link", Constants.ATOM_NS), + LinkType.class, link); + entry.getEntryChildren().add(linkElement); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private ContentType addEntryContent(EntryType entry, Object content) { + ContentType contentWrapper = new ContentType(); + contentWrapper.getContent().add( + new JAXBElement(Constants.ODATA_PROPERTIES_ELEMENT_NAME, content.getClass(), content)); + + entry.getEntryChildren().add( + new JAXBElement(Constants.ATOM_CONTENT_ELEMENT_NAME, ContentType.class, contentWrapper)); + return contentWrapper; + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java index c0d85220473e..0cc41917282f 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java @@ -284,15 +284,7 @@ public boolean isJobFinished(JobInfo initialJobInfo) throws ServiceException { } public List getJobOutputMediaAssets(JobInfo job) throws ServiceException { - List outputMediaAssets = job.getOutputMediaAssets(); - if (outputMediaAssets == null) { - return null; - } - List ret = new ArrayList(); - for (String assetId : outputMediaAssets) { - ret.add(service.get(Asset.get(assetId))); - } - return ret; + return service.list(Asset.list(job.getOutputAssetsLink())); } // Process