From 00c06738f0162c5016d1576a6c4dfe9310c73716 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 17 Oct 2022 15:23:24 -0500 Subject: [PATCH] Use MavenPaths where appropriate (ee9 -> ee8 conversion helper) --- .../TestAnnotationConfiguration.java | 3 ++- .../TestAnnotationConfiguration.java | 3 ++- .../jetty/ee9/webapp/WebAppContextTest.java | 23 +++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/jetty-ee10/jetty-ee10-annotations/src/test/java/org/eclipse/jetty/ee10/annotations/TestAnnotationConfiguration.java b/jetty-ee10/jetty-ee10-annotations/src/test/java/org/eclipse/jetty/ee10/annotations/TestAnnotationConfiguration.java index fea17fc15ec..a454f7ebfd1 100644 --- a/jetty-ee10/jetty-ee10-annotations/src/test/java/org/eclipse/jetty/ee10/annotations/TestAnnotationConfiguration.java +++ b/jetty-ee10/jetty-ee10-annotations/src/test/java/org/eclipse/jetty/ee10/annotations/TestAnnotationConfiguration.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.ee10.webapp.WebAppContext; import org.eclipse.jetty.ee10.webapp.WebDescriptor; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.JAR; +import org.eclipse.jetty.toolchain.test.MavenPaths; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.util.resource.FileSystemPool; @@ -97,7 +98,7 @@ public class TestAnnotationConfiguration testContainerSciJar.toUri().toURL() }, Thread.currentThread().getContextClassLoader()); - targetClasses = ResourceFactory.root().newResource(MavenTestingUtils.getTargetDir().toURI()).resolve("/test-classes"); + targetClasses = ResourceFactory.root().newResource(MavenPaths.targetDir().resolve("test-classes")); classes = List.of(webInfClasses, targetClasses); diff --git a/jetty-ee9/jetty-ee9-annotations/src/test/java/org/eclipse/jetty/ee9/annotations/TestAnnotationConfiguration.java b/jetty-ee9/jetty-ee9-annotations/src/test/java/org/eclipse/jetty/ee9/annotations/TestAnnotationConfiguration.java index e6d6f73ab7c..e5cbe82bb3f 100644 --- a/jetty-ee9/jetty-ee9-annotations/src/test/java/org/eclipse/jetty/ee9/annotations/TestAnnotationConfiguration.java +++ b/jetty-ee9/jetty-ee9-annotations/src/test/java/org/eclipse/jetty/ee9/annotations/TestAnnotationConfiguration.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.ee9.webapp.WebAppContext; import org.eclipse.jetty.ee9.webapp.WebDescriptor; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.JAR; +import org.eclipse.jetty.toolchain.test.MavenPaths; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.util.resource.FileSystemPool; @@ -101,7 +102,7 @@ public class TestAnnotationConfiguration testContainerSciJar.toUri().toURL() }, Thread.currentThread().getContextClassLoader()); - targetClasses = ResourceFactory.root().newResource(MavenTestingUtils.getTargetDir().toURI()).resolve("/test-classes"); + targetClasses = ResourceFactory.root().newResource(MavenPaths.targetDir().resolve("test-classes")); classes = List.of(webInfClasses, targetClasses); diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java index 6f4424c8873..9b6bc2b39d0 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java +++ b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/WebAppContextTest.java @@ -42,6 +42,7 @@ import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.toolchain.test.FS; +import org.eclipse.jetty.toolchain.test.MavenPaths; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; @@ -49,6 +50,7 @@ import org.eclipse.jetty.util.FileID; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.resource.FileSystemPool; +import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.ResourceFactory; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; @@ -406,8 +408,10 @@ public class WebAppContextTest handlers.addHandler(contexts); WebAppContext context = new WebAppContext(); - Path testWebapp = MavenTestingUtils.getTargetPath("test-classes/webapp"); - context.setBaseResource(ResourceFactory.root().newResource(testWebapp)); + Path testWebapp = MavenPaths.findTestResourceDir("webapp"); + Resource testWebappResource = context.getResourceFactory().newResource(testWebapp); + assertTrue(testWebappResource.isDirectory()); + context.setBaseResource(testWebappResource); context.setContextPath("/"); contexts.addHandler(context); @@ -417,7 +421,12 @@ public class WebAppContextTest server.start(); - String rawResponse = connector.getResponse("GET http://localhost:8080 HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n"); + String rawResponse = connector.getResponse(""" + GET http://localhost:8080 HTTP/1.1\r + Host: localhost:8080\r + Connection: close\r + \r + """); HttpTester.Response response = HttpTester.parseResponse(rawResponse); assertThat("Response OK", response.getStatus(), is(HttpStatus.OK_200)); } @@ -560,7 +569,7 @@ public class WebAppContextTest { List references = new ArrayList<>(); - Path extLibs = MavenTestingUtils.getTargetPath("test-classes/ext"); + Path extLibs = MavenPaths.findTestResourceDir("ext"); extLibs = extLibs.toAbsolutePath(); // Absolute reference with trailing slash @@ -575,7 +584,7 @@ public class WebAppContextTest // This will be in the String form similar to "src/test/resources/ext/" (with trailing slash) references.add(Arguments.of(relativeExtLibsDir + File.separator)); - // This will be in the String form similar to "src/test/resources/ext/" (without trailing slash) + // This will be in the String form similar to "src/test/resources/ext" (without trailing slash) references.add(Arguments.of(relativeExtLibsDir)); return references.stream(); @@ -592,7 +601,7 @@ public class WebAppContextTest WebAppContext context = new WebAppContext(); context.setContextPath("/"); - Path warPath = MavenTestingUtils.getTargetPath("test-classes/wars/dump.war"); + Path warPath = MavenPaths.findTestResourceFile("wars/dump.war"); context.setBaseResource(context.getResourceFactory().newResource(warPath)); context.setExtraClasspath(extraClassPathReference); @@ -609,7 +618,7 @@ public class WebAppContextTest WebAppClassLoader webAppClassLoader = (WebAppClassLoader)contextClassLoader; URL[] urls = webAppClassLoader.getURLs(); assertThat("URLs", urls.length, is(1)); - Path extLibs = MavenTestingUtils.getTargetPath("test-classes/ext"); + Path extLibs = MavenPaths.findTestResourceDir("ext"); extLibs = extLibs.toAbsolutePath(); assertThat("URL[0]", urls[0].toURI(), is(extLibs.toUri())); }