Skip to content

Commit 12d5cbf

Browse files
authored
Use Java to run tests instead of python (#5482)
1 parent cd6d1e3 commit 12d5cbf

File tree

29 files changed

+424
-142
lines changed

29 files changed

+424
-142
lines changed

test/v2-migration-tests/pom.xml

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@
2828

2929
<groupId>software.amazon.awssdk</groupId>
3030
<artifactId>v2-migration-tests</artifactId>
31-
3231
<dependencyManagement>
3332
<dependencies>
33+
<dependency>
34+
<groupId>software.amazon.awssdk</groupId>
35+
<artifactId>bom-internal</artifactId>
36+
<version>${project.version}</version>
37+
<type>pom</type>
38+
<scope>import</scope>
39+
</dependency>
3440
<dependency>
3541
<groupId>com.amazonaws</groupId>
3642
<artifactId>aws-java-sdk-bom</artifactId>
@@ -43,6 +49,12 @@
4349
</dependencyManagement>
4450

4551
<dependencies>
52+
<dependency>
53+
<groupId>software.amazon.awssdk</groupId>
54+
<artifactId>utils</artifactId>
55+
<version>${project.version}</version>
56+
</dependency>
57+
4658
<dependency>
4759
<groupId>com.amazonaws</groupId>
4860
<artifactId>aws-java-sdk-core</artifactId>
@@ -76,33 +88,64 @@
7688
<version>${project.version}-PREVIEW</version>
7789
<scope>test</scope>
7890
</dependency>
91+
<dependency>
92+
<groupId>org.junit.jupiter</groupId>
93+
<artifactId>junit-jupiter</artifactId>
94+
<scope>test</scope>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.junit.jupiter</groupId>
98+
<artifactId>junit-jupiter-engine</artifactId>
99+
<version>${junit5.version}</version>
100+
<scope>test</scope>
101+
</dependency>
102+
<dependency>
103+
<groupId>org.apache.logging.log4j</groupId>
104+
<artifactId>log4j-core</artifactId>
105+
<scope>test</scope>
106+
</dependency>
107+
<dependency>
108+
<groupId>org.apache.logging.log4j</groupId>
109+
<artifactId>log4j-iostreams</artifactId>
110+
<version>${log4j.version}</version>
111+
<scope>test</scope>
112+
</dependency>
113+
<dependency>
114+
<groupId>org.apache.logging.log4j</groupId>
115+
<artifactId>log4j-slf4j-impl</artifactId>
116+
<scope>test</scope>
117+
</dependency>
118+
<dependency>
119+
<groupId>org.assertj</groupId>
120+
<artifactId>assertj-core</artifactId>
121+
<scope>test</scope>
122+
</dependency>
79123
</dependencies>
80124

81125
<build>
82126
<plugins>
83127
<plugin>
84-
<artifactId>exec-maven-plugin</artifactId>
85-
<groupId>org.codehaus.mojo</groupId>
86-
<version>${exec-maven-plugin.version}</version>
128+
<groupId>com.github.spotbugs</groupId>
129+
<artifactId>spotbugs-maven-plugin</artifactId>
87130
<configuration>
88-
<skip>${skip.unit.tests}</skip>
131+
<!-- Skipping spotbugs for the generated JMH classes-->
132+
<skip>true</skip>
89133
</configuration>
134+
</plugin>
135+
<plugin>
136+
<groupId>org.apache.maven.plugins</groupId>
137+
<artifactId>maven-dependency-plugin</artifactId>
90138
<executions>
91139
<execution>
92-
<id>run-test-script</id>
93-
<phase>test</phase>
94140
<goals>
95-
<goal>exec</goal>
141+
<goal>analyze-only</goal>
96142
</goals>
97-
<configuration>
98-
<executable>python</executable>
99-
<arguments>
100-
<argument>${basedir}/src/test/resources/run-test</argument>
101-
<argument>-v ${project.version}</argument>
102-
</arguments>
103-
</configuration>
104143
</execution>
105144
</executions>
145+
<configuration>
146+
<!-- Skipping maven dependencies analysis to speed up the build -->
147+
<skip>true</skip>
148+
</configuration>
106149
</plugin>
107150
</plugins>
108151
</build>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.v2migrationtests;
17+
18+
import static java.util.Collections.addAll;
19+
import static software.amazon.awssdk.v2migrationtests.TestUtils.assertTwoDirectoriesHaveSameStructure;
20+
import static software.amazon.awssdk.v2migrationtests.TestUtils.getVersion;
21+
import static software.amazon.awssdk.v2migrationtests.TestUtils.replaceVersion;
22+
import static software.amazon.awssdk.v2migrationtests.TestUtils.run;
23+
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.nio.file.Path;
27+
import java.util.ArrayList;
28+
import java.util.List;
29+
import org.apache.commons.io.FileUtils;
30+
import org.junit.jupiter.api.BeforeAll;
31+
import org.junit.jupiter.api.Test;
32+
import software.amazon.awssdk.utils.Logger;
33+
34+
public class GradleProjectTest {
35+
private static final Logger log = Logger.loggerFor(GradleProjectTest.class);
36+
private static String sdkVersion;
37+
private static Path gradleBefore;
38+
private static Path gradleAfter;
39+
private static Path target;
40+
private static Path gradleActual;
41+
private static Path gradleExpected;
42+
43+
@BeforeAll
44+
static void setUp() throws IOException {
45+
sdkVersion = getVersion();
46+
gradleBefore = new File(GradleProjectTest.class.getResource("gradle/before").getFile()).toPath();
47+
gradleAfter = new File(GradleProjectTest.class.getResource("gradle/after").getFile()).toPath();
48+
target = new File(GradleProjectTest.class.getResource("/").getFile()).toPath().getParent();
49+
50+
gradleActual = target.resolve("gradle/actual");
51+
gradleExpected = target.resolve("gradle/expected");
52+
53+
deleteTempDirectories();
54+
55+
FileUtils.copyDirectory(gradleBefore.toFile(), gradleActual.toFile());
56+
FileUtils.copyDirectory(gradleAfter.toFile(), gradleExpected.toFile());
57+
58+
replaceVersion(gradleActual.resolve("init.gradle"), sdkVersion + "-PREVIEW");
59+
}
60+
61+
private static void deleteTempDirectories() throws IOException {
62+
FileUtils.deleteDirectory(gradleActual.toFile());
63+
FileUtils.deleteDirectory(gradleExpected.toFile());
64+
}
65+
66+
@Test
67+
void gradleProject_shouldConvert() throws IOException {
68+
verifyTransformation();
69+
verifyCompilation();
70+
}
71+
72+
private static void verifyTransformation() throws IOException {
73+
List<String> rewriteArgs = new ArrayList<>();
74+
addAll(rewriteArgs, "./gradlew", "rewriteRun", "--init-script", "init.gradle",
75+
"-Drewrite.activeRecipes=software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2");
76+
77+
run(gradleActual, rewriteArgs.toArray(new String[0]));
78+
// only compares source directory and build.gradle and skip non-code directories such as gradle wrapper
79+
assertTwoDirectoriesHaveSameStructure(gradleActual.resolve("src"), gradleExpected.resolve("src"));
80+
}
81+
82+
private static void verifyCompilation() {
83+
List<String> packageArgs = new ArrayList<>();
84+
addAll(packageArgs, "./gradlew", "build");
85+
run(gradleActual, packageArgs.toArray(new String[0]));
86+
}
87+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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.v2migrationtests;
17+
18+
import static java.util.Collections.addAll;
19+
import static software.amazon.awssdk.v2migrationtests.TestUtils.assertTwoDirectoriesHaveSameStructure;
20+
import static software.amazon.awssdk.v2migrationtests.TestUtils.getVersion;
21+
import static software.amazon.awssdk.v2migrationtests.TestUtils.replaceVersion;
22+
import static software.amazon.awssdk.v2migrationtests.TestUtils.run;
23+
24+
import java.io.File;
25+
import java.io.IOException;
26+
import java.nio.file.Path;
27+
import java.util.ArrayList;
28+
import java.util.List;
29+
import org.apache.commons.io.FileUtils;
30+
import org.junit.jupiter.api.BeforeAll;
31+
import org.junit.jupiter.api.Test;
32+
import software.amazon.awssdk.utils.Logger;
33+
34+
public class MavenProjectTest {
35+
private static final Logger log = Logger.loggerFor(MavenProjectTest.class);
36+
private static String sdkVersion;
37+
private static Path mavenBefore;
38+
private static Path mavenAfter;
39+
private static Path target;
40+
private static Path mavenActual;
41+
private static Path mavenExpected;
42+
43+
@BeforeAll
44+
static void setUp() throws IOException {
45+
sdkVersion = getVersion();
46+
mavenBefore = new File(MavenProjectTest.class.getResource("maven/before").getFile()).toPath();
47+
mavenAfter = new File(MavenProjectTest.class.getResource("maven/after").getFile()).toPath();
48+
target = new File(MavenProjectTest.class.getResource("/").getFile()).toPath().getParent();
49+
50+
mavenActual = target.resolve("maven/actual");
51+
mavenExpected = target.resolve("maven/expected");
52+
53+
deleteTempDirectories();
54+
55+
FileUtils.copyDirectory(mavenBefore.toFile(), mavenActual.toFile());
56+
FileUtils.copyDirectory(mavenAfter.toFile(), mavenExpected.toFile());
57+
58+
replaceVersion(mavenExpected.resolve("pom.xml"), sdkVersion);
59+
replaceVersion(mavenActual.resolve("pom.xml"), sdkVersion);
60+
}
61+
62+
private static void deleteTempDirectories() throws IOException {
63+
FileUtils.deleteDirectory(mavenActual.toFile());
64+
FileUtils.deleteDirectory(mavenExpected.toFile());
65+
}
66+
67+
@Test
68+
void mavenProject_shouldConvert() throws IOException {
69+
verifyTransformation();
70+
verifyCompilation();
71+
}
72+
73+
private static void verifyTransformation() throws IOException {
74+
List<String> rewriteArgs = new ArrayList<>();
75+
addAll(rewriteArgs, "mvn", "org.openrewrite.maven:rewrite-maven-plugin:run",
76+
"-Drewrite.recipeArtifactCoordinates=software.amazon.awssdk:v2-migration:"+ sdkVersion + "-PREVIEW",
77+
"-Drewrite.activeRecipes=software.amazon.awssdk.v2migration.AwsSdkJavaV1ToV2");
78+
79+
run(mavenActual, rewriteArgs.toArray(new String[0]));
80+
FileUtils.deleteDirectory(mavenActual.resolve("target").toFile());
81+
assertTwoDirectoriesHaveSameStructure(mavenActual, mavenExpected);
82+
}
83+
84+
private static void verifyCompilation() {
85+
List<String> packageArgs = new ArrayList<>();
86+
addAll(packageArgs, "mvn", "package");
87+
run(mavenActual, packageArgs.toArray(new String[0]));
88+
}
89+
}

0 commit comments

Comments
 (0)