This is an automated email from the ASF dual-hosted git repository. ebourg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git
commit 612a74e8894ede2737ebaab5dedc1c5d2d4d2bf9 Author: Emmanuel Bourg <ebo...@apache.org> AuthorDate: Mon Apr 13 23:52:10 2020 +0200 Improve the test coverage --- .../jakarta/servlet/CommonGatewayInterface.java | 24 ++++++++++++ .../java/javax/servlet/CommonGatewayInterface.java | 24 ++++++++++++ .../tomcat/jakartaee/ClassConverterTest.java | 33 ++++++++++++++++ .../java/org/apache/tomcat/jakartaee/HelloCGI.java | 21 +++++++++++ .../java/org/apache/tomcat/jakartaee/InfoTest.java | 31 +++++++++++++++ .../apache/tomcat/jakartaee/MigrationTaskTest.java | 2 +- .../org/apache/tomcat/jakartaee/MigrationTest.java | 34 +++++++++++++++++ .../tomcat/jakartaee/PassThroughConverterTest.java | 44 ++++++++++++++++++++++ .../java/org/apache/tomcat/jakartaee/UtilTest.java | 31 +++++++++++++++ src/test/resources/testbuild.xml | 2 +- 10 files changed, 244 insertions(+), 2 deletions(-) diff --git a/src/test/java/jakarta/servlet/CommonGatewayInterface.java b/src/test/java/jakarta/servlet/CommonGatewayInterface.java new file mode 100644 index 0000000..d90bfa1 --- /dev/null +++ b/src/test/java/jakarta/servlet/CommonGatewayInterface.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jakarta.servlet; + +/** + * Bogus class in the jakarta.servlet package used by the unit tests. + */ +public class CommonGatewayInterface { +} diff --git a/src/test/java/javax/servlet/CommonGatewayInterface.java b/src/test/java/javax/servlet/CommonGatewayInterface.java new file mode 100644 index 0000000..40d77ee --- /dev/null +++ b/src/test/java/javax/servlet/CommonGatewayInterface.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.servlet; + +/** + * Bogus class in the javax.servlet package used by the unit tests. + */ +public class CommonGatewayInterface { +} diff --git a/src/test/java/org/apache/tomcat/jakartaee/ClassConverterTest.java b/src/test/java/org/apache/tomcat/jakartaee/ClassConverterTest.java new file mode 100644 index 0000000..7b6fa0f --- /dev/null +++ b/src/test/java/org/apache/tomcat/jakartaee/ClassConverterTest.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.jakartaee; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class ClassConverterTest { + + @Test + public void testConverter() { + Converter converter = new ClassConverter(); + + assertTrue(converter.accepts("HelloServlet.class")); + assertFalse(converter.accepts("HelloServlet.java")); + } +} diff --git a/src/test/java/org/apache/tomcat/jakartaee/HelloCGI.java b/src/test/java/org/apache/tomcat/jakartaee/HelloCGI.java new file mode 100644 index 0000000..fcee807 --- /dev/null +++ b/src/test/java/org/apache/tomcat/jakartaee/HelloCGI.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.jakartaee; + +public class HelloCGI extends javax.servlet.CommonGatewayInterface { +} diff --git a/src/test/java/org/apache/tomcat/jakartaee/InfoTest.java b/src/test/java/org/apache/tomcat/jakartaee/InfoTest.java new file mode 100644 index 0000000..3cdf66b --- /dev/null +++ b/src/test/java/org/apache/tomcat/jakartaee/InfoTest.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.jakartaee; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class InfoTest { + + @Test + public void testGetVersion() { + assertNotNull(Info.getVersion()); + assertTrue(Info.getVersion().matches("migrated-[\\d\\.]+(-SNAPSHOT)?")); + } +} diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTaskTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTaskTest.java index 1baa1d7..23843ec 100644 --- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTaskTest.java +++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTaskTest.java @@ -62,7 +62,7 @@ public class MigrationTaskTest { } @Test(expected = BuildException.class) - public void testUnsupportedKeyStoreType() { + public void testInvalidProfile() { project.executeTarget("invalid-profile"); } diff --git a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java index 813ca55..8ed4310 100644 --- a/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java +++ b/src/test/java/org/apache/tomcat/jakartaee/MigrationTest.java @@ -103,4 +103,38 @@ public class MigrationTest { assertEquals("error code", "1", e.getMessage()); } } + + @Test + public void testMigrateDirectory() throws Exception { + File sourceDirectory = new File("src/test/resources"); + File destinationDirectory = new File("target/test-classes/migration"); + + Migration migration = new Migration(); + migration.setSource(sourceDirectory); + migration.setDestination(destinationDirectory); + boolean success = migration.execute(); + + assertTrue("Migration failed", success); + assertTrue("Destination directory not found", destinationDirectory.exists()); + + File migratedFile = new File("target/test-classes/migration/HelloServlet.java"); + assertTrue("Migrated file not found", migratedFile.exists()); + + String migratedSource = FileUtils.readFileToString(migratedFile, StandardCharsets.UTF_8); + assertFalse("Imports not migrated", migratedSource.contains("import javax.servlet")); + assertTrue("Migrated imports not found", migratedSource.contains("import jakarta.servlet")); + } + + @Test + public void testMigrateClassFile() throws Exception { + File classFile = new File("target/test-classes/org/apache/tomcat/jakartaee/HelloCGI.class"); + + Migration migration = new Migration(); + migration.setSource(classFile); + migration.setDestination(classFile); + migration.execute(); + + Class<?> cls = Class.forName("org.apache.tomcat.jakartaee.HelloCGI"); + assertEquals("jakarta.servlet.CommonGatewayInterface", cls.getSuperclass().getName()); + } } diff --git a/src/test/java/org/apache/tomcat/jakartaee/PassThroughConverterTest.java b/src/test/java/org/apache/tomcat/jakartaee/PassThroughConverterTest.java new file mode 100644 index 0000000..5df0687 --- /dev/null +++ b/src/test/java/org/apache/tomcat/jakartaee/PassThroughConverterTest.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.jakartaee; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class PassThroughConverterTest { + + @Test + public void testConverter() throws Exception { + String content = "javax.servlet"; + + ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes()); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + + Converter converter = new PassThroughConverter(); + + assertTrue(converter.accepts("project.properties")); + + converter.convert(in, out, null); + + assertArrayEquals(content.getBytes(), out.toByteArray()); + } +} diff --git a/src/test/java/org/apache/tomcat/jakartaee/UtilTest.java b/src/test/java/org/apache/tomcat/jakartaee/UtilTest.java new file mode 100644 index 0000000..ae0ef07 --- /dev/null +++ b/src/test/java/org/apache/tomcat/jakartaee/UtilTest.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.jakartaee; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class UtilTest { + + @Test + public void testGetExtension() { + assertEquals("java", Util.getExtension("HelloServlet.java")); + assertEquals("", Util.getExtension("HelloServlet")); + } +} diff --git a/src/test/resources/testbuild.xml b/src/test/resources/testbuild.xml index 3b64b59..19b4dec 100644 --- a/src/test/resources/testbuild.xml +++ b/src/test/resources/testbuild.xml @@ -7,7 +7,7 @@ </target> <target name="invalid-profile"> - <javax2jakarta src="foo" dest="bar" profile="tOmCaT"/> + <javax2jakarta src="foo" dest="bar" profile="jserv"/> </target> </project> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org