Search in sources :

Example 6 with ResendRequest

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);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) Client(jakarta.ws.rs.client.Client) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Example 7 with ResendRequest

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)));
}
Also used : Response(jakarta.ws.rs.core.Response) ResendBatchResponse(com.quorum.tessera.recovery.resend.ResendBatchResponse) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Example 8 with ResendRequest

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);
}
Also used : Response(jakarta.ws.rs.core.Response) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Example 9 with ResendRequest

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);
}
Also used : Response(jakarta.ws.rs.core.Response) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Example 10 with ResendRequest

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);
}
Also used : Response(jakarta.ws.rs.core.Response) URI(java.net.URI) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Aggregations

ResendRequest (com.quorum.tessera.p2p.resend.ResendRequest)13 Response (jakarta.ws.rs.core.Response)12 Test (org.junit.Test)12 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)7 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)4 Client (jakarta.ws.rs.client.Client)4 URI (java.net.URI)3 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)2 PayloadEncoderImpl (com.quorum.tessera.enclave.PayloadEncoderImpl)2 Party (com.quorum.tessera.test.Party)2 PartyHelper (com.quorum.tessera.test.PartyHelper)2 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)2 Entity (jakarta.ws.rs.client.Entity)2 Invocation (jakarta.ws.rs.client.Invocation)2 WebTarget (jakarta.ws.rs.client.WebTarget)2 MediaType (jakarta.ws.rs.core.MediaType)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2