Skip to content

Commit

Permalink
Merge pull request Azure#21 from jcookems/fix593
Browse files Browse the repository at this point in the history
Fix593
  • Loading branch information
jcookems committed Jan 9, 2013
2 parents 5d4e644 + c07e6f7 commit 6460f54
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public LinkInfo getLocatorsLink() {
* @return the link
*/
public LinkInfo getParentAssetsLink() {
// TODO: NEEDS TESTS once we figure out how to create assets with parents
return getRelationLink("ParentAssets");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
import com.microsoft.windowsazure.services.media.implementation.content.JobType;

// TODO: Auto-generated Javadoc
/**
* The Class JobInfo.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
import com.microsoft.windowsazure.services.media.implementation.content.MediaProcessorType;

// TODO: Auto-generated Javadoc
/**
* Data about a Media Processor entity.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public void canCreateAccessPolicyWithReadPermissions() throws Exception {
verifyPolicyProperties("policy", testName, duration, AccessPolicyPermission.READ, policy);
}

// TODO: Null name or duration?

@Test
public void canGetSinglePolicyById() throws Exception {
String expectedName = testPolicyPrefix + "GetOne";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,38 @@

import static org.junit.Assert.*;

import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;

import org.junit.Test;

import com.microsoft.windowsazure.services.core.ServiceException;
import com.microsoft.windowsazure.services.media.models.AccessPolicy;
import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo;
import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission;
import com.microsoft.windowsazure.services.media.models.Asset;
import com.microsoft.windowsazure.services.media.models.AssetFile;
import com.microsoft.windowsazure.services.media.models.AssetInfo;
import com.microsoft.windowsazure.services.media.models.AssetOption;
import com.microsoft.windowsazure.services.media.models.AssetState;
import com.microsoft.windowsazure.services.media.models.ContentKey;
import com.microsoft.windowsazure.services.media.models.ContentKeyInfo;
import com.microsoft.windowsazure.services.media.models.ContentKeyType;
import com.microsoft.windowsazure.services.media.models.Job;
import com.microsoft.windowsazure.services.media.models.JobInfo;
import com.microsoft.windowsazure.services.media.models.LinkInfo;
import com.microsoft.windowsazure.services.media.models.ListResult;
import com.microsoft.windowsazure.services.media.models.Locator;
import com.microsoft.windowsazure.services.media.models.LocatorInfo;
import com.microsoft.windowsazure.services.media.models.LocatorType;
import com.microsoft.windowsazure.services.media.models.Task;
import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation;

public class AssetIntegrationTest extends IntegrationTestBase {

Expand Down Expand Up @@ -301,4 +316,43 @@ public void linkAssetContentKeyInvalidIdFailed() throws ServiceException, URISyn

// Assert
}

@Test
public void canGetParentBackFromAsset() throws ServiceException, InterruptedException {
// Arrange
String originalAssetName = testAssetPrefix + "canGetParentBackFromAsset";
AssetInfo originalAsset = service.create(Asset.create().setName(originalAssetName));

int durationInMinutes = 10;
AccessPolicyInfo accessPolicyInfo = service.create(AccessPolicy.create(testPolicyPrefix
+ "uploadAesPortectedAssetSuccess", durationInMinutes, EnumSet.of(AccessPolicyPermission.WRITE)));

LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfo.getId(), originalAsset.getId(),
LocatorType.SAS));
WritableBlobContainerContract blobWriter = service.createBlobWriter(locatorInfo);

InputStream mpeg4H264InputStream = getClass().getResourceAsStream("/media/MPEG4-H264.mp4");
blobWriter.createBlockBlob("MPEG4-H264.mp4", mpeg4H264InputStream);
service.action(AssetFile.createFileInfos(originalAsset.getId()));

String jobName = testJobPrefix + "createJobSuccess";
CreateBatchOperation taskCreator = Task
.create("nb:mpid:UUID:2f381738-c504-4e4a-a38e-d199e207fcd5",
"<taskBody>" + "<inputAsset>JobInputAsset(0)</inputAsset>"
+ "<outputAsset>JobOutputAsset(0)</outputAsset>" + "</taskBody>")
.setConfiguration("H.264 256k DSL CBR").setName("My encoding Task");
JobInfo jobInfo = service.create(Job.create().setName(jobName).addInputMediaAsset(originalAsset.getId())
.addTaskCreator(taskCreator));

// Act
ListResult<AssetInfo> outputAssets = service.list(Asset.list(jobInfo.getOutputAssetsLink()));
assertEquals(1, outputAssets.size());
AssetInfo childAsset = outputAssets.get(0);

LinkInfo parentAssetLink = childAsset.getParentAssetsLink();
AssetInfo parentAsset = service.get(Asset.get(parentAssetLink));

// Assert
assertEquals(originalAsset.getId(), parentAsset.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public static void cleanup() throws Exception {
}

private static void cleanupEnvironment() {
// TODO: This should be removed once cascade delete is implemented for Assets.
// But for now, trying to delete an asset with fail if there are any
// existing Locators associated with it.
removeAllTestLocators();
removeAllTestAssets();
removeAllTestAccessPolicies();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.microsoft.windowsazure.services.media.models.Job;
import com.microsoft.windowsazure.services.media.models.JobInfo;
import com.microsoft.windowsazure.services.media.models.JobState;
import com.microsoft.windowsazure.services.media.models.LinkInfo;
import com.microsoft.windowsazure.services.media.models.ListResult;
import com.microsoft.windowsazure.services.media.models.Task;
import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation;
Expand All @@ -40,16 +41,16 @@ public class JobIntegrationTest extends IntegrationTestBase {

private static AssetInfo assetInfo;

private void verifyJobInfoEqual(String message, JobInfo expected, JobInfo actual) {
private void verifyJobInfoEqual(String message, JobInfo expected, JobInfo actual) throws ServiceException {
verifyJobProperties(message, expected.getName(), expected.getPriority(), expected.getRunningDuration(),
expected.getState(), expected.getTemplateId(), expected.getCreated(), expected.getLastModified(),
expected.getStartTime(), expected.getEndTime(), actual);
expected.getStartTime(), expected.getEndTime(), null, actual);
}

@SuppressWarnings("deprecation")
private void verifyJobProperties(String message, String testName, Integer priority, double runningDuration,
JobState state, String templateId, Date created, Date lastModified, Date startTime, Date endTime,
JobInfo actualJob) {
Integer expectedTaskCount, JobInfo actualJob) throws ServiceException {
assertNotNull(message, actualJob);

assertNotNull(message + "Id", actualJob.getId());
Expand All @@ -66,8 +67,11 @@ 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 tasks when fixed:
// https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/531
if (expectedTaskCount != null) {
LinkInfo tasksLink = actualJob.getTasksLink();
ListResult<TaskInfo> actualTasks = service.list(Task.list(tasksLink));
assertEquals(message + " tasks size", expectedTaskCount.intValue(), actualTasks.size());
}
}

private JobInfo createJob(String name) throws ServiceException {
Expand Down Expand Up @@ -108,7 +112,7 @@ public void createJobSuccess() throws ServiceException {

// Assert
verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime,
endTime, actualJob);
endTime, 1, actualJob);
}

@Test
Expand All @@ -133,7 +137,7 @@ public void createJobTwoTasksSuccess() throws ServiceException {

// Assert
verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime,
endTime, actualJob);
endTime, 2, actualJob);
}

@Test
Expand All @@ -155,7 +159,7 @@ public void getJobSuccess() throws ServiceException {

// Assert
verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime,
endTime, actualJob);
endTime, 1, actualJob);
}

@Test
Expand All @@ -180,7 +184,12 @@ public void listJobSuccess() throws ServiceException {
verifyListResultContains("listJobs", expectedListJobsResult, actualListJobResult, new ComponentDelegate() {
@Override
public void verifyEquals(String message, Object expected, Object actual) {
verifyJobInfoEqual(message, (JobInfo) expected, (JobInfo) actual);
try {
verifyJobInfoEqual(message, (JobInfo) expected, (JobInfo) actual);
}
catch (ServiceException e) {
fail(e.getMessage());
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ public void cancelTaskSuccess() throws ServiceException, InterruptedException {
//Assert
List<TaskInfo> taskInfos = service.list(Task.list(cancellingJobInfo.getTasksLink()));
for (TaskInfo taskInfo : taskInfos) {
// Replace with enums
// https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/522
verifyTaskPropertiesNoEncryption("canceled task", mediaProcessorId, TaskOption.None, taskBody,
configuration, name, 0, new Date(), null, 0.0, 0.0, null, TaskState.Canceled, taskInfo);
}
Expand Down Expand Up @@ -225,9 +223,6 @@ private void verifyTaskProperties(String message, String mediaProcessorId, TaskO
assertNotNull(message + " getErrorDetails", actual.getErrorDetails());
assertEquals(message + " getErrorDetails.size", 0, actual.getErrorDetails().size());

// TODO: Add tests for Historical events when added
// https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/494

ListResult<AssetInfo> inputAssets = service.list(Asset.list(actual.getInputAssetsLink()));
ListResult<AssetInfo> outputAssets = service.list(Asset.list(actual.getOutputAssetsLink()));

Expand Down

0 comments on commit 6460f54

Please sign in to comment.