@Test
  public void updateLocatorSuccess() throws ServiceException {
    // Arrange
    LocatorType locatorType = LocatorType.OnDemandOrigin;
    LocatorInfo locatorInfo =
        service.create(
            Locator.create(accessPolicyInfoRead.getId(), assetInfo.getId(), locatorType));

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

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

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

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

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

    if (id == null) {
      assertNotNull(message + " Id", actualLocator.getId());
    } else {
      assertEquals(message + " Id", id, actualLocator.getId());
    }
    if (path == null) {
      assertNotNull(message + " path", actualLocator.getPath());
    } else {
      assertEquals(message + " path", path, actualLocator.getPath());
    }
  }
 private void verifyLocatorInfosEqual(String message, LocatorInfo expected, LocatorInfo actual) {
   verifyLocatorProperties(
       message,
       expected.getAccessPolicyId(),
       expected.getAssetId(),
       expected.getLocatorType(),
       expected.getStartTime(),
       expected.getId(),
       expected.getPath(),
       actual);
 }
  @Test
  public void canGetLocatorBackFromAsset() throws Exception {
    LocatorInfo locator =
        service.create(
            Locator.create(accessPolicyInfo.getId(), assetInfo.getId(), LocatorType.SAS));

    ListResult<LocatorInfo> locators = service.list(Locator.list(assetInfo.getLocatorsLink()));

    assertEquals(1, locators.size());
    assertEquals(locator.getId(), locators.get(0).getId());
  }
  @Test
  public void deleteLocatorSuccess() throws ServiceException {
    // Arrange
    LocatorType locatorType = LocatorType.SAS;
    LocatorInfo locatorInfo =
        service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(), locatorType));
    ListResult<LocatorInfo> listLocatorsResult = service.list(Locator.list());
    int assetCountBaseline = listLocatorsResult.size();

    // Act
    service.delete(Locator.delete(locatorInfo.getId()));

    // Assert
    listLocatorsResult = service.list(Locator.list());
    assertEquals("listLocatorsResult.size", assetCountBaseline - 1, listLocatorsResult.size());

    expectedException.expect(ServiceException.class);
    expectedException.expect(new ServiceExceptionMatcher(404));
    service.get(Locator.get(locatorInfo.getId()));
  }
  @Test
  public void updateLocatorNoChangesSuccess() throws ServiceException {
    // Arrange
    LocatorType locatorType = LocatorType.OnDemandOrigin;
    Date expirationDateTime = new Date();
    expirationDateTime.setTime(expirationDateTime.getTime() + tenMinutesInMS);
    Date startTime = new Date();
    startTime.setTime(startTime.getTime() - tenMinutesInMS);

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

    // Act
    service.update(Locator.update(locatorInfo.getId()));
    LocatorInfo updatedLocatorInfo = service.get(Locator.get(locatorInfo.getId()));

    // Assert
    verifyLocatorInfosEqual("updatedLocatorInfo", locatorInfo, updatedLocatorInfo);
  }
  @Test
  public void getLocatorSuccess() throws ServiceException {
    // Arrange
    LocatorType locatorType = LocatorType.SAS;
    Date expectedStartDateTime = new Date();
    expectedStartDateTime.setTime(expectedStartDateTime.getTime() + tenMinutesInMS);

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

    // Act
    LocatorInfo actualLocatorInfo = service.get(Locator.get(expectedLocatorInfo.getId()));

    // Assert
    verifyLocatorInfosEqual("actualLocatorInfo", expectedLocatorInfo, actualLocatorInfo);
  }