Search in sources :

Example 31 with PrivacyGroupEntity

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

Example 32 with PrivacyGroupEntity

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

Example 33 with PrivacyGroupEntity

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

Example 34 with PrivacyGroupEntity

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

Example 35 with PrivacyGroupEntity

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