This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 6a06b3c Add HandlesTypes test
6a06b3c is described below
commit 6a06b3cfff41dc81538c7b93a74dfa13ea5cea9e
Author: remm <[email protected]>
AuthorDate: Tue Apr 20 14:34:04 2021 +0200
Add HandlesTypes test
Based on the way to validate from the BZ 65244 example.
---
test/org/apache/tomcat/util/scan/FooSCI.java | 37 ++++++++++++++
.../apache/tomcat/util/scan/TestClassParser.java | 58 ++++++++++++++++++++++
.../jakarta.servlet.ServletContainerInitializer | 16 ++++++
3 files changed, 111 insertions(+)
diff --git a/test/org/apache/tomcat/util/scan/FooSCI.java
b/test/org/apache/tomcat/util/scan/FooSCI.java
new file mode 100644
index 0000000..be45d4f
--- /dev/null
+++ b/test/org/apache/tomcat/util/scan/FooSCI.java
@@ -0,0 +1,37 @@
+/*
+ * 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.util.scan;
+
+import java.util.Set;
+
+import jakarta.servlet.ServletContainerInitializer;
+import jakarta.servlet.ServletContext;
+import jakarta.servlet.annotation.HandlesTypes;
+
+import org.apache.tomcat.util.scan.TestClassParser.Foo;
+
+@HandlesTypes(Foo.class)
+public class FooSCI implements ServletContainerInitializer {
+
+ static Set<Class<?>> classSet;
+
+ @Override
+ public void onStartup(final Set<Class<?>> set, final ServletContext
servletContext) {
+ classSet = set;
+ }
+
+}
diff --git a/test/org/apache/tomcat/util/scan/TestClassParser.java
b/test/org/apache/tomcat/util/scan/TestClassParser.java
new file mode 100644
index 0000000..3756535
--- /dev/null
+++ b/test/org/apache/tomcat/util/scan/TestClassParser.java
@@ -0,0 +1,58 @@
+/*
+ * 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.util.scan;
+
+import java.io.File;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+
+public class TestClassParser extends TomcatBaseTest {
+
+ @Target({ElementType.TYPE, ElementType.FIELD})
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface Foo {
+ }
+
+ /** and beans */
+ @Foo
+ public class OnClass {
+ }
+
+ public class OnField {
+ @Foo
+ private String name;
+ }
+
+ @Test
+ public void testAnnotations() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+ File appDir = new File("test/webapp-sci");
+ tomcat.addWebapp("", appDir.getAbsolutePath());
+ tomcat.start();
+ Assert.assertTrue(FooSCI.classSet.size() == 2);
+ Assert.assertTrue(FooSCI.classSet.contains(OnClass.class));
+ Assert.assertTrue(FooSCI.classSet.contains(OnField.class));
+ }
+}
diff --git
a/test/webapp-sci/WEB-INF/classes/META-INF/services/jakarta.servlet.ServletContainerInitializer
b/test/webapp-sci/WEB-INF/classes/META-INF/services/jakarta.servlet.ServletContainerInitializer
new file mode 100644
index 0000000..19b37e3
--- /dev/null
+++
b/test/webapp-sci/WEB-INF/classes/META-INF/services/jakarta.servlet.ServletContainerInitializer
@@ -0,0 +1,16 @@
+# 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.
+
+org.apache.tomcat.util.scan.FooSCI
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]