コード例 #1
0
  @Test
  public void canGetAccessPolicyFromLocator() throws Exception {
    LocatorInfo locator =
        service.create(
            Locator.create(accessPolicyInfo.getId(), assetInfo.getId(), LocatorType.SAS));

    AccessPolicyInfo accessPolicy = service.get(AccessPolicy.get(locator.getAccessPolicyLink()));

    assertEquals(accessPolicyInfo.getId(), accessPolicy.getId());
  }
コード例 #2
0
  @Test
  public void listLocatorsSuccess() throws ServiceException {
    // Arrange
    LocatorType locatorType = LocatorType.SAS;
    List<LocatorInfo> expectedLocators = new ArrayList<LocatorInfo>();
    for (int i = 0; i < 2; i++) {
      expectedLocators.add(
          service.create(Locator.create(accessPolicyInfo.getId(), assetInfo.getId(), locatorType)));
    }

    // Act
    ListResult<LocatorInfo> listLocatorsResult = service.list(Locator.list());

    // Assert
    assertNotNull(listLocatorsResult);
    verifyListResultContains(
        "listLocatorsResult",
        expectedLocators,
        listLocatorsResult,
        new ComponentDelegate() {
          @Override
          public void verifyEquals(String message, Object expected, Object actual) {
            verifyLocatorInfosEqual(message, (LocatorInfo) expected, (LocatorInfo) actual);
          }
        });
  }
コード例 #3
0
  @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);
  }
コード例 #4
0
  @Test
  public void createLocatorSuccess() throws ServiceException {
    // Arrange
    LocatorType locatorType = LocatorType.SAS;

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

    // Assert
    verifyLocatorProperties(
        "locatorInfo",
        accessPolicyInfoRead.getId(),
        assetInfo.getId(),
        locatorType,
        null,
        locatorInfo);
  }
コード例 #5
0
  @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());
  }
コード例 #6
0
  @Test
  public void createLocatorWithSpecifiedIdSuccess() throws ServiceException {
    // Arrange
    LocatorType locatorType = LocatorType.SAS;

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

    // Assert
    verifyLocatorProperties(
        "locatorInfo",
        accessPolicyInfoRead.getId(),
        assetInfo.getId(),
        locatorType,
        null,
        locatorInfo);
  }
コード例 #7
0
  @Test
  public void createLocatorOptionsSetStartTimeSuccess() throws ServiceException {
    // Arrange
    Date expectedStartDateTime = new Date();
    expectedStartDateTime.setTime(expectedStartDateTime.getTime() + tenMinutesInMS);
    LocatorType locatorType = LocatorType.SAS;

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

    // Assert
    verifyLocatorProperties(
        "locatorInfo",
        accessPolicyInfo.getId(),
        assetInfo.getId(),
        locatorType,
        expectedStartDateTime,
        locatorInfo);
  }
コード例 #8
0
  @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);
  }
コード例 #9
0
  @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()));
  }
コード例 #10
0
  @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);
  }
コード例 #11
0
  @Test
  public void listLocatorsWithOptions() throws ServiceException {
    List<LocatorInfo> expectedLocators = new ArrayList<LocatorInfo>();
    for (int i = 0; i < 5; i++) {
      expectedLocators.add(
          service.create(
              Locator.create(accessPolicyInfo.getId(), assetInfo.getId(), LocatorType.SAS)));
    }

    ListResult<LocatorInfo> result =
        service.list(
            Locator.list()
                .setTop(3)
                .set(
                    "$filter",
                    "(Id eq '"
                        + expectedLocators.get(1).getId()
                        + "') or ("
                        + "Id eq '"
                        + expectedLocators.get(3).getId()
                        + "')"));

    assertEquals(2, result.size());
  }