-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...e-overrides/src/test/java/software/amazon/awscdk/examples/ResourceOverridesStackTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package software.amazon.awscdk.examples; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.Test; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
import software.amazon.awscdk.core.App; | ||
import software.amazon.awscdk.core.ConstructNode; | ||
import software.amazon.awscdk.core.IConstruct; | ||
import software.amazon.awscdk.core.Stack; | ||
import software.amazon.awscdk.cxapi.CloudFormationStackArtifact; | ||
|
||
import java.io.IOException; | ||
|
||
public class ResourceOverridesStackTest { | ||
private static final ObjectMapper JSON = new ObjectMapper(); | ||
|
||
@Test | ||
public void shouldGenerateValidCloudFormationTemplate() throws Exception { | ||
App app = new App(); | ||
Stack stack = new ResourceOverridesStack(app, "resource-overrides"); | ||
|
||
String actual = getStackTemplateJson(stack) | ||
.toPrettyString(); | ||
String expected = readJsonFromResource("testResourceOverrides.expected.json") | ||
.toPrettyString(); | ||
|
||
JSONAssert.assertEquals(expected, actual, JSONCompareMode.LENIENT); | ||
} | ||
|
||
private static JsonNode readJsonFromResource(String resourceName) throws IOException { | ||
return JSON.readTree( | ||
ResourceOverridesStackTest.class.getResource(resourceName) | ||
); | ||
} | ||
|
||
private static JsonNode getStackTemplateJson(Stack stack) { | ||
IConstruct root = stack.getNode().getRoot(); | ||
CloudFormationStackArtifact stackArtifact = ConstructNode.synth(root.getNode()) | ||
.getStackByName(stack.getStackName()); | ||
|
||
return JSON.valueToTree(stackArtifact.getTemplate()); | ||
} | ||
} |
Oops, something went wrong.