diff --git a/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/EmbeddedTest.java b/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/EmbeddedTest.java deleted file mode 100644 index 147707603f3..00000000000 --- a/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/EmbeddedTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.distributions.test; - -import java.io.BufferedReader; -import java.io.File; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.Collection; - -import javax.naming.InitialContext; -import javax.naming.NamingException; - -import org.glassfish.distributions.test.ejb.SampleEjb; -import org.glassfish.embeddable.CommandResult; -import org.glassfish.embeddable.CommandRunner; -import org.glassfish.embeddable.Deployer; -import org.glassfish.embeddable.GlassFish; -import org.glassfish.embeddable.GlassFishException; -import org.glassfish.embeddable.GlassFishRuntime; -import org.glassfish.embeddable.web.HttpListener; -import org.glassfish.embeddable.web.WebContainer; -import org.glassfish.embeddable.web.WebListener; - -public class EmbeddedTest { - - static GlassFish glassfish; - - @BeforeClass - public static void setup() throws GlassFishException { - glassfish = GlassFishRuntime.bootstrap().newGlassFish(); - glassfish.start(); - - WebContainer webcontainer = - glassfish.getService(WebContainer.class); - Collection listeners = webcontainer.getWebListeners(); - System.out.println("Network listener size before creation " + listeners.size()); - for (WebListener listener : listeners) { - System.out.println("Network listener " + listener.getPort()); - } - - try { - HttpListener listener = new HttpListener(); - listener.setPort(8080); - listener.setId("embedded-listener-1"); - webcontainer.addWebListener(listener); - } catch (Exception e) { - throw new RuntimeException(e); - } - - listeners = webcontainer.getWebListeners(); - System.out.println("Network listener size after creation " + listeners.size()); - Assert.assertTrue(listeners.size() == 1); - for (WebListener listener : listeners) { - System.out.println("Network listener " + listener.getPort()); - } - - } - - @Test - public void testAll() throws GlassFishException { - /* - Set sniffers = new HashSet(); - for (EmbeddedContainer c : server.getContainers()) { - sniffers.addAll(c.getSniffers()); - } - System.out.println("Sniffer size " + sniffers.size()); - for (Sniffer sniffer : sniffers) { - System.out.println("Registered Sniffer " + sniffer.getModuleType()); - } - */ - } - - @Test - public void testEjb() throws GlassFishException { - Deployer deployer = glassfish.getDeployer(); - - URL source = SampleEjb.class.getClassLoader().getResource( - "org/glassfish/distributions/test/ejb/SampleEjb.class"); - String p = source.getPath().substring(0, source.getPath().length() - - "org/glassfish/distributions/test/ejb/SimpleEjb.class".length()); - - String appName = deployer.deploy(new File(p).toURI(), "--name=sample"); - Assert.assertNotNull("AppName is null from deployer of type " + deployer.getClass().getName(), - appName); - - // ok now let's look up the EJB... - try { - InitialContext ic = new InitialContext(); - SampleEjb ejb = (SampleEjb) ic.lookup("java:global/sample/SampleEjb"); - if (ejb != null) { - try { - System.out.println(ejb.saySomething()); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (NamingException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - - deployer.undeploy(appName); - System.out.println("Done with EJB"); - } - - @Test - public void testWeb() throws GlassFishException { - System.out.println("Starting testWeb " + glassfish); - - Deployer deployer = glassfish.getDeployer(); - - URL source = SampleEjb.class.getClassLoader().getResource( - "org/glassfish/distributions/test/web/WebHello.class"); - String p = source.getPath().substring(0, source.getPath().length() - - "org/glassfish/distributions/test/web/WebHello.class".length()); - - File path = new File(p).getParentFile().getParentFile(); - - String name = null; - - if (path.getName().lastIndexOf('.') != -1) { - name = path.getName().substring(0, path.getName().lastIndexOf('.')); - } else { - name = path.getName(); - } - - System.out.println("Deploying " + path + ", name = " + name); - - String appName = deployer.deploy(path.toURI(), "--name=" + name); - - System.out.println("Deployed " + appName); - - Assert.assertTrue(appName != null); - - try { - URL servlet = new URL("http://localhost:8080/test-classes/hello"); - URLConnection yc = servlet.openConnection(); - BufferedReader in = new BufferedReader( - new InputStreamReader( - yc.getInputStream())); - String inputLine = in.readLine(); - if (inputLine != null) { - System.out.println(inputLine); - } - Assert.assertNotNull(inputLine); - Assert.assertEquals(inputLine.trim(), "Hello World !"); - in.close(); - } catch (Exception e) { - e.printStackTrace(); - // do not throw the exception for now, because this may break the build if, - // for example, another instance of glassfish is running on 8080 - // throw e; - } - - if (appName != null) { - deployer.undeploy(appName); - System.out.println("Undeployed " + appName); - } - - } - - @Test - public void commandTest() throws GlassFishException { - CommandRunner commandRunner = glassfish.getCommandRunner(); - - CommandResult commandResult = commandRunner.run("list-modules"); - System.out.println("list-modules command result :\n" + commandResult.getOutput()); - - // Unknown commands throw NPE, uncomment once the issue is fixed. - //commandResult = commandRunner.run("list-contracts"); - //System.out.println("list-contracts command result :\n" + commandResult.getOutput()); - } - - @AfterClass - public static void close() throws GlassFishException { - System.out.println("Stopping server " + glassfish); - if (glassfish != null) { - glassfish.stop(); - glassfish.dispose(); - glassfish = null; - } - } -} diff --git a/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/UnitTest.java b/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/UnitTest.java deleted file mode 100644 index 822b75ca93a..00000000000 --- a/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/UnitTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.distributions.test; - -import jakarta.ejb.EJBException; -import jakarta.ejb.embeddable.EJBContainer; - -import java.io.File; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import javax.naming.Context; - -import org.glassfish.distributions.test.ejb.SampleEjb; - -public class UnitTest { - - @Test - public void test() { - - // Calculate test-classes location - String cname = "org/glassfish/distributions/test/UnitTest.class"; - URL source = UnitTest.class.getClassLoader().getResource(cname); - String dir = source.getPath().substring(0, source.getPath().length()-cname.length()); - - Map p = new HashMap(); - p.put(EJBContainer.MODULES, new File(dir)); - EJBContainer c = EJBContainer.createEJBContainer(p); - // ok now let's look up the EJB... - Context ic = c.getContext(); - try { - System.out.println("Looking up EJB..."); - SampleEjb ejb = (SampleEjb) ic.lookup("java:global/classes/SampleEjb"); - if (ejb!=null) { - System.out.println("Invoking EJB..."); - System.out.println(ejb.saySomething()); - } - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("Done calling EJB"); - - try { - System.out.println("Creating another container without closing..."); - EJBContainer c0 = EJBContainer.createEJBContainer(); - if (c0 != null) - throw new RuntimeException("Create another container"); - } catch (EJBException e) { - System.out.println("Caught expected: " + e.getMessage()); - } - - c.close(); - System.out.println("Creating container after closing the previous..."); - c = EJBContainer.createEJBContainer(p); - c.close(); - } -} diff --git a/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/ejb/SampleEjb.java b/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/ejb/SampleEjb.java deleted file mode 100644 index a4f9f2a1873..00000000000 --- a/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/ejb/SampleEjb.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.distributions.test.ejb; - -import jakarta.ejb.Stateless; - -/** - * @author Jerome Dochez - */ -@Stateless -public class SampleEjb { - - public String saySomething() { - return "boo"; - } -} diff --git a/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/web/WebHello.java b/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/web/WebHello.java deleted file mode 100644 index f372d16576f..00000000000 --- a/appserver/distributions/web/src/test/java/org/glassfish/distributions/test/web/WebHello.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -package org.glassfish.distributions.test.web; - -import jakarta.servlet.ServletException; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import java.io.IOException; -import java.io.PrintWriter; - - -@WebServlet(urlPatterns={"/hello"}) -public class WebHello extends HttpServlet { - - public WebHello() { - System.out.println("Servlet WEB-HELLO initialized"); - } - - public void doGet(HttpServletRequest req, HttpServletResponse res) - throws IOException, ServletException { - PrintWriter pw = res.getWriter(); - try { - pw.println("Hello World !"); - } catch(Exception e) { - e.printStackTrace(); - } - } -} diff --git a/nucleus/parent/pom.xml b/nucleus/parent/pom.xml index 3594d0d67dc..5d6f3eaa544 100644 --- a/nucleus/parent/pom.xml +++ b/nucleus/parent/pom.xml @@ -829,6 +829,26 @@ only + + default-testcompile + compile + + testCompile + + + none + + + + testprocess-annotations + process-classes + + testCompile + + + only + +