use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method savePrivacyGroupWithCallback.
@Test
public void savePrivacyGroupWithCallback() throws Exception {
final PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
Callable<Void> callback = mock(Callable.class);
privacyGroupDAO.save(entity, callback);
EntityManager entityManager = ENTITY_MANAGER.get();
final PrivacyGroupEntity result = entityManager.find(PrivacyGroupEntity.class, "id".getBytes());
assertThat(result).isNotNull();
verify(callback).call();
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method saveDoesNotAllowNullId.
@Test
public void saveDoesNotAllowNullId() {
PrivacyGroupEntity privacyGroup = new PrivacyGroupEntity();
try {
privacyGroupDAO.save(privacyGroup);
failBecauseExceptionWasNotThrown(PersistenceException.class);
} catch (PersistenceException ex) {
String expectedMessage = String.format(testConfig.getRequiredFieldColumnTemplate(), "ID");
assertThat(ex).isInstanceOf(PersistenceException.class).hasMessageContaining(expectedMessage).hasMessageContaining("ID");
}
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method retrieveOrSaveThrows.
@Test(expected = IllegalStateException.class)
public void retrieveOrSaveThrows() {
EntityManagerTemplate template = new EntityManagerTemplate(ENTITY_MANAGER.get().getEntityManagerFactory());
Supplier<PrivacyGroupEntity> mockRetriever = mock(Supplier.class);
when(mockRetriever.get()).thenReturn(null);
Supplier<PrivacyGroupEntity> mockFactory = mock(Supplier.class);
when(mockFactory.get()).thenThrow(new IllegalStateException("OUCH"));
template.retrieveOrSave(mockRetriever, mockFactory);
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method saveAndFindAll.
@Test
public void saveAndFindAll() {
final List<PrivacyGroupEntity> shouldBeEmpty = privacyGroupDAO.findAll();
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.findAll();
assertThat(pgs).isNotEmpty();
assertThat(pgs).containsExactlyInAnyOrder(entity, another);
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupManagerImplTest method testCreateResidentGroup.
@Test
public void testCreateResidentGroup() {
when(privacyGroupUtil.generateLookupId(anyList())).thenReturn("lookup".getBytes());
when(privacyGroupUtil.encode(any())).thenReturn("encoded".getBytes());
when(privacyGroupDAO.retrieve("generatedId".getBytes())).thenReturn(Optional.empty());
final PrivacyGroup privacyGroup = privacyGroupManager.saveResidentGroup("name", "desc", List.of(localKey));
// Verify entity being saved has the correct values
ArgumentCaptor<PrivacyGroupEntity> argCaptor = ArgumentCaptor.forClass(PrivacyGroupEntity.class);
verify(privacyGroupDAO).update(argCaptor.capture());
PrivacyGroupEntity savedEntity = argCaptor.getValue();
assertThat(savedEntity).isNotNull();
assertThat(savedEntity.getId()).isEqualTo("name".getBytes());
assertThat(savedEntity.getLookupId()).isEqualTo("lookup".getBytes());
assertThat(savedEntity.getData()).isEqualTo("encoded".getBytes());
// Verify generated privacy group has the correct values
assertThat(privacyGroup).isNotNull();
assertThat(privacyGroup.getId().getBytes()).isEqualTo("name".getBytes());
assertThat(privacyGroup.getName()).isEqualTo("name");
assertThat(privacyGroup.getDescription()).isEqualTo("desc");
assertThat(privacyGroup.getMembers()).containsExactly(localKey);
assertThat(privacyGroup.getType()).isEqualTo(PrivacyGroup.Type.RESIDENT);
assertThat(privacyGroup.getState()).isEqualTo(PrivacyGroup.State.ACTIVE);
}
Aggregations