Skip to content

Commit

Permalink
feat(init-templates): Java init template tests updated to JUnit 5 (#1…
Browse files Browse the repository at this point in the history
…1101)

closes #10694

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
sullis committed Oct 28, 2020
1 parent 3727c71 commit e0c00a1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
20 changes: 16 additions & 4 deletions packages/aws-cdk/lib/init-templates/app/java/pom.template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cdk.version>%cdk-version%</cdk.version>
<junit.version>5.7.0</junit.version>
</properties>

<build>
Expand Down Expand Up @@ -43,11 +44,22 @@
<version>${cdk.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.18.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.junit.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

public class %name.PascalCased%Test {
private final static ObjectMapper JSON =
Expand All @@ -22,6 +22,7 @@ public void testStack() throws IOException {
// synthesize the stack to a CloudFormation template and compare against
// a checked-in JSON file.
JsonNode actual = JSON.valueToTree(app.synth().getStackArtifact(stack.getArtifactId()).getTemplate());
assertEquals(new ObjectMapper().createObjectNode(), actual);

assertThat(new ObjectMapper().createObjectNode()).isEqualTo(actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cdk.version>%cdk-version%</cdk.version>
<junit.version>5.7.0</junit.version>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -55,11 +56,22 @@
<version>${cdk.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.18.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.myorg;

import software.amazon.awscdk.core.App;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.junit.Test;
import org.hamcrest.CoreMatchers;

import java.io.IOException;
import static org.junit.Assert.assertThat;

import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

public class %name.PascalCased%StackTest {
private final static ObjectMapper JSON =
Expand All @@ -19,6 +19,9 @@ public void testStack() throws IOException {
%name.PascalCased%Stack stack = new %name.PascalCased%Stack(app, "test");

JsonNode actual = JSON.valueToTree(app.synth().getStackArtifact(stack.getArtifactId()).getTemplate());
assertThat(actual.toString(), CoreMatchers.both(CoreMatchers.containsString("AWS::SQS::Queue")).and(CoreMatchers.containsString("AWS::SNS::Topic")));

assertThat(actual.toString())
.contains("AWS::SQS::Queue")
.contains("AWS::SNS::Topic");
}
}

0 comments on commit e0c00a1

Please sign in to comment.