@BeforeClass public static void setUpBeforeClass() throws Exception { CCNTestBase.setUpBeforeClass(); CCNTime version = new CCNTime(); ContentName stringName = testHelper.getClassChildName(STRING_VALUE_NAME); for (int i = 0; i < data.length; ++i) { // save multiple versions of the same object. data[i] = new CCNStringObject(stringName, "Value " + i, SaveType.REPOSITORY, putHandle); Log.info(Log.FAC_TEST, "Saving as version " + version); data[i].save(version); version.increment(1); // avoid version collisions } gone = new CCNStringObject( testHelper.getClassChildName(GONE_VALUE_NAME), GONE_VALUE_NAME, SaveType.REPOSITORY, putHandle); gone.saveAsGone(); TestUtils.checkObject(putHandle, gone); bigData = testHelper.getClassChildName(BIG_VALUE_NAME); bigDataContent = new byte[bigDataLength]; Random rand = new Random(); rand.nextBytes(bigDataContent); bigValueDigest = CCNDigestHelper.digest(bigDataContent); // generate some segmented data CCNRepositoryWriter writer = new CCNRepositoryWriter(putHandle); writer.newVersion(bigData, bigDataContent); }
@Test public void testLinkToUnversioned() throws Exception { Log.info(Log.FAC_TEST, "Starting testLinkToUnversioned"); // test dereferencing link to unversioned data. CCNRepositoryWriter writer = new CCNRepositoryWriter(putHandle); ContentName unversionedDataName = testHelper.getTestChildName("testLinkToUnversioned", "UnversionedBigData"); // generate some segmented data; doesn't version the name writer.newVersion(unversionedDataName, bigDataContent); Link uvBigDataLink = new Link( unversionedDataName, "big", new LinkAuthenticator(new PublisherID(putHandle.keyManager().getDefaultKeyID()))); ContentObject bigDataTarget = uvBigDataLink.dereference(SystemConfiguration.SETTABLE_SHORT_TIMEOUT, getHandle); Log.info( Log.FAC_TEST, "BigData: Dereferenced link " + uvBigDataLink + ", retrieved content " + ((null == bigDataTarget) ? "null" : bigDataTarget.name())); Assert.assertNotNull(bigDataTarget); Assert.assertTrue(uvBigDataLink.targetName().isPrefixOf(bigDataTarget.name())); Assert.assertTrue(SegmentationProfile.isFirstSegment(bigDataTarget.name())); Log.info(Log.FAC_TEST, "Completed testLinkToUnversioned"); }
@Test public void testMissingTarget() throws Exception { Log.info(Log.FAC_TEST, "Starting testMissingTarget"); Link linkToNowhere = new Link(testHelper.getTestChildName("testMissingTarget", "linkToNowhere")); ContentObject nothing = linkToNowhere.dereference(SystemConfiguration.SHORT_TIMEOUT, getHandle); Assert.assertNull(nothing); Log.info(Log.FAC_TEST, "Completed testMissingTarget"); }
@BeforeClass public static void setUpBeforeClass() throws Exception { CCNTestHelper testHelper = new CCNTestHelper(GroupRecursiveKeyUpdateTestRepo.class); directoryBase = testHelper.getTestNamespace("testInOrder"); userNamespace = GroupAccessControlProfile.userNamespaceName(UserConfiguration.defaultNamespace()); groupNamespace = GroupAccessControlProfile.groupNamespaceName(UserConfiguration.defaultNamespace()); userKeyStorePrefix = ContentName.fromNative(UserConfiguration.defaultNamespace(), "_keystore_"); // create user identities with TestUserData td = new CreateUserData(userKeyStorePrefix, numberOfusers, true, "password".toCharArray()); td.publishUserKeysToRepository(userNamespace); friendlyNames = td.friendlyNames().toArray(new String[0]); // create ACM handle = td.getHandleForUser(friendlyNames[1]); acm = new GroupAccessControlManager(directoryBase, groupNamespace, userNamespace, handle); acm.publishMyIdentity( ContentName.fromNative(userNamespace, friendlyNames[1]), handle.keyManager().getDefaultPublicKey()); }
@Before public void setUp() { try { names = new ArrayList<ContentName>(); _putHandle = CCNHandle.open(); _getHandle = CCNHandle.open(); _fileHandle = CCNHandle.open(); getne = new CCNNameEnumerator(_getHandle, this); putne = new CCNNameEnumerator(_putHandle, this); helper = new CCNTestHelper(this.getClass().getName()); _prefix = helper.getClassNamespace(); _class = ContentName.fromNative(_prefix, "classResponder"); _class2 = ContentName.fromNative(_prefix, "classResponder2"); _repo = ContentName.fromNative(_prefix, "repoResponder"); updated = false; putne.registerNameSpace(_prefix); Log.info("registering namespace prefix: {0} count: {1}", _prefix, _prefix.count()); putNERegisterName(_class); addContentToRepo(_repo); } catch (ConfigurationException e) { Assert.fail("Configuration Exception when setting up test. " + e.getMessage()); } catch (IOException e) { Assert.fail("IOException when setting up test. " + e.getMessage()); } }
@Test public void testAutomatedDereferenceForGone() throws Exception { Log.info(Log.FAC_TEST, "Starting testAutomatedDereferenceForGone"); Link versionedLink = new Link(gone.getVersionedName()); LinkObject versionedLinkObject = new LinkObject( testHelper.getTestChildName("testAutomatedDereferenceForGone", "versionedLink"), versionedLink, SaveType.REPOSITORY, putHandle); versionedLinkObject.save(); TestUtils.checkObject(putHandle, versionedLinkObject); Link unversionedLink = new Link(gone.getBaseName()); LinkObject unversionedLinkObject = new LinkObject( testHelper.getTestChildName("testAutomatedDereferenceForGone", "unversionedLink"), unversionedLink, SaveType.REPOSITORY, putHandle); unversionedLinkObject.save(); TestUtils.checkObject(putHandle, unversionedLinkObject); Link twoHopLink = new Link(unversionedLinkObject.getBaseName()); LinkObject twoHopLinkObject = new LinkObject( testHelper.getTestChildName("testAutomatedDereferenceForGone", "twoHopLink"), twoHopLink, SaveType.REPOSITORY, putHandle); twoHopLinkObject.save(); TestUtils.checkObject(putHandle, twoHopLinkObject); // read via the name iself CCNStringObject readObjectControl = new CCNStringObject(gone.getBaseName(), null); Assert.assertEquals(readObjectControl.getVersionedName(), gone.getVersionedName()); Assert.assertTrue(readObjectControl.isGone()); // read via the versioned link. CCNStringObject versionedReadObject = new CCNStringObject(versionedLinkObject.getBaseName(), getHandle); Assert.assertEquals(versionedReadObject.getVersionedName(), gone.getVersionedName()); Assert.assertTrue(versionedReadObject.isGone()); 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(), gone.getVersionedName()); Assert.assertTrue(unversionedReadObject.isGone()); 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(), gone.getVersionedName()); Assert.assertTrue(twoHopReadObject.isGone()); 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 testAutomatedDereferenceForGone"); }
@Test public void testAutomatedDereferenceForStreams() throws Exception { Log.info(Log.FAC_TEST, "Starting testAutomatedDereferenceForStreams"); Link bigDataLink = new Link( bigData, "big", new LinkAuthenticator(new PublisherID(putHandle.keyManager().getDefaultKeyID()))); LinkObject bigDataLinkObject = new LinkObject( testHelper.getTestChildName("testAutomatedDereferenceForStreams", "bigDataLink"), bigDataLink, SaveType.REPOSITORY, putHandle); bigDataLinkObject.save(); TestUtils.checkObject(putHandle, bigDataLinkObject); Link twoHopLink = new Link(bigDataLinkObject.getBaseName()); LinkObject twoHopLinkObject = new LinkObject( testHelper.getTestChildName("testAutomatedDereferenceForStreams", "twoHopLink"), twoHopLink, SaveType.REPOSITORY, putHandle); twoHopLinkObject.save(); TestUtils.checkObject(putHandle, twoHopLinkObject); CCNReader reader = new CCNReader(putHandle); byte[] bigDataReadback = reader.getVersionedData( bigDataLinkObject.getVersionedName(), null, SystemConfiguration.getDefaultTimeout()); byte[] bdrdigest = CCNDigestHelper.digest(bigDataReadback); Log.info( Log.FAC_TEST, "Read back big data via link, got " + bigDataReadback.length + " bytes of an expected " + bigDataLength + ", digest match? " + (0 == DataUtils.compare(bdrdigest, bigValueDigest))); Assert.assertEquals(bigDataLength, bigDataReadback.length); Assert.assertArrayEquals(bdrdigest, bigValueDigest); byte[] bigDataReadback2 = reader.getVersionedData( twoHopLinkObject.getBaseName(), null, SystemConfiguration.getDefaultTimeout()); byte[] bdr2digest = CCNDigestHelper.digest(bigDataReadback); Log.info( Log.FAC_TEST, "Read back big data via two links, got " + bigDataReadback2.length + " bytes of an expected " + bigDataLength + ", digest match? " + (0 == DataUtils.compare(bdr2digest, bigValueDigest))); Assert.assertEquals(bigDataLength, bigDataReadback2.length); Assert.assertArrayEquals(bdr2digest, bigValueDigest); Log.info(Log.FAC_TEST, "Completed testAutomatedDereferenceForStreams"); }