Skip to content

Commit

Permalink
Merge pull request #1071 from alphagov/PP-7609-Pact-test-for-GATEWAY_…
Browse files Browse the repository at this point in the history
…3DS_EXEMPTION_RESULT_OBTAINED

PP-7609 - Pact test for GATEWAY_3DS_EXEMPTION_RESULT_OBTAINED
  • Loading branch information
nimalank7 committed Jan 12, 2021
2 parents 2cd3d3c + 4a2369c commit 761f3c6
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static TestSuite suite() {
consumerToJUnitTest.put("connector", new JUnit4TestAdapter(RefundIncludedInPayoutEventQueueContractTest.class));
consumerToJUnitTest.put("connector", new JUnit4TestAdapter(CancelledByUserEventQueueContractTest.class));
consumerToJUnitTest.put("connector", new JUnit4TestAdapter(UserEmailCollectedEventQueueContractTest.class));
consumerToJUnitTest.put("connector", new JUnit4TestAdapter(Gateway3dsExemptionResultObtainedEventQueueContractTest.class));
return CreateTestSuite.create(consumerToJUnitTest.build());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package uk.gov.pay.ledger.pact;

import au.com.dius.pact.consumer.MessagePactBuilder;
import au.com.dius.pact.consumer.MessagePactProviderRule;
import au.com.dius.pact.consumer.Pact;
import au.com.dius.pact.consumer.PactVerification;
import au.com.dius.pact.model.v3.messaging.MessagePact;
import org.junit.Rule;
import org.junit.Test;
import uk.gov.pay.ledger.rule.AppWithPostgresAndSqsRule;
import uk.gov.pay.ledger.rule.SqsTestDocker;
import uk.gov.pay.ledger.transaction.dao.TransactionDao;
import uk.gov.pay.ledger.transaction.entity.TransactionEntity;
import uk.gov.pay.ledger.util.fixture.QueuePaymentEventFixture;

import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static io.dropwizard.testing.ConfigOverride.config;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.gov.pay.ledger.util.fixture.QueuePaymentEventFixture.aQueuePaymentEventFixture;

public class Gateway3dsExemptionResultObtainedEventQueueContractTest {
@Rule
public MessagePactProviderRule mockProvider = new MessagePactProviderRule(this);

@Rule
public AppWithPostgresAndSqsRule appRule = new AppWithPostgresAndSqsRule(
config("queueMessageReceiverConfig.backgroundProcessingEnabled", "true")
);

private byte[] currentMessage;
private String externalId = "gateway3dsExemptionResultObtained_externalId";
private ZonedDateTime eventDate = ZonedDateTime.parse("2018-03-12T16:25:01.123456Z");

@Pact(provider = "connector", consumer = "ledger")
public MessagePact createGateway3dsExemptionResultObtainedEventPact(MessagePactBuilder builder) {
String gateway3dsExemptionResultObtainedEvent = "GATEWAY_3DS_EXEMPTION_RESULT_OBTAINED";
QueuePaymentEventFixture gateway3dsExemptionResultObtained = aQueuePaymentEventFixture()
.withResourceExternalId(externalId)
.withEventDate(eventDate)
.withEventType(gateway3dsExemptionResultObtainedEvent)
.withDefaultEventDataForEventType(gateway3dsExemptionResultObtainedEvent);

Map<String, String> metadata = new HashMap<>();
metadata.put("contentType", "application/json");

return builder
.expectsToReceive("a gateway 3DS exemption result obtained message")
.withMetadata(metadata)
.withContent(gateway3dsExemptionResultObtained.getAsPact())
.toPact();
}

@Test
@PactVerification({"connector"})
public void test() {
TransactionDao transactionDao = new TransactionDao(appRule.getJdbi());

appRule.getSqsClient().sendMessage(SqsTestDocker.getQueueUrl("event-queue"), new String(currentMessage));

await().atMost(1, TimeUnit.SECONDS).until(
() -> transactionDao.findTransactionByExternalId(externalId).isPresent()
&& transactionDao.findTransactionByExternalId(externalId).get().getTransactionDetails().contains("\"exemption3ds\""));

Optional<TransactionEntity> transaction = transactionDao.findTransactionByExternalId(externalId);

assertThat(transaction.isPresent(), is(true));
assertThat(transaction.get().getExternalId(), is(externalId));
assertThat(transaction.get().getTransactionDetails(), containsString("\"exemption3ds\": \"HONOURED\""));
}

public void setMessage(byte[] messageContents) {
currentMessage = messageContents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ public QueuePaymentEventFixture withDefaultEventDataForEventType(String eventTyp
case "USER_EMAIL_COLLECTED":
eventData = gsonBuilder.create().toJson(Map.of("email", "test@example.org"));
break;
case "GATEWAY_3DS_EXEMPTION_RESULT_OBTAINED":
eventData = gsonBuilder.create().toJson(Map.of("exemption3ds", "HONOURED"));
break;
default:
eventData = gsonBuilder.create().toJson(Map.of("event_data", "event_data"));
}
Expand Down

0 comments on commit 761f3c6

Please sign in to comment.