-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add Kotlin Junit5 message test
- Loading branch information
1 parent
fc7e13e
commit 2750d8a
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
consumer/junit5/src/test/kotlin/au/com/dius/pact/consumer/junit5/KotlinV4MessageTest.kt
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,49 @@ | ||
package au.com.dius.pact.consumer.junit5 | ||
|
||
import au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonBody | ||
import au.com.dius.pact.consumer.dsl.PactBuilder | ||
import au.com.dius.pact.core.model.PactSpecVersion | ||
import au.com.dius.pact.core.model.V4Pact | ||
import au.com.dius.pact.core.model.annotations.Pact | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.hamcrest.Matchers.`is` | ||
import org.hamcrest.Matchers.notNullValue | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(value = [PactConsumerTestExt::class]) | ||
@PactTestFor(providerName = "checkout-service", providerType = ProviderType.ASYNCH, pactVersion = PactSpecVersion.V4) | ||
class KotlinV4MessageTest { | ||
|
||
private val jsonBody = newJsonBody { o -> | ||
o.stringType("purchaseId", "111") | ||
o.stringType("name", "PURCHASE_STARTED") | ||
o.eachLike("products", 1) { items -> | ||
items.stringType("productID", "1") | ||
items.stringType("productType", "FLIGHT") | ||
items.stringType("availabilityId", "28e80c5987c6a242516ccdc004235b5e") | ||
} | ||
}.build() | ||
|
||
@Pact(consumer = "reservation-service", provider = "checkout-service") | ||
fun pactForReservationBooking(builder: PactBuilder): V4Pact { | ||
return builder | ||
.usingLegacyMessageDsl() | ||
.hasPactWith("checkout-service") | ||
.expectsToReceive("a purchase started message to book a reservation") | ||
.withContent(jsonBody) | ||
.toPact() | ||
} | ||
|
||
@Test | ||
@PactTestFor(pactMethod = "pactForReservationBooking") | ||
fun testPactForReservationBooking(pact: V4Pact) { | ||
val message = pact.interactions.firstOrNull() | ||
assertThat(message, `is`(notNullValue())) | ||
assertThat(message!!.asAsynchronousMessage()!!.contents.contents.valueAsString(), | ||
`is`(equalTo("{\"name\":\"PURCHASE_STARTED\",\"products\":[{\"availabilityId\":" + | ||
"\"28e80c5987c6a242516ccdc004235b5e\",\"productID\":\"1\",\"productType\":\"FLIGHT\"}]," + | ||
"\"purchaseId\":\"111\"}"))) | ||
} | ||
} |