Skip to content

Commit

Permalink
Create JSPUseJDKCompilerTests
Browse files Browse the repository at this point in the history
  • Loading branch information
volosied committed Jun 26, 2023
1 parent 1522813 commit d6df827
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.ibm.ws.jsp23.fat.tests.JSPPrepareJSPThreadCountNonDefaultValueTests;
import com.ibm.ws.jsp23.fat.tests.JSPSkipMetaInfTests;
import com.ibm.ws.jsp23.fat.tests.JSPTests;
import com.ibm.ws.jsp23.fat.tests.JSPUseJDKCompilerTests;
import com.ibm.ws.jsp23.fat.tests.JSTLTests;

import componenttest.topology.impl.JavaInfo;
Expand All @@ -52,7 +53,8 @@
JSP23JSP22ServerTest.class,
JSPPrepareJSPThreadCountNonDefaultValueTests.class,
JSPPrepareJSPThreadCountDefaultValueTests.class,
JSTLTests.class
JSTLTests.class,
JSPUseJDKCompilerTests.class
})
public class FATSuite {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*******************************************************************************
* 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.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.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 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.
@SkipForRepeat("CDI-2.0")
@RunWith(FATRunner.class)
public class JSPUseJDKCompilerTests {
private static final String APP_NAME = "TestJSPWithJava8";
private static final Logger LOG = Logger.getLogger(JSPJava11Test.class.getName());

@Server("jspUseJDKCompilerServer")
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 testJava8viaUseJDKCompiler() throws Exception {

ServerConfiguration configuration = server.getServerConfiguration();
LOG.info("Server configuration that was saved: " + configuration);

configuration.getJspEngine().setJavaSourceLevel("8");

server.setMarkToEndOfLog();
server.updateServerConfiguration(configuration);
server.restartApplication(APP_NAME);
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava8.*");

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: onetwothreefour", response.getText().contains("onetwothreefour"));
}

/**
* Simple test for index.jsp. Page uses Java 11's String#strip method
*
* @throws Exception
* if something goes horribly wrong
*/
@Test
public void testJava11viaUseJDKCompiler() throws Exception {

ServerConfiguration configuration = server.getServerConfiguration();
configuration.getJspEngine().setJavaSourceLevel("11");
LOG.info("Server configuration that was updated: " + configuration);
server.setMarkToEndOfLog();
server.updateServerConfiguration(configuration);
server.restartApplication(APP_NAME);
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava8.*");

// ServerConfiguration configuration = server.getServerConfiguration();
// Log.info(JSPJava11Test.class, "testJava11viaUseJDKCompiler", "Server configuration that was saved: " + configuration);
// server.setMarkToEndOfLog();
// server.setServerConfigurationFile("serverConfigs/useJDKCompiler-Source17server.xml");
// server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), true, "CWWKT0016I:.*TestJSPWithJava8.*");

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: onetwothreefour", response.getText().contains("onetwothreefour"));
}


/**
* Simple test for index.jsp. Page uses Java 11's String#strip method
*
* @throws Exception
* if something goes horribly wrong
*/
@Test
public void testJava17viaUseJDKCompiler() throws Exception {

ServerConfiguration configuration = server.getServerConfiguration();
LOG.info("Server configuration that was saved: " + configuration);

configuration.getJspEngine().setJavaSourceLevel("17");

server.setMarkToEndOfLog();
server.updateServerConfiguration(configuration);
server.restartApplication(APP_NAME);
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), false, "CWWKT0016I:.*TestJSPWithJava8.*");

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: onetwothreefour", response.getText().contains("onetwothreefour"));
}
}
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,26 @@
<!--
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>
<feature>localConnector-1.0</feature>
</featureManager>

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

<jspEngine useJDKCompiler="true"/>

</server>

0 comments on commit d6df827

Please sign in to comment.