use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class RestP2pClientTest method sendPartyInfo.
@Test
public void sendPartyInfo() {
try (var entityMockedStatic = mockStatic(Entity.class)) {
Entity<ResendRequest> outboundEntity = mock(Entity.class);
byte[] partyinfoData = "SomeEncodedPartyInfoData".getBytes();
entityMockedStatic.when(() -> Entity.entity(partyinfoData, MediaType.APPLICATION_OCTET_STREAM_TYPE)).thenReturn(outboundEntity);
String targetUrl = "targetUrl";
Client client = mock(Client.class);
WebTarget webTarget = mock(WebTarget.class);
when(client.target(targetUrl)).thenReturn(webTarget);
when(webTarget.path("/partyinfo")).thenReturn(webTarget);
Invocation.Builder invocationBuilder = mock(Invocation.Builder.class);
when(webTarget.request()).thenReturn(invocationBuilder);
Response response = mock(Response.class);
when(response.getStatus()).thenReturn(expectedResponseStatus.getStatusCode());
when(response.readEntity(byte[].class)).thenReturn("Success".getBytes());
when(invocationBuilder.post(outboundEntity)).thenReturn(response);
RestP2pClient restP2pClient = new RestP2pClient(client);
boolean outcome = restP2pClient.sendPartyInfo(targetUrl, partyinfoData);
if (Set.of(Response.Status.OK, Response.Status.CREATED).contains(expectedResponseStatus)) {
assertThat(outcome).isTrue();
} else {
assertThat(outcome).isFalse();
}
entityMockedStatic.verify(() -> Entity.entity(partyinfoData, MediaType.APPLICATION_OCTET_STREAM_TYPE));
entityMockedStatic.verifyNoMoreInteractions();
verify(client).target(targetUrl);
verify(webTarget).path("/partyinfo");
verify(webTarget).request();
verify(invocationBuilder).post(outboundEntity);
verifyNoMoreInteractions(outboundEntity, client, webTarget, invocationBuilder);
}
}
use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class TransactionResourceTest method resend.
@Test
public void resend() {
ResendRequest resendRequest = new ResendRequest();
resendRequest.setType("ALL");
resendRequest.setPublicKey(Base64.getEncoder().encodeToString("JUNIT".getBytes()));
EncodedPayload payload = mock(EncodedPayload.class);
com.quorum.tessera.recovery.resend.ResendResponse resendResponse = mock(com.quorum.tessera.recovery.resend.ResendResponse.class);
when(resendResponse.getPayload()).thenReturn(payload);
when(legacyResendManager.resend(any(com.quorum.tessera.recovery.resend.ResendRequest.class))).thenReturn(resendResponse);
when(payloadEncoder.encode(payload)).thenReturn("SUCCESS".getBytes());
Response result = transactionResource.resend(resendRequest);
assertThat(result.getStatus()).isEqualTo(200);
assertThat(result.getEntity()).isEqualTo("SUCCESS".getBytes());
verify(payloadEncoder).encode(payload);
verify(legacyResendManager).resend(any(com.quorum.tessera.recovery.resend.ResendRequest.class));
payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class ResendAllIT method resendForInvalidKeyErrors.
@Test
public void resendForInvalidKeyErrors() {
// perform resend
final ResendRequest req = new ResendRequest();
req.setType(RESEND_ALL_VALUE);
req.setPublicKey("rUSW9gnm2Unm5ECvEfuU&&&&&&&&59Flw7m7iu6wEo=");
final Response resendRequest = vanillaHttpOnlyClient.target(partyOne.getP2PUri()).path(RESEND_PATH).request().buildPost(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE)).invoke();
assertThat(resendRequest).isNotNull();
assertThat(resendRequest.getStatus()).isEqualTo(400);
}
use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class ResendAllIT method resendForKeyWithNoTransactions.
@Test
public void resendForKeyWithNoTransactions() {
// perform resend
final ResendRequest req = new ResendRequest();
req.setType(RESEND_ALL_VALUE);
req.setPublicKey("rUSW9gnm2Unm5ECvEfuU10LX7KYsN59Flw7m7iu6wEo=");
final Response resendRequest = vanillaHttpOnlyClient.target(partyOne.getP2PUri()).path(RESEND_PATH).request().buildPost(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE)).invoke();
assertThat(resendRequest).isNotNull();
assertThat(resendRequest.getStatus()).isEqualTo(200);
}
use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class ResendAllIT method resendTransactionsForGivenKey.
@Test
public void resendTransactionsForGivenKey() throws UnsupportedEncodingException {
// setup (sending in a tx)
Response sendRawResponse = partyOne.getRestClient().target(partyOne.getQ2TUri()).path("/sendraw").request().header("c11n-from", partyOne.getPublicKey()).header("c11n-to", partyTwo.getPublicKey()).post(Entity.entity(transactionData, MediaType.APPLICATION_OCTET_STREAM));
URI location = sendRawResponse.getLocation();
String hash = sendRawResponse.readEntity(String.class);
final String encodedHash = URLEncoder.encode(hash, UTF_8.toString());
// delete it from sender node
final Response deleteReq = partyOne.getRestClient().target(location).request().delete();
assertThat(deleteReq).isNotNull();
assertThat(deleteReq.getStatus()).isEqualTo(204);
// check it is deleted
final Response deleteCheck = partyOne.getRestClient().target(partyOne.getQ2TUri()).path("transaction").path(encodedHash).request().get();
assertThat(deleteCheck).isNotNull();
assertThat(deleteCheck.getStatus()).isEqualTo(404);
// request resend from recipient
final ResendRequest req = new ResendRequest();
req.setType(RESEND_ALL_VALUE);
req.setPublicKey(partyOne.getPublicKey());
final Response resendRequest = vanillaHttpOnlyClient.target(partyTwo.getP2PUri()).path(RESEND_PATH).request().buildPost(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE)).invoke();
assertThat(resendRequest).isNotNull();
assertThat(resendRequest.getStatus()).isEqualTo(200);
// and fetch the transaction to make sure it is there
final Response resendCheck = partyOne.getRestClient().target(partyOne.getQ2TUri()).path("transaction").path(encodedHash).request().get();
assertThat(resendCheck).isNotNull();
assertThat(resendCheck.getStatus()).isEqualTo(200);
}
Aggregations