Skip to content

Commit

Permalink
Merge branch 'v4.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Aug 1, 2021
2 parents 38c3126 + a816fb8 commit 436662a
Show file tree
Hide file tree
Showing 9 changed files with 594 additions and 17 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
To generate the log, run `git log --pretty='* %h - %s (%an, %ad)' TAGNAME..HEAD` replacing TAGNAME and HEAD as appropriate.

# 4.1.24 - Bugfixes + backports from 4.2.x

* 43ec8749a - fix: previous provider states must not be copied over to new interactions #497 (Ronald Holshausen, Sat Jul 31 16:26:00 2021 +1000)
* 08c639eff - feat: add a message metadata builder DSL #1409 (Ronald Holshausen, Sat Jul 31 16:07:04 2021 +1000)
* 647ec0d20 - chore: fix codenarc (Ronald Holshausen, Sat Jul 31 14:11:23 2021 +1000)
* c4bd5a14e - chore: add test for pactbroker with path in the URL #1399 (Ronald Holshausen, Sat Jul 31 14:07:04 2021 +1000)
* a11b05cde - fix: header values need to be parsed when loaded from older spec pact files #1398 (Ronald Holshausen, Sat Jul 24 16:09:46 2021 +1000)
* 8e3aa2dae - fix: failing test (Ronald Holshausen, Wed Jul 21 16:15:42 2021 +1000)
* 46549eed7 - fix: retry condition for the pactbroker unknown response #1405 (Bryan Woodruff, Tue Jul 20 17:13:40 2021 -0700)
* 2571af65b - fix: don't encode URLs when making requests from HAL links #1388 (Ronald Holshausen, Sat Jul 17 15:58:51 2021 +1000)
* e750ba6c6 - chore: upgrade Tika to 1.27 #1392 (Ronald Holshausen, Sat Jul 17 14:22:08 2021 +1000)
* 4b8be0225 - chore: fix codenarc voilation (Ronald Holshausen, Sat Jul 17 14:13:31 2021 +1000)
* 1d69fa377 - chore: add debug logging to canIDeploy task (Ronald Holshausen, Sat Jul 17 12:16:18 2021 +1000)
* a510b8fff - fix: retain previous summary state when updating markdown report #1128 (Daniel Grech, Thu Jul 15 07:55:07 2021 +0200)
* 0492e871b - chore: fix test after cherry-picked commit (Ronald Holshausen, Sat Jul 24 12:25:51 2021 +1000)
* 29b763879 - feat: Ignore missing part content type headers with multipart bodies #1385 (Ronald Holshausen, Sun Jun 27 15:55:04 2021 +1000)
* 05cafce97 - feat: add option to mock server to disable persistant HTTP/1.1 connections #1383 #342 (Ronald Holshausen, Sun Jun 27 14:22:55 2021 +1000)
* 76d2bbc63 - bump version to 4.1.24 (Ronald Holshausen, Thu Jun 24 11:50:03 2021 +1000)

# 4.2.8 - Bugfix Release

* 0ca295d3b - Merge pull request #1403 from llorentejavier/adding_external_keystore_for_mockserver (Ronald Holshausen, Wed Jul 21 16:18:32 2021 +1000)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package au.com.dius.pact.consumer.junit5;

import au.com.dius.pact.consumer.MessagePactBuilder;
import au.com.dius.pact.core.model.annotations.Pact;
import au.com.dius.pact.consumer.dsl.PactDslJsonBody;
import au.com.dius.pact.core.model.annotations.Pact;
import au.com.dius.pact.core.model.matchingrules.RegexMatcher;
import au.com.dius.pact.core.model.messaging.Message;
import au.com.dius.pact.core.model.messaging.MessagePact;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

@ExtendWith(PactConsumerTestExt.class)
@PactTestFor(providerName = "MessageProvider", providerType = ProviderType.ASYNCH)
Expand All @@ -25,24 +28,30 @@ public MessagePact createPact(MessagePactBuilder builder) {
body.stringValue("testParam1", "value1");
body.stringValue("testParam2", "value2");

Map<String, Object> metadata = new HashMap<>();
metadata.put("metadata1", "metadataValue1");
metadata.put("metadata2", "metadataValue2");
metadata.put("metadata3", 10L);

return builder.given("SomeProviderState")
.expectsToReceive("a test message with metadata")
.withMetadata(metadata)
.withMetadata(md -> {
md.add("metadata1", "metadataValue1");
md.add("metadata2", "metadataValue2");
md.add("metadata3", 10L);
md.matchRegex("partitionKey", "[A-Z]{3}\\d{2}", "ABC01");
})
.withContent(body)
.toPact();
}

@Test
void test(List<Message> messages) {
assertTrue(!messages.isEmpty());
assertTrue(!messages.get(0).getMetadata().isEmpty());
assertEquals("metadataValue1", messages.get(0).getMetadata().get("metadata1"));
assertEquals("metadataValue2", messages.get(0).getMetadata().get("metadata2"));
assertEquals(10L, messages.get(0).getMetadata().get("metadata3"));
assertThat(messages, is(not(empty())));
Message message = messages.get(0);
Map<String, Object> metaData = message.getMetadata();
assertThat(metaData.entrySet(), is(not(empty())));
assertThat(metaData.get("metadata1"), is("metadataValue1"));
assertThat(metaData.get("metadata2"), is("metadataValue2"));
assertThat(metaData.get("metadata3"), is(10L));
assertThat(metaData.get("partitionKey"), is("ABC01"));

assertThat(message.getMatchingRules().rulesForCategory("metadata").allMatchingRules(),
is(Collections.singletonList(new RegexMatcher("[A-Z]{3}\\d{2}"))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.com.dius.pact.consumer

import au.com.dius.pact.consumer.dsl.DslPart
import au.com.dius.pact.consumer.dsl.Matcher
import au.com.dius.pact.consumer.dsl.MetadataBuilder
import au.com.dius.pact.consumer.xml.PactXmlBuilder
import au.com.dius.pact.core.model.BasePact.Companion.DEFAULT_METADATA
import au.com.dius.pact.core.model.Consumer
Expand All @@ -16,6 +17,7 @@ import au.com.dius.pact.core.model.RequestResponseInteraction
import au.com.dius.pact.core.model.RequestResponsePact
import au.com.dius.pact.core.model.UnknownPactSource
import au.com.dius.pact.core.model.V4Pact
import au.com.dius.pact.core.model.generators.Category
import au.com.dius.pact.core.model.messaging.Message
import au.com.dius.pact.core.model.messaging.MessagePact
import java.util.function.Function
Expand Down Expand Up @@ -142,6 +144,23 @@ class MessagePactBuilder @JvmOverloads constructor(
return this
}

/**
* Adds the expected metadata to the message using a builder
*/
fun withMetadata(consumer: java.util.function.Consumer<MetadataBuilder>): MessagePactBuilder {
if (messages.isEmpty()) {
throw InvalidPactException("expectsToReceive is required before withMetaData")
}

val message = messages.last()
val metadataBuilder = MetadataBuilder()
consumer.accept(metadataBuilder)
message.metadata = metadataBuilder.values
message.matchingRules.addCategory(metadataBuilder.matchers)
message.generators.addGenerators(Category.METADATA, metadataBuilder.generators)
return this
}

/**
* Adds the JSON body as the message content
*/
Expand Down
Loading

0 comments on commit 436662a

Please sign in to comment.