Skip to content

Commit

Permalink
Create basic Java 11 & 17 JSP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
volosied committed Jun 22, 2023
1 parent a1ca05b commit 51b4f28
Show file tree
Hide file tree
Showing 14 changed files with 391 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.ibm.ws.fat.util.FatLogHandler;
import com.ibm.ws.jsp23.fat.tests.JSP23JSP22ServerTest;
import com.ibm.ws.jsp23.fat.tests.JSPCdiTest;
import com.ibm.ws.jsp23.fat.tests.JSPJava11Test;
import com.ibm.ws.jsp23.fat.tests.JSPJava17Test;
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 @@ -44,6 +46,8 @@
JSPTests.class,
JSPSkipMetaInfTests.class,
JSPJava8Test.class,
JSPJava11Test.class,
JSPJava17Test.class,
JSPCdiTest.class,
JSP23JSP22ServerTest.class,
JSPPrepareJSPThreadCountNonDefaultValueTests.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*******************************************************************************
* 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
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.ws.jsp23.fat.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

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.Server;
import componenttest.annotation.SkipForRepeat;
import componenttest.custom.junit.runner.FATRunner;
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.
*
* 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 = 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("The response did not contain: success", response.getText().contains("success"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*******************************************************************************
* 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
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.ws.jsp23.fat.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

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.Server;
import componenttest.annotation.SkipForRepeat;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.topology.impl.LibertyServer;

/**
* 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"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dropins
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
###############################################################################
# Copyright (c) 2014 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
#
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
bootstrap.include=../testports.properties
osgi.console=7777
com.ibm.ws.logging.trace.specification=*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HTTPChannel=all:TCPChannel=all:GenericBNF=all:com.ibm.ws.jsp*=all

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Copyright (c) 2020 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
Contributors:
IBM Corporation - initial API and implementation
-->
<server description="Server for testing JavaServer Pages 2.3">

<include location="../fatTestPorts.xml"/>

<featureManager>
<feature>jsp-2.3</feature>
</featureManager>

<logging traceSpecification="*=info=enabled:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HTTPChannel=all:TCPChannel=all:GenericBNF=all:com.ibm.ws.jsp*=all" maxFileSize="32" maxFiles="24" traceFormat="BASIC"/>

<jspEngine javaSourceLevel="17"/>

</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dropins
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
###############################################################################
# Copyright (c) 2014 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
#
# Contributors:
# IBM Corporation - initial API and implementation
###############################################################################
bootstrap.include=../testports.properties
osgi.console=7777
com.ibm.ws.logging.trace.specification=*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HTTPChannel=all:TCPChannel=all:GenericBNF=all:com.ibm.ws.jsp*=all

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
Copyright (c) 2020 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
Contributors:
IBM Corporation - initial API and implementation
-->
<server description="Server for testing JavaServer Pages 2.3">

<include location="../fatTestPorts.xml"/>

<featureManager>
<feature>jsp-2.3</feature>
</featureManager>

<logging traceSpecification="*=info=enabled:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HTTPChannel=all:TCPChannel=all:GenericBNF=all:com.ibm.ws.jsp*=all" maxFileSize="32" maxFiles="24" traceFormat="BASIC"/>

<jspEngine javaSourceLevel="17"/>

</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<permissions xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/permissions_7.xsd"
version="7">

<permission>
<class-name>java.lang.RuntimePermission</class-name>
<name>getClassLoader</name>
</permission>

</permissions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
Contributors:
IBM Corporation - initial API and implementation
-->
<web-app
version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

<display-name>Java11JSP</display-name>

</web-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
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
Contributors:
IBM Corporation - initial API and implementation
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Java 11 Compilation</title>
</head>
<body>

Testing Java 11's String.strip function:
<% out.print(" success ".strip()); %>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
Contributors:
IBM Corporation - initial API and implementation
-->
<web-app
version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

<display-name>TestJSPWithJava11</display-name>

</web-app>
Loading

0 comments on commit 51b4f28

Please sign in to comment.