use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.
the class PrivacyGroupManagerImplTest method testLegacyPrivacyGroupExisted.
@Test
public void testLegacyPrivacyGroupExisted() {
final List<PublicKey> members = List.of(localKey, mock(PublicKey.class), mock(PublicKey.class));
when(privacyGroupUtil.generateId(anyList())).thenReturn("generatedId".getBytes());
when(privacyGroupDAO.retrieve("generatedId".getBytes())).thenReturn(Optional.of(mock(PrivacyGroupEntity.class)));
final PrivacyGroup privacyGroup = privacyGroupManager.createLegacyPrivacyGroup(localKey, members);
assertThat(privacyGroup).isNotNull();
verify(privacyGroupDAO).retrieveOrSave(any());
}
use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.
the class PrivacyGroupManagerImplTest method testStorePrivacyGroup.
@Test
public void testStorePrivacyGroup() {
final PrivacyGroup mockPrivacyGroup = mock(PrivacyGroup.class);
when(mockPrivacyGroup.getId()).thenReturn(PrivacyGroup.Id.fromBytes("id".getBytes()));
final byte[] encoded = "encoded".getBytes();
when(privacyGroupUtil.decode(encoded)).thenReturn(mockPrivacyGroup);
when(privacyGroupUtil.generateLookupId(anyList())).thenReturn("lookup".getBytes());
when(privacyGroupDAO.retrieve("id".getBytes())).thenReturn(Optional.empty());
privacyGroupManager.storePrivacyGroup(encoded);
ArgumentCaptor<PrivacyGroupEntity> argCaptor = ArgumentCaptor.forClass(PrivacyGroupEntity.class);
verify(privacyGroupDAO).save(argCaptor.capture());
final PrivacyGroupEntity saved = argCaptor.getValue();
assertThat(saved).isNotNull();
assertThat(saved.getId()).isEqualTo("id".getBytes());
assertThat(saved.getLookupId()).isEqualTo("lookup".getBytes());
assertThat(saved.getData()).isEqualTo("encoded".getBytes());
}
use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.
the class PrivacyGroupManagerImplTest method findPrivacyGroupByType.
@Test
public void findPrivacyGroupByType() {
final PrivacyGroupEntity mockResult1 = mock(PrivacyGroupEntity.class);
final PrivacyGroup mockPrivacyGroup1 = mock(PrivacyGroup.class);
when(mockPrivacyGroup1.getState()).thenReturn(PrivacyGroup.State.ACTIVE);
when(mockPrivacyGroup1.getType()).thenReturn(PrivacyGroup.Type.RESIDENT);
when(mockResult1.getData()).thenReturn("data1".getBytes());
final PrivacyGroupEntity mockResult2 = mock(PrivacyGroupEntity.class);
final PrivacyGroup mockPrivacyGroup2 = mock(PrivacyGroup.class);
when(mockPrivacyGroup2.getState()).thenReturn(PrivacyGroup.State.DELETED);
when(mockPrivacyGroup2.getType()).thenReturn(PrivacyGroup.Type.RESIDENT);
when(mockResult2.getData()).thenReturn("data2".getBytes());
final PrivacyGroupEntity mockResult3 = mock(PrivacyGroupEntity.class);
final PrivacyGroup mockPrivacyGroup3 = mock(PrivacyGroup.class);
when(mockPrivacyGroup3.getState()).thenReturn(PrivacyGroup.State.ACTIVE);
when(mockPrivacyGroup3.getType()).thenReturn(PrivacyGroup.Type.PANTHEON);
when(mockResult3.getData()).thenReturn("data3".getBytes());
when(privacyGroupUtil.decode("data1".getBytes())).thenReturn(mockPrivacyGroup1);
when(privacyGroupUtil.decode("data2".getBytes())).thenReturn(mockPrivacyGroup2);
when(privacyGroupUtil.decode("data3".getBytes())).thenReturn(mockPrivacyGroup3);
when(privacyGroupDAO.findAll()).thenReturn(List.of(mockResult1, mockResult2, mockResult3));
final List<PrivacyGroup> result = privacyGroupManager.findPrivacyGroupByType(PrivacyGroup.Type.RESIDENT);
assertThat(result).isNotNull();
assertThat(result).containsExactly(mockPrivacyGroup1);
verify(privacyGroupDAO).findAll();
}
use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.
the class PrivacyGroupManagerImplTest method testDeletePrivacyGroup.
@Test
public void testDeletePrivacyGroup() {
PublicKey from = PublicKey.from("r1".getBytes());
PrivacyGroupEntity retrievedEt = mock(PrivacyGroupEntity.class);
when(retrievedEt.getData()).thenReturn("data".getBytes());
PrivacyGroup mockPG = mock(PrivacyGroup.class);
when(mockPG.getId()).thenReturn(PrivacyGroup.Id.fromBytes("id".getBytes()));
when(mockPG.getMembers()).thenReturn(List.of(PublicKey.from("r1".getBytes()), PublicKey.from("r2".getBytes())));
when(mockPG.getState()).thenReturn(PrivacyGroup.State.ACTIVE);
when(mockPG.getType()).thenReturn(PrivacyGroup.Type.PANTHEON);
when(privacyGroupDAO.retrieve("id".getBytes())).thenReturn(Optional.of(retrievedEt));
when(privacyGroupUtil.decode("data".getBytes())).thenReturn(mockPG);
when(privacyGroupUtil.encode(any())).thenReturn("deletedData".getBytes());
when(privacyGroupUtil.generateLookupId(any())).thenReturn("lookup".getBytes());
doAnswer(invocation -> {
Callable callable = invocation.getArgument(1);
callable.call();
return mock(PrivacyGroupEntity.class);
}).when(privacyGroupDAO).update(any(), any());
PrivacyGroup result = privacyGroupManager.deletePrivacyGroup(from, PrivacyGroup.Id.fromBytes("id".getBytes()));
assertThat(result.getState()).isEqualTo(PrivacyGroup.State.DELETED);
verify(privacyGroupDAO).retrieve("id".getBytes());
verify(privacyGroupDAO).update(any(), any());
// Verify payload being distributed has the correct values
ArgumentCaptor<byte[]> payloadCaptor = ArgumentCaptor.forClass(byte[].class);
ArgumentCaptor<List<PublicKey>> recipientsCaptor = ArgumentCaptor.forClass(List.class);
verify(publisher).publishPrivacyGroup(payloadCaptor.capture(), recipientsCaptor.capture());
assertThat(payloadCaptor.getValue()).isEqualTo("deletedData".getBytes());
assertThat(recipientsCaptor.getValue()).containsAll(List.of(PublicKey.from("r1".getBytes()), PublicKey.from("r2".getBytes())));
ArgumentCaptor<PrivacyGroup> argCaptor = ArgumentCaptor.forClass(PrivacyGroup.class);
verify(privacyGroupUtil).encode(argCaptor.capture());
PrivacyGroup deletedPg = argCaptor.getValue();
assertThat(deletedPg.getId()).isEqualTo(PrivacyGroup.Id.fromBytes("id".getBytes()));
assertThat(deletedPg.getState()).isEqualTo(PrivacyGroup.State.DELETED);
}
use of com.quorum.tessera.enclave.PrivacyGroup in project tessera by ConsenSys.
the class PrivacyGroupManagerImplTest method testRetrievePrivacyGroup.
@Test
public void testRetrievePrivacyGroup() {
final PrivacyGroup.Id id = PrivacyGroup.Id.fromBytes("id".getBytes());
final PrivacyGroupEntity mockResult = mock(PrivacyGroupEntity.class);
final PrivacyGroup mockPrivacyGroup = mock(PrivacyGroup.class);
when(mockPrivacyGroup.getState()).thenReturn(PrivacyGroup.State.ACTIVE);
when(mockResult.getData()).thenReturn("data".getBytes());
when(privacyGroupUtil.decode("data".getBytes())).thenReturn(mockPrivacyGroup);
when(privacyGroupDAO.retrieve("id".getBytes())).thenReturn(Optional.of(mockResult));
final PrivacyGroup result = privacyGroupManager.retrievePrivacyGroup(id);
assertThat(result).isNotNull();
assertThat(result).isEqualTo(mockPrivacyGroup);
verify(privacyGroupDAO).retrieve("id".getBytes());
}
Aggregations