Permalink
Browse files

Merge pull request #31 from christav/test-fixes-527-544

Test fixes 527 544
  • Loading branch information...
2 parents be3e551 + c864a9c commit ac144858afe38f6dad915f946bed3133398508b4 @christav christav committed Dec 14, 2012
@@ -78,9 +78,6 @@ public static Creator create(String accessPolicyId, String assetId, LocatorType
/** The content access token. */
private String contentAccessComponent;
- /** The expiration date time. */
- private Date expirationDateTime;
-
/** The locator type. */
private final LocatorType locatorType;
@@ -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);
}
@@ -158,18 +154,6 @@ public Creator setStartDateTime(Date startDateTime) {
}
/**
- * 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.
*
* @param contentAccessComponent
@@ -103,7 +103,7 @@ public void canGetSinglePolicyById() throws Exception {
@Test
public void canGetSinglePolicyByInvalidId() throws Exception {
expectedException.expect(ServiceException.class);
- expectedException.expect(new ServiceExceptionMatcher(500));
+ expectedException.expect(new ServiceExceptionMatcher(400));
service.get(AccessPolicy.get(invalidId));
}
@@ -189,7 +189,7 @@ public void canDeleteAccessPolicyById() throws Exception {
@Test
public void canDeleteAccessPolicyByInvalidId() throws Exception {
expectedException.expect(ServiceException.class);
- expectedException.expect(new ServiceExceptionMatcher(500));
+ expectedException.expect(new ServiceExceptionMatcher(400));
service.delete(AccessPolicy.delete(invalidId));
}
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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());
-
}
-
}
@@ -159,15 +159,14 @@ private static void removeAllTestJobs() {
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,
@@ -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);
@@ -134,27 +134,13 @@ public void createLocatorWithSpecifiedIdSuccess() throws ServiceException {
}
@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(),
@@ -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()));
@@ -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()));
@@ -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);
@@ -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

0 comments on commit ac14485

Please sign in to comment.