This is an automated email from the ASF dual-hosted git repository. radcortez pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomee.git
commit f5f202b027a4dc58e4e37a9a503c531df209a9c9 Author: Roberto Cortez <[email protected]> AuthorDate: Fri Dec 14 15:16:14 2018 +0000 TOMEE-2365 - Added initial test to setup module. --- tomee/tomee-security/pom.xml | 9 ++- .../tomee/security/servlet/SimpleServletTest.java | 78 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/tomee/tomee-security/pom.xml b/tomee/tomee-security/pom.xml index 064e5bb..d7943de 100644 --- a/tomee/tomee-security/pom.xml +++ b/tomee/tomee-security/pom.xml @@ -37,7 +37,14 @@ <dependency> <groupId>${project.groupId}</groupId> <artifactId>javaee-api</artifactId> - <classifier>tomcat</classifier> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>openejb-server</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>openejb-http</artifactId> </dependency> </dependencies> </project> diff --git a/tomee/tomee-security/src/test/java/org/apache/tomee/security/servlet/SimpleServletTest.java b/tomee/tomee-security/src/test/java/org/apache/tomee/security/servlet/SimpleServletTest.java new file mode 100644 index 0000000..08e3c6d --- /dev/null +++ b/tomee/tomee-security/src/test/java/org/apache/tomee/security/servlet/SimpleServletTest.java @@ -0,0 +1,78 @@ +/* + * 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.tomee.security.servlet; + +import org.apache.openejb.jee.WebApp; +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.loader.IO; +import org.apache.openejb.testing.Classes; +import org.apache.openejb.testing.Configuration; +import org.apache.openejb.testing.EnableServices; +import org.apache.openejb.testing.Module; +import org.apache.openejb.testng.PropertiesBuilder; +import org.apache.openejb.util.NetworkUtil; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +@RunWith(ApplicationComposer.class) +@EnableServices("http") +public class SimpleServletTest { + private static int port = -1; + + @BeforeClass + public static void beforeClass() { + port = NetworkUtil.getNextAvailablePort(); + } + + @Configuration + public Properties props() { + return new PropertiesBuilder().p("httpejbd.port", Integer.toString(port)).build(); + } + + @Module + @Classes(TestServlet.class) + public WebApp app() { + return new WebApp().contextRoot("/servlet"); + } + + @Test + public void servlet() throws Exception { + assertEquals("ok!", IO.slurp(new URL("http://localhost:" + port + "/servlet/test"))); + } + + @WebServlet(urlPatterns = "/test") + public static class TestServlet extends HttpServlet { + @Override + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) + throws ServletException, IOException { + resp.getWriter().write("ok!"); + } + } + +}
