Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for contextInitialized listener in a ScatteredArchive
Signed-off-by:Ondro Mihalyi <mihalyi@omnifish.ee>
- Loading branch information
Showing
7 changed files
with
251 additions
and
44 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
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
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
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
21 changes: 21 additions & 0 deletions
21
...a/org/glassfish/tests/embedded/scatteredarchive/contextInitialized/ApplicationStatus.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,21 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* 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.tests.embedded.scatteredarchive.contextInitialized; | ||
|
||
public class ApplicationStatus { | ||
|
||
static int contextInitializedCounter = 0; | ||
} |
41 changes: 41 additions & 0 deletions
41
...ish/tests/embedded/scatteredarchive/contextInitialized/ContextInitializedTestServlet.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 (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* 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.tests.embedded.scatteredarchive.contextInitialized; | ||
|
||
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(name = "ContextInitializedTestServlet", | ||
urlPatterns = "/ContextInitializedTestServlet") | ||
public class ContextInitializedTestServlet extends HttpServlet { | ||
|
||
public static final String LABEL_CONTEXT_INITIALIZED_COUNTER = "Number of times context was initialized"; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest httpServletRequest, | ||
HttpServletResponse httpServletResponse) throws ServletException, IOException { | ||
PrintWriter out = httpServletResponse.getWriter(); | ||
out.println(LABEL_CONTEXT_INITIALIZED_COUNTER + ":" + ApplicationStatus.contextInitializedCounter); | ||
out.flush(); | ||
out.close(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
.../org/glassfish/tests/embedded/scatteredarchive/contextInitialized/DispatcherListener.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,34 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* 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.tests.embedded.scatteredarchive.contextInitialized; | ||
|
||
import static java.lang.System.Logger.Level.INFO; | ||
|
||
import jakarta.servlet.ServletContextEvent; | ||
import jakarta.servlet.ServletContextListener; | ||
import jakarta.servlet.annotation.WebListener; | ||
|
||
@WebListener | ||
public class DispatcherListener implements ServletContextListener { | ||
|
||
private static final System.Logger logger = System.getLogger(DispatcherListener.class.getName()); | ||
|
||
@Override | ||
public void contextInitialized(ServletContextEvent sce) { | ||
logger.log(INFO, "Listener initialized"); | ||
ApplicationStatus.contextInitializedCounter++; | ||
} | ||
} |