Skip to content

Commit aeb3b25

Browse files
committed
Add more tests
1 parent dae1b10 commit aeb3b25

File tree

8 files changed

+213
-39
lines changed

8 files changed

+213
-39
lines changed

migration-tool/pom.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030
Migration tool to help users migrate from AWS SDK for Java v1 to AWS SDK for Java v2
3131
</description>
3232

33-
<properties>
34-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35-
<maven.compiler.source>1.8</maven.compiler.source>
36-
<maven.compiler.target>1.8</maven.compiler.target>
37-
</properties>
38-
3933
<dependencyManagement>
4034
<dependencies>
4135
<dependency>
@@ -88,6 +82,13 @@
8882
<version>${junit5.version}</version>
8983
<scope>test</scope>
9084
</dependency>
85+
<!-- Used in UpgradeSdkDependenciesTest -->
86+
<dependency>
87+
<groupId>software.amazon.awssdk</groupId>
88+
<artifactId>sqs</artifactId>
89+
<scope>test</scope>
90+
<version>${awsjavasdk.version}</version>
91+
</dependency>
9192
</dependencies>
9293

9394
<build>
@@ -111,9 +112,7 @@
111112
<goal>exec</goal>
112113
</goals>
113114
<configuration>
114-
<executable>python</executable>
115-
<commandlineArgs>${basedir}/src/main/resources/generate-recipes
116-
</commandlineArgs>
115+
<executable>${basedir}/src/main/resources/generate-recipes</executable>
117116
</configuration>
118117
</execution>
119118
</executions>

test/migration-tool-tests/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# AWS SDK Migration Tool Tests
2+
3+
## Description
4+
This module is used to test `migration-tool`. It contains an application that uses the AWS SDK for Java v1
5+
and performs `mvn open:rewrite` to migrate it to the AWS SDK for Java v2 and compares the transformed code
6+
with the expected code for verification. The test code is in [run-test](./src/test/resources/run-test).

test/migration-tool-tests/pom.xml

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
<groupId>software.amazon.awssdk</groupId>
3030
<artifactId>migration-tool-tests</artifactId>
3131

32-
<properties>
33-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34-
<maven.compiler.source>1.8</maven.compiler.source>
35-
<maven.compiler.target>1.8</maven.compiler.target>
36-
</properties>
37-
3832
<dependencyManagement>
3933
<dependencies>
4034
<dependency>
@@ -52,35 +46,38 @@
5246
<dependency>
5347
<groupId>com.amazonaws</groupId>
5448
<artifactId>aws-java-sdk-sqs</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>software.amazon.awssdk</groupId>
53+
<artifactId>migration-tool</artifactId>
54+
<version>${project.version}</version>
55+
<scope>test</scope>
5556
</dependency>
5657
</dependencies>
5758

5859
<build>
5960
<plugins>
6061
<plugin>
61-
<groupId>org.openrewrite.maven</groupId>
62-
<artifactId>rewrite-maven-plugin</artifactId>
63-
<version>5.18.0</version>
64-
<configuration>
65-
<activeRecipes>
66-
<recipe>software.amazon.awssdk.UpgradeJavaSdk2</recipe>
67-
</activeRecipes>
68-
</configuration>
69-
<dependencies>
70-
<dependency>
71-
<groupId>software.amazon.awssdk</groupId>
72-
<artifactId>migration-tool</artifactId>
73-
<version>${awsjavasdk.version}</version>
74-
</dependency>
75-
</dependencies>
62+
<artifactId>exec-maven-plugin</artifactId>
63+
<groupId>org.codehaus.mojo</groupId>
64+
<version>${exec-maven-plugin.version}</version>
65+
<executions>
66+
<execution>
67+
<id>run-test-script</id>
68+
<phase>test</phase>
69+
<goals>
70+
<goal>exec</goal>
71+
</goals>
72+
<configuration>
73+
<executable>${basedir}/src/test/resources/run-test</executable>
74+
<arguments>
75+
<argument>-v ${project.version}</argument>
76+
</arguments>
77+
</configuration>
78+
</execution>
79+
</executions>
7680
</plugin>
77-
<plugin>
78-
<groupId>com.github.spotbugs</groupId>
79-
<artifactId>spotbugs-maven-plugin</artifactId>
80-
<configuration>
81-
<skip>true</skip>
82-
</configuration>
83-
</plugin>
8481
</plugins>
8582
</build>
8683

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<groupId>software.amazon.awssdk</groupId>
23+
<artifactId>sample-application</artifactId>
24+
<version>1.2.3</version>
25+
26+
<dependencyManagement>
27+
<dependencies>
28+
<dependency>
29+
<groupId>software.amazon.awssdk</groupId>
30+
<artifactId>bom</artifactId>
31+
<version>2.23.0-SNAPSHOT</version>
32+
<type>pom</type>
33+
<scope>import</scope>
34+
</dependency>
35+
</dependencies>
36+
37+
</dependencyManagement>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>software.amazon.awssdk</groupId>
42+
<artifactId>sqs</artifactId>
43+
<version>2.23.0-SNAPSHOT</version>
44+
</dependency>
45+
</dependencies>
46+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 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+
*/
15+
16+
package software.amazon.awssdk.migrationtool.test;
17+
18+
import software.amazon.awssdk.services.sqs.SqsClient;
19+
20+
public class Application {
21+
22+
private Application() {
23+
24+
}
25+
26+
public static void main(String... args) {
27+
SqsClient sqs = SqsClient.builder().build();
28+
sqs.listQueues();
29+
}
30+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<groupId>software.amazon.awssdk</groupId>
23+
<artifactId>sample-application</artifactId>
24+
<version>1.2.3</version>
25+
26+
<dependencyManagement>
27+
<dependencies>
28+
<dependency>
29+
<groupId>com.amazonaws</groupId>
30+
<artifactId>aws-java-sdk-bom</artifactId>
31+
<version>1.11.1000</version>
32+
<type>pom</type>
33+
<scope>import</scope>
34+
</dependency>
35+
</dependencies>
36+
37+
</dependencyManagement>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>com.amazonaws</groupId>
42+
<artifactId>aws-java-sdk-sqs</artifactId>
43+
</dependency>
44+
</dependencies>
45+
</project>

test/migration-tool-tests/src/main/java/software/amazon/awssdk/migrationtool/test/Application.java renamed to test/migration-tool-tests/src/test/resources/before/src/main/java/software/amazon/awssdk/migration/tool/Application.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.amazonaws.services.sqs.AmazonSQS;
1919
import com.amazonaws.services.sqs.AmazonSQSClient;
20-
import com.amazonaws.services.sqs.model.ListQueuesResult;
2120

2221
public class Application {
2322

@@ -27,6 +26,6 @@ private Application() {
2726

2827
public static void main(String... args) {
2928
AmazonSQS sqs = AmazonSQSClient.builder().build();
30-
ListQueuesResult listQueuesResult = sqs.listQueues();
29+
sqs.listQueues();
3130
}
3231
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
3+
import subprocess
4+
import filecmp
5+
import os
6+
import shutil, errno
7+
import argparse
8+
9+
RESOURCE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "resources")
10+
BEFORE_DIR = os.path.join(RESOURCE_DIR, "before")
11+
AFTER_DIR = os.path.join(RESOURCE_DIR, "after")
12+
TARGET_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(os.path.join(__file__, "../../")))), "target/generated-test-sources/project")
13+
def main():
14+
parser = argparse.ArgumentParser()
15+
parser.add_argument('-v', '--version', dest='version',
16+
default='')
17+
args = parser.parse_args()
18+
run_test(args.version.strip())
19+
20+
def run_test(version):
21+
if os.path.exists(TARGET_DIR) and os.path.isdir(TARGET_DIR):
22+
shutil.rmtree(TARGET_DIR)
23+
copy_directory(BEFORE_DIR, TARGET_DIR)
24+
25+
subprocess.run(["mvn", "org.openrewrite.maven:rewrite-maven-plugin:run",
26+
"-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:migration-tool:"+ version,
27+
"-Drewrite.activeRecipes=software.amazon.awssdk.UpgradeJavaSdk2"], cwd=TARGET_DIR)
28+
shutil.rmtree(os.path.join(TARGET_DIR, "target"))
29+
comparison = filecmp.dircmp(TARGET_DIR, AFTER_DIR)
30+
is_same = compare_directory(filecmp.dircmp(TARGET_DIR, AFTER_DIR))
31+
if not is_same:
32+
comparison.report_full_closure()
33+
raise Exception("The transformed directory('target/generated-test-sources/project') does not match with the expected one('src/test/resources/after')")
34+
35+
def compare_directory(dcmp):
36+
if dcmp.diff_files or dcmp.left_only or dcmp.right_only:
37+
return False
38+
for sub_dcmp in dcmp.subdirs.values():
39+
if not compare_directory(sub_dcmp):
40+
return False
41+
return True
42+
43+
def copy_directory(src, dst):
44+
try:
45+
shutil.copytree(src, dst)
46+
except OSError as exc:
47+
if exc.errno in (errno.ENOTDIR, errno.EINVAL):
48+
shutil.copy(src, dst)
49+
else: raise
50+
51+
if __name__ == '__main__':
52+
main()

0 commit comments

Comments
 (0)