Skip to content

Commit 17926e0

Browse files
author
diwakar
committed
- Adding Junit testing support for working with Named Profiles
- Added KMS Key support to easily whitelist services and work with KMS - Added pre-commit hooks and other missing boostrap setup
1 parent ba6bd66 commit 17926e0

File tree

10 files changed

+1054
-0
lines changed

10 files changed

+1054
-0
lines changed

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.4.0
4+
hooks:
5+
- id: check-case-conflict
6+
- id: detect-private-key
7+
- id: end-of-file-fixer
8+
- id: mixed-line-ending
9+
args:
10+
- --fix=lf
11+
- id: trailing-whitespace
12+
- id: pretty-format-json
13+
args:
14+
- --autofix
15+
- --indent=2
16+
- --no-sort-keys
17+
- id: check-merge-conflict
18+
- id: check-yaml
19+
exclude: codebuild-ci.yaml

buildspec.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 0.2
2+
phases:
3+
install:
4+
runtime-versions:
5+
java: openjdk8
6+
python: 3.7
7+
commands:
8+
- pip install pre-commit cloudformation-cli-java-plugin
9+
build:
10+
commands:
11+
- pre-commit run --all-files
12+
- mvn clean verify --no-transfer-progress
13+
- mvn clean verify --no-transfer-progress

licenseHeader

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/

lombok.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lombok.addLombokGeneratedAnnotation = true

pom.xml

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>software.amazon.cloudformation.test</groupId>
9+
<artifactId>cloudformation-cli-java-plugin-testing-support</artifactId>
10+
<name>aws-cloudformation-local-test</name>
11+
<version>1.0</version>
12+
<packaging>jar</packaging>
13+
14+
<properties>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<maven.compiler.target>1.8</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
19+
<checkstyle.version>8.18</checkstyle.version>
20+
<commons-io.version>2.6</commons-io.version>
21+
<maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
22+
<mockito.version>2.26.0</mockito.version>
23+
<jackson.version>2.10.1</jackson.version>
24+
<maven-javadoc-plugin.version>3.1.1</maven-javadoc-plugin.version>
25+
</properties>
26+
27+
<dependencies>
28+
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
29+
<dependency>
30+
<groupId>org.projectlombok</groupId>
31+
<artifactId>lombok</artifactId>
32+
<version>1.18.4</version>
33+
<scope>provided</scope>
34+
</dependency>
35+
36+
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
37+
<dependency>
38+
<groupId>org.mockito</groupId>
39+
<artifactId>mockito-core</artifactId>
40+
<version>${mockito.version}</version>
41+
<scope>test</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>org.junit.jupiter</groupId>
46+
<artifactId>junit-jupiter</artifactId>
47+
<version>5.5.0-M1</version>
48+
</dependency>
49+
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
50+
<dependency>
51+
<groupId>org.assertj</groupId>
52+
<artifactId>assertj-core</artifactId>
53+
<version>3.12.2</version>
54+
<scope>test</scope>
55+
</dependency>
56+
57+
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
58+
<dependency>
59+
<groupId>org.slf4j</groupId>
60+
<artifactId>slf4j-api</artifactId>
61+
<version>1.7.25</version>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>software.amazon.awssdk</groupId>
66+
<artifactId>aws-core</artifactId>
67+
<version>2.10.91</version>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>software.amazon.awssdk</groupId>
72+
<artifactId>sts</artifactId>
73+
<version>2.10.91</version>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>software.amazon.awssdk</groupId>
78+
<artifactId>kms</artifactId>
79+
<version>2.10.91</version>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>software.amazon.cloudformation</groupId>
84+
<artifactId>aws-cloudformation-rpdk-java-plugin</artifactId>
85+
<version>1.0.2</version>
86+
</dependency>
87+
88+
<dependency>
89+
<groupId>org.mockito</groupId>
90+
<artifactId>mockito-core</artifactId>
91+
<version>2.26.0</version>
92+
<scope>compile</scope>
93+
</dependency>
94+
95+
<dependency>
96+
<groupId>com.fasterxml.jackson.core</groupId>
97+
<artifactId>jackson-databind</artifactId>
98+
<version>${jackson.version}</version>
99+
</dependency>
100+
101+
102+
</dependencies>
103+
104+
<build>
105+
<plugins>
106+
<plugin>
107+
<groupId>org.apache.maven.plugins</groupId>
108+
<artifactId>maven-surefire-plugin</artifactId>
109+
<version>3.0.0-M3</version>
110+
</plugin>
111+
<plugin>
112+
<groupId>org.apache.maven.plugins</groupId>
113+
<artifactId>maven-compiler-plugin</artifactId>
114+
<version>3.8.1</version>
115+
<configuration>
116+
<compilerArgs>
117+
<arg>-Xlint:all,-options,-processing</arg>
118+
<arg>-Werror</arg>
119+
</compilerArgs>
120+
</configuration>
121+
</plugin>
122+
<plugin>
123+
<groupId>org.apache.maven.plugins</groupId>
124+
<artifactId>maven-shade-plugin</artifactId>
125+
<version>2.3</version>
126+
<configuration>
127+
<createDependencyReducedPom>false</createDependencyReducedPom>
128+
</configuration>
129+
<executions>
130+
<execution>
131+
<phase>package</phase>
132+
<goals>
133+
<goal>shade</goal>
134+
</goals>
135+
</execution>
136+
</executions>
137+
</plugin>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-resources-plugin</artifactId>
141+
<version>2.4</version>
142+
</plugin>
143+
<plugin>
144+
<groupId>org.apache.maven.plugins</groupId>
145+
<artifactId>maven-javadoc-plugin</artifactId>
146+
<version>${maven-javadoc-plugin.version}</version>
147+
<configuration>
148+
<show>public</show>
149+
<bottom><![CDATA[Copyright &#169; 2019 Amazon Web Services, Inc. All Rights Reserved.]]></bottom>
150+
</configuration>
151+
<executions>
152+
<execution>
153+
<id>attach-javadocs</id>
154+
<goals>
155+
<goal>jar</goal>
156+
</goals>
157+
</execution>
158+
</executions>
159+
</plugin>
160+
<plugin>
161+
<groupId>org.jacoco</groupId>
162+
<artifactId>jacoco-maven-plugin</artifactId>
163+
<version>0.8.4</version>
164+
<configuration>
165+
<excludes>
166+
<exclude>**/BaseConfiguration*</exclude>
167+
<exclude>**/BaseHandler*</exclude>
168+
<exclude>**/HandlerWrapper*</exclude>
169+
</excludes>
170+
</configuration>
171+
<executions>
172+
<execution>
173+
<goals>
174+
<goal>prepare-agent</goal>
175+
</goals>
176+
</execution>
177+
<execution>
178+
<id>report</id>
179+
<phase>test</phase>
180+
<goals>
181+
<goal>report</goal>
182+
</goals>
183+
</execution>
184+
<execution>
185+
<id>jacoco-check</id>
186+
<goals>
187+
<goal>check</goal>
188+
</goals>
189+
<configuration>
190+
<rules>
191+
<rule>
192+
<element>PACKAGE</element>
193+
<limits>
194+
<limit>
195+
<counter>BRANCH</counter>
196+
<value>COVEREDRATIO</value>
197+
<minimum>0.8</minimum>
198+
</limit>
199+
<limit>
200+
<counter>LINE</counter>
201+
<value>COVEREDRATIO</value>
202+
<minimum>0.8</minimum>
203+
</limit>
204+
<limit>
205+
<counter>INSTRUCTION</counter>
206+
<value>COVEREDRATIO</value>
207+
<minimum>0.8</minimum>
208+
</limit>
209+
</limits>
210+
</rule>
211+
</rules>
212+
</configuration>
213+
</execution>
214+
</executions>
215+
</plugin>
216+
</plugins>
217+
</build>
218+
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package software.amazon.cloudformation.test;
2+
3+
import org.junit.jupiter.api.TestInstance;
4+
import org.mockito.Mockito;
5+
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
6+
import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy;
7+
import software.amazon.cloudformation.proxy.Credentials;
8+
import software.amazon.cloudformation.proxy.DelayFactory;
9+
import software.amazon.cloudformation.proxy.LoggerProxy;
10+
import software.amazon.cloudformation.proxy.ResourceHandlerRequest;
11+
12+
import java.time.Duration;
13+
14+
/**
15+
* Abstract base class that does some of the mocking and proxy setup that you need for
16+
* testing each of your handlers consistently in order for CRUD + L
17+
*/
18+
@lombok.Getter
19+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
20+
public abstract class AbstractLifecycleTestBase {
21+
22+
private final LoggerProxy loggerProxy = Mockito.mock(LoggerProxy.class);
23+
private final AwsSessionCredentials sessionCredentials;
24+
private final AmazonWebServicesClientProxy proxy;
25+
26+
protected AbstractLifecycleTestBase(final AwsSessionCredentials credentials) {
27+
this(credentials, DelayFactory.CONSTANT_DEFAULT_DELAY_FACTORY);
28+
}
29+
30+
protected AbstractLifecycleTestBase(final AwsSessionCredentials sessionCredentials,
31+
final DelayFactory factory) {
32+
this.sessionCredentials = sessionCredentials;
33+
proxy = new AmazonWebServicesClientProxy(
34+
loggerProxy,
35+
new Credentials(
36+
sessionCredentials.accessKeyId(),
37+
sessionCredentials.secretAccessKey(),
38+
sessionCredentials.sessionToken()),
39+
() -> Duration.ofMinutes(15).toMillis(),
40+
factory);
41+
}
42+
43+
protected <T> ResourceHandlerRequest<T> createRequest(T model) {
44+
return createRequest(model, null);
45+
}
46+
47+
protected <T> ResourceHandlerRequest<T> createRequest(T model,
48+
T current) {
49+
return ResourceHandlerRequest.<T>builder().desiredResourceState(model)
50+
.previousResourceState(current).build();
51+
}
52+
53+
54+
}

0 commit comments

Comments
 (0)