-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDKStackAssert.java
580 lines (494 loc) · 25.3 KB
/
CDKStackAssert.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
/*
* Licensed to Muhammad Hamadto
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* See the NOTICE file distributed with this work for additional information regarding copyright ownership.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sandpipers.cdk.assertion;
import static io.sandpipers.cdk.assertion.CdkResourceType.APPRUNNER_SERVICE;
import static io.sandpipers.cdk.assertion.CdkResourceType.APPRUNNER_VPC_CONNECTOR;
import static io.sandpipers.cdk.assertion.CdkResourceType.EC2_SECURITY_GROUP;
import static io.sandpipers.cdk.assertion.CdkResourceType.EC2_SECURITY_GROUP_INGRESS;
import static software.amazon.awscdk.assertions.Match.stringLikeRegexp;
import java.util.Map;
import java.util.Map.Entry;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assertions;
import software.amazon.awscdk.assertions.Template;
@SuppressWarnings("unchecked")
public class CDKStackAssert extends AbstractAssert<CDKStackAssert, Template> {
private CDKStackAssert(final Template actual) {
super(actual, CDKStackAssert.class);
}
/**
* Fluent assertions for CDK resources. Assertions are done directly on an object of
* {@link software.amazon.awscdk.assertions.Template}.
*
* @param actual {@link Template} instance
* @return {@link CDKStackAssert} instance
*/
public static CDKStackAssert assertThat(final Template actual) {
return new CDKStackAssert(actual);
}
/**
* Fluent assertions for <code>AWS::ApiGateway::RestApi</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link RestApiAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id rest api id
* @return {@link RestApiAssert} instance
*/
public RestApiAssert containsRestApi(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.APIGATEWAY_RESTAPI, id);
return RestApiAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::ApiGateway::Account</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link ApiAccountAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id of the rest api account
* @return {@link ApiAccountAssert} instance
*/
public ApiAccountAssert containsApiAccount(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.APIGATEWAY_ACCOUNT, id);
return ApiAccountAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::ApiGateway::Deployment</code>. Assertions are done directly on
* an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link ApiDeploymentAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id Rest API deployement id
* @return {@link ApiDeploymentAssert} instance
*/
public ApiDeploymentAssert containsApiDeployment(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.APIGATEWAY_DEPLOYMENT, id);
return ApiDeploymentAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::ApiGateway::Method</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link ApiMethodAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id Rest API method id
* @return {@link ApiMethodAssert} instance
*/
public ApiMethodAssert containsApiMethod(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.APIGATEWAY_METHOD, id);
return ApiMethodAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::ApiGateway::Stage</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link ApiStageAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id Rest API stage id
* @return {@link ApiStageAssert} instance
*/
public ApiStageAssert containsApiStage(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.APIGATEWAY_STAGE, id);
return ApiStageAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::ApiGateway::Resource</code>. Assertions are done directly on
* an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link ApiResourceAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id Rest API resource id
*/
public ApiResourceAssert containsApiResource(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.APIGATEWAY_RESOURCE, id);
return ApiResourceAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::IAM::Policy</code>. Assertions are done directly on an object
* of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been extracted
* from, then {@link PolicyAssert} should be used instead. <br/><br/>
* <p>
* Example usage can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-lambda/src/test/java/com/sandpipers/cdk/example/lambda">sandpipers-cdk-example-lambda/test</a>
* </p>
*
* @param id policy id
* @return {@link PolicyAssert} instance
*/
public PolicyAssert containsPolicy(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.POLICY, id);
return PolicyAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::IAM::Role</code>. Assertions are done directly on an object of
* {@link software.amazon.awscdk.assertions.Template}. If a resource map has been extracted from,
* then {@link RoleAssert} should be used instead. <br/><br/>
* <p>
* Example usage can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-lambda/src/test/java/com/sandpipers/cdk/example/lambda">sandpipers-cdk-example-lambda/test</a>
* </p>
*
* @param id managed policy arn
* @return {@link RoleAssert} instance
*/
public RoleAssert containsRole(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.ROLE, id);
return RoleAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::Lambda::Function</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link LambdaAssert} should be used instead. <br/><br/>
* <p>
* Example usage can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-lambda/src/test/java/com/sandpipers/cdk/example/lambda">sandpipers-cdk-example-lambda/test</a>
* </p>
*
* @param id expected function id
* @return {@link LambdaAssert} instance
*/
public LambdaAssert containsFunction(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.LAMBDA_FUNCTION, id);
return LambdaAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::Lambda::EventInvokeConfig</code>. Assertions are done directly
* on an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link LambdaEventInvokeConfigAssert} should be used instead.
*
* <p>
* Example usage can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-lambda/src/test/java/com/sandpipers/cdk/example/lambda">sandpipers-cdk-example-lambda/test</a>
* </p>
*
* @param id the id of the lambda event invoke config
* @return {@link LambdaEventInvokeConfigAssert} instance
*/
public LambdaEventInvokeConfigAssert containsLambdaEventInvokeConfig(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.LAMBDA_EVENT_INVOKE_CONFIG, id);
return LambdaEventInvokeConfigAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::Permission::Permission</code>. Assertions are done directly on
* an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link LambdaPermissionAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in:
* <ul>
* <li><a href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-lambda/src/test/java/com/sandpipers/cdk/example/lambda">sandpipers-cdk-example-lambda/test</a></li>
* <li><a href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a></li>
* </ul>
* </p>
*
* @param id the name of the lambda permission
* @return {@link LambdaPermissionAssert} instance
*/
public LambdaPermissionAssert containsLambdaPermission(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.LAMBDA_PERMISSION, id);
return LambdaPermissionAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::ApiGateway::BasePathMapping</code>. Assertions are done
* directly on an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map
* has been extracted from, then {@link ApiDomainNameAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id the name of the domain name
* @return {@link ApiDomainNameAssert} instance
*/
public ApiDomainNameAssert containsApiDomainName(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.APIGATEWAY_DOMAIN_NAME, id);
return ApiDomainNameAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::ApiGateway::BasePathMapping</code>. Assertions are done
* directly on an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map
* has been extracted from, then {@link ApiBasePathMappingAssert} should be used instead.
* <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id the name of the mapping
* @return {@link ApiBasePathMappingAssert} instance
*/
public ApiBasePathMappingAssert containsApiPathMapping(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.APIGATEWAY_BASE_PATH_MAPPING, id);
return ApiBasePathMappingAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::SQS::QueuePolicy</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link QueuePolicyAssert} should be used instead.
*
* <p>
* Example:
* </p>
* <pre>
* {@code
* CDKStackAssert.assertThat(template)
* .containsQueuePolicy("examplelambdafunctionfailurequeue(.*)", "sqs:SendMessage", "examplelambdafunctionfailurequeue(.*)", "sns.amazonaws.com")
* .hasEffect("Allow")
* .hasCondition("ArnEquals", "aws:SourceArn", "examplelambdafunctionfailuretopic(.*)");
* }
* </pre>
*
* @param id the queue policy id
* @return {@link QueuePolicyAssert} instance
*/
public QueuePolicyAssert containsQueuePolicy(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.QUEUE_POLICY, id);
return QueuePolicyAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::SQS::Queue</code>. Assertions are done directly on an object
* of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been extracted
* from, then {@link QueueAssert} should be used instead.
*
* <p>
* Example usage can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-sqs/src/test/java/com/sandpipers/cdk/example/sqs">sandpipers-cdk-example-sqs/test</a>
* </p>
*
* @param id the key of the queue
* @return {@link QueueAssert} instance
*/
public QueueAssert containsQueue(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.QUEUE, id);
return QueueAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::SNS::Topic</code>. Assertions are done directly on an object
* of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been extracted
* from, then {@link TopicAssert} should be used instead.
*
* <p>
* Example usage can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-sns/src/test/java/com/sandpipers/cdk/example/sns">sandpipers-cdk-example-sns/test</a>
* </p>
*
* @param id the key of the topic
* @return {@link TopicAssert} instance
*/
public TopicAssert containsTopic(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.TOPIC, id);
return TopicAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::SNS::Subscription</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link TopicSubscriptionAssert} should be used instead.
*
* <p>
* Example usage can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-sns/src/test/java/com/sandpipers/cdk/example/sns">sandpipers-cdk-example-sns/test</a>
* </p>
*
* @param id the topic subscription id
* @return {@link TopicSubscriptionAssert} instance
*/
public TopicSubscriptionAssert containsTopicSubscription(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.TOPIC_SUBSCRIPTION, id);
return TopicSubscriptionAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::CertificateManager::Certificate</code>. Assertions are done
* directly on an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map
* has been extracted from, then {@link CertificateAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apigateway/src/test/java/com/sandpipers/cdk/example/apigateway">sandpipers-cdk-example-apigateway/test</a>
* </p>
*
* @param id the name of the certificate
* @return {@link CertificateAssert} instance
*/
public CertificateAssert containsCertificate(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.CERTIFICATEMANAGER_CERTIFICATE, id);
return CertificateAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::Route53::ARecord</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link RecordSetAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-route53/src/test/java/com/sandpipers/cdk/example/route53">sandpipers-cdk-example-route53/test</a>
* </p>
*
* @param id the name of the record set
* @return {@link RecordSetAssert} instance
*/
public RecordSetAssert containsRecordSet(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.ROUTE53_RECORD_SET, id);
return RecordSetAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::Route53::ARecord</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link HostedZoneAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-route53/src/test/java/com/sandpipers/cdk/example/route53">sandpipers-cdk-example-route53/test</a>
* </p>
*
* @param id the name of the hosted zone
* @return {@link HostedZoneAssert} instance
*/
public HostedZoneAssert containsHostedZone(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.ROUTE53_HOSTED_ZONE, id);
return HostedZoneAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::DynamoDB::GlobalTable</code>. Assertions are done directly on
* an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link DynamoDBGlobalTableAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/muhamadto/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-dynamodb/src/test/java/com/sandpipers/cdk/example/dynamodb">sandpipers-cdk-example-dynamodb/test</a>
* </p>
*
* @param id the name of the table
* @return {@link DynamoDBGlobalTableAssert} instance
*/
public DynamoDBGlobalTableAssert containsDynamoDBTable(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
CdkResourceType.DYNAMODB_GLOBAL_TABLE, id);
return DynamoDBGlobalTableAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::AppRunner::Service</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link AppRunnerAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/sandpip3rs/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apprunner/src/test/java/io/sandpipers/cdk/example/apprunner">sandpipers-cdk-examples/sandpipers-cdk-example-apprunner/test</a>
* </p>
*
* @param id the name of the app runner service
* @return {@link AppRunnerAssert} instance
*/
public AppRunnerAssert containsAppRunnerService(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual, APPRUNNER_SERVICE, id);
return AppRunnerAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::AppRunner::VpcConnector</code>. Assertions are done directly
* on an object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link VpcConnectorAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/sandpip3rs/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apprunner/src/test/java/io/sandpipers/cdk/example/apprunner">sandpipers-cdk-examples/sandpipers-cdk-example-apprunner/test</a>
* </p>
*
* @param id the name of the vpc connector
* @return {@link VpcConnectorAssert} instance
*/
public VpcConnectorAssert containsVpcConnector(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual,
APPRUNNER_VPC_CONNECTOR, id);
return VpcConnectorAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::EC2::SecurityGroup</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link SecurityGroupAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/sandpip3rs/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apprunner/src/test/java/io/sandpipers/cdk/example/apprunner">sandpipers-cdk-examples/sandpipers-cdk-example-apprunner/test</a>
* </p>
*
* @param id the name of the security group
* @return {@link SecurityGroupAssert} instance
*/
public SecurityGroupAssert containsSecurityGroup(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual, EC2_SECURITY_GROUP, id);
return SecurityGroupAssert.assertThat(resource.getValue());
}
/**
* Fluent assertions for <code>AWS::EC2::SecurityGroupIngress</code>. Assertions are done directly on an
* object of {@link software.amazon.awscdk.assertions.Template}. If a resource map has been
* extracted from, then {@link SecurityGroupIngressAssert} should be used instead. <br/><br/>
* <p>
* Example usages can be found in <a
* href="https://github.com/sandpip3rs/sandpipers-cdk/tree/main/sandpipers-cdk-examples/sandpipers-cdk-example-apprunner/src/test/java/io/sandpipers/cdk/example/apprunner">sandpipers-cdk-examples/sandpipers-cdk-example-apprunner/test</a>
* </p>
*
* @param id the name of the security group
* @return {@link SecurityGroupIngressAssert} instance
*/
public SecurityGroupIngressAssert containsSecurityGroupIngressRule(final String id) {
final Entry<String, Map<String, Object>> resource = containsResource(actual, EC2_SECURITY_GROUP_INGRESS, id);
return SecurityGroupIngressAssert.assertThat(resource.getValue());
}
private Entry<String, Map<String, Object>> containsResource(
final Template template,
final CdkResourceType cdkResourceType,
final String id) {
final Entry<String, Map<String, Object>> resource = template.findResources(cdkResourceType.getValue())
.entrySet()
.stream()
.filter(entry -> stringLikeRegexp(id).test(entry.getKey()).getIsSuccess())
.findFirst()
.orElseThrow();
Assertions.assertThat(resource)
.isNotNull();
return resource;
}
}