forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#1266 from stuartwdouglas/1055
Merge web.xml and annotations
- Loading branch information
Showing
6 changed files
with
253 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
extensions/undertow/deployment/src/test/java/io/quarkus/undertow/test/AnnotatedFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. | ||
* | ||
* Licensed 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 io.quarkus.undertow.test; | ||
|
||
import java.io.IOException; | ||
import java.util.Enumeration; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.http.HttpFilter; | ||
|
||
@WebFilter(urlPatterns = "/*") | ||
public class AnnotatedFilter extends HttpFilter { | ||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
Enumeration<String> attributeNames = request.getServletContext().getAttributeNames(); | ||
while (attributeNames.hasMoreElements()) { | ||
response.getWriter().println(attributeNames.nextElement()); | ||
} | ||
response.getWriter().println("annotated filter"); | ||
chain.doFilter(request, response); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
extensions/undertow/deployment/src/test/java/io/quarkus/undertow/test/AnnotatedListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. | ||
* | ||
* Licensed 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 io.quarkus.undertow.test; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
import javax.servlet.annotation.WebListener; | ||
|
||
@WebListener | ||
public class AnnotatedListener implements ServletContextListener { | ||
@Override | ||
public void contextInitialized(ServletContextEvent sce) { | ||
sce.getServletContext().setAttribute("annotated listener", true); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...ertow/deployment/src/test/java/io/quarkus/undertow/test/AnnotationWithWebXmlTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. | ||
* | ||
* Licensed 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 io.quarkus.undertow.test; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class AnnotationWithWebXmlTestCase { | ||
|
||
static final String WEB_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + | ||
"\n" + | ||
"<web-app version=\"3.0\"\n" + | ||
" xmlns=\"http://java.sun.com/xml/ns/javaee\"\n" + | ||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + | ||
" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\"\n" | ||
+ | ||
" metadata-complete=\"false\">\n" + | ||
" <servlet>\n" + | ||
" <servlet-name>mapped</servlet-name>\n" + | ||
" <servlet-class>" + WebXmlServlet.class.getName() + "</servlet-class>\n" + | ||
" </servlet>\n" + | ||
"\n" + | ||
" <servlet-mapping>\n" + | ||
" <servlet-name>mapped</servlet-name>\n" + | ||
" <url-pattern>/mapped</url-pattern>\n" + | ||
" </servlet-mapping>" + | ||
"\n" + | ||
" <filter> \n" + | ||
" <filter-name>mapped-filter</filter-name>\n" + | ||
" <filter-class>" + WebXmlFilter.class.getName() + "</filter-class> \n" + | ||
" </filter> \n" + | ||
" <filter-mapping> \n" + | ||
" <filter-name>mapped-filter</filter-name>\n" + | ||
" <url-pattern>/*</url-pattern> \n" + | ||
" </filter-mapping> " + | ||
"\n" + | ||
" <listener>\n" + | ||
" <listener-class>" + WebXmlListener.class.getName() + "</listener-class>\n" + | ||
" </listener>" + | ||
"</web-app>"; | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(WebXmlServlet.class, TestServlet.class, | ||
WebXmlFilter.class, AnnotatedFilter.class, | ||
WebXmlListener.class, AnnotatedListener.class) | ||
.addAsManifestResource(new StringAsset(WEB_XML), "web.xml")); | ||
|
||
@Test | ||
public void testWebXmlServlet() { | ||
RestAssured.when().get("/mapped").then() | ||
.statusCode(200) | ||
.body(containsString("web xml listener")) | ||
.body(containsString("annotated listener")) | ||
.body(containsString("web xml filter")) | ||
.body(containsString("annotated filter")) | ||
.body(containsString("web xml servlet")); | ||
} | ||
|
||
@Test | ||
public void testAnnotatedServlet() { | ||
RestAssured.when().get("/test").then() | ||
.statusCode(200) | ||
.body(containsString("web xml listener")) | ||
.body(containsString("annotated listener")) | ||
.body(containsString("web xml filter")) | ||
.body(containsString("annotated filter")) | ||
.body(containsString("test servlet")); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
extensions/undertow/deployment/src/test/java/io/quarkus/undertow/test/WebXmlFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. | ||
* | ||
* Licensed 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 io.quarkus.undertow.test; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.http.HttpFilter; | ||
|
||
public class WebXmlFilter extends HttpFilter { | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
response.getWriter().println("web xml filter"); | ||
chain.doFilter(request, response); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
extensions/undertow/deployment/src/test/java/io/quarkus/undertow/test/WebXmlListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2018 Red Hat, Inc. | ||
* | ||
* Licensed 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 io.quarkus.undertow.test; | ||
|
||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
import javax.servlet.annotation.WebListener; | ||
|
||
public class WebXmlListener implements ServletContextListener { | ||
@Override | ||
public void contextInitialized(ServletContextEvent sce) { | ||
sce.getServletContext().setAttribute("web xml listener", true); | ||
} | ||
} |