-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PP-7609 - Pact test for GATEWAY_3DS_EXEMPTION_RESULT_OBTAINED
Description: - This PR creates the JSON file which is needed on the consumer side to verify the pact as well as testing whether the transaction row contains the exemption3ds field - With @alexbishop1
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
.../java/uk/gov/pay/ledger/pact/Gateway3dsExemptionResultObtainedEventQueueContractTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters