String testData = "data";
Data data = new Data(testData).setProtectedEntry();
// put with protection key
FuturePut futurePut1 = p1.put(lKey).setData(cKey, data).setDomainKey(dKey).keyPair(keyPair).start();
futurePut1.awaitUninterruptibly();
assertTrue(futurePut1.isSuccess());
// verify put from peer 1
FutureGet futureGet1a = p1.get(lKey).setContentKey(cKey).setDomainKey(dKey).start();
futureGet1a.awaitUninterruptibly();
assertTrue(futureGet1a.isSuccess());
Data retData = futureGet1a.getData();
assertEquals(testData, (String) retData.object());
assertEquals(keyPair.getPublic(), retData.publicKey());
// verify put from peer 2
FutureGet futureGet1b = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).start();
futureGet1b.awaitUninterruptibly();
assertTrue(futureGet1b.isSuccess());
retData = futureGet1b.getData();
assertEquals(testData, (String) retData.object());
assertEquals(keyPair.getPublic(), retData.publicKey());
// try a put without a protection key (through peer 2)
Data data2 = new Data("data2");
FuturePut futurePut2 = p2.put(lKey).setData(cKey, data2).setDomainKey(dKey).start();
futurePut2.awaitUninterruptibly();
assertFalse(futurePut2.isSuccess());
// verify that nothing changed from peer 1
FutureGet futureGet2a = p1.get(lKey).setContentKey(cKey).setDomainKey(dKey).start();
futureGet2a.awaitUninterruptibly();
assertTrue(futureGet2a.isSuccess());
retData = futureGet2a.getData();
// should have been not modified
assertEquals(testData, (String) retData.object());
assertEquals(keyPair.getPublic(), retData.publicKey());
// verify that nothing changed from peer 2
FutureGet futureGet2b = p2.get(lKey).setContentKey(cKey).setDomainKey(dKey).start();
futureGet2b.awaitUninterruptibly();
assertTrue(futureGet2b.isSuccess());
retData = futureGet2b.getData();
// should have been not modified
assertEquals(testData, (String) retData.object());
assertEquals(keyPair.getPublic(), retData.publicKey());
// overwrite
String newTestData = "new data";
data = new Data(newTestData).setProtectedEntry();
// sign put message with protection keys
FuturePut futurePut4 = p1.put(lKey).setData(cKey, data).keyPair(keyPair).setDomainKey(dKey).start();
futurePut4.awaitUninterruptibly();
Assert.assertTrue(futurePut4.isSuccess());
// verify overwrite from peer 1
FutureGet futureGet4a = p1.get(lKey).setContentKey(cKey).setDomainKey(dKey).start();
futureGet4a.awaitUninterruptibly();
assertTrue(futureGet4a.isSuccess());