use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method saveDoesNotAllowNullData.
@Test
public void saveDoesNotAllowNullData() {
PrivacyGroupEntity privacyGroup = new PrivacyGroupEntity();
privacyGroup.setId("id".getBytes());
try {
privacyGroupDAO.save(privacyGroup);
failBecauseExceptionWasNotThrown(PersistenceException.class);
} catch (PersistenceException ex) {
String expectedMessage = String.format(testConfig.getRequiredFieldColumnTemplate(), "DATA");
assertThat(ex).isInstanceOf(PersistenceException.class).hasMessageContaining(expectedMessage).hasMessageContaining("DATA");
}
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method retrieveOrSaveExistedEntity.
@Test
public void retrieveOrSaveExistedEntity() {
final PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
privacyGroupDAO.save(entity);
final Optional<PrivacyGroupEntity> existed = privacyGroupDAO.retrieve("id".getBytes());
assertThat(existed).isPresent();
privacyGroupDAO.retrieveOrSave(entity);
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method retrieveOrSaveValidError.
@Test(expected = PersistenceException.class)
public void retrieveOrSaveValidError() {
final PrivacyGroupEntity entity = new PrivacyGroupEntity(null, "lookup".getBytes(), "data".getBytes());
privacyGroupDAO.retrieveOrSave(entity);
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method saveAndRetrieve.
@Test
public void saveAndRetrieve() {
PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
privacyGroupDAO.save(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("data".getBytes());
}
use of com.quorum.tessera.data.PrivacyGroupEntity in project tessera by ConsenSys.
the class PrivacyGroupDAOTest method concurrentSavesExceptionIgnoredIfCausedByDuplicate.
@Test
public void concurrentSavesExceptionIgnoredIfCausedByDuplicate() throws InterruptedException {
final List<PrivacyGroupEntity> shouldBeEmpty = privacyGroupDAO.findByLookupId("lookup".getBytes());
assertThat(shouldBeEmpty).isEmpty();
ExecutorService executor = Executors.newCachedThreadPool();
final PrivacyGroupEntity entity = new PrivacyGroupEntity("id".getBytes(), "lookup".getBytes(), "data".getBytes());
final Callable<PrivacyGroupEntity> create = () -> privacyGroupDAO.retrieveOrSave(entity);
List<Callable<PrivacyGroupEntity>> callables = Stream.generate(() -> create).limit(3).collect(Collectors.toList());
executor.invokeAll(callables).stream().map(future -> {
try {
return future.get();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}).forEach(System.out::println);
}
Aggregations