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 testThumbnails() throws Exception { Log.info(Log.FAC_TEST, "Starting testThumbnails"); byte[] fakeImageData1 = "xxx".getBytes(); ContentName thumbNailBase = new ContentName(testHelper.getTestNamespace("testThumbnails"), "thumbnailBaseFile"); CCNStringObject cso = new CCNStringObject( thumbNailBase, "thumbNailBase", CCNFlowControl.SaveType.REPOSITORY, putHandle); cso.save(); cso.close(); ContentName origVersion = SegmentationProfile.segmentRoot( VersioningProfile.getLatestVersion( thumbNailBase, cso.getContentPublisher(), SystemConfiguration.LONG_TIMEOUT, putHandle.defaultVerifier(), getHandle) .name()); ContentName thumbName = ThumbnailProfile.getLatestVersion( thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle); Log.info(Log.FAC_TEST, "Check that we can retrieve a simple thumbnail"); RepositoryFileOutputStream thumbImage1 = new RepositoryFileOutputStream(thumbName, putHandle); thumbImage1.write(fakeImageData1, 0, fakeImageData1.length); thumbImage1.close(); ContentName checkThumbName = ThumbnailProfile.getLatestVersion( thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle); checkData(checkThumbName, fakeImageData1); Log.info(Log.FAC_TEST, "Check that we can retrieve a second version of a thumbnail"); byte[] fakeImageData2 = "yyy".getBytes(); ContentName thumbName2 = VersioningProfile.updateVersion(checkThumbName); RepositoryFileOutputStream thumbImage2 = new RepositoryFileOutputStream(thumbName2, putHandle); thumbImage2.write(fakeImageData2, 0, fakeImageData2.length); thumbImage2.close(); checkThumbName = ThumbnailProfile.getLatestVersion( thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle); checkData(checkThumbName, fakeImageData2); Log.info( Log.FAC_TEST, "Check that we can retrieve a thumbnail associated with a second version of a file"); cso = new CCNStringObject( thumbNailBase, "thumbNailBase", CCNFlowControl.SaveType.REPOSITORY, putHandle); cso.save(); cso.close(); byte[] fakeImageData3 = "zzz".getBytes(); thumbName = ThumbnailProfile.getLatestVersion( thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle); RepositoryFileOutputStream thumbImage3 = new RepositoryFileOutputStream(thumbName, putHandle); thumbImage3.write(fakeImageData3, 0, fakeImageData3.length); thumbImage3.close(); checkThumbName = ThumbnailProfile.getLatestVersion( thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle); checkData(checkThumbName, fakeImageData3); Log.info( Log.FAC_TEST, "Check that we can retrieve a second thumbnail associated with a second version of a file"); byte[] fakeImageData4 = "fff".getBytes(); thumbName2 = VersioningProfile.updateVersion(checkThumbName); RepositoryFileOutputStream thumbImage4 = new RepositoryFileOutputStream(thumbName2, putHandle); thumbImage4.write(fakeImageData4, 0, fakeImageData4.length); thumbImage4.close(); checkThumbName = ThumbnailProfile.getLatestVersion( thumbNailBase, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle); checkData(checkThumbName, fakeImageData4); Log.info( Log.FAC_TEST, "Check that we can retrieve the correct thumbnail associated with an arbitrary version of a file"); checkThumbName = ThumbnailProfile.getLatestVersion( origVersion, "image.png".getBytes(), SystemConfiguration.LONG_TIMEOUT, putHandle); checkData(checkThumbName, fakeImageData2); Log.info(Log.FAC_TEST, "Completed testThumbnails"); }