diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/AttributeNormalizerTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/AttributeNormalizerTest.java index 4b9bc92aa72..95afd3bfcd0 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/AttributeNormalizerTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/AttributeNormalizerTest.java @@ -25,18 +25,39 @@ import java.util.stream.Stream; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.resource.FileSystemPool; import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.resource.ResourceFactory; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.is; public class AttributeNormalizerTest { + private static ResourceFactory.Closeable RESOURCE_FACTORY; + + @BeforeEach + public void beforeEach() + { + assertThat(FileSystemPool.INSTANCE.mounts(), empty()); + RESOURCE_FACTORY = ResourceFactory.closeable(); + } + + @AfterEach + public void afterEach() + { + IO.close(RESOURCE_FACTORY); + assertThat(FileSystemPool.INSTANCE.mounts(), empty()); + } + public static Stream scenarios() throws IOException { final List data = new ArrayList<>(); @@ -324,7 +345,7 @@ public class AttributeNormalizerTest .forEach((entry) -> System.setProperty(entry.getKey(), entry.getValue())); // Setup normalizer - Resource webresource = Resource.newResource(war); + Resource webresource = RESOURCE_FACTORY.newResource(war); this.normalizer = new AttributeNormalizer(webresource); } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/PreconfigureStandardTestWar.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/PreconfigureStandardTestWar.java index 5875adc46ca..cef88bce6c3 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/PreconfigureStandardTestWar.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/PreconfigureStandardTestWar.java @@ -13,12 +13,13 @@ package org.eclipse.jetty.ee9.quickstart; -import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.toolchain.test.FS; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,23 +33,30 @@ public class PreconfigureStandardTestWar public static void main(String[] args) throws Exception { - String target = "target/test-standard-preconfigured"; - File file = new File(target); - if (file.exists()) - IO.delete(file); + Path workdir = MavenTestingUtils.getTargetTestingPath(PreconfigureStandardTestWar.class.getSimpleName()); + FS.ensureDirExists(workdir); - File realmPropertiesDest = new File("target/test-standard-realm.properties"); - if (realmPropertiesDest.exists()) - IO.delete(realmPropertiesDest); + Path target = workdir.resolve("test-standard-preconfigured"); + FS.ensureEmpty(target); - Resource realmPropertiesSrc = Resource.newResource("src/test/resources/realm.properties"); - realmPropertiesSrc.copyTo(realmPropertiesDest.toPath()); + Path realmPropertiesDest = target.resolve("test-standard-realm.properties"); + Files.deleteIfExists(realmPropertiesDest); + + Path realmPropertiesSrc = MavenTestingUtils.getTestResourcePathFile("realm.properties"); + Files.copy(realmPropertiesSrc, realmPropertiesDest); System.setProperty("jetty.home", "target"); - PreconfigureQuickStartWar.main("target/test-standard.war", target, "src/test/resources/test.xml"); + PreconfigureQuickStartWar.main( + MavenTestingUtils.getTargetFile("test-standard.war").toString(), + target.toString(), + MavenTestingUtils.getTestResourceFile("test-spec.xml").toString()); LOG.info("Preconfigured in {}ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - __start)); - // IO.copy(new FileInputStream("target/test-standard-preconfigured/WEB-INF/quickstart-web.xml"),System.out); + if (LOG.isDebugEnabled()) + { + Path quickStartXml = target.resolve("WEB-INF/quickstart-web.xml"); + System.out.println(Files.readString(quickStartXml)); + } } } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/QuickStartTest.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/QuickStartTest.java index d312f46d904..75d30165932 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/QuickStartTest.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/QuickStartTest.java @@ -28,8 +28,8 @@ import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.IO; -import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.resource.ResourceFactory; import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlParser.Node; import org.hamcrest.Matchers; @@ -45,10 +45,12 @@ public class QuickStartTest @Test public void testStandardTestWar() throws Exception { + WebAppContext webapp = new WebAppContext(); + //Generate the quickstart PreconfigureStandardTestWar.main(new String[]{}); - WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-standard-preconfigured/WEB-INF/quickstart-web.xml")); + WebDescriptor descriptor = new WebDescriptor(ResourceFactory.of(webapp).newResource("./target/test-standard-preconfigured/WEB-INF/quickstart-web.xml")); descriptor.parse(WebDescriptor.getParser(!QuickStartGeneratorConfiguration.LOG.isDebugEnabled())); Node node = descriptor.getRoot(); assertThat(node, Matchers.notNullValue()); @@ -59,11 +61,10 @@ public class QuickStartTest String war = "target/test-standard-preconfigured"; //optional jetty context xml file to configure the webapp - Resource contextXml = Resource.newResource("src/test/resources/test.xml"); + Resource contextXml = ResourceFactory.of(webapp).newResource("src/test/resources/test.xml"); Server server = new Server(0); - WebAppContext webapp = new WebAppContext(); webapp.addConfiguration(new QuickStartConfiguration(), new EnvConfiguration(), new PlusConfiguration(), @@ -95,13 +96,15 @@ public class QuickStartTest @Test public void testSpecWar() throws Exception { + WebAppContext webapp = new WebAppContext(); + //Generate the quickstart xml PreconfigureSpecWar.main(new String[]{}); Path webXmlPath = MavenTestingUtils.getTargetPath().resolve("test-spec-preconfigured/WEB-INF/quickstart-web.xml"); assertTrue(Files.exists(webXmlPath), "Path should exist:" + webXmlPath); - WebDescriptor descriptor = new WebDescriptor(Resource.newResource(webXmlPath)); + WebDescriptor descriptor = new WebDescriptor(ResourceFactory.of(webapp).newResource(webXmlPath)); descriptor.parse(WebDescriptor.getParser(!QuickStartGeneratorConfiguration.LOG.isDebugEnabled())); Node node = descriptor.getRoot(); assertThat(node, Matchers.notNullValue()); @@ -112,11 +115,10 @@ public class QuickStartTest String war = "target/test-spec-preconfigured"; //optional jetty context xml file to configure the webapp - Resource contextXml = Resource.newResource("src/test/resources/test-spec.xml"); + Resource contextXml = ResourceFactory.of(webapp).newResource("src/test/resources/test-spec.xml"); Server server = new Server(0); - WebAppContext webapp = new WebAppContext(); webapp.addConfiguration(new QuickStartConfiguration(), new EnvConfiguration(), new PlusConfiguration(), @@ -150,10 +152,12 @@ public class QuickStartTest @Test public void testJNDIWar() throws Exception { + WebAppContext webapp = new WebAppContext(); + //Generate the quickstart PreconfigureJNDIWar.main(new String[]{}); - WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-jndi-preconfigured/WEB-INF/quickstart-web.xml")); + WebDescriptor descriptor = new WebDescriptor(ResourceFactory.of(webapp).newResource("./target/test-jndi-preconfigured/WEB-INF/quickstart-web.xml")); descriptor.parse(WebDescriptor.getParser(!QuickStartGeneratorConfiguration.LOG.isDebugEnabled())); Node node = descriptor.getRoot(); assertThat(node, Matchers.notNullValue()); @@ -164,11 +168,10 @@ public class QuickStartTest String war = "target/test-jndi-preconfigured"; //optional jetty context xml file to configure the webapp - Resource contextXml = Resource.newResource("src/test/resources/test-jndi.xml"); + Resource contextXml = ResourceFactory.of(webapp).newResource("src/test/resources/test-jndi.xml"); Server server = new Server(0); - WebAppContext webapp = new WebAppContext(); webapp.addConfiguration(new QuickStartConfiguration(), new EnvConfiguration(), new PlusConfiguration(), diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/Quickstart.java b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/Quickstart.java index feda478af59..f85cbff3b97 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/Quickstart.java +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-quickstart/src/test/java/org/eclipse/jetty/ee9/quickstart/Quickstart.java @@ -19,6 +19,7 @@ import org.eclipse.jetty.ee9.plus.webapp.PlusConfiguration; import org.eclipse.jetty.ee9.webapp.WebAppContext; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.util.resource.ResourceFactory; import org.eclipse.jetty.xml.XmlConfiguration; public class Quickstart @@ -33,13 +34,13 @@ public class Quickstart String war = args[0]; //optional jetty context xml file to configure the webapp + WebAppContext webapp = new WebAppContext(); Resource contextXml = null; if (args.length > 1) - contextXml = Resource.newResource(args[1]); + contextXml = ResourceFactory.of(webapp).newResource(args[1]); Server server = new Server(8080); - WebAppContext webapp = new WebAppContext(); webapp.addConfiguration(new QuickStartConfiguration(), new EnvConfiguration(), new PlusConfiguration(),