use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class RestPayloadPublisherTest method publishMandatoryRecipientsToNodesThatDoNotSupport.
@Test
public void publishMandatoryRecipientsToNodesThatDoNotSupport() {
String targetUrl = "http://someplace.com";
EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getPrivacyMode()).thenReturn(PrivacyMode.MANDATORY_RECIPIENTS);
byte[] payloadData = "Some Data".getBytes();
when(payloadEncoder.encode(encodedPayload)).thenReturn(payloadData);
PublicKey recipientKey = mock(PublicKey.class);
NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.supportedApiVersions()).thenReturn(Set.of("v2", "2.1", "3.0"));
Recipient recipient = mock(Recipient.class);
when(recipient.getKey()).thenReturn(recipientKey);
when(recipient.getUrl()).thenReturn(targetUrl);
when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
when(discovery.getRemoteNodeInfo(recipientKey)).thenReturn(nodeInfo);
assertThatExceptionOfType(MandatoryRecipientsNotSupportedException.class).isThrownBy(() -> payloadPublisher.publishPayload(encodedPayload, recipientKey)).withMessageContaining("Transactions with mandatory recipients are not currently supported on recipient");
verify(discovery).getRemoteNodeInfo(eq(recipientKey));
payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class RestPayloadPublisherTest method handleConnectionError.
@Test
public void handleConnectionError() {
final String targetUri = "http://jimmywhite.com";
final PublicKey recipientKey = mock(PublicKey.class);
Recipient recipient = mock(Recipient.class);
when(recipient.getKey()).thenReturn(recipientKey);
when(recipient.getUrl()).thenReturn(targetUri);
NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
when(nodeInfo.getUrl()).thenReturn(targetUri);
when(discovery.getRemoteNodeInfo(recipientKey)).thenReturn(nodeInfo);
Client client = mock(Client.class);
when(client.target(targetUri)).thenThrow(ProcessingException.class);
final EncodedPayload payload = mock(EncodedPayload.class);
when(payload.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
when(payloadEncoder.encode(payload)).thenReturn("SomeData".getBytes());
RestPayloadPublisher restPayloadPublisher = new RestPayloadPublisher(client, discovery);
try {
restPayloadPublisher.publishPayload(payload, recipientKey);
failBecauseExceptionWasNotThrown(NodeOfflineException.class);
} catch (NodeOfflineException ex) {
assertThat(ex).hasMessageContaining(targetUri);
verify(client).target(targetUri);
verify(discovery).getRemoteNodeInfo(eq(recipientKey));
verify(payloadEncoder).encode(payload);
verify(discovery).getRemoteNodeInfo(eq(recipientKey));
payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class AutoDiscoveryTest method onUpdateSendHasTwoKeys.
@Test
public void onUpdateSendHasTwoKeys() {
String uri = "http://mynode.com";
PublicKey key = mock(PublicKey.class);
Recipient recipient = Recipient.of(key, uri);
PublicKey otherKey = mock(PublicKey.class);
Recipient other = Recipient.of(otherKey, uri);
List<Recipient> recipients = List.of(recipient, other);
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(uri).withRecipients(recipients).build();
List<ActiveNode> storedNodes = new ArrayList<>();
doAnswer(invocation -> {
storedNodes.add(invocation.getArgument(0));
return null;
}).when(networkStore).store(any(ActiveNode.class));
discovery.onUpdate(nodeInfo);
assertThat(storedNodes).hasSize(1);
ActiveNode result = storedNodes.iterator().next();
assertThat(result.getUri()).isEqualTo(NodeUri.create(uri));
assertThat(result.getKeys()).containsExactlyInAnyOrder(key, otherKey);
verify(networkStore).store(any(ActiveNode.class));
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class DisabledAutoDiscoveryTest method onUpdateIgnoreKeysNotOwnedBySender.
@Test
public void onUpdateIgnoreKeysNotOwnedBySender() {
String uri = "http://renoraynes.com";
PublicKey key = mock(PublicKey.class);
PublicKey key2 = mock(PublicKey.class);
Recipient recipient = Recipient.of(key, uri);
Recipient other = Recipient.of(key2, "http://othernode.com");
List<Recipient> recipients = List.of(recipient, other);
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(uri).withRecipients(recipients).withSupportedApiVersions(List.of("Two", "Fifty")).build();
List<ActiveNode> storedNodes = new ArrayList<>();
doAnswer(invocation -> {
storedNodes.add(invocation.getArgument(0));
return null;
}).when(networkStore).store(any(ActiveNode.class));
discovery.onUpdate(nodeInfo);
assertThat(storedNodes).hasSize(1);
ActiveNode result = storedNodes.iterator().next();
assertThat(result.getUri()).isEqualTo(NodeUri.create(uri));
assertThat(result.getKeys()).containsExactly(key);
assertThat(result.getSupportedVersions()).containsExactlyInAnyOrder("Two", "Fifty");
verify(networkStore).store(any(ActiveNode.class));
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class DisabledAutoDiscoveryTest method onUpdateNodeSendsNewKey.
@Test
public void onUpdateNodeSendsNewKey() {
String url = knownPeers.iterator().next().asString();
PublicKey key = mock(PublicKey.class);
List<Recipient> recipients = List.of(Recipient.of(key, url));
List<ActiveNode> storedNodes = new ArrayList<>();
doAnswer(invocation -> {
storedNodes.add(invocation.getArgument(0));
return null;
}).when(networkStore).store(any(ActiveNode.class));
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(recipients).build();
discovery.onUpdate(nodeInfo);
assertThat(storedNodes).hasSize(1);
ActiveNode savedNode = storedNodes.get(0);
assertThat(savedNode.getKeys()).containsExactly(key);
assertThat(savedNode.getUri()).isEqualTo(NodeUri.create(url));
verify(networkStore).store(any(ActiveNode.class));
}
Aggregations