Skip to content

Commit 2975f37

Browse files
committed
Update existing pact tests to use V4 API.
This is required as a result of the version bump of Pact in the prior commit.
1 parent d1dbe5d commit 2975f37

File tree

2 files changed

+53
-35
lines changed

2 files changed

+53
-35
lines changed

service/src/test/java/bio/terra/workspace/pact/ProfileApiTest.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import static org.junit.jupiter.api.Assertions.assertThrows;
44

55
import au.com.dius.pact.consumer.MockServer;
6+
import au.com.dius.pact.consumer.dsl.PactBuilder;
67
import au.com.dius.pact.consumer.dsl.PactDslJsonBody;
7-
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
88
import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
99
import au.com.dius.pact.consumer.junit5.PactTestFor;
10-
import au.com.dius.pact.core.model.RequestResponsePact;
10+
import au.com.dius.pact.core.model.V4Pact;
1111
import au.com.dius.pact.core.model.annotations.Pact;
1212
import bio.terra.workspace.app.configuration.external.SpendProfileConfiguration;
1313
import bio.terra.workspace.service.iam.AuthenticatedUserRequest;
@@ -32,7 +32,7 @@ public class ProfileApiTest {
3232
static final String dummyGCPProfileId = "37bfb7e0-8261-4160-9ae7-882800d6464f";
3333

3434
@Pact(consumer = "wsm-consumer", provider = "bpm-provider")
35-
public RequestResponsePact existingAzureBillingProfile(PactDslWithProvider builder) {
35+
public V4Pact existingAzureBillingProfile(PactBuilder builder) {
3636
var billingProfileResponseShape =
3737
new PactDslJsonBody()
3838
.stringValue("cloudPlatform", CloudPlatform.AZURE.toSql())
@@ -41,6 +41,7 @@ public RequestResponsePact existingAzureBillingProfile(PactDslWithProvider build
4141
.stringType("managedResourceGroupId")
4242
.uuid("id");
4343
return builder
44+
.usingLegacyDsl()
4445
.given("an Azure billing profile")
4546
.uponReceiving("A request to retrieve a billing profile")
4647
.method("GET")
@@ -53,17 +54,18 @@ public RequestResponsePact existingAzureBillingProfile(PactDslWithProvider build
5354
.willRespondWith()
5455
.status(200)
5556
.body(billingProfileResponseShape)
56-
.toPact();
57+
.toPact(V4Pact.class);
5758
}
5859

5960
@Pact(consumer = "wsm-consumer", provider = "bpm-provider")
60-
public RequestResponsePact existingGCPBillingProfile(PactDslWithProvider builder) {
61+
public V4Pact existingGCPBillingProfile(PactBuilder builder) {
6162
var billingProfileResponseShape =
6263
new PactDslJsonBody()
6364
.stringValue("cloudPlatform", CloudPlatform.GCP.toSql())
6465
.stringType("billingAccountId")
6566
.uuid("id");
6667
return builder
68+
.usingLegacyDsl()
6769
.given("a GCP billing profile")
6870
.uponReceiving("A request to retrieve a billing profile")
6971
.method("GET")
@@ -73,19 +75,20 @@ public RequestResponsePact existingGCPBillingProfile(PactDslWithProvider builder
7375
.willRespondWith()
7476
.status(200)
7577
.body(billingProfileResponseShape)
76-
.toPact();
78+
.toPact(V4Pact.class);
7779
}
7880

7981
@Pact(consumer = "wsm-consumer", provider = "bpm-provider")
80-
public RequestResponsePact billingProfileUnAvailable(PactDslWithProvider builder) {
82+
public V4Pact billingProfileUnAvailable(PactBuilder builder) {
8183
return builder
84+
.usingLegacyDsl()
8285
.uponReceiving("A request to retrieve a billing profile")
8386
.method("GET")
8487
// there's no state set on this pact, so this id won't exist in bpm
8588
.path(String.format("/api/profiles/v1/%s", dummyAzureProfileId))
8689
.willRespondWith()
8790
.status(403)
88-
.toPact();
91+
.toPact(V4Pact.class);
8992
}
9093

9194
@Test

service/src/test/java/bio/terra/workspace/pact/TpsApiTest.java

+42-27
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import static org.mockito.Mockito.*;
66

77
import au.com.dius.pact.consumer.MockServer;
8+
import au.com.dius.pact.consumer.dsl.PactBuilder;
89
import au.com.dius.pact.consumer.dsl.PactDslJsonArray;
910
import au.com.dius.pact.consumer.dsl.PactDslJsonBody;
10-
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
1111
import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
1212
import au.com.dius.pact.consumer.junit5.PactTestFor;
1313
import au.com.dius.pact.core.model.RequestResponsePact;
14+
import au.com.dius.pact.core.model.V4Pact;
1415
import au.com.dius.pact.core.model.annotations.Pact;
1516
import bio.terra.policy.model.*;
1617
import bio.terra.workspace.app.configuration.external.FeatureConfiguration;
@@ -109,8 +110,9 @@ void setup(MockServer mockServer) throws Exception {
109110
}
110111

111112
@Pact(consumer = "wsm", provider = "tps")
112-
public RequestResponsePact createPaoWithNoExistingPolicy(PactDslWithProvider builder) {
113+
public RequestResponsePact createPaoWithNoExistingPolicy(PactBuilder builder) {
113114
return builder
115+
.usingLegacyDsl()
114116
.uponReceiving("A request to create a policy")
115117
.method("POST")
116118
.path("/api/policy/v1alpha1/pao")
@@ -133,8 +135,9 @@ public void testCreatingAPolicyWithNoExistingPolicy() throws Exception {
133135
}
134136

135137
@Pact(consumer = "wsm", provider = "tps")
136-
public RequestResponsePact createPaoWithAPreexistingPolicy(PactDslWithProvider builder) {
138+
public RequestResponsePact createPaoWithAPreexistingPolicy(PactBuilder builder) {
137139
return builder
140+
.usingLegacyDsl()
138141
.given(existingPolicyState)
139142
.uponReceiving("A request to create a policy that already exists")
140143
.method("POST")
@@ -163,8 +166,9 @@ public void creatingAPolicyThatAlreadyExists() {
163166
}
164167

165168
@Pact(consumer = "wsm", provider = "tps")
166-
public RequestResponsePact deletePaoThatExists(PactDslWithProvider builder) {
169+
public V4Pact deletePaoThatExists(PactBuilder builder) {
167170
return builder
171+
.usingLegacyDsl()
168172
.given(existingPolicyState)
169173
.uponReceiving("A request to delete a policy")
170174
.method("DELETE")
@@ -173,7 +177,7 @@ public RequestResponsePact deletePaoThatExists(PactDslWithProvider builder) {
173177
"/api/policy/v1alpha1/pao/%s".formatted(existingPolicyId))
174178
.willRespondWith()
175179
.status(HttpStatus.OK.value())
176-
.toPact();
180+
.toPact(V4Pact.class);
177181
}
178182

179183
@Test
@@ -183,7 +187,7 @@ public void deletingAnExistingPolicy() throws Exception {
183187
}
184188

185189
@Pact(consumer = "wsm", provider = "tps")
186-
public RequestResponsePact getPaoWithAnExistingPolicy(PactDslWithProvider builder) {
190+
public V4Pact getPaoWithAnExistingPolicy(PactBuilder builder) {
187191
var policyResponseShape =
188192
new PactDslJsonBody()
189193
.valueFromProviderState("objectId", existingPolicyProviderStateValue, existingPolicyId)
@@ -193,6 +197,7 @@ public RequestResponsePact getPaoWithAnExistingPolicy(PactDslWithProvider builde
193197
.object("attributes", tpsPolicyInputsObjectShape);
194198

195199
return builder
200+
.usingLegacyDsl()
196201
.given(existingPolicyState)
197202
.uponReceiving("A request to retrieve a policy")
198203
.method("GET")
@@ -202,7 +207,7 @@ public RequestResponsePact getPaoWithAnExistingPolicy(PactDslWithProvider builde
202207
.willRespondWith()
203208
.status(HttpStatus.OK.value())
204209
.body(policyResponseShape)
205-
.toPact();
210+
.toPact(V4Pact.class);
206211
}
207212

208213
@Test
@@ -224,14 +229,15 @@ public void retrievingAnExistingPolicy() throws Exception {
224229
}
225230

226231
@Pact(consumer = "wsm", provider = "tps")
227-
public RequestResponsePact getPaoThatDoesNotExist(PactDslWithProvider builder) {
232+
public V4Pact getPaoThatDoesNotExist(PactBuilder builder) {
228233
return builder
234+
.usingLegacyDsl()
229235
.uponReceiving("A request to retrieve a policy that doesn't exist")
230236
.method("GET")
231237
.matchPath("/api/policy/v1alpha1/pao/%s".formatted(UUID_REGEX))
232238
.willRespondWith()
233239
.status(HttpStatus.NOT_FOUND.value())
234-
.toPact();
240+
.toPact(V4Pact.class);
235241
}
236242

237243
@Test
@@ -241,7 +247,7 @@ public void retrievingAPolicyThatDoesNotExist() {
241247
}
242248

243249
@Pact(consumer = "wsm", provider = "tps")
244-
public RequestResponsePact linkPaoWhenBothExist(PactDslWithProvider builder) {
250+
public V4Pact linkPaoWhenBothExist(PactBuilder builder) {
245251
var linkRequestShape =
246252
new PactDslJsonBody()
247253
.valueFromProviderState(
@@ -254,6 +260,7 @@ public RequestResponsePact linkPaoWhenBothExist(PactDslWithProvider builder) {
254260
.object("resultingPao");
255261

256262
return builder
263+
.usingLegacyDsl()
257264
.given(existingPolicyState)
258265
.given(secondPolicyState)
259266
.uponReceiving("A request to link the policies")
@@ -266,7 +273,7 @@ public RequestResponsePact linkPaoWhenBothExist(PactDslWithProvider builder) {
266273
.willRespondWith()
267274
.status(HttpStatus.OK.value())
268275
.body(linkResponseShape)
269-
.toPact();
276+
.toPact(V4Pact.class);
270277
}
271278

272279
@Test
@@ -277,7 +284,7 @@ public void linkTwoExistingPaosWithNoConflicts() throws Exception {
277284
}
278285

279286
@Pact(consumer = "wsm", provider = "tps")
280-
public RequestResponsePact mergePaoWhenBothExist(PactDslWithProvider builder) {
287+
public V4Pact mergePaoWhenBothExist(PactBuilder builder) {
281288
var linkRequestShape =
282289
new PactDslJsonBody()
283290
.valueFromProviderState(
@@ -291,6 +298,7 @@ public RequestResponsePact mergePaoWhenBothExist(PactDslWithProvider builder) {
291298
.object("resultingPao");
292299

293300
return builder
301+
.usingLegacyDsl()
294302
.given(existingPolicyState)
295303
.given(secondPolicyState)
296304
.uponReceiving("A request to link the policies")
@@ -303,7 +311,7 @@ public RequestResponsePact mergePaoWhenBothExist(PactDslWithProvider builder) {
303311
.willRespondWith()
304312
.status(HttpStatus.OK.value())
305313
.body(linkResponseShape)
306-
.toPact();
314+
.toPact(V4Pact.class);
307315
}
308316

309317
@Test
@@ -315,7 +323,7 @@ public void mergingTwoExistingPaos() throws Exception {
315323
}
316324

317325
@Pact(consumer = "wsm", provider = "tps")
318-
public RequestResponsePact replacePaoThatExists(PactDslWithProvider builder) {
326+
public V4Pact replacePaoThatExists(PactBuilder builder) {
319327
var updateRequestShape =
320328
new PactDslJsonBody()
321329
.object("newAttributes", tpsPolicyInputsObjectShape)
@@ -326,6 +334,7 @@ public RequestResponsePact replacePaoThatExists(PactDslWithProvider builder) {
326334
.object("conflicts", new PactDslJsonArray())
327335
.object("resultingPao"); // TpsPaoGetResult
328336
return builder
337+
.usingLegacyDsl()
329338
.given(existingPolicyState)
330339
.uponReceiving("A request to update a policy")
331340
.method("PUT")
@@ -337,7 +346,7 @@ public RequestResponsePact replacePaoThatExists(PactDslWithProvider builder) {
337346
.willRespondWith()
338347
.status(HttpStatus.OK.value())
339348
.body(updateResponseShape)
340-
.toPact();
349+
.toPact(V4Pact.class);
341350
}
342351

343352
@Test
@@ -351,7 +360,7 @@ public void replacingAnExistingPaoWithNoConflicts() throws Exception {
351360
}
352361

353362
@Pact(consumer = "wsm", provider = "tps")
354-
public RequestResponsePact updatePaoPreexistingNoConflicts(PactDslWithProvider builder) {
363+
public V4Pact updatePaoPreexistingNoConflicts(PactBuilder builder) {
355364
var updateRequestShape =
356365
new PactDslJsonBody()
357366
.object("addAttributes", tpsPolicyInputsObjectShape)
@@ -363,6 +372,7 @@ public RequestResponsePact updatePaoPreexistingNoConflicts(PactDslWithProvider b
363372
.object("conflicts", new PactDslJsonArray())
364373
.object("resultingPao"); // TpsPaoGetResult
365374
return builder
375+
.usingLegacyDsl()
366376
.given(existingPolicyState)
367377
.uponReceiving("A request to update a policy")
368378
.method("PATCH")
@@ -374,7 +384,7 @@ public RequestResponsePact updatePaoPreexistingNoConflicts(PactDslWithProvider b
374384
.willRespondWith()
375385
.status(HttpStatus.OK.value())
376386
.body(updateResponseShape)
377-
.toPact();
387+
.toPact(V4Pact.class);
378388
}
379389

380390
@Test
@@ -391,8 +401,9 @@ public void updatingAnExistingPaoWithNoConflicts() throws Exception {
391401
}
392402

393403
@Pact(consumer = "wsm", provider = "tps")
394-
public RequestResponsePact listValidRegions(PactDslWithProvider builder) {
404+
public V4Pact listValidRegions(PactBuilder builder) {
395405
return builder
406+
.usingLegacyDsl()
396407
.given(existingPolicyState)
397408
.uponReceiving("A request to list the valid regions for a policy using the id")
398409
.method("GET")
@@ -403,7 +414,7 @@ public RequestResponsePact listValidRegions(PactDslWithProvider builder) {
403414
.willRespondWith()
404415
.status(HttpStatus.OK.value())
405416
.body(new PactDslJsonArray().stringType())
406-
.toPact();
417+
.toPact(V4Pact.class);
407418
}
408419

409420
@Test
@@ -414,8 +425,9 @@ public void listingValidRegionsOnAWorkspace() throws Exception {
414425
}
415426

416427
@Pact(consumer = "wsm", provider = "tps")
417-
public RequestResponsePact listValidByPolicyInput(PactDslWithProvider builder) {
428+
public V4Pact listValidByPolicyInput(PactBuilder builder) {
418429
return builder
430+
.usingLegacyDsl()
419431
.given(existingPolicyState)
420432
.uponReceiving("A request to list the valid regions for a policy using policy input")
421433
.method("POST")
@@ -426,7 +438,7 @@ public RequestResponsePact listValidByPolicyInput(PactDslWithProvider builder) {
426438
.willRespondWith()
427439
.status(HttpStatus.OK.value())
428440
.body(new PactDslJsonArray().stringType())
429-
.toPact();
441+
.toPact(V4Pact.class);
430442
}
431443

432444
@Test
@@ -445,7 +457,7 @@ public void listingValidRegionsOnAPolicy() throws Exception {
445457
}
446458

447459
@Pact(consumer = "wsm", provider = "tps")
448-
public RequestResponsePact explainingAWorkspacePolicy(PactDslWithProvider builder) {
460+
public V4Pact explainingAWorkspacePolicy(PactBuilder builder) {
449461
var explainResponse =
450462
new PactDslJsonBody()
451463
.numberType("depth")
@@ -455,6 +467,7 @@ public RequestResponsePact explainingAWorkspacePolicy(PactDslWithProvider builde
455467
"policyInput",
456468
new PactDslJsonBody().stringType("namespace").stringType("name").closeObject());
457469
return builder
470+
.usingLegacyDsl()
458471
.given(existingPolicyState)
459472
.uponReceiving("A request to explain the policy")
460473
.method("GET")
@@ -465,7 +478,7 @@ public RequestResponsePact explainingAWorkspacePolicy(PactDslWithProvider builde
465478
.willRespondWith()
466479
.status(HttpStatus.OK.value())
467480
.body(explainResponse)
468-
.toPact();
481+
.toPact(V4Pact.class);
469482
}
470483

471484
@Test
@@ -486,7 +499,7 @@ public void explainingAPolicy() throws Exception {
486499
}
487500

488501
@Pact(consumer = "wsm", provider = "tps")
489-
public RequestResponsePact getLocationInfo(PactDslWithProvider builder) {
502+
public V4Pact getLocationInfo(PactBuilder builder) {
490503
var locationArray =
491504
new PactDslJsonArray()
492505
.eachArrayLike()
@@ -502,6 +515,7 @@ public RequestResponsePact getLocationInfo(PactDslWithProvider builder) {
502515
.object("regions", new PactDslJsonArray().stringType())
503516
.object("locations", locationArray);
504517
return builder
518+
.usingLegacyDsl()
505519
.uponReceiving("A request for information about a location")
506520
.method("GET")
507521
.path("/api/policy/v1alpha1/location")
@@ -510,7 +524,7 @@ public RequestResponsePact getLocationInfo(PactDslWithProvider builder) {
510524
.willRespondWith()
511525
.status(HttpStatus.OK.value())
512526
.body(responseShape)
513-
.toPact();
527+
.toPact(V4Pact.class);
514528
}
515529

516530
@Test
@@ -521,7 +535,7 @@ public void retrievingInformationOnALocation() throws Exception {
521535
}
522536

523537
@Pact(consumer = "wsm", provider = "tps")
524-
public RequestResponsePact getLocationInfoWithNullLocation(PactDslWithProvider builder) {
538+
public V4Pact getLocationInfoWithNullLocation(PactBuilder builder) {
525539
var locationArray =
526540
new PactDslJsonArray()
527541
.eachArrayLike()
@@ -537,14 +551,15 @@ public RequestResponsePact getLocationInfoWithNullLocation(PactDslWithProvider b
537551
.object("regions", new PactDslJsonArray().stringType())
538552
.object("locations", locationArray);
539553
return builder
554+
.usingLegacyDsl()
540555
.uponReceiving("A request for information about a null location")
541556
.method("GET")
542557
.path("/api/policy/v1alpha1/location")
543558
.matchQuery("platform", cloudPlatformTpsRegex)
544559
.willRespondWith()
545560
.status(HttpStatus.OK.value())
546561
.body(responseShape)
547-
.toPact();
562+
.toPact(V4Pact.class);
548563
}
549564

550565
@Test

0 commit comments

Comments
 (0)