Search in sources :

Example 1 with PrivacyGroupEntity

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");
    }
}
Also used : PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity) PersistenceException(jakarta.persistence.PersistenceException)

Example 2 with PrivacyGroupEntity

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);
}
Also used : PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity)

Example 3 with PrivacyGroupEntity

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);
}
Also used : PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity)

Example 4 with PrivacyGroupEntity

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());
}
Also used : PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity)

Example 5 with PrivacyGroupEntity

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);
}
Also used : java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Callable(java.util.concurrent.Callable) PersistenceException(jakarta.persistence.PersistenceException) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Mockito(org.mockito.Mockito) EntityManagerTemplate(com.quorum.tessera.data.EntityManagerTemplate) PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity) TestConfig(com.quorum.tessera.data.TestConfig) Stream(java.util.stream.Stream) Persistence(jakarta.persistence.Persistence) EntityManager(jakarta.persistence.EntityManager) org.junit(org.junit) PrivacyGroupDAO(com.quorum.tessera.data.PrivacyGroupDAO) ExecutorService(java.util.concurrent.ExecutorService) Parameterized(org.junit.runners.Parameterized) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) PrivacyGroupEntity(com.quorum.tessera.data.PrivacyGroupEntity) ExecutorService(java.util.concurrent.ExecutorService) Callable(java.util.concurrent.Callable) PersistenceException(jakarta.persistence.PersistenceException)

Aggregations

PrivacyGroupEntity (com.quorum.tessera.data.PrivacyGroupEntity)35 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)17 Test (org.junit.Test)12 PublicKey (com.quorum.tessera.encryption.PublicKey)8 EntityManager (jakarta.persistence.EntityManager)7 PersistenceException (jakarta.persistence.PersistenceException)6 PrivacyViolationException (com.quorum.tessera.transaction.exception.PrivacyViolationException)3 Callable (java.util.concurrent.Callable)3 EntityManagerTemplate (com.quorum.tessera.data.EntityManagerTemplate)2 List (java.util.List)2 PrivacyGroupDAO (com.quorum.tessera.data.PrivacyGroupDAO)1 TestConfig (com.quorum.tessera.data.TestConfig)1 PrivacyGroupNotFoundException (com.quorum.tessera.privacygroup.exception.PrivacyGroupNotFoundException)1 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 Persistence (jakarta.persistence.Persistence)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Supplier (java.util.function.Supplier)1