Permalink
Browse files

Merge pull request #59 from WindowsAzure/dev

Dev
  • Loading branch information...
2 parents 57dba1e + be3e551 commit 1fc20d543a6b0f5891a44067ec23b2c8f0d0228c Albert Cheng committed Dec 13, 2012
@@ -100,6 +100,17 @@ public LinkInfo getLink(String rel) {
}
/**
+ * 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
*
* @return List of the links.
@@ -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 @@
@XmlElement(name = "TemplateId", namespace = Constants.ODATA_DATA_NS)
protected String templateId;
- /** The output media assets. */
- protected List<String> outputMediaAssets;
-
- /** The input media assets. */
- protected List<String> inputMediaAssets;
-
/** The tasks. */
@XmlElement(name = "TaskBody", namespace = Constants.ODATA_DATA_NS)
protected String taskBody;
@@ -281,46 +274,6 @@ public JobType setTemplateId(String templateId) {
}
/**
- * Gets the output media assets.
- *
- * @return the output media assets
- */
- public List<String> getOutputMediaAssets() {
- return outputMediaAssets;
- }
-
- /**
- * Sets the output media assets.
- *
- * @param uriList
- * the new output media assets
- */
- public JobType setOutputMediaAssets(List<String> outputMediaAssets) {
- this.outputMediaAssets = outputMediaAssets;
- return this;
- }
-
- /**
- * Gets the input media assets.
- *
- * @return the input media assets
- */
- public List<String> getInputMediaAssets() {
- return inputMediaAssets;
- }
-
- /**
- * Sets the input media assets.
- *
- * @param uriList
- * the new input media assets
- */
- public JobType setInputMediaAssets(List<String> inputMediaAssets) {
- this.inputMediaAssets = inputMediaAssets;
- return this;
- }
-
- /**
* Gets the tasks.
*
* @return the tasks
@@ -184,6 +184,18 @@ public Creator setState(AssetState state) {
}
/**
+ * 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<AssetInfo> list(LinkInfo link) {
+ return new DefaultListOperation<AssetInfo>(link.getHref(), new GenericType<ListResult<AssetInfo>>() {
+ });
+ }
+
+ /**
* Create an operation that will update the given asset.
*
* @param assetId
@@ -62,7 +62,7 @@ private Job() {
}
/**
- * Creates the.
+ * Creates an operation to create a new job.
*
* @param serviceUri
* the service uri
@@ -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<String> 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<String> 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");
}
}
@@ -55,13 +55,12 @@
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<String> inputMediaAssets, List<String> 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<String> inputMediaAssets = null;
- List<String> 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<String> inputMediaAssets = null;
- List<String> 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<String> inputMediaAssets = null;
- List<String> 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<AssetInfo> inputs = service.list(Asset.list(actualJob.getInputAssetsLink()));
+ ListResult<AssetInfo> 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));
+ }
}
@@ -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<AssetInfo> 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<LinkType> linkElement = new JAXBElement<LinkType>(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<ContentType>(Constants.ATOM_CONTENT_ELEMENT_NAME, ContentType.class, contentWrapper));
+ return contentWrapper;
+ }
}
@@ -284,15 +284,7 @@ public boolean isJobFinished(JobInfo initialJobInfo) throws ServiceException {
}
public List<AssetInfo> getJobOutputMediaAssets(JobInfo job) throws ServiceException {
- List<String> outputMediaAssets = job.getOutputMediaAssets();
- if (outputMediaAssets == null) {
- return null;
- }
- List<AssetInfo> ret = new ArrayList<AssetInfo>();
- for (String assetId : outputMediaAssets) {
- ret.add(service.get(Asset.get(assetId)));
- }
- return ret;
+ return service.list(Asset.list(job.getOutputAssetsLink()));
}
// Process

0 comments on commit 1fc20d5

Please sign in to comment.