-
-
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.
fix: Message metadata is parsed as JSON, so need to check for JSON ty…
…pes #1749
- Loading branch information
1 parent
3809c9b
commit 2a641c4
Showing
5 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...r/junit5/src/test/java/au/com/dius/pact/consumer/junit5/AsyncMessageWithMetadataTest.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,39 @@ | ||
package au.com.dius.pact.consumer.junit5; | ||
|
||
import au.com.dius.pact.consumer.MessagePactBuilder; | ||
import au.com.dius.pact.consumer.dsl.Matchers; | ||
import au.com.dius.pact.consumer.dsl.PactDslJsonBody; | ||
import au.com.dius.pact.core.model.V4Interaction; | ||
import au.com.dius.pact.core.model.V4Pact; | ||
import au.com.dius.pact.core.model.annotations.Pact; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
import static org.hamcrest.core.Is.is; | ||
|
||
@ExtendWith(PactConsumerTestExt.class) | ||
@PactTestFor(providerName = "AmqpProviderWithMetadata", providerType = ProviderType.ASYNCH) | ||
public class AsyncMessageWithMetadataTest { | ||
|
||
@Pact(consumer = "test_consumer") | ||
public V4Pact withMetadata(MessagePactBuilder builder) { | ||
return builder | ||
.given("Some State") | ||
.expectsToReceive("A message with metadata") | ||
.withMetadata(Map.of("someKey", Matchers.string("someString"))) | ||
.withContent(new PactDslJsonBody().stringType("someField", "someValue")) | ||
.toPact(V4Pact.class); | ||
} | ||
|
||
@Test | ||
@PactTestFor | ||
void test(List<V4Interaction.AsynchronousMessage> messages) { | ||
assertThat(new String(messages.get(0).contentsAsBytes()), is("{\"someField\":\"someValue\"}")); | ||
assertThat(messages.get(0).getMetadata(), hasEntry("someKey", "someString")); | ||
} | ||
} |
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
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
34 changes: 34 additions & 0 deletions
34
provider/junit5/src/test/java/au/com/dius/pact/provider/junit5/MessageWithMetadataTest.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,34 @@ | ||
package au.com.dius.pact.provider.junit5; | ||
|
||
import au.com.dius.pact.provider.MessageAndMetadata; | ||
import au.com.dius.pact.provider.PactVerifyProvider; | ||
import au.com.dius.pact.provider.junitsupport.Provider; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactFolder; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.util.Map; | ||
|
||
@Provider("AmqpProviderWithMetadata") | ||
@PactFolder("src/test/resources/amqp_pacts") | ||
class MessageWithMetadataTest { | ||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider.class) | ||
void testTemplate(PactVerificationContext context) { | ||
context.verifyInteraction(); | ||
} | ||
|
||
@BeforeEach | ||
void before(PactVerificationContext context) { | ||
context.setTarget(new MessageTestTarget()); | ||
} | ||
|
||
@PactVerifyProvider("A message with metadata") | ||
public MessageAndMetadata verifyV4MessageWithMetadataForOrder() { | ||
return new MessageAndMetadata( | ||
"{\"someField\": \"someValue\"}".getBytes(), | ||
Map.of("someKey", "different string pact but same type") | ||
); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
provider/junit5/src/test/resources/amqp_pacts/message_with_metadata_v4.json
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,56 @@ | ||
{ | ||
"consumer": { | ||
"name": "test_consumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"contents": { | ||
"content": { | ||
"someField": "someValue" | ||
}, | ||
"contentType": "application/json", | ||
"encoded": false | ||
}, | ||
"description": "A message with metadata", | ||
"matchingRules": { | ||
"body": { | ||
"$.someField": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
} | ||
}, | ||
"metadata": { | ||
"someKey": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"metadata": { | ||
"contentType": "application/json", | ||
"someKey": "someString" | ||
}, | ||
"pending": false, | ||
"type": "Asynchronous/Messages" | ||
} | ||
], | ||
"metadata": { | ||
"pact-jvm": { | ||
"version": "4.6.5" | ||
}, | ||
"pactSpecification": { | ||
"version": "4.0" | ||
} | ||
}, | ||
"provider": { | ||
"name": "AmqpProviderWithMetadata" | ||
} | ||
} |