You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jb...@apache.org on 2013/07/29 02:01:15 UTC

svn commit: r1507874 - /tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java

Author: jboynes
Date: Mon Jul 29 00:01:15 2013
New Revision: 1507874

URL: http://svn.apache.org/r1507874
Log:
Test case should assert SCI is actually loaded

Modified:
    tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java

Modified: tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java?rev=1507874&r1=1507873&r2=1507874&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java (original)
+++ tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java Mon Jul 29 00:01:15 2013
@@ -16,23 +16,34 @@
  */
 package org.apache.jasper.servlet;
 
-import java.util.ServiceLoader;
+import java.io.File;
+import java.util.Collection;
 
 import javax.servlet.ServletContainerInitializer;
+import javax.servlet.ServletContext;
 
+import org.junit.Assert;
 import org.junit.Test;
 
-/**
- *
- */
-public class TestJasperInitializer {
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.catalina.startup.WebappServiceLoader;
+
+public class TestJasperInitializer extends TomcatBaseTest {
 
     @Test
-    public void testServiceLoader() {
-        ServiceLoader<ServletContainerInitializer> initializers =
-                ServiceLoader.load(ServletContainerInitializer.class);
-        for (ServletContainerInitializer initializer : initializers) {
-            System.out.println(initializer.getClass().getName());
-        }
+    public void testServiceLoader() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        File appDir = new File("test/webapp");
+        // app dir is relative to server home
+        StandardContext standardContext = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        tomcat.start();
+
+        ServletContext context = standardContext.getServletContext();
+        WebappServiceLoader<ServletContainerInitializer> loader = new WebappServiceLoader<>(context);
+        Collection<ServletContainerInitializer> initializers = loader.load(ServletContainerInitializer.class);
+        Assert.assertEquals(1, initializers.size());
+        Assert.assertTrue(initializers.iterator().next() instanceof JasperInitializer);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1507874 - /tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java

Posted by Mark Thomas <ma...@apache.org>.
On 29/07/2013 20:34, Jeremy Boynes wrote:
> On Mon, Jul 29, 2013 at 10:19 AM, Mark Thomas <ma...@apache.org> wrote:
> 
>>
>> Looking forward to the point where we use an SCI for JSPs, we don't want
>> to / shouldn't have to do this for every test that uses JSPs.
>>
>> addWebapp() is the interface that provides the settings from the default
>> web.xml and should be just like deploying a webapp in Tomcat.
>> This should enable container SCIs (JSP & WebSocket).
>>
>> addContext() is the 100% programmatic interface that requires the user
>> to explicitly enable everything. Currently, scanning for SCI
>> @HandlesTypes matches isn't supported with addContext(). I think that is
>> the way to go and we should just document it.
>>
> 
> This was an explicit test for the loading mechanism. addWebapp() does add
> the SCI in the normal way

Then I don't get why you are testing the loading mechanism with a
context created with addWebapp().

Mark

 - that was actually the problem that led to bug
> 55319: by adding the SCI it triggered annotation scanning which failed
> because the parent classloader contained test classes with invalid
> annotations (which should not have been scanned because isWebapp was false
> but that was not being captured in the fragment by the scanner).
> 
> HTH
> Jeremy
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1507874 - /tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java

Posted by Jeremy Boynes <jb...@apache.org>.
On Mon, Jul 29, 2013 at 10:19 AM, Mark Thomas <ma...@apache.org> wrote:

>
> Looking forward to the point where we use an SCI for JSPs, we don't want
> to / shouldn't have to do this for every test that uses JSPs.
>
> addWebapp() is the interface that provides the settings from the default
> web.xml and should be just like deploying a webapp in Tomcat.
> This should enable container SCIs (JSP & WebSocket).
>
> addContext() is the 100% programmatic interface that requires the user
> to explicitly enable everything. Currently, scanning for SCI
> @HandlesTypes matches isn't supported with addContext(). I think that is
> the way to go and we should just document it.
>

This was an explicit test for the loading mechanism. addWebapp() does add
the SCI in the normal way - that was actually the problem that led to bug
55319: by adding the SCI it triggered annotation scanning which failed
because the parent classloader contained test classes with invalid
annotations (which should not have been scanned because isWebapp was false
but that was not being captured in the fragment by the scanner).

HTH
Jeremy

Re: svn commit: r1507874 - /tomcat/trunk/test/org/apache/jasper/servlet/TestJasperInitializer.java

Posted by Mark Thomas <ma...@apache.org>.
On 29/07/2013 02:01, jboynes@apache.org wrote:
> Author: jboynes
> Date: Mon Jul 29 00:01:15 2013
> New Revision: 1507874
> 
> URL: http://svn.apache.org/r1507874
> Log:
> Test case should assert SCI is actually loaded

<snip/>

> +    public void testServiceLoader() throws Exception {
> +        Tomcat tomcat = getTomcatInstance();
> +        File appDir = new File("test/webapp");
> +        // app dir is relative to server home
> +        StandardContext standardContext = (StandardContext) tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
> +        tomcat.start();
> +
> +        ServletContext context = standardContext.getServletContext();
> +        WebappServiceLoader<ServletContainerInitializer> loader = new WebappServiceLoader<>(context);
> +        Collection<ServletContainerInitializer> initializers = loader.load(ServletContainerInitializer.class);

Looking forward to the point where we use an SCI for JSPs, we don't want
to / shouldn't have to do this for every test that uses JSPs.

addWebapp() is the interface that provides the settings from the default
web.xml and should be just like deploying a webapp in Tomcat.
This should enable container SCIs (JSP & WebSocket).

addContext() is the 100% programmatic interface that requires the user
to explicitly enable everything. Currently, scanning for SCI
@HandlesTypes matches isn't supported with addContext(). I think that is
the way to go and we should just document it.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org