This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new cbe795f774 Expand coverage further
cbe795f774 is described below
commit cbe795f774c7883ec8ee348773d86a5c4db4bf31
Author: remm <[email protected]>
AuthorDate: Tue Nov 26 13:47:45 2024 +0100
Expand coverage further
---
.../catalina/startup/TestTomcatStandalone.java | 142 +++++++++++++++------
1 file changed, 106 insertions(+), 36 deletions(-)
diff --git a/test/org/apache/catalina/startup/TestTomcatStandalone.java
b/test/org/apache/catalina/startup/TestTomcatStandalone.java
index d8304515b5..1b1f3d752a 100644
--- a/test/org/apache/catalina/startup/TestTomcatStandalone.java
+++ b/test/org/apache/catalina/startup/TestTomcatStandalone.java
@@ -18,9 +18,12 @@ package org.apache.catalina.startup;
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.Inet4Address;
import java.net.InetAddress;
+import java.net.MalformedURLException;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.URI;
@@ -43,57 +46,117 @@ import org.apache.tomcat.util.file.ConfigFileLoader;
public class TestTomcatStandalone extends LoggingBaseTest {
+ private static final String TEST_WEBAPP_CONTEXT_XML =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<Context docBase=\"${user.dir}/test/webapp-2.2\"
ignoreAnnotations=\"true\">\n" +
+ "</Context>";
+
+ private static final long LAST_MODIFIED = System.currentTimeMillis();
protected class ServerXml extends CatalinaBaseConfigurationSource {
+
+ class MemoryResource extends Resource {
+ MemoryResource(InputStream inputStream, URI uri) {
+ super(inputStream, uri);
+ }
+ @Override
+ public long getLastModified() throws MalformedURLException,
IOException {
+ return LAST_MODIFIED;
+ }
+ }
+
public ServerXml() {
super(getTemporaryDirectory(), null);
}
- private static final String SERVER_XML = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n"
- + "<Server port=\"8005\" shutdown=\"SHUTDOWN\">\n"
- + " <Listener
className=\"org.apache.catalina.startup.VersionLoggerListener\" />\n"
- + " <Listener
className=\"org.apache.catalina.core.AprLifecycleListener\" SSLEngine=\"on\"
/>\n"
- + " <Listener
className=\"org.apache.catalina.core.JreMemoryLeakPreventionListener\" />\n"
- + " <Listener
className=\"org.apache.catalina.mbeans.GlobalResourcesLifecycleListener\" />\n"
- + " <Listener
className=\"org.apache.catalina.core.ThreadLocalLeakPreventionListener\" />\n"
- + "\n" + " <GlobalNamingResources>\n"
- + " <Resource name=\"UserDatabase\" auth=\"Container\"\n"
- + " type=\"org.apache.catalina.UserDatabase\"\n"
- + " description=\"User database that can be
updated and saved\"\n"
- + "
factory=\"org.apache.catalina.users.MemoryUserDatabaseFactory\"\n"
- + " pathname=\"conf/tomcat-users.xml\" />\n"
- + " </GlobalNamingResources>\n" + "\n"
- + " <Service name=\"Catalina\">\n" + "\n"
- + " <Connector port=\"0\" protocol=\"HTTP/1.1\"\n"
- + " connectionTimeout=\"20000\"\n"
- + " redirectPort=\"8443\"\n"
- + " maxParameterCount=\"1000\"\n"
- + " />\n"
- + " <Engine name=\"Catalina\" defaultHost=\"localhost\">\n"
- + "\n"
- + " <Realm
className=\"org.apache.catalina.realm.LockOutRealm\">\n"
- + " <Realm
className=\"org.apache.catalina.realm.UserDatabaseRealm\"\n"
- + " resourceName=\"UserDatabase\"/>\n"
- + " </Realm>\n" + "\n"
- + " <Host name=\"localhost\" appBase=\"webapps\"\n"
- + " unpackWARs=\"true\" autoDeploy=\"true\">\n"
- + "\n"
- + " <Valve
className=\"org.apache.catalina.valves.AccessLogValve\" directory=\"logs\"\n"
- + " prefix=\"localhost_access_log\"
suffix=\".txt\"\n"
- + " pattern=\"%h %l %u %t "%r" %s %b\"
/>\n"
- + "\n" + " </Host>\n" + " </Engine>\n"
- + " </Service>\n" + "</Server>";
+ private static final String SERVER_XML =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<Server port=\"8005\" shutdown=\"SHUTDOWN\">\n" +
+ " <Listener
className=\"org.apache.catalina.startup.VersionLoggerListener\" />\n" +
+ " <Listener
className=\"org.apache.catalina.core.AprLifecycleListener\" SSLEngine=\"on\"
/>\n" +
+ " <Listener
className=\"org.apache.catalina.core.JreMemoryLeakPreventionListener\" />\n" +
+ " <Listener
className=\"org.apache.catalina.mbeans.GlobalResourcesLifecycleListener\" />\n"
+
+ " <Listener
className=\"org.apache.catalina.core.ThreadLocalLeakPreventionListener\" />\n" +
+ " <GlobalNamingResources>\n" +
+ " <Resource name=\"UserDatabase\" auth=\"Container\"\n" +
+ " type=\"org.apache.catalina.UserDatabase\"\n" +
+ " description=\"User database that can be updated
and saved\"\n" +
+ "
factory=\"org.apache.catalina.users.MemoryUserDatabaseFactory\"\n" +
+ " pathname=\"conf/tomcat-users.xml\" />\n" +
+ " </GlobalNamingResources>\n" + "\n" +
+ " <Service name=\"Catalina\">\n" +
+ " <Connector port=\"0\" protocol=\"HTTP/1.1\"\n" +
+ " connectionTimeout=\"20000\"\n" +
+ " redirectPort=\"8443\" />\n" +
+ " <Engine name=\"Catalina\" defaultHost=\"localhost\">\n" +
"\n" +
+ " <Realm
className=\"org.apache.catalina.realm.LockOutRealm\">\n" +
+ " <Realm
className=\"org.apache.catalina.realm.UserDatabaseRealm\"\n" +
+ " resourceName=\"UserDatabase\"/>\n" +
+ " </Realm>\n" + "\n" +
+ " <Host name=\"localhost\" appBase=\"webapps\"\n" +
+ " unpackWARs=\"true\" autoDeploy=\"true\">\n" +
"\n" +
+ " <Valve
className=\"org.apache.catalina.valves.AccessLogValve\" directory=\"logs\"\n" +
+ " prefix=\"localhost_access_log\"
suffix=\".txt\"\n" +
+ " pattern=\"%h %l %u %t "%r" %s %b\"
/>\n" +
+ " </Host>\n" +
+ " </Engine>\n" +
+ " </Service>\n" +
+ "</Server>";
+
+ private static final String CONTEXT_XML =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<Context>\n" +
+ " <JarScanner scanClassPath=\"false\" />\n" +
+ " <WatchedResource>WEB-INF/web.xml</WatchedResource>\n" +
+ "
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>\n" +
+ "
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>\n" +
+ " <Manager pathname=\"SESSIONS.ser\" />\n" +
+ "</Context>";
+
+ private static final String TOMCAT_USERS_XML =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<tomcat-users xmlns=\"http://tomcat.apache.org/xml\"\n" +
+ "
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ "
xsi:schemaLocation=\"http://tomcat.apache.org/xml tomcat-users.xsd\"\n" +
+ " version=\"1.0\">\n" +
+ " <user username=\"tomcat\" password=\"tomcat\"
roles=\"tomcat,manager-status\"/>\n" +
+ "</tomcat-users>";
@Override
public Resource getServerXml() throws IOException {
Resource resource;
try {
- resource = new Resource(new
ByteArrayInputStream(SERVER_XML.getBytes(StandardCharsets.ISO_8859_1)),
- new URI("file:server.xml"));
+ resource = new MemoryResource(new
ByteArrayInputStream(SERVER_XML.getBytes(StandardCharsets.UTF_8)),
+ new URI("file:conf/server.xml"));
} catch (URISyntaxException e) {
throw new IOException(e);
}
return resource;
}
+
+ @Override
+ public Resource getResource(String name) throws IOException {
+ if (Constants.DefaultContextXml.equals(name)) {
+ Resource resource;
+ try {
+ resource = new MemoryResource(new
ByteArrayInputStream(CONTEXT_XML.getBytes(StandardCharsets.UTF_8)),
+ new URI("file:conf/context.xml"));
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
+ }
+ return resource;
+ } else if ("conf/tomcat-users.xml".equals(name)) {
+ Resource resource;
+ try {
+ resource = new MemoryResource(new
ByteArrayInputStream(TOMCAT_USERS_XML.getBytes(StandardCharsets.UTF_8)),
+ new URI("file:conf/tomcat-users.xml"));
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
+ }
+ return resource;
+ }
+ return super.getResource(name);
+ }
+
}
@Test
@@ -168,6 +231,13 @@ public class TestTomcatStandalone extends LoggingBaseTest {
public void testStandalone() throws Exception {
ConfigFileLoader.setSource(new ServerXml());
+ // Add descriptor to deploy
+ File descriptorsFolder = new File(getTemporaryDirectory(),
"conf/Catalina/localhost");
+ Assert.assertTrue(descriptorsFolder.mkdirs());
+ try (FileOutputStream os = new FileOutputStream(new
File(descriptorsFolder, "test.xml"))) {
+ os.write(TEST_WEBAPP_CONTEXT_XML.getBytes(StandardCharsets.UTF_8));
+ }
+
Catalina catalina = new Catalina();
catalina.setAwait(true);
File generatedCodeLocation = new File(getTemporaryDirectory(),
"generated");
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]