Skip to content

Commit

Permalink
Merge pull request #35 from christav/locator-expiration-not-used-541
Browse files Browse the repository at this point in the history
Removing setExpirationTime from locator update
  • Loading branch information
jcookems committed Dec 15, 2012
2 parents 875d24f + eadf37c commit bbec594
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 48 deletions.
Expand Up @@ -242,9 +242,6 @@ public static class Updater extends EntityOperationBase implements EntityUpdateO
/** The start date time. */ /** The start date time. */
private Date startDateTime; private Date startDateTime;


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

/** /**
* Instantiates a new updater. * Instantiates a new updater.
* *
Expand All @@ -260,7 +257,7 @@ public Updater(String locatorId) {
*/ */
@Override @Override
public Object getRequestContents() { public Object getRequestContents() {
return new LocatorRestType().setStartTime(startDateTime).setExpirationDateTime(expirationDateTime); return new LocatorRestType().setStartTime(startDateTime);
} }


/* (non-Javadoc) /* (non-Javadoc)
Expand All @@ -282,19 +279,6 @@ public Updater setStartDateTime(Date startDateTime) {
this.startDateTime = startDateTime; this.startDateTime = startDateTime;
return this; return this;
} }

/**
* Set when the locator will expire.
*
* @param expirationDateTime
* the expiration date & time
* @return Updater instance
*/
public Updater setExpirationDateTime(Date expirationDateTime) {
this.expirationDateTime = expirationDateTime;
return this;
}

} }


/** /**
Expand Down
Expand Up @@ -46,33 +46,24 @@ public class LocatorIntegrationTests extends IntegrationTestBase {
private static int minuteInMS = 60 * 1000; private static int minuteInMS = 60 * 1000;
private static int tenMinutesInMS = 10 * 60 * 1000; private static int tenMinutesInMS = 10 * 60 * 1000;


private Date calculateDefaultExpectedExpDate(AccessPolicyInfo accessPolicy, AssetInfo asset) {
return new Date(asset.getLastModified().getTime() + (long) accessPolicy.getDurationInMinutes() * minuteInMS);
}

private void verifyLocatorInfosEqual(String message, LocatorInfo expected, LocatorInfo actual) { private void verifyLocatorInfosEqual(String message, LocatorInfo expected, LocatorInfo actual) {
verifyLocatorProperties(message, expected.getAccessPolicyId(), expected.getAssetId(), verifyLocatorProperties(message, expected.getAccessPolicyId(), expected.getAssetId(),
expected.getLocatorType(), expected.getStartTime(), expected.getExpirationDateTime(), expected.getId(), expected.getLocatorType(), expected.getStartTime(), expected.getId(), expected.getPath(), actual);
expected.getPath(), actual);
} }


private void verifyLocatorProperties(String message, String accessPolicyId, String assetId, private void verifyLocatorProperties(String message, String accessPolicyId, String assetId,
LocatorType locatorType, Date startTime, Date expirationDateTime, LocatorInfo actualLocator) { LocatorType locatorType, Date startTime, LocatorInfo actualLocator) {
verifyLocatorProperties(message, accessPolicyId, assetId, locatorType, startTime, expirationDateTime, null, verifyLocatorProperties(message, accessPolicyId, assetId, locatorType, startTime, null, null, actualLocator);
null, actualLocator);
} }


private void verifyLocatorProperties(String message, String accessPolicyId, String assetId, private void verifyLocatorProperties(String message, String accessPolicyId, String assetId,
LocatorType locatorType, Date startTime, Date expirationDateTime, String id, String path, LocatorType locatorType, Date startTime, String id, String path, LocatorInfo actualLocator) {
LocatorInfo actualLocator) {
assertNotNull(message, actualLocator); assertNotNull(message, actualLocator);
assertEquals(message + " accessPolicyId", accessPolicyId, actualLocator.getAccessPolicyId()); assertEquals(message + " accessPolicyId", accessPolicyId, actualLocator.getAccessPolicyId());
assertEquals(message + " assetId", assetId, actualLocator.getAssetId()); assertEquals(message + " assetId", assetId, actualLocator.getAssetId());
assertEquals(message + " locatorType", locatorType, actualLocator.getLocatorType()); assertEquals(message + " locatorType", locatorType, actualLocator.getLocatorType());


assertDateApproxEquals(message + " startTime", startTime, actualLocator.getStartTime()); assertDateApproxEquals(message + " startTime", startTime, actualLocator.getStartTime());
assertDateApproxEquals(message + " expirationDateTime", expirationDateTime,
actualLocator.getExpirationDateTime());


if (id == null) { if (id == null) {
assertNotNull(message + " Id", actualLocator.getId()); assertNotNull(message + " Id", actualLocator.getId());
Expand Down Expand Up @@ -106,30 +97,28 @@ public void instanceSetup() throws Exception {
public void createLocatorSuccess() throws ServiceException { public void createLocatorSuccess() throws ServiceException {
// Arrange // Arrange
LocatorType locatorType = LocatorType.SAS; LocatorType locatorType = LocatorType.SAS;
Date expectedExpirationDateTime = calculateDefaultExpectedExpDate(accessPolicyInfoRead, assetInfo);


// Act // Act
LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfoRead.getId(), assetInfo.getId(), LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfoRead.getId(), assetInfo.getId(),
locatorType)); locatorType));


// Assert // Assert
verifyLocatorProperties("locatorInfo", accessPolicyInfoRead.getId(), assetInfo.getId(), locatorType, null, verifyLocatorProperties("locatorInfo", accessPolicyInfoRead.getId(), assetInfo.getId(), locatorType, null,
expectedExpirationDateTime, locatorInfo); locatorInfo);
} }


@Test @Test
public void createLocatorWithSpecifiedIdSuccess() throws ServiceException { public void createLocatorWithSpecifiedIdSuccess() throws ServiceException {
// Arrange // Arrange
LocatorType locatorType = LocatorType.SAS; LocatorType locatorType = LocatorType.SAS;
Date expectedExpirationDateTime = calculateDefaultExpectedExpDate(accessPolicyInfoRead, assetInfo);


// Act // Act
LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfoRead.getId(), assetInfo.getId(), LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfoRead.getId(), assetInfo.getId(),
locatorType).setId(String.format("nb:lid:UUID:%s", UUID.randomUUID().toString()))); locatorType).setId(String.format("nb:lid:UUID:%s", UUID.randomUUID().toString())));


// Assert // Assert
verifyLocatorProperties("locatorInfo", accessPolicyInfoRead.getId(), assetInfo.getId(), locatorType, null, verifyLocatorProperties("locatorInfo", accessPolicyInfoRead.getId(), assetInfo.getId(), locatorType, null,
expectedExpirationDateTime, locatorInfo); locatorInfo);
} }


@Test @Test
Expand All @@ -138,16 +127,14 @@ public void createLocatorOptionsSetStartTimeSuccess() throws ServiceException {
Date expectedStartDateTime = new Date(); Date expectedStartDateTime = new Date();
expectedStartDateTime.setTime(expectedStartDateTime.getTime() + tenMinutesInMS); expectedStartDateTime.setTime(expectedStartDateTime.getTime() + tenMinutesInMS);
LocatorType locatorType = LocatorType.SAS; LocatorType locatorType = LocatorType.SAS;
Date expectedExpirationDateTime = new Date(expectedStartDateTime.getTime()
+ (long) accessPolicyInfo.getDurationInMinutes() * minuteInMS);


// Act // Act
LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(), LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(),
locatorType).setStartDateTime(expectedStartDateTime)); locatorType).setStartDateTime(expectedStartDateTime));


// Assert // Assert
verifyLocatorProperties("locatorInfo", accessPolicyInfo.getId(), assetInfo.getId(), locatorType, verifyLocatorProperties("locatorInfo", accessPolicyInfo.getId(), assetInfo.getId(), locatorType,
expectedStartDateTime, expectedExpirationDateTime, locatorInfo); expectedStartDateTime, locatorInfo);
} }


@Test @Test
Expand Down Expand Up @@ -229,20 +216,20 @@ public void updateLocatorSuccess() throws ServiceException {
LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfoRead.getId(), assetInfo.getId(), LocatorInfo locatorInfo = service.create(Locator.create(accessPolicyInfoRead.getId(), assetInfo.getId(),
locatorType)); locatorType));


Date expirationDateTime = new Date();
expirationDateTime.setTime(expirationDateTime.getTime() + tenMinutesInMS);
Date startTime = new Date(); Date startTime = new Date();
startTime.setTime(startTime.getTime() - tenMinutesInMS); startTime.setTime(startTime.getTime() - tenMinutesInMS);


// Act // Act
service.update(Locator.update(locatorInfo.getId()).setExpirationDateTime(expirationDateTime) service.update(Locator.update(locatorInfo.getId()).setStartDateTime(startTime));
.setStartDateTime(startTime));
LocatorInfo updatedLocatorInfo = service.get(Locator.get(locatorInfo.getId())); LocatorInfo updatedLocatorInfo = service.get(Locator.get(locatorInfo.getId()));


// Assert // Assert
Date expectedExpiration = new Date();
expectedExpiration.setTime(startTime.getTime() + (long) accessPolicyInfoRead.getDurationInMinutes()
* minuteInMS);

verifyLocatorProperties("updatedLocatorInfo", locatorInfo.getAccessPolicyId(), locatorInfo.getAssetId(), verifyLocatorProperties("updatedLocatorInfo", locatorInfo.getAccessPolicyId(), locatorInfo.getAssetId(),
locatorInfo.getLocatorType(), startTime, expirationDateTime, locatorInfo.getId(), locatorInfo.getLocatorType(), startTime, locatorInfo.getId(), locatorInfo.getPath(), updatedLocatorInfo);
locatorInfo.getPath(), updatedLocatorInfo);
} }


@Test @Test
Expand Down
Expand Up @@ -157,19 +157,16 @@ public void locatorUpdateReturnsExpectedUri() throws Exception {
} }


@Test @Test
public void locatorUpdateCanStartAndExpirationTime() throws Exception { public void locatorUpdateCanSetStarTime() throws Exception {
Date now = new Date(); Date now = new Date();


Date tenMinutesAgo = new Date(now.getTime() - 10 * 60 * 1000); Date tenMinutesAgo = new Date(now.getTime() - 10 * 60 * 1000);
Date twoHoursFromNow = new Date(now.getTime() + 2 * 60 * 60 * 1000);


EntityUpdateOperation updater = Locator.update(exampleLocatorId).setStartDateTime(tenMinutesAgo) EntityUpdateOperation updater = Locator.update(exampleLocatorId).setStartDateTime(tenMinutesAgo);
.setExpirationDateTime(twoHoursFromNow);


LocatorRestType payload = (LocatorRestType) updater.getRequestContents(); LocatorRestType payload = (LocatorRestType) updater.getRequestContents();


assertEquals(tenMinutesAgo, payload.getStartTime()); assertEquals(tenMinutesAgo, payload.getStartTime());
assertEquals(twoHoursFromNow, payload.getExpirationDateTime());
} }


@Test @Test
Expand Down

0 comments on commit bbec594

Please sign in to comment.