Skip to content

Commit

Permalink
Create Java 11, 17, & 21 Tests for JSP
Browse files Browse the repository at this point in the history
  • Loading branch information
volosied committed Dec 13, 2023
1 parent b5b8f2b commit 28e5949
Show file tree
Hide file tree
Showing 31 changed files with 840 additions and 27 deletions.
3 changes: 0 additions & 3 deletions dev/com.ibm.ws.jsp.2.3_fat/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# http://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# IBM Corporation - initial API and implementation
#*******************************************************************************
-include= ~../cnf/resources/bnd/bundle.props
bVersion=1.0
Expand Down
3 changes: 0 additions & 3 deletions dev/com.ibm.ws.jsp.2.3_fat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
dependencies {
requiredLibs project(':io.openliberty.org.apache.commons.codec'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import com.ibm.ws.jsp23.fat.tests.JSP23JSP22ServerTest;
import com.ibm.ws.jsp23.fat.tests.JSPCdiTest;
import com.ibm.ws.jsp23.fat.tests.JSPExceptionTests;
import com.ibm.ws.jsp23.fat.tests.JSPJava11Test;
import com.ibm.ws.jsp23.fat.tests.JSPJava17Test;
import com.ibm.ws.jsp23.fat.tests.JSPJava21Test;
import com.ibm.ws.jsp23.fat.tests.JSPJava8Test;
import com.ibm.ws.jsp23.fat.tests.JSPPrepareJSPThreadCountDefaultValueTests;
import com.ibm.ws.jsp23.fat.tests.JSPPrepareJSPThreadCountNonDefaultValueTests;
Expand All @@ -42,6 +45,9 @@
JSPExceptionTests.class,
JSPSkipMetaInfTests.class,
JSPJava8Test.class,
JSPJava11Test.class,
JSPJava17Test.class,
JSPJava21Test.class,
JSPCdiTest.class,
JSP23JSP22ServerTest.class,
JSPPrepareJSPThreadCountNonDefaultValueTests.class,
Expand Down
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}"));
}
}
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"));
}
}
Loading

0 comments on commit 28e5949

Please sign in to comment.