Exemple #1
0
  private User getFriendlyName(
      PublisherPublicKeyDigest digest, CCNHandle tempReadHandle, CCNHandle tempWriteHandle)
      throws MalformedContentNameStringException, IOException {
    User userFriendlyName = null;
    if (_userToDigestHash.containsKey(digest)) {
      userFriendlyName = _userToDigestHash.get(digest);
      Log.info("GET digest: " + digest.digest() + " --> " + userFriendlyName.getUserName());
    } else {
      Log.info("We DON'T have an entry in our hash for this " + digest);
    }

    if (userFriendlyName == null) {

      // Its not in the hashMap.. So, try and read the user's
      // friendly name from the ContentName and then add it to
      // the hashMap....
      String userNameStr = _namespaceStr + MEMBER_COMPONENT;
      _userNamespace =
          KeyProfile.keyName(ContentName.fromURI(userNameStr), _readString.getContentPublisher());

      try {
        _readNameString =
            new CCNStringObject(_userNamespace, (String) null, SaveType.RAW, tempReadHandle);
      } catch (Exception e) {
        e.printStackTrace();
      }

      _readNameString.update(WAIT_TIME_FOR_FRIENDLY_NAME);

      if (_readNameString.available()) {

        if (_readString.getContentPublisher().equals(_readNameString.getContentPublisher())) {
          userFriendlyName =
              addNameToHash(_readNameString.getContentPublisher(), _readNameString.string());
        }
      } else {
        userFriendlyName =
            new Speaker(
                "", "", _readString.getContentPublisher().shortFingerprint().substring(0, 8));
      }
    }
    return userFriendlyName;
  }
  @Test
  public void testAutomatedDereferenceForObjects() throws Exception {
    Log.info(Log.FAC_TEST, "Starting testAutomatedDereferenceForObjects");

    Link versionedLink = new Link(data[1].getVersionedName());
    LinkObject versionedLinkObject =
        new LinkObject(
            testHelper.getTestChildName("testAutomatedDereferenceForObjects", "versionedLink"),
            versionedLink,
            SaveType.REPOSITORY,
            putHandle);
    versionedLinkObject.save();
    TestUtils.checkObject(putHandle, versionedLinkObject);

    Link unversionedLink = new Link(data[1].getBaseName());
    LinkObject unversionedLinkObject =
        new LinkObject(
            testHelper.getTestChildName("testAutomatedDereferenceForObjects", "unversionedLink"),
            unversionedLink,
            SaveType.REPOSITORY,
            putHandle);
    unversionedLinkObject.save();
    TestUtils.checkObject(putHandle, unversionedLinkObject);

    Link twoHopLink = new Link(unversionedLinkObject.getBaseName());
    LinkObject twoHopLinkObject =
        new LinkObject(
            testHelper.getTestChildName("testAutomatedDereferenceForObjects", "twoHopLink"),
            twoHopLink,
            SaveType.REPOSITORY,
            putHandle);
    twoHopLinkObject.save();
    TestUtils.checkObject(putHandle, twoHopLinkObject);

    // read via the name iself
    CCNStringObject readObjectControl =
        new CCNStringObject(data[data.length - 1].getBaseName(), null);
    Assert.assertEquals(
        readObjectControl.getVersionedName(), data[data.length - 1].getVersionedName());
    Assert.assertEquals(readObjectControl.string(), data[data.length - 1].string());

    // read via the versioned link.
    CCNStringObject versionedReadObject =
        new CCNStringObject(versionedLinkObject.getBaseName(), getHandle);
    Assert.assertEquals(versionedReadObject.getVersionedName(), data[1].getVersionedName());
    Assert.assertEquals(versionedReadObject.string(), data[1].string());
    Assert.assertNotNull(versionedReadObject.getDereferencedLink());
    Assert.assertEquals(versionedReadObject.getDereferencedLink(), versionedLinkObject);

    // read latest version via the unversioned link
    CCNStringObject unversionedReadObject =
        new CCNStringObject(unversionedLinkObject.getBaseName(), getHandle);
    Assert.assertEquals(
        unversionedReadObject.getVersionedName(), data[data.length - 1].getVersionedName());
    Assert.assertEquals(unversionedReadObject.string(), data[data.length - 1].string());
    Assert.assertNotNull(unversionedReadObject.getDereferencedLink());
    Assert.assertEquals(unversionedReadObject.getDereferencedLink(), unversionedLinkObject);

    // read via the two-hop link
    CCNStringObject twoHopReadObject =
        new CCNStringObject(twoHopLinkObject.getBaseName(), getHandle);
    Assert.assertEquals(
        twoHopReadObject.getVersionedName(), data[data.length - 1].getVersionedName());
    Assert.assertEquals(twoHopReadObject.string(), data[data.length - 1].string());
    Assert.assertNotNull(twoHopReadObject.getDereferencedLink());
    Assert.assertEquals(twoHopReadObject.getDereferencedLink(), unversionedLinkObject);
    Assert.assertNotNull(twoHopReadObject.getDereferencedLink().getDereferencedLink());
    Assert.assertEquals(
        twoHopReadObject.getDereferencedLink().getDereferencedLink(), twoHopLinkObject);

    Log.info(Log.FAC_TEST, "Completed testAutomatedDereferenceForObjects");
  }