KeyPair protectionKey1 = EncryptionUtil.generateRSAKeyPair();
KeyPair protectionKey2 = EncryptionUtil.generateRSAKeyPair();
NetworkManager node = network.get(random.nextInt(networkSize));
H2HTestData data1 = new H2HTestData("bla1");
data1.generateVersionKey();
Parameters parameters1 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
.setContentKey(contentKey).setVersionKey(data1.getVersionKey()).setData(data1)
.setProtectionKeys(protectionKey1);
// initial put
FuturePut futurePut = node.getDataManager().putUnblocked(parameters1);
futurePut.awaitUninterruptibly();
// check if put was ok
FutureGet futureGet = node.getDataManager().getVersionUnblocked(parameters1);
futureGet.awaitUninterruptibly();
assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());
// try to remove without a protection key
Parameters parameters2 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
.setContentKey(contentKey).setVersionKey(data1.getVersionKey()).setData(data1);
FutureRemove futureRemove = node.getDataManager().removeVersionUnblocked(parameters2);
futureRemove.awaitUninterruptibly();
// should have been not modified
futureGet = node.getDataManager().getVersionUnblocked(parameters1);
futureGet.awaitUninterruptibly();
assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());
// try to remove with wrong protection key
Parameters parameters3 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
.setContentKey(contentKey).setVersionKey(data1.getVersionKey())
.setProtectionKeys(protectionKey2);
futureRemove = node.getDataManager().removeVersionUnblocked(parameters3);
futureRemove.awaitUninterruptibly();
// should have been not modified
futureGet = node.getDataManager().getVersionUnblocked(parameters1);
futureGet.awaitUninterruptibly();
assertEquals(data1.getTestString(), ((H2HTestData) futureGet.getData().object()).getTestString());
// remove with correct content protection key
Parameters parameters4 = new Parameters().setLocationKey(locationKey).setDomainKey(domainKey)
.setContentKey(contentKey).setVersionKey(data1.getVersionKey()).setData(data1)
.setProtectionKeys(protectionKey1);
futureRemove = node.getDataManager().removeVersionUnblocked(parameters4);
futureRemove.awaitUninterruptibly();
// should have been removed