From 8fd2e588a7d2a62718bd77ac4d2f73ba169f1937 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Mon, 14 Dec 2020 10:19:31 +0100 Subject: [PATCH] Issue #5763 Fix TestJettyEmbedded test (#5764) * Issue #5763 Fix TestJettyEmbedded test Signed-off-by: Jan Bartel * Better test directory usage Signed-off-by: Joakim Erdfelt Co-authored-by: Joakim Erdfelt --- .../jetty/maven/plugin/TestJettyEmbedder.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestJettyEmbedder.java b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestJettyEmbedder.java index 4135be70801..35795db40ed 100644 --- a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestJettyEmbedder.java +++ b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/TestJettyEmbedder.java @@ -13,6 +13,7 @@ package org.eclipse.jetty.maven.plugin; +import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -21,23 +22,31 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.toolchain.test.jupiter.WorkDir; +import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension; +import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +@ExtendWith(WorkDirExtension.class) public class TestJettyEmbedder { + public WorkDir workDir; @Test public void testJettyEmbedderFromDefaults() throws Exception { + Path baseResource = workDir.getEmptyPathDir(); MavenWebAppContext webApp = new MavenWebAppContext(); + webApp.setBaseResource(new PathResource(baseResource)); MavenServerConnector connector = new MavenServerConnector(); connector.setPort(0); - + JettyEmbedder jetty = new JettyEmbedder(); jetty.setHttpConnector(connector); jetty.setExitVm(false); @@ -49,12 +58,12 @@ public class TestJettyEmbedder jetty.setLoginServices(null); jetty.setContextXml(MavenTestingUtils.getTestResourceFile("embedder-context.xml").getAbsolutePath()); jetty.setWebApp(webApp); - + try { jetty.start(); assertEquals("/embedder", webApp.getContextPath()); - assertTrue(webApp.isStarted()); + assertTrue(webApp.isAvailable()); assertNotNull(jetty.getServer()); assertTrue(jetty.getServer().isStarted()); assertNotNull(jetty.getServer().getConnectors()); @@ -65,12 +74,14 @@ public class TestJettyEmbedder jetty.stop(); } } - + @Test public void testJettyEmbedder() throws Exception { MavenWebAppContext webApp = new MavenWebAppContext(); + Path baseResource = workDir.getEmptyPathDir(); + webApp.setBaseResource(Resource.newResource(baseResource)); Server server = new Server(); Map jettyProperties = new HashMap<>(); jettyProperties.put("jetty.server.dumpAfterStart", "false"); @@ -78,10 +89,10 @@ public class TestJettyEmbedder ContextHandler otherHandler = new ContextHandler(); otherHandler.setContextPath("/other"); otherHandler.setBaseResource(Resource.newResource(MavenTestingUtils.getTestResourceDir("root"))); - + MavenServerConnector connector = new MavenServerConnector(); connector.setPort(0); - + JettyEmbedder jetty = new JettyEmbedder(); jetty.setHttpConnector(connector); jetty.setExitVm(false); @@ -98,7 +109,7 @@ public class TestJettyEmbedder { jetty.start(); assertEquals("/embedder", webApp.getContextPath()); - assertTrue(webApp.isStarted()); + assertTrue(webApp.isAvailable()); assertNotNull(jetty.getServer()); assertTrue(jetty.getServer().isStarted()); assertNotNull(jetty.getServer().getConnectors());