-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Java 11, 17, & 21 Tests for JSP
- Loading branch information
Showing
31 changed files
with
840 additions
and
27 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
126 changes: 126 additions & 0 deletions
126
dev/com.ibm.ws.jsp.2.3_fat/fat/src/com/ibm/ws/jsp23/fat/tests/JSPJava11Test.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,126 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package com.ibm.ws.jsp23.fat.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.Collections; | ||
import java.util.logging.Logger; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.ibm.websphere.simplicity.ShrinkHelper; | ||
import com.ibm.websphere.simplicity.config.ServerConfiguration; | ||
import com.ibm.ws.jsp23.fat.JSPUtils; | ||
import com.meterware.httpunit.GetMethodWebRequest; | ||
import com.meterware.httpunit.WebConversation; | ||
import com.meterware.httpunit.WebRequest; | ||
import com.meterware.httpunit.WebResponse; | ||
|
||
import componenttest.annotation.MinimumJavaLevel; | ||
import componenttest.annotation.Server; | ||
import componenttest.annotation.SkipForRepeat; | ||
import componenttest.custom.junit.runner.FATRunner; | ||
import componenttest.custom.junit.runner.Mode; | ||
import componenttest.custom.junit.runner.Mode.TestMode; | ||
import componenttest.topology.impl.LibertyServer; | ||
|
||
/** | ||
* JSP 2.3 tests which use Java 11 specific features. | ||
* | ||
* Tests must only run when Java 11 is in use. Runs only in FULL as Java 8 and 17 test also cover these options. | ||
* | ||
* Tests that just need to drive a simple request using our WebBrowser object can be placed in this class. | ||
* | ||
*/ | ||
// No need to run against cdi-2.0 since these tests don't use CDI at all. | ||
@Mode(TestMode.FULL) | ||
@MinimumJavaLevel(javaLevel = 11) | ||
@SkipForRepeat("CDI-2.0") | ||
@RunWith(FATRunner.class) | ||
public class JSPJava11Test { | ||
private static final String APP_NAME = "TestJSPWithJava11"; | ||
private static final Logger LOG = Logger.getLogger(JSPJava11Test.class.getName()); | ||
|
||
@Server("jspJava11Server") | ||
public static LibertyServer server; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
ShrinkHelper.defaultDropinApp(server, APP_NAME + ".war"); | ||
|
||
server.startServer(JSPJava11Test.class.getSimpleName() + ".log"); | ||
} | ||
|
||
@AfterClass | ||
public static void testCleanup() throws Exception { | ||
// Stop the server | ||
if (server != null && server.isStarted()) { | ||
server.stopServer(); | ||
} | ||
} | ||
|
||
/** | ||
* Simple test for index.jsp. Page uses Java 11's String#strip method | ||
* | ||
* @throws Exception | ||
* if something goes horribly wrong | ||
*/ | ||
@Test | ||
public void testJava11JSP() throws Exception { | ||
WebConversation wc = new WebConversation(); | ||
wc.setExceptionsThrownOnErrorStatus(false); | ||
|
||
String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp"); | ||
LOG.info("url: " + url); | ||
|
||
WebRequest request = new GetMethodWebRequest(url); | ||
WebResponse response = wc.getResponse(request); | ||
LOG.info("Servlet response : " + response.getText()); | ||
|
||
assertEquals("Expected " + 200 + " status code was not returned!", | ||
200, response.getResponseCode()); | ||
assertTrue("Java 11's String strip() method failed", response.getText().contains("success-strip")); | ||
assertTrue("Java 11's String lines() did not return a stream.", response.getText().contains("java.util.stream.ReferencePipeline")); | ||
assertTrue("Java 11's Map copyOf method failed", response.getText().contains("{key=success-copyof}")); | ||
} | ||
|
||
@Test | ||
public void testJava11viaUseJDKCompiler() throws Exception { | ||
|
||
ServerConfiguration configuration = server.getServerConfiguration(); | ||
configuration.getJspEngine().setUseJDKCompiler(true); | ||
LOG.info("New server configuration used: " + configuration); | ||
server.setMarkToEndOfLog(); | ||
server.updateServerConfiguration(configuration); | ||
server.restartApplication(APP_NAME); | ||
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava11.*"); | ||
|
||
WebConversation wc = new WebConversation(); | ||
wc.setExceptionsThrownOnErrorStatus(false); | ||
|
||
String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp"); | ||
LOG.info("url: " + url); | ||
|
||
WebRequest request = new GetMethodWebRequest(url); | ||
WebResponse response = wc.getResponse(request); | ||
LOG.info("Servlet response : " + response.getText()); | ||
|
||
assertEquals("Expected " + 200 + " status code was not returned!", | ||
200, response.getResponseCode()); | ||
assertTrue("Java 11's String strip() method failed", response.getText().contains("success-strip")); | ||
assertTrue("Java 11's String lines() did not return a stream.", response.getText().contains("java.util.stream.ReferencePipeline")); | ||
assertTrue("Java 11's Map copyOf method failed", response.getText().contains("{key=success-copyof}")); | ||
} | ||
} |
154 changes: 154 additions & 0 deletions
154
dev/com.ibm.ws.jsp.2.3_fat/fat/src/com/ibm/ws/jsp23/fat/tests/JSPJava17Test.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,154 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package com.ibm.ws.jsp23.fat.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.Collections; | ||
import java.util.logging.Logger; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.ibm.websphere.simplicity.ShrinkHelper; | ||
import com.ibm.ws.jsp23.fat.JSPUtils; | ||
import com.meterware.httpunit.GetMethodWebRequest; | ||
import com.meterware.httpunit.WebConversation; | ||
import com.meterware.httpunit.WebRequest; | ||
import com.meterware.httpunit.WebResponse; | ||
|
||
import componenttest.annotation.MinimumJavaLevel; | ||
import componenttest.annotation.MaximumJavaLevel; | ||
import componenttest.annotation.Server; | ||
import componenttest.annotation.SkipForRepeat; | ||
import componenttest.custom.junit.runner.FATRunner; | ||
import componenttest.topology.impl.LibertyServer; | ||
|
||
import com.ibm.websphere.simplicity.config.ServerConfiguration; | ||
/** | ||
* JSP 2.3 tests which use Java 17 specific features. | ||
* | ||
* Tests must only run when Java 17 is in use. | ||
* | ||
* Tests that just need to drive a simple request using our WebBrowser object can be placed in this class. | ||
* | ||
*/ | ||
// No need to run against cdi-2.0 since these tests don't use CDI at all. | ||
@MinimumJavaLevel(javaLevel = 17) | ||
@SkipForRepeat("CDI-2.0") | ||
@RunWith(FATRunner.class) | ||
public class JSPJava17Test { | ||
private static final String APP_NAME = "TestJSPWithJava17"; | ||
private static final Logger LOG = Logger.getLogger(JSPJava17Test.class.getName()); | ||
|
||
@Server("jspJava17Server") | ||
public static LibertyServer server; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
ShrinkHelper.defaultDropinApp(server, APP_NAME + ".war"); | ||
|
||
server.startServer(JSPJava17Test.class.getSimpleName() + ".log"); | ||
} | ||
|
||
@AfterClass | ||
public static void testCleanup() throws Exception { | ||
// Stop the server | ||
if (server != null && server.isStarted()) { | ||
server.stopServer(); | ||
} | ||
} | ||
|
||
/** | ||
* Simple test for index.jsp. Page uses Java 17's instanceof pattern matching | ||
* | ||
* @throws Exception | ||
* if something goes horribly wrong | ||
*/ | ||
@Test | ||
public void testJava17JSP() throws Exception { | ||
WebConversation wc = new WebConversation(); | ||
wc.setExceptionsThrownOnErrorStatus(false); | ||
|
||
String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp"); | ||
LOG.info("url: " + url); | ||
|
||
WebRequest request = new GetMethodWebRequest(url); | ||
WebResponse response = wc.getResponse(request); | ||
LOG.info("Servlet response : " + response.getText()); | ||
|
||
assertEquals("Expected " + 200 + " status code was not returned!", | ||
200, response.getResponseCode()); | ||
assertTrue("The response did not contain: success", response.getText().contains("success-text-block")); | ||
assertTrue("The response did not contain: success", response.getText().contains("success-pattern-matching")); | ||
} | ||
|
||
@Test | ||
public void testJava17viaUseJDKCompiler() throws Exception { | ||
|
||
ServerConfiguration configuration = server.getServerConfiguration(); | ||
configuration.getJspEngine().setUseJDKCompiler(true); | ||
LOG.info("New server configuration used: " + configuration); | ||
|
||
server.setMarkToEndOfLog(); | ||
server.updateServerConfiguration(configuration); | ||
server.restartApplication(APP_NAME); | ||
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava17.*"); | ||
|
||
WebConversation wc = new WebConversation(); | ||
wc.setExceptionsThrownOnErrorStatus(false); | ||
|
||
String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp"); | ||
LOG.info("url: " + url); | ||
|
||
WebRequest request = new GetMethodWebRequest(url); | ||
WebResponse response = wc.getResponse(request); | ||
LOG.info("Servlet response : " + response.getText()); | ||
|
||
assertEquals("Expected " + 200 + " status code was not returned!", | ||
200, response.getResponseCode()); | ||
assertTrue("The response did not contain: success", response.getText().contains("success-text-block")); | ||
assertTrue("The response did not contain: success", response.getText().contains("success-pattern-matching")); | ||
} | ||
|
||
/* | ||
* Verifies that javaSourceLevel overrides jdkSourceLevel if both are set. | ||
*/ | ||
@Test | ||
public void testBothjdkSourceLevelAndjavaSourceLevel() throws Exception { | ||
|
||
ServerConfiguration configuration = server.getServerConfiguration(); | ||
configuration.getJspEngine().setJdkSourceLevel("18"); | ||
LOG.info("New server configuration used: " + configuration); | ||
|
||
server.setMarkToEndOfLog(); | ||
server.updateServerConfiguration(configuration); | ||
server.restartApplication(APP_NAME); | ||
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava17.*"); | ||
|
||
WebConversation wc = new WebConversation(); | ||
wc.setExceptionsThrownOnErrorStatus(false); | ||
|
||
String url = JSPUtils.createHttpUrlString(server, APP_NAME, "index.jsp"); | ||
LOG.info("url: " + url); | ||
|
||
WebRequest request = new GetMethodWebRequest(url); | ||
WebResponse response = wc.getResponse(request); | ||
LOG.info("Servlet response : " + response.getText()); | ||
|
||
assertEquals("Expected " + 200 + " status code was not returned!", | ||
200, response.getResponseCode()); | ||
assertTrue("The response did not contain: success", response.getText().contains("success-text-block")); | ||
assertTrue("The response did not contain: success", response.getText().contains("success-pattern-matching")); | ||
} | ||
} |
Oops, something went wrong.