Skip to content

Commit

Permalink
Fixed two test breaks, removed expiration as a settable property for …
Browse files Browse the repository at this point in the history
…locator
  • Loading branch information
Chris Tavares committed Dec 13, 2012
1 parent 60eb02f commit c864a9c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 60 deletions.
Expand Up @@ -78,9 +78,6 @@ public static class Creator extends EntityOperationSingleResultBase<LocatorInfo>
/** The content access token. */
private String contentAccessComponent;

/** The expiration date time. */
private Date expirationDateTime;

/** The locator type. */
private final LocatorType locatorType;

Expand Down Expand Up @@ -116,8 +113,7 @@ protected Creator(String accessPolicyId, String assetId, LocatorType locatorType
@Override
public Object getRequestContents() {
return new LocatorRestType().setId(id).setAccessPolicyId(accessPolicyId).setAssetId(assetId)
.setStartTime(startDateTime).setExpirationDateTime(expirationDateTime)
.setType(locatorType.getCode()).setBaseUri(baseUri)
.setStartTime(startDateTime).setType(locatorType.getCode()).setBaseUri(baseUri)
.setContentAccessComponent(contentAccessComponent).setPath(path);
}

Expand Down Expand Up @@ -157,18 +153,6 @@ public Creator setStartDateTime(Date startDateTime) {
return this;
}

/**
* Set the date and time at which the locator will expire.
*
* @param expirationDateTime
* Expiration date and time
* @return The creator instance (for function chaining)
*/
public Creator setExpirationDateTime(Date expirationDateTime) {
this.expirationDateTime = expirationDateTime;
return this;
}

/**
* Sets the content access component.
*
Expand Down
Expand Up @@ -61,7 +61,7 @@ public static void setup() throws Exception {
@Test
public void canCreateFileForUploadedBlob() throws Exception {
AssetInfo asset = createTestAsset("createFileForUploadedBlob");
LocatorInfo locator = createLocator(writePolicy, asset, 5, 10);
LocatorInfo locator = createLocator(writePolicy, asset, 5);
WritableBlobContainerContract blobWriter = service.createBlobWriter(locator);

createAndUploadBlob(blobWriter, BLOB_NAME, firstPrimes);
Expand All @@ -78,7 +78,7 @@ public void canCreateFileForUploadedBlob() throws Exception {
@Test
public void canCreateFileEntityDirectly() throws Exception {
AssetInfo asset = createTestAsset("createFileEntityDirectly");
LocatorInfo locator = createLocator(writePolicy, asset, 5, 10);
LocatorInfo locator = createLocator(writePolicy, asset, 5);
WritableBlobContainerContract blobWriter = service.createBlobWriter(locator);

createAndUploadBlob(blobWriter, BLOB_NAME_2, firstPrimes);
Expand All @@ -102,7 +102,7 @@ public void canCreateFileEntityDirectly() throws Exception {
public void canCreateAssetWithMultipleFiles() throws Exception {
AssetInfo asset = createTestAsset("createWithMultipleFiles");
AccessPolicyInfo policy = createWritePolicy("createWithMultipleFiles", 10);
LocatorInfo locator = createLocator(policy, asset, 5, 10);
LocatorInfo locator = createLocator(policy, asset, 5);

WritableBlobContainerContract blobWriter = service.createBlobWriter(locator);

Expand Down Expand Up @@ -140,7 +140,7 @@ public int compare(AssetFileInfo o1, AssetFileInfo o2) {
public void canCreateFileAndThenUpdateIt() throws Exception {
AssetInfo asset = createTestAsset("createAndUpdate");
AccessPolicyInfo policy = createWritePolicy("createAndUpdate", 10);
LocatorInfo locator = createLocator(policy, asset, 5, 10);
LocatorInfo locator = createLocator(policy, asset, 5);
WritableBlobContainerContract blobWriter = service.createBlobWriter(locator);

createAndUploadBlob(blobWriter, "toUpdate.bin", firstPrimes);
Expand All @@ -158,7 +158,7 @@ public void canCreateFileAndThenUpdateIt() throws Exception {
public void canDeleteFileFromAsset() throws Exception {
AssetInfo asset = createTestAsset("deleteFile");
AccessPolicyInfo policy = createWritePolicy("deleteFile", 10);
LocatorInfo locator = createLocator(policy, asset, 5, 10);
LocatorInfo locator = createLocator(policy, asset, 5);
WritableBlobContainerContract blobWriter = service.createBlobWriter(locator);

createAndUploadBlob(blobWriter, "todelete.bin", firstPrimes);
Expand Down Expand Up @@ -232,7 +232,5 @@ private void verifyAssetInfoProperties(String message, String id, String name, S
assertDateApproxEquals(message + ".getLastModified", lastModified, assetFile.getLastModified());
assertEquals(message + ".getContentChecksum", contentChecksum, assetFile.getContentChecksum());
assertEquals(message + ".getMimeType", mimeType, assetFile.getMimeType());

}

}
Expand Up @@ -159,15 +159,14 @@ interface ComponentDelegate {
void verifyEquals(String message, Object expected, Object actual);
}

protected static LocatorInfo createLocator(AccessPolicyInfo accessPolicy, AssetInfo asset, int startDeltaMinutes,
int expirationDeltaMinutes) throws ServiceException {
protected static LocatorInfo createLocator(AccessPolicyInfo accessPolicy, AssetInfo asset, int startDeltaMinutes)
throws ServiceException {

Date now = new Date();
Date start = new Date(now.getTime() - (startDeltaMinutes * 60 * 1000));
Date expire = new Date(now.getTime() + (expirationDeltaMinutes * 60 * 1000));

return service.create(Locator.create(accessPolicy.getId(), asset.getId(), LocatorType.SAS)
.setStartDateTime(start).setExpirationDateTime(expire));
return service.create(Locator.create(accessPolicy.getId(), asset.getId(), LocatorType.SAS).setStartDateTime(
start));
}

protected <T> void verifyListResultContains(List<T> expectedInfos, Collection<T> actualInfos,
Expand Down
Expand Up @@ -117,7 +117,7 @@ public static void setup() throws Exception {

AccessPolicyInfo accessPolicyInfo = service.create(AccessPolicy.create(testPolicyPrefix + name, 10,
EnumSet.of(AccessPolicyPermission.WRITE)));
LocatorInfo locator = createLocator(accessPolicyInfo, assetInfo, 5, 10);
LocatorInfo locator = createLocator(accessPolicyInfo, assetInfo, 5);
WritableBlobContainerContract blobWriter = service.createBlobWriter(locator);
InputStream blobContent = new ByteArrayInputStream(testBlobData);
blobWriter.createBlockBlob(testBlobName, blobContent);
Expand Down
Expand Up @@ -133,28 +133,14 @@ public void createLocatorWithSpecifiedIdSuccess() throws ServiceException {
expectedExpirationDateTime, locatorInfo);
}

@Test
public void createLocatorOptionsSetExpirationDateTimeSuccess() throws ServiceException {
// Arrange
Date expectedExpirationDateTime = new Date();
expectedExpirationDateTime.setTime(expectedExpirationDateTime.getTime() + tenMinutesInMS);
LocatorType locatorType = LocatorType.SAS;

// Act
LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(),
locatorType).setExpirationDateTime(expectedExpirationDateTime));
// Assert
verifyLocatorProperties("locatorInfo", accessPolicyInfo.getId(), assetInfo.getId(), locatorType, null,
expectedExpirationDateTime, locatorInfo);
}

@Test
public void createLocatorOptionsSetStartTimeSuccess() throws ServiceException {
// Arrange
Date expectedStartDateTime = new Date();
expectedStartDateTime.setTime(expectedStartDateTime.getTime() + tenMinutesInMS);
LocatorType locatorType = LocatorType.SAS;
Date expectedExpirationDateTime = calculateDefaultExpectedExpDate(accessPolicyInfo, assetInfo);
Date expectedExpirationDateTime = new Date(expectedStartDateTime.getTime()
+ (long) accessPolicyInfo.getDurationInMinutes() * minuteInMS);

// Act
LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(),
Expand All @@ -171,11 +157,9 @@ public void getLocatorSuccess() throws ServiceException {
LocatorType locatorType = LocatorType.SAS;
Date expectedStartDateTime = new Date();
expectedStartDateTime.setTime(expectedStartDateTime.getTime() + tenMinutesInMS);
Date expectedExpirationDateTime = new Date(expectedStartDateTime.getTime() + tenMinutesInMS);

LocatorInfo expectedLocatorInfo = service.create(Locator
.create(accessPolicyInfo.getId(), assetInfo.getId(), locatorType)
.setStartDateTime(expectedStartDateTime).setExpirationDateTime(expectedExpirationDateTime));
LocatorInfo expectedLocatorInfo = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(),
locatorType).setStartDateTime(expectedStartDateTime));

// Act
LocatorInfo actualLocatorInfo = service.get(Locator.get(expectedLocatorInfo.getId()));
Expand Down Expand Up @@ -271,9 +255,8 @@ public void updateLocatorNoChangesSuccess() throws ServiceException {
Date startTime = new Date();
startTime.setTime(startTime.getTime() - tenMinutesInMS);

LocatorInfo locatorInfo = service.create(Locator
.create(accessPolicyInfoRead.getId(), assetInfo.getId(), locatorType)
.setExpirationDateTime(expirationDateTime).setStartDateTime(startTime));
LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfoRead.getId(), assetInfo.getId(),
locatorType).setStartDateTime(startTime));

// Act
service.update(Locator.update(locatorInfo.getId()));
Expand Down
Expand Up @@ -52,7 +52,7 @@ public static void setup() throws Exception {
AccessPolicyInfo policy = service.create(AccessPolicy.create(testPolicyPrefix + "uploadWritePolicy", 10,
EnumSet.of(AccessPolicyPermission.WRITE)));

LocatorInfo locator = createLocator(policy, asset, 5, 10);
LocatorInfo locator = createLocator(policy, asset, 5);

blobWriter = service.createBlobWriter(locator);

Expand Down
Expand Up @@ -67,21 +67,18 @@ public void createLocatorHasCorrectPayload() throws Exception {
}

@Test
public void createLocatorCanSetTimes() throws Exception {
public void createLocatorCanSetStartTime() throws Exception {
Date now = new Date();
Date tomorrow = new Date(now.getTime() + 24 * 60 * 60 * 1000);

EntityCreationOperation<LocatorInfo> creator = Locator
.create(exampleAccessPolicyId, exampleAssetId, LocatorType.SAS).setStartDateTime(now)
.setExpirationDateTime(tomorrow);
EntityCreationOperation<LocatorInfo> creator = Locator.create(exampleAccessPolicyId, exampleAssetId,
LocatorType.SAS).setStartDateTime(now);

LocatorRestType locatorType = (LocatorRestType) creator.getRequestContents();

assertEquals(exampleAssetId, locatorType.getAssetId());
assertEquals(exampleAccessPolicyId, locatorType.getAccessPolicyId());
assertEquals(LocatorType.SAS.getCode(), locatorType.getType().intValue());
assertEquals(now, locatorType.getStartTime());
assertEquals(tomorrow, locatorType.getExpirationDateTime());
}

@Test
Expand Down

0 comments on commit c864a9c

Please sign in to comment.