Test the migration of a jar file
diff --git a/pom.xml b/pom.xml
index eb2a753..b66f833 100644
--- a/pom.xml
+++ b/pom.xml
@@ -119,6 +119,29 @@
<plugins>
<plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>3.0.0</version>
+ <executions>
+ <execution>
+ <id>create-test-jars</id>
+ <phase>process-test-classes</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <jar destfile="target/test-classes/cgi-api.jar" basedir="target/test-classes" includes="**/CommonGatewayInterface*"/>
+ <jar destfile="target/test-classes/hellocgi.jar" basedir="target/test-classes" includes="**/HelloCGI*">
+ <manifest>
+ <attribute name="Implementation-Version" value="1.2.3"/>
+ </manifest>
+ </jar>
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<reuseForks>false</reuseForks>
diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
index 8ed4310..9ba59b0 100644
--- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
+++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java
@@ -18,7 +18,10 @@
package org.apache.tomcat.jakartaee;
import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
+import java.util.jar.JarFile;
import org.apache.commons.io.FileUtils;
import org.junit.After;
@@ -137,4 +140,27 @@
Class<?> cls = Class.forName("org.apache.tomcat.jakartaee.HelloCGI");
assertEquals("jakarta.servlet.CommonGatewayInterface", cls.getSuperclass().getName());
}
+
+ @Test
+ public void testMigrateJarFile() throws Exception {
+ File jarFile = new File("target/test-classes/hellocgi.jar");
+
+ Migration migration = new Migration();
+ migration.setSource(jarFile);
+ migration.setDestination(jarFile);
+ migration.execute();
+
+ File cgiapiFile = new File("target/test-classes/cgi-api.jar");
+ URLClassLoader classloader = new URLClassLoader(new URL[]{jarFile.toURI().toURL(), cgiapiFile.toURI().toURL()},ClassLoader.getSystemClassLoader().getParent());
+
+ Class<?> cls = Class.forName("org.apache.tomcat.jakartaee.HelloCGI", true, classloader);
+ assertEquals("jakarta.servlet.CommonGatewayInterface", cls.getSuperclass().getName());
+
+ // check the modification of the Implementation-Version manifest attribute
+ JarFile jar = new JarFile(jarFile);
+ String implementationVersion = jar.getManifest().getMainAttributes().getValue("Implementation-Version");
+ assertNotNull("Missing Implementation-Version manifest attribute", implementationVersion);
+ assertNotEquals("Implementation-Version manifest attribute not changed", "1.2.3", implementationVersion);
+ assertTrue("Implementation-Version manifest attribute doesn't match the expected pattern", implementationVersion.matches("1\\.2\\.3-migrated-[\\d\\.]+.*"));
+ }
}