Search in sources :

Example 1 with AUTHORISE

use of uk.gov.pay.connector.gateway.GatewayOperation.AUTHORISE in project pay-connector by alphagov.

the class ClientFactoryIT method shouldUseGatewaySpecificReadTimeoutOverride_whenSpecified.

@Test
public void shouldUseGatewaySpecificReadTimeoutOverride_whenSpecified() {
    app = startApp("config/client-factory-test-config-with-worldpay-timeout-override.yaml", false);
    when(mockMetricRegistry.register(any(), any())).thenReturn(null);
    String path = "/hello";
    wireMockRule.stubFor(get(urlPathEqualTo("/hello")).willReturn(aResponse().withBody("world").withStatus(200).withFixedDelay(2000)));
    Client client = new ClientFactory(app.getEnvironment(), app.getConfiguration()).createWithDropwizardClient(WORLDPAY, AUTHORISE, mockMetricRegistry);
    Invocation.Builder request = client.target(getServerUrl()).path(path).request();
    Long authOverriddenTimeout = app.getConfiguration().getWorldpayConfig().getJerseyClientOverrides().map(override -> override.getAuth().getReadTimeout().toMicroseconds()).orElse(0L);
    assertGatewayFailure(request, authOverriddenTimeout);
}
Also used : IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Client(javax.ws.rs.client.Client) AUTHORISE(uk.gov.pay.connector.gateway.GatewayOperation.AUTHORISE) SMARTPAY(uk.gov.pay.connector.gateway.PaymentGatewayName.SMARTPAY) Assert.assertThat(org.junit.Assert.assertThat) After(org.junit.After) ClientFactory(uk.gov.pay.connector.gateway.ClientFactory) SocketTimeoutException(java.net.SocketTimeoutException) Matchers.lessThan(org.hamcrest.Matchers.lessThan) PortFactory(uk.gov.service.payments.commons.testing.port.PortFactory) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) ResourceHelpers(io.dropwizard.testing.ResourceHelpers) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) MetricRegistry(com.codahale.metrics.MetricRegistry) DropwizardTestSupport(io.dropwizard.testing.DropwizardTestSupport) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Test(org.junit.Test) ClientProperties(org.glassfish.jersey.client.ClientProperties) Invocation(javax.ws.rs.client.Invocation) Mockito.when(org.mockito.Mockito.when) ConnectorConfiguration(uk.gov.pay.connector.app.ConnectorConfiguration) String.format(java.lang.String.format) ConnectorApp(uk.gov.pay.connector.app.ConnectorApp) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) WORLDPAY(uk.gov.pay.connector.gateway.PaymentGatewayName.WORLDPAY) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Mockito.any(org.mockito.Mockito.any) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Invocation(javax.ws.rs.client.Invocation) ClientFactory(uk.gov.pay.connector.gateway.ClientFactory) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 2 with AUTHORISE

use of uk.gov.pay.connector.gateway.GatewayOperation.AUTHORISE in project pay-connector by alphagov.

the class ClientFactoryIT method shouldUseGatewaySpecificReadTimeoutOverrideForSmartpay_whenSpecified.

@Test
public void shouldUseGatewaySpecificReadTimeoutOverrideForSmartpay_whenSpecified() {
    app = startApp("config/client-factory-test-config-with-smartpay-timeout-override.yaml", false);
    when(mockMetricRegistry.register(any(), any())).thenReturn(null);
    String path = "/hello";
    wireMockRule.stubFor(get(urlPathEqualTo("/hello")).willReturn(aResponse().withBody("world").withStatus(200).withFixedDelay(2000)));
    Client client = new ClientFactory(app.getEnvironment(), app.getConfiguration()).createWithDropwizardClient(SMARTPAY, AUTHORISE, mockMetricRegistry);
    Invocation.Builder request = client.target(getServerUrl()).path(path).request();
    Long authOverriddenTimeout = app.getConfiguration().getSmartpayConfig().getJerseyClientOverrides().map(override -> override.getAuth().getReadTimeout().toMicroseconds()).orElse(0L);
    assertGatewayFailure(request, authOverriddenTimeout);
}
Also used : IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Client(javax.ws.rs.client.Client) AUTHORISE(uk.gov.pay.connector.gateway.GatewayOperation.AUTHORISE) SMARTPAY(uk.gov.pay.connector.gateway.PaymentGatewayName.SMARTPAY) Assert.assertThat(org.junit.Assert.assertThat) After(org.junit.After) ClientFactory(uk.gov.pay.connector.gateway.ClientFactory) SocketTimeoutException(java.net.SocketTimeoutException) Matchers.lessThan(org.hamcrest.Matchers.lessThan) PortFactory(uk.gov.service.payments.commons.testing.port.PortFactory) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) ResourceHelpers(io.dropwizard.testing.ResourceHelpers) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) MetricRegistry(com.codahale.metrics.MetricRegistry) DropwizardTestSupport(io.dropwizard.testing.DropwizardTestSupport) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Test(org.junit.Test) ClientProperties(org.glassfish.jersey.client.ClientProperties) Invocation(javax.ws.rs.client.Invocation) Mockito.when(org.mockito.Mockito.when) ConnectorConfiguration(uk.gov.pay.connector.app.ConnectorConfiguration) String.format(java.lang.String.format) ConnectorApp(uk.gov.pay.connector.app.ConnectorApp) WireMockClassRule(com.github.tomakehurst.wiremock.junit.WireMockClassRule) WORLDPAY(uk.gov.pay.connector.gateway.PaymentGatewayName.WORLDPAY) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Mockito.any(org.mockito.Mockito.any) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Invocation(javax.ws.rs.client.Invocation) ClientFactory(uk.gov.pay.connector.gateway.ClientFactory) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)2 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)2 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)2 WireMock.getRequestedFor (com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor)2 WireMock.urlEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo)2 WireMock.urlPathEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo)2 WireMockClassRule (com.github.tomakehurst.wiremock.junit.WireMockClassRule)2 DropwizardTestSupport (io.dropwizard.testing.DropwizardTestSupport)2 ResourceHelpers (io.dropwizard.testing.ResourceHelpers)2 String.format (java.lang.String.format)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Client (javax.ws.rs.client.Client)2 Invocation (javax.ws.rs.client.Invocation)2 ClientProperties (org.glassfish.jersey.client.ClientProperties)2 Matchers.lessThan (org.hamcrest.Matchers.lessThan)2 IsInstanceOf.instanceOf (org.hamcrest.core.IsInstanceOf.instanceOf)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertThat (org.junit.Assert.assertThat)2 Assert.fail (org.junit.Assert.fail)2