use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method saveAndUpdate.
@Test
public void saveAndUpdate() {
PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
privacyGroupDAO.save(entity);
entity.setData("newData".getBytes());
privacyGroupDAO.update(entity);
Optional<PrivacyGroupEntity> retrieved = privacyGroupDAO.retrieve("id".getBytes());
assertThat(retrieved).isPresent();
assertThat(retrieved.get().getId()).isEqualTo("id".getBytes());
assertThat(retrieved.get().getLookupId()).isEqualTo("lookup".getBytes());
assertThat(retrieved.get().getData()).isEqualTo("newData".getBytes());
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method updatePrivacyGroupWithRuntimeException.
@Test
public void updatePrivacyGroupWithRuntimeException() 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.update(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();
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method saveDuplicateIdThrowException.
@Test
public void saveDuplicateIdThrowException() {
PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
privacyGroupDAO.save(entity);
try {
privacyGroupDAO.save(entity);
failBecauseExceptionWasNotThrown(PersistenceException.class);
} catch (PersistenceException ex) {
assertThat(ex).isInstanceOf(PersistenceException.class).hasMessageContaining(testConfig.getUniqueConstraintViolationMessage());
}
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method updatePrivacyGroupWithCallback.
@Test
public void updatePrivacyGroupWithCallback() throws Exception {
final PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
Callable<Void> callback = mock(Callable.class);
privacyGroupDAO.update(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 savePrivacyGroupWithCallbackException.
@Test
public void savePrivacyGroupWithCallbackException() 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.save(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();
}
Aggregations