Class Template

java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.assertions.Template
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.98.0 (build 00b106d)", date="2024-05-02T15:58:20.352Z") @Stability(Stable) public class Template extends software.amazon.jsii.JsiiObject
Suite of assertions that can be run on a CDK stack.

Typically used, as part of unit tests, to validate that the rendered CloudFormation template has expected resources and properties.

Example:

 import software.amazon.awscdk.Stack;
 import software.amazon.awscdk.assertions.Template;
 Stack stack = new Stack();
 // ...
 Template template = Template.fromStack(stack);
 
  • Constructor Details

    • Template

      protected Template(software.amazon.jsii.JsiiObjectRef objRef)
    • Template

      protected Template(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
  • Method Details

    • fromJSON

      @Stability(Stable) @NotNull public static Template fromJSON(@NotNull Map<String,? extends Object> template, @Nullable TemplateParsingOptions templateParsingOptions)
      Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object.

      Parameters:
      template - the CloudFormation template formatted as a nested set of records. This parameter is required.
      templateParsingOptions - Optional param to configure template parsing behavior, such as disregarding circular dependencies.
    • fromJSON

      @Stability(Stable) @NotNull public static Template fromJSON(@NotNull Map<String,? extends Object> template)
      Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object.

      Parameters:
      template - the CloudFormation template formatted as a nested set of records. This parameter is required.
    • fromStack

      @Stability(Stable) @NotNull public static Template fromStack(@NotNull Stack stack, @Nullable TemplateParsingOptions templateParsingOptions)
      Base your assertions on the CloudFormation template synthesized by a CDK Stack.

      Parameters:
      stack - the CDK Stack to run assertions on. This parameter is required.
      templateParsingOptions - Optional param to configure template parsing behavior, such as disregarding circular dependencies.
    • fromStack

      @Stability(Stable) @NotNull public static Template fromStack(@NotNull Stack stack)
      Base your assertions on the CloudFormation template synthesized by a CDK Stack.

      Parameters:
      stack - the CDK Stack to run assertions on. This parameter is required.
    • fromString

      @Stability(Stable) @NotNull public static Template fromString(@NotNull String template, @Nullable TemplateParsingOptions templateParsingOptions)
      Base your assertions from an existing CloudFormation template formatted as a JSON string.

      Parameters:
      template - the CloudFormation template in. This parameter is required.
      templateParsingOptions - Optional param to configure template parsing behavior, such as disregarding circular dependencies.
    • fromString

      @Stability(Stable) @NotNull public static Template fromString(@NotNull String template)
      Base your assertions from an existing CloudFormation template formatted as a JSON string.

      Parameters:
      template - the CloudFormation template in. This parameter is required.
    • allResources

      @Stability(Stable) public void allResources(@NotNull String type, @NotNull Object props)
      Assert that all resources of the given type contain the given definition in the CloudFormation template.

      By default, performs partial matching on the resource, via the Match.objectLike(). To configure different behavior, use other matchers in the Match class.

      Parameters:
      type - the resource type;. This parameter is required.
      props - the entire definition of the resources as they should be expected in the template. This parameter is required.
    • allResourcesProperties

      @Stability(Stable) public void allResourcesProperties(@NotNull String type, @NotNull Object props)
      Assert that all resources of the given type contain the given properties CloudFormation template.

      By default, performs partial matching on the Properties key of the resource, via the Match.objectLike(). To configure different behavior, use other matchers in the Match class.

      Parameters:
      type - the resource type;. This parameter is required.
      props - the 'Properties' section of the resource as should be expected in the template. This parameter is required.
    • findConditions

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findConditions(@NotNull String logicalId, @Nullable Object props)
      Get the set of matching Conditions that match the given properties in the CloudFormation template.

      Parameters:
      logicalId - the name of the condition. This parameter is required.
      props - by default, matches all Conditions in the template.
    • findConditions

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findConditions(@NotNull String logicalId)
      Get the set of matching Conditions that match the given properties in the CloudFormation template.

      Parameters:
      logicalId - the name of the condition. This parameter is required.
    • findMappings

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findMappings(@NotNull String logicalId, @Nullable Object props)
      Get the set of matching Mappings that match the given properties in the CloudFormation template.

      Parameters:
      logicalId - the name of the mapping. This parameter is required.
      props - by default, matches all Mappings in the template.
    • findMappings

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findMappings(@NotNull String logicalId)
      Get the set of matching Mappings that match the given properties in the CloudFormation template.

      Parameters:
      logicalId - the name of the mapping. This parameter is required.
    • findOutputs

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findOutputs(@NotNull String logicalId, @Nullable Object props)
      Get the set of matching Outputs that match the given properties in the CloudFormation template.

      Parameters:
      logicalId - the name of the output. This parameter is required.
      props - by default, matches all Outputs in the template.
    • findOutputs

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findOutputs(@NotNull String logicalId)
      Get the set of matching Outputs that match the given properties in the CloudFormation template.

      Parameters:
      logicalId - the name of the output. This parameter is required.
    • findParameters

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findParameters(@NotNull String logicalId, @Nullable Object props)
      Get the set of matching Parameters that match the given properties in the CloudFormation template.

      Parameters:
      logicalId - the name of the parameter. This parameter is required.
      props - by default, matches all Parameters in the template.
    • findParameters

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findParameters(@NotNull String logicalId)
      Get the set of matching Parameters that match the given properties in the CloudFormation template.

      Parameters:
      logicalId - the name of the parameter. This parameter is required.
    • findResources

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findResources(@NotNull String type, @Nullable Object props)
      Get the set of matching resources of a given type and properties in the CloudFormation template.

      Parameters:
      type - the type to match in the CloudFormation template. This parameter is required.
      props - by default, matches all resources with the given type.
    • findResources

      @Stability(Stable) @NotNull public Map<String,Map<String,Object>> findResources(@NotNull String type)
      Get the set of matching resources of a given type and properties in the CloudFormation template.

      Parameters:
      type - the type to match in the CloudFormation template. This parameter is required.
    • hasCondition

      @Stability(Stable) public void hasCondition(@NotNull String logicalId, @NotNull Object props)
      Assert that a Condition with the given properties exists in the CloudFormation template.

      By default, performs partial matching on the resource, via the Match.objectLike(). To configure different behavior, use other matchers in the Match class.

      Parameters:
      logicalId - the name of the mapping. This parameter is required.
      props - the output as should be expected in the template. This parameter is required.
    • hasMapping

      @Stability(Stable) public void hasMapping(@NotNull String logicalId, @NotNull Object props)
      Assert that a Mapping with the given properties exists in the CloudFormation template.

      By default, performs partial matching on the resource, via the Match.objectLike(). To configure different behavior, use other matchers in the Match class.

      Parameters:
      logicalId - the name of the mapping. This parameter is required.
      props - the output as should be expected in the template. This parameter is required.
    • hasOutput

      @Stability(Stable) public void hasOutput(@NotNull String logicalId, @NotNull Object props)
      Assert that an Output with the given properties exists in the CloudFormation template.

      By default, performs partial matching on the resource, via the Match.objectLike(). To configure different behavior, use other matchers in the Match class.

      Parameters:
      logicalId - the name of the output. This parameter is required.
      props - the output as should be expected in the template. This parameter is required.
    • hasParameter

      @Stability(Stable) public void hasParameter(@NotNull String logicalId, @NotNull Object props)
      Assert that a Parameter with the given properties exists in the CloudFormation template.

      By default, performs partial matching on the parameter, via the Match.objectLike(). To configure different behavior, use other matchers in the Match class.

      Parameters:
      logicalId - the name of the parameter. This parameter is required.
      props - the parameter as should be expected in the template. This parameter is required.
    • hasResource

      @Stability(Stable) public void hasResource(@NotNull String type, @NotNull Object props)
      Assert that a resource of the given type and given definition exists in the CloudFormation template.

      By default, performs partial matching on the resource, via the Match.objectLike(). To configure different behavior, use other matchers in the Match class.

      Parameters:
      type - the resource type;. This parameter is required.
      props - the entire definition of the resource as should be expected in the template. This parameter is required.
    • hasResourceProperties

      @Stability(Stable) public void hasResourceProperties(@NotNull String type, @NotNull Object props)
      Assert that a resource of the given type and properties exists in the CloudFormation template.

      By default, performs partial matching on the Properties key of the resource, via the Match.objectLike(). To configure different behavior, use other matchers in the Match class.

      Parameters:
      type - the resource type;. This parameter is required.
      props - the 'Properties' section of the resource as should be expected in the template. This parameter is required.
    • resourceCountIs

      @Stability(Stable) public void resourceCountIs(@NotNull String type, @NotNull Number count)
      Assert that the given number of resources of the given type exist in the template.

      Parameters:
      type - the resource type;. This parameter is required.
      count - number of expected instances. This parameter is required.
    • resourcePropertiesCountIs

      @Stability(Stable) public void resourcePropertiesCountIs(@NotNull String type, @NotNull Object props, @NotNull Number count)
      Assert that the given number of resources of the given type and properties exists in the CloudFormation template.

      Parameters:
      type - the resource type;. This parameter is required.
      props - the 'Properties' section of the resource as should be expected in the template. This parameter is required.
      count - number of expected instances. This parameter is required.
    • templateMatches

      @Stability(Stable) public void templateMatches(@NotNull Object expected)
      Assert that the CloudFormation template matches the given value.

      Parameters:
      expected - the expected CloudFormation template as key-value pairs. This parameter is required.
    • toJSON

      @Stability(Stable) @NotNull public Map<String,Object> toJSON()
      The CloudFormation template deserialized into an object.