diff --git a/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java b/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java index ea06afc67e50..71f1ca033044 100644 --- a/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java +++ b/tests/test-distribution/test-distribution-common/src/test/java/org/eclipse/jetty/tests/distribution/DistributionTests.java @@ -50,6 +50,7 @@ import org.eclipse.jetty.io.Content; import org.eclipse.jetty.io.content.ByteBufferContentSource; import org.eclipse.jetty.tests.hometester.JettyHomeTester; +import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.PathMatchers; import org.eclipse.jetty.util.BlockingArrayQueue; import org.eclipse.jetty.util.ssl.SslContextFactory; @@ -1529,4 +1530,85 @@ public void testRangeRequestMultiPartRangeResponse(String env) throws Exception } } } + + @ParameterizedTest + @ValueSource(strings = {"ee8", "ee9", "ee10"}) + public void testXmlDeployWarNotInWebapps(String env) throws Exception + { + Path jettyBase = newTestJettyBaseDirectory(); + String jettyVersion = System.getProperty("jettyVersion"); + JettyHomeTester distribution = JettyHomeTester.Builder.newInstance() + .jettyVersion(jettyVersion) + .jettyBase(jettyBase) + .mavenLocalRepository(System.getProperty("mavenRepoPath")) + .build(); + + int httpPort = distribution.freePort(); + + String[] argsConfig = { + "--add-modules=http," + toEnvironment("deploy", env) + "," + toEnvironment("webapp", env) + }; + + try (JettyHomeTester.Run runConfig = distribution.start(argsConfig)) + { + assertTrue(runConfig.awaitFor(START_TIMEOUT, TimeUnit.SECONDS)); + assertEquals(0, runConfig.getExitValue()); + + String[] argsStart = { + "jetty.http.port=" + httpPort, + "jetty.httpConfig.port=" + httpPort + }; + + // Put war into ${jetty.base}/wars/ directory + File srcWar = distribution.resolveArtifact("org.eclipse.jetty." + env + ".demos:jetty-" + env + "-demo-simple-webapp:war:" + jettyVersion); + Path warsDir = jettyBase.resolve("wars"); + FS.ensureDirExists(warsDir); + Path destWar = warsDir.resolve("demo.war"); + Files.copy(srcWar.toPath(), destWar); + + // Create XML for deployable + String xml = """ + + + + + /demo + %s + + """.formatted(env, destWar.toString()); + Files.writeString(jettyBase.resolve("webapps/demo.xml"), xml, StandardCharsets.UTF_8); + + // Specify Environment Properties for this raw XML based deployable + String props = """ + environment=%s + """.formatted(env); + Files.writeString(jettyBase.resolve("webapps/demo.properties"), props, StandardCharsets.UTF_8); + + /* The jetty.base tree should now look like this + * + * ${jetty.base} + * ├── resources/ + * │ └── jetty-logging.properties + * ├── start.d/ + * │ ├── ${env}-deploy.ini + * │ ├── ${env}-webapp.ini + * │ └── http.ini + * ├── wars/ + * │ └── demo.war + * ├── webapps/ + * │ ├── demo.properties + * │ └── demo.xml + * └── work/ + */ + + try (JettyHomeTester.Run runStart = distribution.start(argsStart)) + { + assertTrue(runStart.awaitConsoleLogsFor("Started oejs.Server@", START_TIMEOUT, TimeUnit.SECONDS)); + + startHttpClient(); + ContentResponse response = client.GET("http://localhost:" + httpPort + "/demo/index.html"); + assertEquals(HttpStatus.OK_200, response.getStatus()); + } + } + } }