3030import org .junit .jupiter .api .extension .ExtendWith ;
3131
3232import au .com .dius .pact .consumer .MockServer ;
33+ import au .com .dius .pact .consumer .dsl .PactDslJsonBody ;
3334import au .com .dius .pact .consumer .dsl .PactDslWithProvider ;
3435import au .com .dius .pact .consumer .junit5 .PactConsumerTestExt ;
3536import au .com .dius .pact .consumer .junit5 .PactTestFor ;
@@ -48,10 +49,17 @@ public V4Pact getMax(PactDslWithProvider builder) throws IOException {
4849 return builder
4950 .given ("Three customers" )
5051 .uponReceiving ("GET request for 0815" )
51- .method ("GET" )
5252 .path ("/delivery-addresses/0815" )
53+ .method ("GET" )
5354 .willRespondWith ()
5455 .status (200 )
56+ .body (new PactDslJsonBody ()
57+ .stringValue ("recipient" , "Max Mustermann" )
58+ .stringValue ("city" , "26122 Oldenburg" )
59+ .object ("street" )
60+ .stringValue ("name" , "Poststr." )
61+ .stringValue ("number" , "1" )
62+ .closeObject ())
5563 .toPact (V4Pact .class );
5664 }
5765
@@ -63,7 +71,7 @@ public V4Pact dontGetMissing(PactDslWithProvider builder) throws IOException {
6371 .path ("/delivery-addresses/0817" )
6472 .method ("GET" )
6573 .willRespondWith ()
66- .status (204 )
74+ .status (404 )
6775 .toPact (V4Pact .class );
6876 }
6977
@@ -75,6 +83,13 @@ public V4Pact updateMax(PactDslWithProvider builder) throws IOException {
7583 .path ("/delivery-addresses/0815" )
7684 .method ("POST" )
7785 .matchHeader ("Content-Type" , "application/json.*" , "application/json" )
86+ .body (new PactDslJsonBody ()
87+ .stringValue ("recipient" , "Erika Mustermann" )
88+ .stringValue ("city" , "45127 Essen" )
89+ .object ("street" )
90+ .stringValue ("name" , "II. Hagen" )
91+ .stringValue ("number" , "7" )
92+ .closeObject ())
7893 .willRespondWith ()
7994 .status (200 )
8095 .toPact (V4Pact .class );
@@ -85,10 +100,20 @@ public V4Pact dontUpdateSherlock(PactDslWithProvider builder) throws IOException
85100 return builder
86101 .given ("Three customers" )
87102 .uponReceiving ("POST request for 007" )
88- .method ("POST" )
89103 .path ("/delivery-addresses/007" )
104+ .method ("POST" )
105+ .matchHeader ("Content-Type" , "application/json.*" , "application/json" )
106+ .body (new PactDslJsonBody ()
107+ .stringValue ("recipient" , "Sherlock Holmes" )
108+ .stringValue ("city" , "London NW1 6XE" )
109+ .object ("street" )
110+ .stringValue ("name" , "Baker Street" )
111+ .stringValue ("number" , "221B" )
112+ .closeObject ())
90113 .willRespondWith ()
91114 .status (400 )
115+ .matchHeader ("Content-Type" , "application/problem\\ +json.*" , "application/problem+json" )
116+ .body (new PactDslJsonBody ().stringMatcher ("detail" , ".*" , "Addresses from UK are not supported for delivery" ))
92117 .toPact (V4Pact .class );
93118 }
94119
0 commit comments