use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupManagerImpl method createPrivacyGroup.
@Override
public PrivacyGroup createPrivacyGroup(String name, String description, PublicKey from, List<PublicKey> members, byte[] seed) {
final Set<PublicKey> localKeys = enclave.getPublicKeys();
if (!members.contains(from)) {
throw new PrivacyViolationException("The list of members in a privacy group should include self");
}
final byte[] groupIdBytes = privacyGroupUtil.generateId(members, seed);
final PrivacyGroup created = PrivacyGroup.Builder.create().withPrivacyGroupId(groupIdBytes).withName(name).withDescription(description).withMembers(members).withSeed(seed).withType(PrivacyGroup.Type.PANTHEON).withState(PrivacyGroup.State.ACTIVE).build();
final byte[] lookupId = privacyGroupUtil.generateLookupId(members);
final byte[] encodedData = privacyGroupUtil.encode(created);
final List<PublicKey> forwardingMembers = members.stream().filter(Predicate.not(localKeys::contains)).collect(Collectors.toList());
privacyGroupDAO.save(new PrivacyGroupEntity(groupIdBytes, lookupId, encodedData), () -> {
publisher.publishPrivacyGroup(encodedData, forwardingMembers);
return null;
});
return created;
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method saveAndFindByLookupId.
@Test
public void saveAndFindByLookupId() {
final List<PrivacyGroupEntity> shouldBeEmpty = privacyGroupDAO.findByLookupId("lookup".getBytes());
assertThat(shouldBeEmpty).isEmpty();
final PrivacyGroupEntity entity = new PrivacyGroupEntity("id1".getBytes(), "lookup".getBytes(), "data".getBytes());
privacyGroupDAO.save(entity);
final PrivacyGroupEntity another = new PrivacyGroupEntity("id2".getBytes(), "lookup".getBytes(), "data".getBytes());
privacyGroupDAO.save(another);
final List<PrivacyGroupEntity> pgs = privacyGroupDAO.findByLookupId("lookup".getBytes());
assertThat(pgs).isNotEmpty();
assertThat(pgs).containsExactlyInAnyOrder(entity, another);
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method updatePrivacyGroupWithCallbackException.
@Test
public void updatePrivacyGroupWithCallbackException() throws Exception {
final PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
Callable<Void> callback = mock(Callable.class);
when(callback.call()).thenThrow(new Exception("OUCH"));
try {
privacyGroupDAO.update(entity, callback);
failBecauseExceptionWasNotThrown(PersistenceException.class);
} catch (PersistenceException ex) {
assertThat(ex).isNotNull().hasMessageContaining("OUCH");
}
EntityManager entityManager = ENTITY_MANAGER.get();
final PrivacyGroupEntity result = entityManager.find(PrivacyGroupEntity.class, "id".getBytes());
assertThat(result).isNull();
verify(callback).call();
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method retrieveOrSave.
@Test
public void retrieveOrSave() {
final List<PrivacyGroupEntity> shouldBeEmpty = privacyGroupDAO.findByLookupId("lookup".getBytes());
assertThat(shouldBeEmpty).isEmpty();
final PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
privacyGroupDAO.retrieveOrSave(entity);
Optional<PrivacyGroupEntity> retrieved = privacyGroupDAO.retrieve("id".getBytes());
assertThat(retrieved).isPresent();
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method savePrivacyGroupWithRuntimeException.
@Test
public void savePrivacyGroupWithRuntimeException() throws Exception {
final PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
Callable<Void> callback = mock(Callable.class);
when(callback.call()).thenThrow(new RuntimeException("OUCH"));
try {
privacyGroupDAO.save(entity, callback);
failBecauseExceptionWasNotThrown(RuntimeException.class);
} catch (RuntimeException ex) {
assertThat(ex).isNotNull().hasMessageContaining("OUCH");
}
EntityManager entityManager = ENTITY_MANAGER.get();
final PrivacyGroupEntity result = entityManager.find(PrivacyGroupEntity.class, "id".getBytes());
assertThat(result).isNull();
verify(callback).call();
}
Aggregations