Jetty-12.0.x tests in parallel (down build time on CI from 1h25 to 55min) some modules are still not parallel due to some static usage (#9635)

* parallel tests runs

---------

Signed-off-by: Olivier Lamy <olamy@apache.org>
This commit is contained in:
Olivier Lamy 2023-04-21 10:42:12 +10:00 committed by GitHub
parent 43e8c83e24
commit 46018e6057
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
232 changed files with 1569 additions and 1754 deletions

View File

@ -96,6 +96,20 @@ all | `jetty-home/target/jetty-home-<ver>.tar.gz`
Note: The build tests do a lot of stress testing, and on some machines it is necessary to set the
file descriptor limit to greater than 2048 for the tests to all pass successfully (check your `ulimit -n` value).
Note: The tests are running in parallel using [Junit5 parallel execution](https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution).
This is configurable using the following properties:
```
# to enable/disable the parallel execution
-Djunit.jupiter.execution.parallel.enabled=true/false
# number of tests executed in parallel
-Djunit.jupiter.execution.parallel.config.fixed.parallelism=2
```
If a test cannot be runned in parallel because accessing/modifying some static fields or for any other reasons, the test should be marked with the annotation
```java
@Isolated("Access static field of Configurations")
```
Professional Services
---------------------

View File

@ -609,7 +609,7 @@ public class HttpClientTLSTest
latch.countDown();
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
@Test

View File

@ -95,7 +95,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class HttpClientTest extends AbstractHttpClientServerTest
{
public WorkDir testdir;
@ParameterizedTest
@ArgumentsSource(ScenarioProvider.class)
@ -546,8 +545,9 @@ public class HttpClientTest extends AbstractHttpClientServerTest
@ParameterizedTest
@ArgumentsSource(ScenarioProvider.class)
public void testExchangeIsCompleteOnlyWhenBothRequestAndResponseAreComplete(Scenario scenario) throws Exception
public void testExchangeIsCompleteOnlyWhenBothRequestAndResponseAreComplete(Scenario scenario, WorkDir workDir) throws Exception
{
Path targetTestsDir = workDir.getEmptyPathDir();
start(scenario, new EmptyServerHandler()
{
@Override
@ -561,7 +561,6 @@ public class HttpClientTest extends AbstractHttpClientServerTest
});
// Prepare a big file to upload
Path targetTestsDir = testdir.getEmptyPathDir();
Files.createDirectories(targetTestsDir);
Path file = Paths.get(targetTestsDir.toString(), "http_client_conversation.big");
try (OutputStream output = Files.newOutputStream(file, StandardOpenOption.CREATE))

View File

@ -15,6 +15,7 @@ package org.eclipse.jetty.deploy;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@ -35,11 +36,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@ExtendWith(WorkDirExtension.class)
public class AppLifeCycleTest
{
public WorkDir testdir;
private void assertNoPath(String from, String to)
{
assertPath(from, to, new ArrayList<String>());
assertPath(from, to, new ArrayList<>());
}
private void assertPath(AppLifeCycle lifecycle, String from, String to, List<String> expected)
@ -89,30 +88,21 @@ public class AppLifeCycleTest
@Test
public void testFindPathDeployedStarted()
{
List<String> expected = new ArrayList<String>();
expected.add("deployed");
expected.add("starting");
expected.add("started");
List<String> expected = List.of("deployed", "starting", "started");
assertPath("deployed", "started", expected);
}
@Test
public void testFindPathDeployedUndeployed()
{
List<String> expected = new ArrayList<String>();
expected.add("deployed");
expected.add("undeploying");
expected.add("undeployed");
List<String> expected = List.of("deployed", "undeploying", "undeployed");
assertPath("deployed", "undeployed", expected);
}
@Test
public void testFindPathStartedDeployed()
{
List<String> expected = new ArrayList<String>();
expected.add("started");
expected.add("stopping");
expected.add("deployed");
List<String> expected = List.of("started", "stopping", "deployed");
assertPath("started", "deployed", expected);
}
@ -125,34 +115,21 @@ public class AppLifeCycleTest
@Test
public void testFindPathStartedUndeployed()
{
List<String> expected = new ArrayList<String>();
expected.add("started");
expected.add("stopping");
expected.add("deployed");
expected.add("undeploying");
expected.add("undeployed");
List<String> expected = List.of("started", "stopping", "deployed", "undeploying", "undeployed");
assertPath("started", "undeployed", expected);
}
@Test
public void testFindPathUndeployedDeployed()
{
List<String> expected = new ArrayList<String>();
expected.add("undeployed");
expected.add("deploying");
expected.add("deployed");
List<String> expected = List.of("undeployed", "deploying", "deployed");
assertPath("undeployed", "deployed", expected);
}
@Test
public void testFindPathUndeployedStarted()
{
List<String> expected = new ArrayList<String>();
expected.add("undeployed");
expected.add("deploying");
expected.add("deployed");
expected.add("starting");
expected.add("started");
List<String> expected = List.of("undeployed", "deploying", "deployed", "starting", "started");
assertPath("undeployed", "started", expected);
}
@ -169,12 +146,13 @@ public class AppLifeCycleTest
* @throws IOException on test failure
*/
@Test
public void testFindPathMultiple() throws IOException
public void testFindPathMultiple(WorkDir workDir) throws IOException
{
Path tmpPath = workDir.getEmptyPathDir();
AppLifeCycle lifecycle = new AppLifeCycle();
List<String> expected = new ArrayList<String>();
List<String> expected = new ArrayList<>();
File outputDir = testdir.getEmptyPathDir().toFile();
File outputDir = tmpPath.toFile();
// Modify graph to add new 'staging' -> 'staged' between 'deployed' and 'started'
GraphOutputDot.write(lifecycle, new File(outputDir, "multiple-1.dot")); // before change

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.deploy;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Set;
@ -34,7 +35,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@ExtendWith(WorkDirExtension.class)
public class DeploymentManagerTest
{
public WorkDir testdir;
@Test
public void testReceiveApp() throws Exception
@ -135,12 +135,13 @@ public class DeploymentManagerTest
}
@Test
public void testXmlConfigured() throws Exception
public void testXmlConfigured(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
XmlConfiguredJetty jetty = null;
try
{
jetty = new XmlConfiguredJetty(testdir.getEmptyPathDir());
jetty = new XmlConfiguredJetty(testdir);
jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-http.xml");
jetty.addConfiguration("jetty-deploymgr-contexts.xml");

View File

@ -44,15 +44,13 @@ public class ContextProviderRuntimeUpdatesTest
{
private static final Logger LOG = LoggerFactory.getLogger(ContextProviderRuntimeUpdatesTest.class);
public WorkDir testdir;
private static XmlConfiguredJetty jetty;
private final AtomicInteger _scans = new AtomicInteger();
private int _providerCount;
public void createJettyBase() throws Exception
public void createJettyBase(Path testdir) throws Exception
{
testdir.ensureEmpty();
jetty = new XmlConfiguredJetty(testdir.getEmptyPathDir());
jetty = new XmlConfiguredJetty(testdir);
Path resourceBase = jetty.getJettyBasePath().resolve("resourceBase");
FS.ensureDirExists(resourceBase);
@ -118,9 +116,10 @@ public class ContextProviderRuntimeUpdatesTest
* @throws IOException on test failure
*/
@Test
public void testAfterStartupContext() throws Exception
public void testAfterStartupContext(WorkDir workDir) throws Exception
{
createJettyBase();
Path testdir = workDir.getEmptyPathDir();
createJettyBase(testdir);
startJetty();
jetty.copyWebapp("bar-core-context.xml", "bar.xml");
@ -134,9 +133,10 @@ public class ContextProviderRuntimeUpdatesTest
* @throws IOException on test failure
*/
@Test
public void testAfterStartupThenRemoveContext() throws Exception
public void testAfterStartupThenRemoveContext(WorkDir workDir) throws Exception
{
createJettyBase();
Path testdir = workDir.getEmptyPathDir();
createJettyBase(testdir);
startJetty();
jetty.copyWebapp("bar-core-context.xml", "bar.xml");
@ -154,9 +154,10 @@ public class ContextProviderRuntimeUpdatesTest
* @throws Exception on test failure
*/
@Test
public void testAfterStartupThenUpdateContext() throws Exception
public void testAfterStartupThenUpdateContext(WorkDir workDir) throws Exception
{
createJettyBase();
Path testdir = workDir.getEmptyPathDir();
createJettyBase(testdir);
startJetty();

View File

@ -32,13 +32,15 @@ import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith(WorkDirExtension.class)
public class ContextProviderStartupTest
{
public WorkDir testdir;
public WorkDir workDir;
public Path testdir;
private static XmlConfiguredJetty jetty;
@BeforeEach
public void setupEnvironment() throws Exception
{
jetty = new XmlConfiguredJetty(testdir.getEmptyPathDir());
testdir = workDir.getEmptyPathDir();
jetty = new XmlConfiguredJetty(testdir);
Path resourceBase = jetty.getJettyBasePath().resolve("resourceBase");
FS.ensureDirExists(resourceBase);

View File

@ -74,7 +74,6 @@ public class XmlConfiguredJetty
public XmlConfiguredJetty(Path testDir) throws IOException
{
FS.ensureEmpty(testDir);
_jettyBase = testDir.resolve("base");
FS.ensureDirExists(_jettyBase);
@ -261,7 +260,7 @@ public class XmlConfiguredJetty
}
this._server = server;
this._server.setStopTimeout(10);
this._server.setStopTimeout(10000);
this._contexts = (ContextHandlerCollection)ids.get("Contexts");
}

View File

@ -38,13 +38,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class EtagUtilsTest
{
public WorkDir workDir;
@Test
public void testCalcWeakETag() throws IOException
public void testCalcWeakETag(WorkDir workDir) throws IOException
{
Path root = workDir.getEmptyPathDir();
Path testFile = root.resolve("test.dat");
Path tmpPath = workDir.getEmptyPathDir();
Path testFile = tmpPath.resolve("test.dat");
System.out.println("testFile" + testFile.toString());
Files.writeString(testFile, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
String weakEtag = EtagUtils.computeWeakEtag(testFile);
@ -53,13 +53,13 @@ public class EtagUtilsTest
}
@Test
public void testCalcWeakETagSameFileDifferentLocations() throws IOException
public void testCalcWeakETagSameFileDifferentLocations(WorkDir workDir) throws IOException
{
Path root = workDir.getEmptyPathDir();
Path testFile = root.resolve("test.dat");
Path tmpPath = workDir.getEmptyPathDir();
Path testFile = tmpPath.resolve("test.dat");
Files.writeString(testFile, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Path altDir = root.resolve("alt");
Path altDir = tmpPath.resolve("alt");
FS.ensureDirExists(altDir);
Path altFile = altDir.resolve("test.dat");
Files.copy(testFile, altFile);

View File

@ -27,6 +27,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.awaitility.Awaitility;
import org.eclipse.jetty.http.HostPortHttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpScheme;
@ -500,7 +501,7 @@ public class HTTP2Test extends AbstractTest
}
});
assertTrue(exchangeLatch2.await(5, TimeUnit.SECONDS));
assertEquals(1, session.getStreams().size());
await().atMost(Duration.ofSeconds(5)).until(() -> session.getStreams().size(), is(1));
// Create a fourth stream.
MetaData.Request request4 = newRequest("GET", HttpFields.EMPTY);

View File

@ -50,6 +50,7 @@ import org.junit.jupiter.api.Test;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.jupiter.api.Assertions.assertTrue;
// Sibling of ConnectionPoolTest, but using H2 to multiplex connections.
@ -337,7 +338,7 @@ public class MultiplexedConnectionPoolTest
assertThat(response.getStatus(), Matchers.is(200));
// Check that the pool never grows above 1.
assertThat(poolRef.get().size(), is(1));
assertThat(poolRef.get().size(), lessThan(2));
Thread.sleep(maxDuration * 2);
}

View File

@ -454,7 +454,7 @@ public class StreamResetTest extends AbstractTest
// Wait for the server to receive the reset and process
// it, and for the client to process the window updates.
await().atMost(5, TimeUnit.SECONDS)
await().atMost(10, TimeUnit.SECONDS)
.until(() -> ((HTTP2Session)client).updateSendWindow(0), Matchers.greaterThan(0));
}

View File

@ -11,6 +11,9 @@
<name>Core :: HTTP3 :: Tests</name>
<properties>
<!-- too flaky to support parallel tests in CI -->
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
<junit.jupiter.execution.parallel.config.fixed.parallelism>2</junit.jupiter.execution.parallel.config.fixed.parallelism>
<maven.deploy.skip>true</maven.deploy.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties>

View File

@ -103,7 +103,7 @@ public class AbstractClientServerTest
protected Session.Client newSession(Session.Client.Listener listener) throws Exception
{
InetSocketAddress address = new InetSocketAddress("localhost", connector.getLocalPort());
return http3Client.connect(address, listener).get(5, TimeUnit.SECONDS);
return http3Client.connect(address, listener).get(30, TimeUnit.SECONDS);
}
protected MetaData.Request newRequest(String path)

View File

@ -1232,13 +1232,13 @@ public class GoAwayTest extends AbstractClientServerTest
}
});
assertTrue(settingsLatch.await(5, TimeUnit.SECONDS));
assertTrue(settingsLatch.await(10, TimeUnit.SECONDS));
server.stop();
assertTrue(clientGoAwayLatch.await(5, TimeUnit.SECONDS));
assertTrue(clientDisconnectLatch.await(5, TimeUnit.SECONDS));
assertTrue(serverDisconnectLatch.await(5, TimeUnit.SECONDS));
assertTrue(clientGoAwayLatch.await(10, TimeUnit.SECONDS));
assertTrue(clientDisconnectLatch.await(10, TimeUnit.SECONDS));
assertTrue(serverDisconnectLatch.await(10, TimeUnit.SECONDS));
await().atMost(1, TimeUnit.SECONDS).until(() -> serverSessionRef.get().getProtocolSession().getQuicSession().getQuicConnection().getEndPoint().isOpen(), is(false));
await().atMost(1, TimeUnit.SECONDS).until(() -> clientSession.getProtocolSession().getQuicSession().getQuicConnection().getEndPoint().isOpen(), is(false));

View File

@ -77,7 +77,7 @@ public class HttpClientTransportOverHTTP3Test extends AbstractClientServerTest
});
ContentResponse response = httpClient.newRequest("https://localhost:" + connector.getLocalPort())
.timeout(5, TimeUnit.SECONDS)
.timeout(10, TimeUnit.SECONDS)
.send();
assertEquals(content, response.getContentAsString());
}
@ -179,7 +179,7 @@ public class HttpClientTransportOverHTTP3Test extends AbstractClientServerTest
latch.countDown();
});
assertTrue(beforeContentLatch.await(5, TimeUnit.SECONDS));
assertTrue(beforeContentLatch.await(10, TimeUnit.SECONDS));
// Verify that the response is not completed yet.
assertFalse(latch.await(1, TimeUnit.SECONDS));

View File

@ -57,10 +57,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
@ExtendWith(WorkDirExtension.class)
public class IOTest
{
public WorkDir workDir;
@Test
public void testIO() throws Exception
@ -428,10 +427,10 @@ public class IOTest
}
@Test
public void testGatherWrite() throws Exception
public void testGatherWrite(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Path file = Files.createTempFile(dir, "test", ".txt");
Path tmpPath = workDir.getEmptyPathDir();
Path file = Files.createTempFile(tmpPath, "test", ".txt");
FileChannel out = FileChannel.open(file,
StandardOpenOption.CREATE,
StandardOpenOption.READ,
@ -604,4 +603,5 @@ public class IOTest
assertFalse(Files.isSymbolicLink(realPath));
assertFalse(Files.isSymbolicLink(linkPath));
}
}

View File

@ -33,17 +33,20 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class KeystoreGeneratorTest
{
private Server _server;
@ -57,9 +60,10 @@ public class KeystoreGeneratorTest
@BeforeEach
public void before(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
// Generate a test keystore.
String password = "myKeystorePassword";
Path outputFile = workDir.getEmptyPathDir().resolve("keystore-test.p12");
Path outputFile = tmpPath.resolve("keystore-test.p12");
File myPassword = KeystoreGenerator.generateTestKeystore(outputFile.toString(), password);
assertTrue(myPassword.exists());

View File

@ -233,6 +233,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
* Feed a full header method
*/
@Test
@Tag("flaky")
public void testFullMethod() throws Exception
{
// TODO this test is flakey

View File

@ -33,10 +33,12 @@ import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.toolchain.xhtml.CatalogXHTML;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.w3c.dom.Document;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
@ -50,13 +52,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@ExtendWith(WorkDirExtension.class)
public class ResourceListingTest
{
@Test
public void testBasicResourceXHtmlListingRoot(WorkDir workDir) throws IOException
{
Path root = workDir.getEmptyPathDir();
FS.touch(root.resolve("entry1.txt"));
FS.touch(root.resolve("entry2.dat"));
Files.createDirectory(root.resolve("dirFoo"));
@ -86,7 +88,6 @@ public class ResourceListingTest
public void testBasicResourceXHtmlListingDeep(WorkDir workDir) throws IOException
{
Path root = workDir.getEmptyPathDir();
FS.touch(root.resolve("entry1.txt"));
FS.touch(root.resolve("entry2.dat"));
Files.createDirectory(root.resolve("dirFoo"));
@ -116,7 +117,6 @@ public class ResourceListingTest
public void testResourceCollectionXHtmlListingContext(WorkDir workDir) throws IOException
{
Path root = workDir.getEmptyPathDir();
Path docrootA = root.resolve("docrootA");
Files.createDirectory(docrootA);
FS.touch(docrootA.resolve("entry1.txt"));
@ -180,7 +180,6 @@ public class ResourceListingTest
public void testListingFilenamesOnly(WorkDir workDir) throws Exception
{
Path docRoot = workDir.getEmptyPathDir();
/* create some content in the docroot */
FS.ensureDirExists(docRoot);
Path one = docRoot.resolve("one");
@ -209,9 +208,8 @@ public class ResourceListingTest
@Test
public void testListingProperUrlEncoding(WorkDir workDir) throws Exception
{
Path docRoot = workDir.getEmptyPathDir();
/* create some content in the docroot */
Path docRoot = workDir.getEmptyPathDir();
Path wackyDir = docRoot.resolve("dir;"); // this should not be double-encoded.
FS.ensureDirExists(wackyDir);
@ -255,7 +253,6 @@ public class ResourceListingTest
public void testListingWithQuestionMarks(WorkDir workDir) throws Exception
{
Path docRoot = workDir.getEmptyPathDir();
/* create some content in the docroot */
FS.ensureDirExists(docRoot.resolve("one"));
FS.ensureDirExists(docRoot.resolve("two"));
@ -279,7 +276,6 @@ public class ResourceListingTest
public void testListingEncoding(WorkDir workDir) throws Exception
{
Path docRoot = workDir.getEmptyPathDir();
/* create some content in the docroot */
Path one = docRoot.resolve("one");
FS.ensureDirExists(one);

View File

@ -32,8 +32,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ExtendWith(WorkDirExtension.class)
@Disabled // TODO
@ExtendWith(WorkDirExtension.class)
public class FileBufferedResponseHandlerTest
{
private static final Logger LOG = LoggerFactory.getLogger(FileBufferedResponseHandlerTest.class);

View File

@ -34,11 +34,13 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.extension.ExtendWith;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -46,6 +48,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class MultiPartFormDataHandlerTest
{
private Server server;
@ -246,8 +249,9 @@ public class MultiPartFormDataHandlerTest
}
@Test
public void testAsyncMultiPartResponse(@TempDir Path tempDir) throws Exception
public void testAsyncMultiPartResponse(WorkDir workDir) throws Exception
{
Path tempDir = workDir.getEmptyPathDir();
start(new Handler.Abstract.NonBlocking()
{
@Override

View File

@ -36,6 +36,7 @@ import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.component.LifeCycle;
@ -43,6 +44,7 @@ import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@ -51,17 +53,16 @@ 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 TryPathsHandlerTest
{
public WorkDir workDir;
private static final String CONTEXT_PATH = "/ctx";
private Server server;
private SslContextFactory.Server sslContextFactory;
private ServerConnector connector;
private ServerConnector sslConnector;
private Path rootPath;
private void start(List<String> paths, Handler handler) throws Exception
private void start(List<String> paths, Handler handler, Path tmpPath) throws Exception
{
server = new Server();
connector = new ServerConnector(server, 1, 1);
@ -74,8 +75,7 @@ public class TryPathsHandlerTest
server.addConnector(sslConnector);
ContextHandler context = new ContextHandler(CONTEXT_PATH);
rootPath = workDir.getEmptyPathDir();
context.setBaseResourceAsPath(rootPath);
context.setBaseResourceAsPath(tmpPath);
server.setHandler(context);
TryPathsHandler tryPaths = new TryPathsHandler();
@ -94,8 +94,9 @@ public class TryPathsHandlerTest
}
@Test
public void testTryPaths() throws Exception
public void testTryPaths(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
ResourceHandler resourceHandler = new ResourceHandler()
{
@Override
@ -123,7 +124,7 @@ public class TryPathsHandlerTest
}
});
start(List.of("/maintenance.txt", "$path", "/forward?p=$path"), resourceHandler);
start(List.of("/maintenance.txt", "$path", "/forward?p=$path"), resourceHandler, tmpPath);
try (SocketChannel channel = SocketChannel.open())
{
@ -139,7 +140,7 @@ public class TryPathsHandlerTest
// Create the specific static file that is requested.
String path = "idx.txt";
Files.writeString(rootPath.resolve(path), "hello", StandardOpenOption.CREATE);
Files.writeString(tmpPath.resolve(path), "hello", StandardOpenOption.CREATE);
// Make a second request with the specific file.
request = HttpTester.newRequest();
request.setURI(CONTEXT_PATH + "/" + path);
@ -151,7 +152,7 @@ public class TryPathsHandlerTest
// Create the "maintenance" file, it should be served first.
path = "maintenance.txt";
Files.writeString(rootPath.resolve(path), "maintenance", StandardOpenOption.CREATE);
Files.writeString(tmpPath.resolve(path), "maintenance", StandardOpenOption.CREATE);
// Make a third request with any path, we should get the maintenance file.
request = HttpTester.newRequest();
request.setURI(CONTEXT_PATH + "/whatever");
@ -164,8 +165,9 @@ public class TryPathsHandlerTest
}
@Test
public void testTryPathsWithPathMappings() throws Exception
public void testTryPathsWithPathMappings(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
ResourceHandler resourceHandler = new ResourceHandler()
{
@Override
@ -204,7 +206,7 @@ public class TryPathsHandlerTest
}
});
start(List.of("/maintenance.txt", "$path", "/forward?p=$path"), pathMappingsHandler);
start(List.of("/maintenance.txt", "$path", "/forward?p=$path"), pathMappingsHandler, tmpPath);
try (SocketChannel channel = SocketChannel.open())
{
@ -220,7 +222,7 @@ public class TryPathsHandlerTest
// Create the specific static file that is requested.
String path = "idx.txt";
Files.writeString(rootPath.resolve(path), "hello", StandardOpenOption.CREATE);
Files.writeString(tmpPath.resolve(path), "hello", StandardOpenOption.CREATE);
// Make a second request with the specific file.
request = HttpTester.newRequest();
request.setURI(CONTEXT_PATH + "/" + path);
@ -231,7 +233,7 @@ public class TryPathsHandlerTest
assertEquals("hello", response.getContent());
// Request an existing PHP file.
Files.writeString(rootPath.resolve("index.php"), "raw-php-contents", StandardOpenOption.CREATE);
Files.writeString(tmpPath.resolve("index.php"), "raw-php-contents", StandardOpenOption.CREATE);
request = HttpTester.newRequest();
request.setURI(CONTEXT_PATH + "/index.php");
channel.write(request.generate());
@ -242,7 +244,7 @@ public class TryPathsHandlerTest
// Create the "maintenance" file, it should be served first.
path = "maintenance.txt";
Files.writeString(rootPath.resolve(path), "maintenance", StandardOpenOption.CREATE);
Files.writeString(tmpPath.resolve(path), "maintenance", StandardOpenOption.CREATE);
// Make a second request with any path, we should get the maintenance file.
request = HttpTester.newRequest();
request.setURI(CONTEXT_PATH + "/whatever");
@ -255,8 +257,9 @@ public class TryPathsHandlerTest
}
@Test
public void testTryPathsAsync404() throws Exception
public void testTryPathsAsync404(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
ResourceHandler resourceHandler = new ResourceHandler()
{
@Override
@ -301,7 +304,7 @@ public class TryPathsHandlerTest
}
});
start(List.of("/notFound", "/maintenance.txt", "$path", "/forward?p=$path"), resourceHandler);
start(List.of("/notFound", "/maintenance.txt", "$path", "/forward?p=$path"), resourceHandler, tmpPath);
try (SocketChannel channel = SocketChannel.open())
{
@ -317,7 +320,7 @@ public class TryPathsHandlerTest
// Create the specific static file that is requested.
String path = "idx.txt";
Files.writeString(rootPath.resolve(path), "hello", StandardOpenOption.CREATE);
Files.writeString(tmpPath.resolve(path), "hello", StandardOpenOption.CREATE);
// Make a second request with the specific file.
request = HttpTester.newRequest();
request.setURI(CONTEXT_PATH + "/" + path);
@ -329,7 +332,7 @@ public class TryPathsHandlerTest
// Create the "maintenance" file, it should be served first.
path = "maintenance.txt";
Files.writeString(rootPath.resolve(path), "maintenance", StandardOpenOption.CREATE);
Files.writeString(tmpPath.resolve(path), "maintenance", StandardOpenOption.CREATE);
// Make a third request with any path, we should get the maintenance file.
request = HttpTester.newRequest();
request.setURI(CONTEXT_PATH + "/whatever");
@ -342,8 +345,9 @@ public class TryPathsHandlerTest
}
@Test
public void testSecureRequestIsForwarded() throws Exception
public void testSecureRequestIsForwarded(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
String path = "/secure";
start(List.of("$path"), new Handler.Abstract.NonBlocking()
{
@ -357,7 +361,7 @@ public class TryPathsHandlerTest
callback.succeeded();
return true;
}
});
}, tmpPath);
try (SSLSocket sslSocket = sslContextFactory.newSslSocket())
{

View File

@ -64,6 +64,7 @@ import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.Sha1Sum;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
@ -75,6 +76,7 @@ import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ -97,6 +99,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@ExtendWith(WorkDirExtension.class)
public class GzipHandlerTest
{
protected static final int DEFAULT_OUTPUT_BUFFER_SIZE = new HttpConfiguration().getOutputBufferSize();
@ -124,7 +127,6 @@ public class GzipHandlerTest
private static final String CONTENT_ETAG = String.format("W/\"%x\"", CONTENT.hashCode());
private static final String CONTENT_ETAG_GZIP = String.format("W/\"%x" + CompressedContentFormat.GZIP.getEtagSuffix() + "\"", CONTENT.hashCode());
public WorkDir _workDir;
private Server _server;
private ServerConnector _httpConnector;
private LocalConnector _connector;
@ -599,12 +601,13 @@ public class GzipHandlerTest
}
@Test
public void testExcludePaths() throws Exception
public void testExcludePaths(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
_gzipHandler.addIncludedMimeTypes("text/plain");
_gzipHandler.setExcludedPaths("*.txt");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -691,11 +694,11 @@ public class GzipHandlerTest
}
@Test
public void testExcludedMimeTypesUpperCase() throws Exception
public void testExcludedMimeTypesUpperCase(WorkDir workDir) throws Exception
{
_gzipHandler.addExcludedMimeTypes("text/PLAIN");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -991,12 +994,12 @@ public class GzipHandlerTest
}
@Test
public void testIncludedExcludePaths() throws Exception
public void testIncludedExcludePaths(WorkDir workDir) throws Exception
{
_gzipHandler.setExcludedPaths("/ctx/bad.txt");
_gzipHandler.setIncludedPaths("*.txt");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -1064,11 +1067,11 @@ public class GzipHandlerTest
}
@Test
public void testIncludedMimeTypes() throws Exception
public void testIncludedMimeTypes(WorkDir workDir) throws Exception
{
_gzipHandler.addIncludedMimeTypes("text/plain");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -1121,11 +1124,11 @@ public class GzipHandlerTest
* </p>
*/
@Test
public void testIncludedMimeTypesPrecompressedByWrappedHandler() throws Exception
public void testIncludedMimeTypesPrecompressedByWrappedHandler(WorkDir workDir) throws Exception
{
_gzipHandler.addIncludedMimeTypes("image/svg+xml");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -1281,11 +1284,11 @@ public class GzipHandlerTest
}
@Test
public void testRequestAcceptEncodingWithQuality() throws Exception
public void testRequestAcceptEncodingWithQuality(WorkDir workDir) throws Exception
{
_gzipHandler.addIncludedMimeTypes("text/plain");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -1337,11 +1340,11 @@ public class GzipHandlerTest
* See: <a href="http://bugs.eclipse.org/388072">Bugzilla #388072</a>
*/
@Test
public void testRequestAcceptEncodingWithZeroQuality() throws Exception
public void testRequestAcceptEncodingWithZeroQuality(WorkDir workDir) throws Exception
{
_gzipHandler.addIncludedMimeTypes("text/plain");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -1391,11 +1394,11 @@ public class GzipHandlerTest
*/
@ParameterizedTest
@MethodSource("compressibleSizesSource")
public void testRequestIfModifiedSinceInFutureGzipCompressedResponse(int fileSize) throws Exception
public void testRequestIfModifiedSinceInFutureGzipCompressedResponse(int fileSize, WorkDir workDir) throws Exception
{
_gzipHandler.addIncludedMimeTypes("text/plain");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -1441,11 +1444,11 @@ public class GzipHandlerTest
*/
@ParameterizedTest
@MethodSource("compressibleSizesSource")
public void testRequestIfModifiedSinceInPastGzipCompressedResponse(int fileSize) throws Exception
public void testRequestIfModifiedSinceInPastGzipCompressedResponse(int fileSize, WorkDir workDir) throws Exception
{
_gzipHandler.addIncludedMimeTypes("text/plain");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -1522,11 +1525,11 @@ public class GzipHandlerTest
}
@Test
public void testResponseCustomMimeTypeSVG() throws Exception
public void testResponseCustomMimeTypeSVG(WorkDir workDir) throws Exception
{
_gzipHandler.addIncludedMimeTypes("image/svg+xml");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);
@ -1601,11 +1604,11 @@ public class GzipHandlerTest
@ParameterizedTest
@MethodSource("compressibleSizesSource")
public void testSimpleCompressedResponse(int fileSize) throws Exception
public void testSimpleCompressedResponse(int fileSize, WorkDir workDir) throws Exception
{
_gzipHandler.addIncludedMimeTypes("text/plain");
Path contextDir = _workDir.getEmptyPathDir().resolve("context");
Path tmpPath = workDir.getEmptyPathDir();
Path contextDir = tmpPath.resolve("context");
FS.ensureDirExists(contextDir);
_contextHandler.setBaseResourceAsPath(contextDir);

View File

@ -28,6 +28,8 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- we need this as some tests assert Logging content which is done in a static way -->
<reuseForks>false</reuseForks>
<argLine>
@{argLine} ${jetty.surefire.argLine} --add-reads org.eclipse.jetty.logging=java.management
</argLine>

View File

@ -25,6 +25,7 @@ import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
import org.slf4j.LoggerFactory;
import static org.hamcrest.MatcherAssert.assertThat;
@ -32,6 +33,7 @@ import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Isolated("Because the test is making assertions on Logger which is static and may have data from other tests")
public class JMXTest
{
@Test

View File

@ -9,6 +9,7 @@
<name>Core :: Start</name>
<description>The start utility</description>
<properties>
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
<bundle-symbolic-name>${project.groupId}.start</bundle-symbolic-name>
<spotbugs.onlyAnalyze>org.eclipse.jetty.start.*</spotbugs.onlyAnalyze>
</properties>

View File

@ -22,12 +22,15 @@ import java.util.List;
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;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class FSTest
{
@Test
@ -54,8 +57,8 @@ public class FSTest
@Test
public void testExtractEscaperZip(WorkDir workDir) throws IOException
{
Path archive = MavenPaths.findTestResourceFile("bad-libs/escaper.zip");
Path dest = workDir.getEmptyPathDir();
Path archive = MavenPaths.findTestResourceFile("bad-libs/escaper.zip");
Path bad = Path.of("/tmp/evil.txt");
Files.deleteIfExists(bad);
assertThrows(IOException.class, () -> FS.extractZip(archive, dest));

View File

@ -22,7 +22,6 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
@ -133,7 +132,7 @@ public class MainTest
}
// Test a System Property that comes from JVM
List<String> warnings = output.stream().filter((line) -> line.startsWith("WARN")).collect(Collectors.toList());
List<String> warnings = output.stream().filter((line) -> line.startsWith("WARN")).toList();
// warnings.forEach(System.out::println);
Iterator<String> warningIter = warnings.iterator();

View File

@ -38,14 +38,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class ModuleGraphWriterTest
{
public WorkDir testdir;
@Test
public void testGenerateNothingEnabled() throws IOException
public void testGenerateNothingEnabled(WorkDir workDir) throws IOException
{
Path baseDir = workDir.getEmptyPathDir();
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("dist-home");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"jetty.version=TEST"};
// Configuration
@ -75,7 +74,7 @@ public class ModuleGraphWriterTest
{
if (execDotCmd("dot", "-V"))
{
Path outputPng = testdir.getPath().resolve("output.png");
Path outputPng = baseDir.resolve("output.png");
assertTrue(execDotCmd("dot", "-Tpng", "-o" + outputPng, dotFile.toString()));
assertThat("PNG File does not exist", FS.exists(outputPng));

View File

@ -35,14 +35,13 @@ import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class ModuleTest
{
public WorkDir testdir;
@Test
public void testLoadMain() throws IOException
public void testLoadMain(WorkDir workDir) throws IOException
{
Path baseDir = workDir.getEmptyPathDir();
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("dist-home");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"jetty.version=TEST"};
// Configuration

View File

@ -41,14 +41,12 @@ public class ModulesTest
{
private static final String TEST_SOURCE = "<test>";
public WorkDir testdir;
@Test
public void testLoadAllModules() throws IOException
public void testLoadAllModules(WorkDir workDir) throws IOException
{
Path baseDir = workDir.getEmptyPathDir();
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("dist-home");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"jetty.version=TEST"};
// Configuration
@ -140,11 +138,11 @@ public class ModulesTest
}
@Test
public void testResolveServerHttp() throws IOException
public void testResolveServerHttp(WorkDir workDir) throws IOException
{
Path baseDir = workDir.getEmptyPathDir();
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("dist-home");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"jetty.version=TEST"};
// Configuration
@ -203,11 +201,11 @@ public class ModulesTest
}
@Test
public void testResolveNotRequiredModuleNotFound() throws IOException
public void testResolveNotRequiredModuleNotFound(WorkDir workDir) throws IOException
{
Path baseDir = workDir.getEmptyPathDir();
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("non-required-deps");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"bar.type=cannot-find-me"};
// Configuration
@ -252,11 +250,11 @@ public class ModulesTest
}
@Test
public void testResolveNotRequiredModuleFound() throws IOException
public void testResolveNotRequiredModuleFound(WorkDir workDir) throws IOException
{
Path baseDir = workDir.getEmptyPathDir();
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("non-required-deps");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"bar.type=dive"};
// Configuration
@ -303,11 +301,11 @@ public class ModulesTest
}
@Test
public void testResolveNotRequiredModuleFoundDynamic() throws IOException
public void testResolveNotRequiredModuleFoundDynamic(WorkDir workDir) throws IOException
{
Path baseDir = workDir.getEmptyPathDir();
// Test Env
Path homeDir = MavenTestingUtils.getTestResourcePathDir("non-required-deps");
Path baseDir = testdir.getEmptyPathDir();
String[] cmdLine = new String[]{"bar.type=dynamic"};
// Configuration

View File

@ -31,14 +31,12 @@ import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith(WorkDirExtension.class)
public class PathFinderTest
{
public WorkDir testdir;
@Test
public void testFindInis() throws IOException
public void testFindInis(WorkDir workDir) throws IOException
{
Path basePath = workDir.getPath();
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
Path homePath = homeDir.toPath().toAbsolutePath();
Path basePath = testdir.getEmptyPathDir();
PathFinder finder = new PathFinder();
finder.setFileMatcher("glob:**/*.ini");
@ -60,11 +58,11 @@ public class PathFinderTest
}
@Test
public void testFindMods() throws IOException
public void testFindMods(WorkDir workDir) throws IOException
{
Path basePath = workDir.getEmptyPathDir();
File homeDir = MavenTestingUtils.getTestResourceDir("dist-home");
Path homePath = homeDir.toPath().toAbsolutePath();
Path basePath = testdir.getEmptyPathDir();
List<String> expected = new ArrayList<>();
File modulesDir = new File(homeDir, "modules");

View File

@ -27,16 +27,12 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.IO;
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.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class PropertyPassingTest
{
private static class ConsoleCapture implements Runnable
@ -90,8 +86,6 @@ public class PropertyPassingTest
}
}
public WorkDir testingdir;
@Test
public void testAsJvmArg() throws IOException, InterruptedException
{

View File

@ -24,7 +24,7 @@ public final class StartMatchers
{
public static Matcher<Path> pathExists()
{
return new BaseMatcher<Path>()
return new BaseMatcher<>()
{
@Override
public boolean matches(Object item)
@ -49,7 +49,7 @@ public final class StartMatchers
public static Matcher<Path> notPathExists()
{
return new BaseMatcher<Path>()
return new BaseMatcher<>()
{
@Override
public boolean matches(Object item)
@ -74,7 +74,7 @@ public final class StartMatchers
public static Matcher<Path> fileExists()
{
return new BaseMatcher<Path>()
return new BaseMatcher<>()
{
@Override
public boolean matches(Object item)

View File

@ -36,10 +36,9 @@ import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;
@ExtendWith(WorkDirExtension.class)
@ExtendWith(WorkDirExtension.class)
public class ConfigSourcesTest
{
public WorkDir testdir;
private void assertIdOrder(ConfigSources sources, String... expectedOrder)
{
@ -78,15 +77,16 @@ public class ConfigSourcesTest
}
@Test
public void testOrderBasicConfig() throws IOException
public void testOrderBasicConfig(WorkDir workDir) throws IOException
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1");
@ -102,20 +102,21 @@ public class ConfigSourcesTest
}
@Test
public void testOrderWith1ExtraConfig() throws IOException
public void testOrderWith1ExtraConfig(WorkDir workDir) throws IOException
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
common = common.toRealPath();
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1",
@ -132,20 +133,21 @@ public class ConfigSourcesTest
}
@Test
public void testCommandLine1ExtraFromSimpleProp() throws Exception
public void testCommandLine1ExtraFromSimpleProp(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common, "start.ini", "jetty.http.port=8080");
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1");
@ -174,15 +176,16 @@ public class ConfigSourcesTest
}
@Test
public void testCommandLine1ExtraFromPropPrefix() throws Exception
public void testCommandLine1ExtraFromPropPrefix(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create opt
Path opt = testdir.getPathFile("opt");
Path opt = testdir.resolve("opt");
FS.ensureEmpty(opt);
// Create common
@ -191,7 +194,7 @@ public class ConfigSourcesTest
TestEnv.makeFile(common, "start.ini", "jetty.http.port=8080");
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1");
@ -221,15 +224,16 @@ public class ConfigSourcesTest
}
@Test
public void testCommandLine1ExtraFromCompoundProp() throws Exception
public void testCommandLine1ExtraFromCompoundProp(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create opt
Path opt = testdir.getPathFile("opt");
Path opt = testdir.resolve("opt");
FS.ensureEmpty(opt);
// Create common
@ -238,7 +242,7 @@ public class ConfigSourcesTest
TestEnv.makeFile(common, "start.ini", "jetty.http.port=8080");
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1");
@ -271,20 +275,21 @@ public class ConfigSourcesTest
}
@Test
public void testRefCommon() throws Exception
public void testRefCommon(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common, "start.ini", "jetty.http.port=8080");
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1",
@ -306,24 +311,25 @@ public class ConfigSourcesTest
}
@Test
public void testRefCommonAndCorp() throws Exception
public void testRefCommonAndCorp(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common, "start.ini", "jetty.http.port=8080");
// Create corp
Path corp = testdir.getPathFile("corp");
Path corp = testdir.resolve("corp");
FS.ensureEmpty(corp);
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1",
@ -349,28 +355,29 @@ public class ConfigSourcesTest
}
@Test
public void testRefCommonRefCorp() throws Exception
public void testRefCommonRefCorp(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create corp
Path corp = testdir.getPathFile("corp");
Path corp = testdir.resolve("corp");
FS.ensureEmpty(corp);
TestEnv.makeFile(corp, "start.ini",
"jetty.http.port=9090");
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common, "start.ini",
"--include-jetty-dir=" + corp,
"jetty.http.port=8080");
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1",
@ -395,21 +402,22 @@ public class ConfigSourcesTest
}
@Test
public void testRefCommonRefCorpFromSimpleProps() throws Exception
public void testRefCommonRefCorpFromSimpleProps(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create corp
Path corp = testdir.getPathFile("corp");
Path corp = testdir.resolve("corp");
FS.ensureEmpty(corp);
TestEnv.makeFile(corp, "start.ini",
"jetty.http.port=9090");
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common, "start.ini",
"my.corp=" + corp,
@ -417,7 +425,7 @@ public class ConfigSourcesTest
"jetty.http.port=8080");
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1",
@ -444,35 +452,36 @@ public class ConfigSourcesTest
}
@Test
public void testRefCommonRefCorpCmdLineRef() throws Exception
public void testRefCommonRefCorpCmdLineRef(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create devops
Path devops = testdir.getPathFile("devops");
Path devops = testdir.resolve("devops");
FS.ensureEmpty(devops);
TestEnv.makeFile(devops, "start.ini",
"--modules=logging",
"jetty.http.port=2222");
// Create corp
Path corp = testdir.getPathFile("corp");
Path corp = testdir.resolve("corp");
FS.ensureEmpty(corp);
TestEnv.makeFile(corp, "start.ini",
"jetty.http.port=9090");
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common, "start.ini",
"--include-jetty-dir=" + corp,
"jetty.http.port=8080");
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1",
@ -502,28 +511,29 @@ public class ConfigSourcesTest
}
@Test
public void testRefCommonRefCorpCmdLineProp() throws Exception
public void testRefCommonRefCorpCmdLineProp(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create corp
Path corp = testdir.getPathFile("corp");
Path corp = testdir.resolve("corp");
FS.ensureEmpty(corp);
TestEnv.makeFile(corp, "start.ini",
"jetty.http.port=9090");
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
TestEnv.makeFile(common, "start.ini",
"--include-jetty-dir=" + corp,
"jetty.http.port=8080");
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1",
@ -551,19 +561,20 @@ public class ConfigSourcesTest
}
@Test
public void testBadDoubleRef() throws Exception
public void testBadDoubleRef(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Create home
Path home = testdir.getPathFile("home");
Path home = testdir.resolve("home");
FS.ensureEmpty(home);
TestEnv.copyTestDir("dist-home", home);
// Create common
Path common = testdir.getPathFile("common");
Path common = testdir.resolve("common");
FS.ensureEmpty(common);
// Create corp
Path corp = testdir.getPathFile("corp");
Path corp = testdir.resolve("corp");
FS.ensureEmpty(corp);
TestEnv.makeFile(corp, "start.ini",
// standard property
@ -579,7 +590,7 @@ public class ConfigSourcesTest
"--include-jetty-dir=" + corp);
// Create base
Path base = testdir.getPathFile("base");
Path base = testdir.resolve("base");
FS.ensureEmpty(base);
TestEnv.makeFile(base, "start.ini",
"jetty.http.host=127.0.0.1",

View File

@ -42,15 +42,17 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
@ExtendWith(WorkDirExtension.class)
public class MavenLocalRepoFileInitializerTest
{
public WorkDir testdir;
public WorkDir workDir;
public Path testdir;
private BaseHome baseHome;
@BeforeEach
public void setupBaseHome() throws IOException
{
Path homeDir = testdir.getEmptyPathDir().resolve("home");
Path baseDir = testdir.getEmptyPathDir().resolve("base");
testdir = workDir.getEmptyPathDir();
Path homeDir = testdir.resolve("home");
Path baseDir = testdir.resolve("base");
FS.ensureDirExists(homeDir);
FS.ensureDirExists(baseDir);
@ -192,7 +194,7 @@ public class MavenLocalRepoFileInitializerTest
assertThat("coords.toCentralURI", coords.toCentralURI().toASCIIString(),
is(repo.getRemoteUri() + "org/eclipse/jetty/jetty-http/9.4.31.v20200723/jetty-http-9.4.31.v20200723-tests.jar"));
Path destination = testdir.getEmptyPathDir().resolve("jetty-http-9.4.31.v20200723-tests.jar");
Path destination = testdir.resolve("jetty-http-9.4.31.v20200723-tests.jar");
Files.deleteIfExists(destination);
repo.download(coords.toCentralURI(), destination);
assertThat(Files.exists(destination), is(true));
@ -204,7 +206,7 @@ public class MavenLocalRepoFileInitializerTest
public void testDownloadSnapshotRepo()
throws Exception
{
Path snapshotLocalRepoDir = testdir.getPath().resolve("snapshot-repo");
Path snapshotLocalRepoDir = testdir.resolve("snapshot-repo");
FS.ensureEmpty(snapshotLocalRepoDir);
MavenLocalRepoFileInitializer repo =
@ -233,7 +235,7 @@ public class MavenLocalRepoFileInitializerTest
public void testDownloadSnapshotRepoWithExtractDeep()
throws Exception
{
Path snapshotLocalRepoDir = testdir.getPath().resolve("snapshot-repo");
Path snapshotLocalRepoDir = testdir.resolve("snapshot-repo");
FS.ensureEmpty(snapshotLocalRepoDir);
MavenLocalRepoFileInitializer repo =
@ -251,7 +253,7 @@ public class MavenLocalRepoFileInitializerTest
public void testDownloadSnapshotRepoWithExtractDefault()
throws Exception
{
Path snapshotLocalRepoDir = testdir.getPath().resolve("snapshot-repo");
Path snapshotLocalRepoDir = testdir.resolve("snapshot-repo");
FS.ensureEmpty(snapshotLocalRepoDir);
MavenLocalRepoFileInitializer repo =

View File

@ -40,14 +40,18 @@ import org.eclipse.jetty.start.StartEnvironment;
import org.eclipse.jetty.start.StartLog;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public abstract class AbstractUseCase
{
public WorkDir workDir;
public Path testdir;
protected Path homeDir;
protected Path baseDir;
@ -62,8 +66,7 @@ public abstract class AbstractUseCase
@BeforeEach
public void setupTest() throws IOException
{
Path testdir = workDir.getEmptyPathDir();
testdir = workDir.getEmptyPathDir();
// Create empty base directory for testcase to use
baseDir = testdir.resolve("test-base");
FS.ensureDirExists(baseDir);

View File

@ -184,9 +184,7 @@ public class BasicTest extends AbstractUseCase
ExecResults results = exec(runArgs, true);
// === Validate Resulting XMLs
List<String> expectedXmls = Arrays.asList(
"${jetty.home}/etc/logging-a.xml"
);
List<String> expectedXmls = List.of("${jetty.home}/etc/logging-a.xml");
List<String> actualXmls = results.getXmls();
assertThat("XML Resolution Order", actualXmls, contains(expectedXmls.toArray()));
@ -221,9 +219,7 @@ public class BasicTest extends AbstractUseCase
ExecResults results = exec(runArgs, true);
// === Validate Resulting XMLs
List<String> expectedXmls = Arrays.asList(
"${jetty.home}/etc/logging-b.xml"
);
List<String> expectedXmls = List.of("${jetty.home}/etc/logging-b.xml");
List<String> actualXmls = results.getXmls();
assertThat("XML Resolution Order", actualXmls, contains(expectedXmls.toArray()));
@ -374,7 +370,7 @@ public class BasicTest extends AbstractUseCase
@Test
public void testHomeWithSpaces() throws Exception
{
homeDir = workDir.getPath().resolve("jetty home with spaces");
homeDir = testdir.resolve("jetty home with spaces");
FS.ensureDirExists(homeDir);
setupDistHome();

View File

@ -60,6 +60,7 @@ import org.eclipse.jetty.util.NanoTime;
import org.eclipse.jetty.util.component.LifeCycle;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@ -488,6 +489,7 @@ public class HttpClientStreamTest extends AbstractTest
@ParameterizedTest
@MethodSource("transports")
@Tag("flaky")
public void testDownloadWithCloseBeforeContent(Transport transport) throws Exception
{
byte[] data = new byte[128 * 1024];
@ -533,6 +535,7 @@ public class HttpClientStreamTest extends AbstractTest
}
@ParameterizedTest
@Tag("flaky")
@MethodSource("transports")
public void testDownloadWithCloseMiddleOfContent(Transport transport) throws Exception
{

View File

@ -92,7 +92,7 @@ public class TrailersTest extends AbstractTest
requestTrailers.put(trailerName, trailerValue);
}
var response = listener.get(5, TimeUnit.SECONDS);
var response = listener.get(10, TimeUnit.SECONDS);
// Read slowly.
try (InputStream input = listener.getInputStream())

View File

@ -82,7 +82,7 @@ public class FileIDTest
@MethodSource("basenameCases")
public void testGetBasename(String input, String expected) throws IOException
{
Path outputJar = workDir.getEmptyPathDir().resolve("test.jar");
Path outputJar = workDir.getPath().resolve("test.jar");
Map<String, String> env = new HashMap<>();
env.put("create", "true");
@ -181,7 +181,7 @@ public class FileIDTest
@MethodSource("hasNamedPathSegmentCasesTrue")
public void testHasNamedPathSegmentsTrueZipFs(String input, String dirname) throws IOException
{
Path outputJar = workDir.getEmptyPathDir().resolve("test.jar");
Path outputJar = workDir.getPath().resolve("test.jar");
Map<String, String> env = new HashMap<>();
env.put("create", "true");
@ -211,7 +211,7 @@ public class FileIDTest
@MethodSource("hasNamedPathSegmentFalseZipFsCases")
public void testHasNamedPathSegmentFalseZipFs(String input, String dirname) throws IOException
{
Path outputJar = workDir.getEmptyPathDir().resolve("test.jar");
Path outputJar = workDir.getPath().resolve("test.jar");
Map<String, String> env = new HashMap<>();
env.put("create", "true");
@ -422,7 +422,7 @@ public class FileIDTest
})
public void testIsMetaInfVersions(String input) throws IOException
{
Path outputJar = workDir.getEmptyPathDir().resolve("test.jar");
Path outputJar = workDir.getPath().resolve("test.jar");
Map<String, String> env = new HashMap<>();
env.put("create", "true");
@ -514,7 +514,7 @@ public class FileIDTest
})
public void testNotMetaInfVersions(String input) throws IOException
{
Path outputJar = workDir.getEmptyPathDir().resolve("test.jar");
Path outputJar = workDir.getPath().resolve("test.jar");
Map<String, String> env = new HashMap<>();
env.put("create", "true");

View File

@ -44,8 +44,6 @@ import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class MultiReleaseJarFileTest
{
public WorkDir workDir;
private void createExampleJar(Path outputJar) throws IOException
{
Map<String, String> env = new HashMap<>();
@ -93,9 +91,9 @@ public class MultiReleaseJarFileTest
}
@Test
public void testStreamAllFiles() throws Exception
public void testStreamAllFiles(WorkDir workDir) throws Exception
{
Path exampleJar = workDir.getEmptyPathDir().resolve("multirelease.jar");
Path exampleJar = workDir.getPath().resolve("multirelease.jar");
createExampleJar(exampleJar);
try (MultiReleaseJarFile jarFile = new MultiReleaseJarFile(exampleJar))
@ -128,7 +126,7 @@ public class MultiReleaseJarFileTest
}
@Test
public void testClassLoaderWithMultiReleaseBehaviors() throws Exception
public void testClassLoaderWithMultiReleaseBehaviors(WorkDir workDir) throws Exception
{
Path exampleJar = workDir.getEmptyPathDir().resolve("multirelease.jar");
createExampleJar(exampleJar);
@ -153,7 +151,7 @@ public class MultiReleaseJarFileTest
}
@Test
public void testStreamAllFilesForEachEntries() throws IOException
public void testStreamAllFilesForEachEntries(WorkDir workDir) throws IOException
{
List<String> entries = new ArrayList<>();

View File

@ -41,7 +41,8 @@ import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class RolloverFileOutputStreamTest
{
public WorkDir testingDir;
public WorkDir workDir;
private static ZoneId toZoneId(String timezoneId)
{
@ -184,8 +185,7 @@ public class RolloverFileOutputStreamTest
@Test
public void testFileHandling() throws Exception
{
Path testPath = testingDir.getEmptyPathDir();
Path testPath = workDir.getEmptyPathDir();
ZoneId zone = toZoneId("Australia/Sydney");
ZonedDateTime now = toDateTime("2016.04.10-08:30:12.3 AM AEDT", zone);
@ -287,8 +287,7 @@ public class RolloverFileOutputStreamTest
@Test
public void testRollover() throws Exception
{
Path testPath = testingDir.getEmptyPathDir();
Path testPath = workDir.getEmptyPathDir();
ZoneId zone = toZoneId("Australia/Sydney");
ZonedDateTime now = toDateTime("2016.04.10-11:59:55.0 PM AEDT", zone);
@ -327,8 +326,7 @@ public class RolloverFileOutputStreamTest
@Test
public void testRolloverBackup() throws Exception
{
Path testPath = testingDir.getEmptyPathDir();
Path testPath = workDir.getEmptyPathDir();
ZoneId zone = toZoneId("Australia/Sydney");
ZonedDateTime now = toDateTime("2016.04.10-11:59:55.0 PM AEDT", zone);

View File

@ -51,7 +51,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class ScannerTest
{
public WorkDir workDir;
private Path _directory;
public Path _directory;
private Scanner _scanner;
private final BlockingQueue<Event> _queue = new LinkedBlockingQueue<>();
private final BlockingQueue<Set<String>> _bulk = new LinkedBlockingQueue<>();

View File

@ -55,6 +55,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class URIUtilTest
{
public WorkDir workDir;
public static Stream<Arguments> encodePathSource()
@ -674,9 +675,10 @@ public class URIUtilTest
}
@Test
public void testCorrectBadFileURIActualFile(WorkDir workDir) throws Exception
public void testCorrectBadFileURIActualFile() throws Exception
{
Path testfile = workDir.getEmptyPathDir().resolve("testCorrectBadFileURIActualFile.txt");
Path testDir = workDir.getEmptyPathDir();
Path testfile = testDir.resolve("testCorrectBadFileURIActualFile.txt");
FS.touch(testfile);
URI expectedUri = testfile.toUri(); // correct URI with `://`
@ -796,7 +798,7 @@ public class URIUtilTest
@MethodSource("resourceUriLastSegmentSource")
public void testFileUriGetUriLastPathSegment(String basePath, String expectedName) throws IOException
{
Path root = workDir.getPath();
Path root = workDir.getEmptyPathDir();
Path base = root.resolve(basePath);
if (basePath.endsWith("/"))
{

View File

@ -54,9 +54,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class CombinedResourceTest
{
private final ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable();
public WorkDir workDir;
private final ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable();
@BeforeEach
public void beforeEach()
{
@ -145,6 +147,7 @@ public class CombinedResourceTest
@Test
public void testCopyTo() throws Exception
{
Path destDir = workDir.getEmptyPathDir();
Path one = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/one");
Path two = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/two");
Path three = MavenTestingUtils.getTestResourcePathDir("org/eclipse/jetty/util/resource/three");
@ -154,7 +157,6 @@ public class CombinedResourceTest
resourceFactory.newResource(two),
resourceFactory.newResource(three)
);
Path destDir = workDir.getEmptyPathDir();
rc.copyTo(destDir);
Resource r = resourceFactory.newResource(destDir);

View File

@ -72,7 +72,6 @@ import static org.junit.jupiter.api.condition.OS.WINDOWS;
@ExtendWith(WorkDirExtension.class)
public class FileSystemResourceTest
{
public WorkDir workDir;
@BeforeEach
public void beforeEach()
@ -209,9 +208,9 @@ public class FileSystemResourceTest
}
@Test
public void testNewResourceWithSpace() throws Exception
public void testNewResourceWithSpace(WorkDir workDir) throws Exception
{
Path dir = workDir.getPath().normalize().toRealPath();
Path dir = workDir.getEmptyPathDir().normalize().toRealPath();
Path baseDir = dir.resolve("base with spaces");
FS.ensureDirExists(baseDir);
@ -232,10 +231,9 @@ public class FileSystemResourceTest
}
@Test
public void testResolvePathClass()
public void testResolvePathClass(WorkDir workDir)
{
Path dir = workDir.getEmptyPathDir();
Path subdir = dir.resolve("sub");
FS.ensureDirExists(subdir);
@ -248,7 +246,7 @@ public class FileSystemResourceTest
}
@Test
public void testResolveRootPath() throws Exception
public void testResolveRootPath(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Path subdir = dir.resolve("sub");
@ -274,10 +272,9 @@ public class FileSystemResourceTest
}
@Test
public void testAccessUniCodeFile() throws Exception
public void testAccessUniCodeFile(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
String readableRootDir = findAnyDirectoryOffRoot(dir.getFileSystem());
assumeTrue(readableRootDir != null, "Readable Root Dir found");
@ -352,7 +349,7 @@ public class FileSystemResourceTest
}
@Test
public void testIsContainedIn() throws Exception
public void testIsContainedIn(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
@ -365,7 +362,7 @@ public class FileSystemResourceTest
}
@Test
public void testIsDirectory() throws Exception
public void testIsDirectory(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
@ -384,10 +381,10 @@ public class FileSystemResourceTest
}
@Test
public void testLastModified() throws Exception
public void testLastModified(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Path file = workDir.getPathFile("foo");
Path file = dir.resolve("foo");
Files.createFile(file);
Instant expected = Files.getLastModifiedTime(file).toInstant();
@ -398,7 +395,7 @@ public class FileSystemResourceTest
}
@Test
public void testLength() throws Exception
public void testLength(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
@ -414,7 +411,7 @@ public class FileSystemResourceTest
}
@Test
public void testDelete() throws Exception
public void testDelete(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
@ -432,11 +429,9 @@ public class FileSystemResourceTest
}
@Test
public void testName() throws Exception
public void testName(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
String expected = dir.toAbsolutePath().toString();
Resource base = ResourceFactory.root().newResource(dir);
@ -444,11 +439,9 @@ public class FileSystemResourceTest
}
@Test
public void testFileName() throws Exception
public void testFileName(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
String expected = dir.getFileName().toString();
Resource base = ResourceFactory.root().newResource(dir);
@ -456,11 +449,9 @@ public class FileSystemResourceTest
}
@Test
public void testInputStream() throws Exception
public void testInputStream(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path file = dir.resolve("foo");
String content = "Foo is here";
touchFile(file, content);
@ -477,11 +468,9 @@ public class FileSystemResourceTest
}
@Test
public void testReadableByteChannel() throws Exception
public void testReadableByteChannel(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path file = dir.resolve("foo");
String content = "Foo is here";
@ -504,11 +493,9 @@ public class FileSystemResourceTest
}
@Test
public void testGetURI() throws Exception
public void testGetURI(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path file = dir.resolve("foo");
Files.createFile(file);
@ -520,11 +507,9 @@ public class FileSystemResourceTest
}
@Test
public void testList() throws Exception
public void testList(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Files.createFile(dir.resolve("foo"));
Files.createFile(dir.resolve("bar"));
Files.createDirectories(dir.resolve("tick"));
@ -545,10 +530,9 @@ public class FileSystemResourceTest
}
@Test
public void testSymlink() throws Exception
public void testSymlink(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Path foo = dir.resolve("foo");
Path bar = dir.resolve("bar");
@ -585,11 +569,9 @@ public class FileSystemResourceTest
}
@Test
public void testNonExistentSymlink() throws Exception
public void testNonExistentSymlink(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path foo = dir.resolve("foo"); // does not exist
Path bar = dir.resolve("bar"); // to become a link to "foo"
@ -616,10 +598,9 @@ public class FileSystemResourceTest
}
@Test
public void testCaseInsensitiveAlias() throws Exception
public void testCaseInsensitiveAlias(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path path = dir.resolve("file");
Files.createFile(path);
@ -653,11 +634,9 @@ public class FileSystemResourceTest
*/
@Test
@EnabledOnOs(WINDOWS)
public void testCase8dot3Alias() throws Exception
public void testCase8dot3Alias(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path path = dir.resolve("TextFile.Long.txt");
Files.createFile(path);
@ -690,11 +669,9 @@ public class FileSystemResourceTest
*/
@Test
@EnabledOnOs(WINDOWS)
public void testNTFSFileStreamAlias() throws Exception
public void testNTFSFileStreamAlias(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path path = dir.resolve("testfile");
Files.createFile(path);
@ -732,11 +709,9 @@ public class FileSystemResourceTest
*/
@Test
@EnabledOnOs(WINDOWS)
public void testNTFSFileDataStreamAlias() throws Exception
public void testNTFSFileDataStreamAlias(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path path = dir.resolve("testfile");
Files.createFile(path);
@ -776,11 +751,9 @@ public class FileSystemResourceTest
*/
@Test
@EnabledOnOs(WINDOWS)
public void testNTFSFileEncodedDataStreamAlias() throws Exception
public void testNTFSFileEncodedDataStreamAlias(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path path = dir.resolve("testfile");
Files.createFile(path);
@ -810,10 +783,9 @@ public class FileSystemResourceTest
}
@Test
public void testSemicolon() throws Exception
public void testSemicolon(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
try
{
// attempt to create file
@ -831,11 +803,9 @@ public class FileSystemResourceTest
}
@Test
public void testSingleQuote() throws Exception
public void testSingleQuote(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
try
{
// attempt to create file
@ -857,11 +827,9 @@ public class FileSystemResourceTest
}
@Test
public void testSingleBackTick() throws Exception
public void testSingleBackTick(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
try
{
// attempt to create file
@ -883,11 +851,9 @@ public class FileSystemResourceTest
}
@Test
public void testBrackets() throws Exception
public void testBrackets(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
try
{
// attempt to create file
@ -909,11 +875,9 @@ public class FileSystemResourceTest
}
@Test
public void testBraces() throws Exception
public void testBraces(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
try
{
// attempt to create file
@ -936,11 +900,9 @@ public class FileSystemResourceTest
}
@Test
public void testCaret() throws Exception
public void testCaret(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
try
{
// attempt to create file
@ -962,11 +924,9 @@ public class FileSystemResourceTest
}
@Test
public void testPipe() throws Exception
public void testPipe(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
try
{
// attempt to create file
@ -993,7 +953,7 @@ public class FileSystemResourceTest
* @throws Exception failed test
*/
@Test
public void testExistNormal() throws Exception
public void testExistNormal(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
@ -1001,13 +961,13 @@ public class FileSystemResourceTest
Path path = dir.resolve("a.jsp");
Files.createFile(path);
URI ref = workDir.getPath().toUri().resolve("a.jsp");
URI ref = dir.toUri().resolve("a.jsp");
Resource fileres = ResourceFactory.root().newResource(ref);
assertThat("Resource: " + fileres, fileres.exists(), is(true));
}
@Test
public void testSingleQuoteInFileName() throws Exception
public void testSingleQuoteInFileName(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
@ -1062,18 +1022,16 @@ public class FileSystemResourceTest
}
@Test
public void testExistBadURINull() throws Exception
public void testExistBadURINull(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path path = dir.resolve("a.jsp");
Files.createFile(path);
try
{
// request with null at end
URI uri = workDir.getPath().toUri().resolve("a.jsp%00");
URI uri = dir.toUri().resolve("a.jsp%00");
assertThat("Null URI", uri, notNullValue());
Resource r = ResourceFactory.root().newResource(uri);
@ -1088,18 +1046,16 @@ public class FileSystemResourceTest
}
@Test
public void testExistBadURINullX() throws Exception
public void testExistBadURINullX(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path path = dir.resolve("a.jsp");
Files.createFile(path);
try
{
// request with null and x at end
URI uri = workDir.getPath().toUri().resolve("a.jsp%00x");
URI uri = dir.toUri().resolve("a.jsp%00x");
assertThat("NullX URI", uri, notNullValue());
Resource r = ResourceFactory.root().newResource(uri);
@ -1114,11 +1070,9 @@ public class FileSystemResourceTest
}
@Test
public void testResolveWindowsSlash() throws Exception
public void testResolveWindowsSlash(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path basePath = dir.resolve("base");
FS.ensureDirExists(basePath);
Path dirPath = basePath.resolve("aa");
@ -1156,11 +1110,9 @@ public class FileSystemResourceTest
}
@Test
public void testResolveWindowsExtensionLess() throws Exception
public void testResolveWindowsExtensionLess(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path basePath = dir.resolve("base");
FS.ensureDirExists(basePath);
Path dirPath = basePath.resolve("aa");
@ -1197,11 +1149,9 @@ public class FileSystemResourceTest
}
@Test
public void testResolveInitialSlash() throws Exception
public void testResolveInitialSlash(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path basePath = dir.resolve("base");
FS.ensureDirExists(basePath);
Path filePath = basePath.resolve("foo.txt");
@ -1227,11 +1177,9 @@ public class FileSystemResourceTest
}
@Test
public void testResolveInitialDoubleSlash() throws Exception
public void testResolveInitialDoubleSlash(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path basePath = dir.resolve("base");
FS.ensureDirExists(basePath);
Path filePath = basePath.resolve("foo.txt");
@ -1257,11 +1205,9 @@ public class FileSystemResourceTest
}
@Test
public void testResolveDoubleSlash() throws Exception
public void testResolveDoubleSlash(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path basePath = dir.resolve("base");
FS.ensureDirExists(basePath);
Path dirPath = basePath.resolve("aa");
@ -1289,11 +1235,9 @@ public class FileSystemResourceTest
}
@Test
public void testEncoding() throws Exception
public void testEncoding(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Files.createDirectories(dir);
Path specials = dir.resolve("a file with,spe#ials");
Files.createFile(specials);
@ -1306,11 +1250,10 @@ public class FileSystemResourceTest
}
@Test
public void testUtf8Dir() throws Exception
public void testUtf8Dir(WorkDir workDir) throws Exception
{
Path dir = workDir.getEmptyPathDir();
Path utf8Dir;
Path dir = workDir.getEmptyPathDir();
try
{
utf8Dir = dir.resolve("bãm");

View File

@ -46,7 +46,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class MountedPathResourceTest
{
public WorkDir workDir;
@BeforeEach
public void beforeEach()
@ -61,7 +60,7 @@ public class MountedPathResourceTest
}
@Test
public void testJarFile()
public void testJarFile(WorkDir workDir)
throws Exception
{
Path testZip = MavenTestingUtils.getTestResourcePathFile("TestData/test.zip");
@ -78,7 +77,7 @@ public class MountedPathResourceTest
assertTrue(Resources.isReadableFile(file));
assertThat(file.getFileName(), is("numbers"));
Path extract = workDir.getPathFile("extract");
Path extract = workDir.getEmptyPathDir().resolve("extract");
FS.ensureEmpty(extract);
r.copyTo(extract);
@ -94,7 +93,7 @@ public class MountedPathResourceTest
entries = r.list().stream().map(Resource::getFileName).toList();
assertThat(entries, containsInAnyOrder("alphabet", "numbers"));
Path extract2 = workDir.getPathFile("extract2");
Path extract2 = workDir.getEmptyPathDir().resolve("extract2");
FS.ensureEmpty(extract2);
r.copyTo(extract2);

View File

@ -29,11 +29,13 @@ import java.util.Map;
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.IO;
import org.eclipse.jetty.util.URIUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -51,6 +53,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@ExtendWith(WorkDirExtension.class)
public class PathResourceTest
{
private static final Logger LOG = LoggerFactory.getLogger(PathResourceTest.class);
@ -143,7 +146,8 @@ public class PathResourceTest
@Test
public void testJarFileIsAliasFile(WorkDir workDir) throws IOException
{
Path testJar = workDir.getEmptyPathDir().resolve("test.jar");
Path tmpPath = workDir.getEmptyPathDir();
Path testJar = tmpPath.resolve("test.jar");
Map<String, String> env = new HashMap<>();
env.put("create", "true");
@ -186,8 +190,9 @@ public class PathResourceTest
@Test
public void testJarFileIsAliasDirectory(WorkDir workDir) throws IOException
{
Path tmpPath = workDir.getEmptyPathDir();
boolean supportsUtf8Dir = false;
Path testJar = workDir.getEmptyPathDir().resolve("test.jar");
Path testJar = tmpPath.resolve("test.jar");
Map<String, String> env = new HashMap<>();
env.put("create", "true");
@ -268,7 +273,8 @@ public class PathResourceTest
@Test
public void testNullCharEndingFilename(WorkDir workDir) throws Exception
{
Path testJar = workDir.getEmptyPathDir().resolve("test.jar");
Path tmpPath = workDir.getEmptyPathDir();
Path testJar = tmpPath.resolve("test.jar");
Map<String, String> env = new HashMap<>();
env.put("create", "true");
@ -344,7 +350,8 @@ public class PathResourceTest
@Test
public void testSymlink(WorkDir workDir) throws Exception
{
Path testJar = workDir.getEmptyPathDir().resolve("test.jar");
Path tmpPath = workDir.getEmptyPathDir();
Path testJar = tmpPath.resolve("test.jar");
Path foo = null;
Path bar = null;
@ -453,7 +460,6 @@ public class PathResourceTest
public void testResolveNavigation(WorkDir workDir) throws Exception
{
Path docroot = workDir.getEmptyPathDir();
Path dir = docroot.resolve("dir");
Files.createDirectory(dir);
@ -480,7 +486,6 @@ public class PathResourceTest
public void testUnicodeResolve(WorkDir workDir) throws Exception
{
Path docroot = workDir.getEmptyPathDir();
Path dir = docroot.resolve("dir");
Files.createDirectory(dir);

View File

@ -42,8 +42,6 @@ public class ResourceAliasTest
private final ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable();
public WorkDir workDir;
@BeforeEach
public void beforeEach()
{
@ -58,10 +56,9 @@ public class ResourceAliasTest
}
@Test
public void testAliasNavigation() throws IOException
public void testAliasNavigation(WorkDir workDir) throws IOException
{
Path docroot = workDir.getEmptyPathDir();
Path dir = docroot.resolve("dir");
Files.createDirectory(dir);
@ -86,10 +83,9 @@ public class ResourceAliasTest
}
@Test
public void testPercentPaths() throws IOException
public void testPercentPaths(WorkDir workDir) throws IOException
{
Path baseDir = workDir.getEmptyPathDir();
Path foo = baseDir.resolve("%foo");
Files.createDirectories(foo);
@ -123,10 +119,9 @@ public class ResourceAliasTest
}
@Test
public void testNullCharEndingFilename() throws Exception
public void testNullCharEndingFilename(WorkDir workDir) throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
Path file = baseDir.resolve("test.txt");
FS.touch(file);

View File

@ -256,8 +256,6 @@ public class ResourceTest
return cases.stream();
}
public WorkDir workDir;
@ParameterizedTest
@MethodSource("scenarios")
public void testResourceExists(Scenario data)
@ -342,6 +340,7 @@ public class ResourceTest
public void testResourceExtraSlashStripping(WorkDir workDir) throws IOException
{
Path docRoot = workDir.getEmptyPathDir();
Files.createDirectories(docRoot.resolve("d/e/f"));
Resource ra = resourceFactory.newResource(docRoot);
@ -368,7 +367,7 @@ public class ResourceTest
@Test
public void testClimbAboveBase(WorkDir workDir)
{
Path testdir = workDir.getEmptyPathDir().resolve("foo/bar");
Path testdir = workDir.getEmptyPathDir();
FS.ensureDirExists(testdir);
Resource resource = resourceFactory.newResource(testdir);
assertThrows(IllegalArgumentException.class, () -> resource.resolve(".."));

View File

@ -11,6 +11,7 @@
<name>Core :: Websocket :: Tests</name>
<properties>
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
<bundle-symbolic-name>${project.groupId}.core.tests</bundle-symbolic-name>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.deploy.skip>true</maven.deploy.skip>

View File

@ -43,6 +43,7 @@ import org.eclipse.jetty.logging.StdErrAppender;
import org.eclipse.jetty.toolchain.test.FS;
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.IO;
import org.eclipse.jetty.util.annotation.Name;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
@ -57,6 +58,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@ -82,6 +84,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class XmlConfigurationTest
{
private static final String STRING_ARRAY_XML = "<Array type=\"String\"><Item type=\"String\">String1</Item><Item type=\"String\">String2</Item></Array>";

View File

@ -28,22 +28,22 @@ 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;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
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.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class TestAnnotationConfiguration
{
public static class TestableAnnotationConfiguration extends AnnotationConfiguration
@ -57,7 +57,6 @@ public class TestAnnotationConfiguration
}
}
public WorkDir workDir;
public Path web25;
public Path web31false;
public Path web31true;
@ -65,7 +64,7 @@ public class TestAnnotationConfiguration
public Path testSciJar;
public Path testContainerSciJar;
public Path testWebInfClassesJar;
public Path unpacked;
public WorkDir workDir;
public URLClassLoader containerLoader;
public URLClassLoader webAppLoader;
public List<Resource> classes;
@ -75,7 +74,6 @@ public class TestAnnotationConfiguration
@BeforeEach
public void setup() throws Exception
{
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
web25 = MavenTestingUtils.getTestResourcePathFile("web25.xml");
web31false = MavenTestingUtils.getTestResourcePathFile("web31false.xml");
web31true = MavenTestingUtils.getTestResourcePathFile("web31true.xml");
@ -87,9 +85,8 @@ public class TestAnnotationConfiguration
testContainerSciJar = jarDir.resolve("test-sci-for-container-path.jar");
testWebInfClassesJar = jarDir.resolve("test-sci-for-webinf.jar");
Path unpacked = workDir.getEmptyPathDir();
// unpack some classes to pretend that are in WEB-INF/classes
unpacked = workDir.getEmptyPathDir();
FS.cleanDirectory(unpacked);
JAR.unpack(testWebInfClassesJar.toFile(), unpacked.toFile());
webInfClasses = ResourceFactory.root().newResource(unpacked);
@ -108,12 +105,6 @@ public class TestAnnotationConfiguration
containerLoader);
}
@AfterEach
public void afterEach()
{
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
}
@Test
public void testAnnotationScanControl() throws Exception
{

View File

@ -23,11 +23,13 @@ import org.eclipse.jetty.ee10.webapp.MetaData;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.ee10.webapp.WebDescriptor;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.xml.XmlParser;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -35,9 +37,9 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class TestAnnotationDecorator
{
public WorkDir workDir;
public class TestWebDescriptor extends WebDescriptor
{
@ -81,17 +83,14 @@ public class TestAnnotationDecorator
}
@Test
public void testAnnotationDecorator() throws Exception
public void testAnnotationDecorator(WorkDir workDir) throws Exception
{
Path docroot = workDir.getEmptyPathDir();
Path dummyDescriptor = docroot.resolve("dummy.xml");
Files.createFile(dummyDescriptor);
Resource dummyResource = ResourceFactory.root().newResource(dummyDescriptor);
assertThrows(NullPointerException.class, () ->
{
new AnnotationDecorator(null);
});
assertThrows(NullPointerException.class, () -> new AnnotationDecorator(null));
WebAppContext context = new WebAppContext();
AnnotationDecorator decorator = new AnnotationDecorator(context);

View File

@ -48,7 +48,6 @@ import static org.hamcrest.Matchers.in;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -99,12 +98,10 @@ public class TestAnnotationParser
}
}
public WorkDir testdir;
@Test
public void testSampleAnnotation() throws Exception
public void testSampleAnnotation(WorkDir workDir) throws Exception
{
Path root = testdir.getEmptyPathDir();
Path root = workDir.getEmptyPathDir();
copyClass(ClassA.class, root);
AnnotationParser parser = new AnnotationParser();
@ -149,9 +146,9 @@ public class TestAnnotationParser
}
@Test
public void testMultiAnnotation() throws Exception
public void testMultiAnnotation(WorkDir workDir) throws Exception
{
Path root = testdir.getEmptyPathDir();
Path root = workDir.getEmptyPathDir();
copyClass(ClassB.class, root);
AnnotationParser parser = new AnnotationParser();
@ -254,14 +251,15 @@ public class TestAnnotationParser
}
@Test
public void testBasedirExclusion() throws Exception
public void testBasedirExclusion(WorkDir workDir) throws Exception
{
Path testdir = workDir.getEmptyPathDir();
// Build up basedir, which itself has a path segment that violates java package and classnaming.
// The basedir should have no effect on annotation scanning.
// Intentionally using a base directory name that starts with a "."
// This mimics what you see in jenkins, hudson, hadoop, solr, camel, and selenium for their
// installed and/or managed webapps
Path basedir = testdir.getPathFile(".base/workspace/classes");
Path basedir = testdir.resolve(".base/workspace/classes");
FS.ensureEmpty(basedir);
// Copy in class that is known to have annotations.
@ -288,8 +286,8 @@ public class TestAnnotationParser
{
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
{
Resource testJar = resourceFactory.newResource(MavenTestingUtils.getTargetFile("test-classes/tinytest.jar").toPath());
Resource testJar2 = resourceFactory.newResource(MavenTestingUtils.getTargetFile("test-classes/tinytest_copy.jar").toPath());
Resource testJar = resourceFactory.newResource(MavenTestingUtils.getTargetPath("test-classes/tinytest.jar"));
Resource testJar2 = resourceFactory.newResource(MavenTestingUtils.getTargetPath("test-classes/tinytest_copy.jar"));
AnnotationParser parser = new AnnotationParser();
DuplicateClassScanHandler handler = new DuplicateClassScanHandler();
Set<AnnotationParser.Handler> handlers = Collections.singleton(handler);

View File

@ -20,18 +20,21 @@ import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.ee10.webapp.WebDescriptor;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
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.assertNull;
@ExtendWith(WorkDirExtension.class)
public class TestRunAsAnnotation
{
public WorkDir workDir;
@Test
public void testRunAsAnnotation() throws Exception
public void testRunAsAnnotation(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
WebAppContext wac = new WebAppContext();
//pre-add a servlet but not by descriptor
@ -47,7 +50,7 @@ public class TestRunAsAnnotation
holder2.setHeldClass(ServletC.class);
holder2.setInitOrder(1);
wac.getServletHandler().addServletWithMapping(holder2, "/foo2/*");
Path fakeXml = workDir.getEmptyPathDir().resolve("fake.xml");
Path fakeXml = tmpPath.resolve("fake.xml");
Files.createFile(fakeXml);
wac.getMetaData().setOrigin(holder2.getName() + ".servlet.run-as", new WebDescriptor(wac.getResourceFactory().newResource(fakeXml)));

View File

@ -53,8 +53,6 @@ import static org.junit.jupiter.api.Assertions.fail;
@ExtendWith(WorkDirExtension.class)
public class TestServletAnnotations
{
public WorkDir workDir;
public class TestWebServletAnnotationHandler extends WebServletAnnotationHandler
{
List<DiscoveredAnnotation> _list = null;
@ -74,7 +72,7 @@ public class TestServletAnnotations
}
@Test
public void testServletAnnotation() throws Exception
public void testServletAnnotation(WorkDir workDir) throws Exception
{
Path root = workDir.getEmptyPathDir();
copyClass(org.eclipse.jetty.ee10.annotations.ServletC.class, root);

View File

@ -73,7 +73,7 @@ public class TestJettyJspServlet
_server.setHandler(context);
context.setClassLoader(new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()));
ServletHolder jspHolder = context.addServlet(JettyJspServlet.class, "/*");
jspHolder.setInitParameter("scratchdir", workdir.getPath().toString());
jspHolder.setInitParameter("scratchdir", workdir.getEmptyPathDir().toString());
context.setBaseResourceAsPath(baseDir);
context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
ServletHolder dfltHolder = new ServletHolder();

View File

@ -40,22 +40,21 @@ public class FastFileServerTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
"many troubles, but most of them never happened. - Mark Twain";
public WorkDir workDir;
private WorkDir workDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
Path textFile = workDir.getEmptyPathDir().resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{
writer.write(TEXT_CONTENT);
}
//TODO fix me
// server = FastFileServer.createServer(0, baseDir.toFile());
//server = FastFileServer.createServer(0, baseDir.toFile());
server.start();
}

View File

@ -40,14 +40,13 @@ public class FileServerTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
"many troubles, but most of them never happened. - Mark Twain";
public WorkDir workDir;
public Path baseDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
public void startServer(WorkDir workDir) throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{

View File

@ -39,14 +39,13 @@ public class FileServerXmlTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "I am an old man and I have known a great " +
"many troubles, but most of them never happened. - Mark Twain";
public WorkDir workDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
public void startServer(WorkDir workDir) throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{

View File

@ -52,7 +52,6 @@ public class JarServerTest extends AbstractEmbeddedTest
public void stopServer() throws Exception
{
server.stop();
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
}
@Test

View File

@ -25,11 +25,9 @@ import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.ConnectionStatistics;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.opentest4j.AssertionFailedError;
import static org.hamcrest.MatcherAssert.assertThat;
@ -39,7 +37,6 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
@ExtendWith(WorkDirExtension.class)
public class OneServletContextJmxStatsTest extends AbstractEmbeddedTest
{
private Server server;

View File

@ -40,14 +40,15 @@ import static org.hamcrest.Matchers.is;
public class OneServletContextTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "The secret of getting ahead is getting started. - Mark Twain";
public WorkDir workDir;
public Path baseDir;
private Server server;
@BeforeEach
public void startServer() throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{

View File

@ -41,14 +41,15 @@ import static org.hamcrest.Matchers.is;
public class OneServletContextWithSessionTest extends AbstractEmbeddedTest
{
private static final String TEXT_CONTENT = "Do the right thing. It will gratify some people and astonish the rest. - Mark Twain";
public WorkDir workDir;
private Server server;
public WorkDir workDir;
private Path baseDir;
@BeforeEach
public void startServer() throws Exception
{
Path baseDir = workDir.getEmptyPathDir();
baseDir = workDir.getEmptyPathDir();
Path textFile = baseDir.resolve("simple.txt");
try (BufferedWriter writer = Files.newBufferedWriter(textFile, UTF_8))
{

View File

@ -20,6 +20,7 @@ import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.file.Path;
import org.eclipse.jetty.ee10.annotations.AnnotationConfiguration;
import org.eclipse.jetty.ee10.webapp.Configurations;
@ -32,14 +33,17 @@ import org.eclipse.jetty.toolchain.test.IO;
import org.eclipse.jetty.toolchain.test.JAR;
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.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class JspIncludeTest
{
private static Server server;
@ -48,6 +52,7 @@ public class JspIncludeTest
@BeforeAll
public static void startServer(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
// Setup Server
server = new Server();
ServerConnector connector = new ServerConnector(server);
@ -55,7 +60,7 @@ public class JspIncludeTest
server.addConnector(connector);
//Base dir for test
File testDir = workDir.getEmptyPathDir().toFile();
File testDir = tmpPath.toFile();
File testLibDir = new File(testDir, "WEB-INF/lib");
FS.ensureDirExists(testLibDir);

View File

@ -11,6 +11,7 @@
<name>EE10 :: Jetty Maven Plugin</name>
<description>Jetty EE10 maven plugins</description>
<properties>
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
<bundle-symbolic-name>${project.groupId}.maven.plugin</bundle-symbolic-name>
<jetty.stopKey>FREEBEER</jetty.stopKey>
<jetty.jvmArgs></jetty.jvmArgs>

View File

@ -22,6 +22,7 @@ import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.nio.file.Path;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
@ -31,11 +32,14 @@ import java.util.Random;
import org.awaitility.Awaitility;
import org.eclipse.jetty.toolchain.test.FS;
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.IO;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -44,11 +48,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
* Test the JettyForkedChild class, which
* is the main that is executed by jetty:run/start in mode FORKED.
*/
@ExtendWith(WorkDirExtension.class)
public class TestForkedChild
{
File testDir;
File baseDir;
File tmpDir;
Path tmpDir;
File tokenFile;
File webappPropsFile;
int stopPort;
@ -79,7 +84,7 @@ public class TestForkedChild
MavenWebAppContext webapp = new MavenWebAppContext();
webapp.setContextPath("/foo");
webapp.setTempDirectory(tmpDir);
webapp.setTempDirectory(tmpDir.toFile());
webapp.setBaseResourceAsPath(baseDir.toPath());
WebAppPropertyConverter.toProperties(webapp, webappPropsFile, null);
child = new JettyForkedChild(cmd.toArray(new String[0]));
@ -94,13 +99,13 @@ public class TestForkedChild
}
@BeforeEach
public void setUp()
public void setUp(WorkDir workDir)
{
tmpDir = workDir.getEmptyPathDir();
baseDir = MavenTestingUtils.getTestResourceDir("root");
testDir = MavenTestingUtils.getTargetTestingDir("forkedChild");
FS.ensureEmpty(testDir);
tmpDir = new File(testDir, "tmp");
webappPropsFile = new File(testDir, "webapp.props");
webappPropsFile = new File(tmpDir.toFile(), "webapp.props");
String stopPortString = System.getProperty("stop.port");
assertNotNull(stopPortString, "stop.port System property");
@ -111,7 +116,7 @@ public class TestForkedChild
Random random = new Random();
token = Long.toString(random.nextLong() ^ System.currentTimeMillis(), 36).toUpperCase(Locale.ENGLISH);
tokenFile = testDir.toPath().resolve(token + ".txt").toFile();
tokenFile = tmpDir.resolve(token + ".txt").toFile();
}
@AfterEach

View File

@ -34,10 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class TestJettyEmbedder
{
public WorkDir workDir;
@Test
public void testJettyEmbedderFromDefaults() throws Exception
public void testJettyEmbedderFromDefaults(WorkDir workDir) throws Exception
{
Path basePath = workDir.getEmptyPathDir();
MavenWebAppContext webApp = new MavenWebAppContext();
@ -74,11 +72,11 @@ public class TestJettyEmbedder
}
@Test
public void testJettyEmbedder()
public void testJettyEmbedder(WorkDir workDir)
throws Exception
{
Path basePath = workDir.getPath();
MavenWebAppContext webApp = new MavenWebAppContext();
Path basePath = workDir.getEmptyPathDir();
webApp.setBaseResourceAsPath(basePath);
Server server = new Server();
Map<String, String> jettyProperties = new HashMap<>();

View File

@ -19,8 +19,10 @@ import java.nio.file.Path;
import org.eclipse.jetty.server.Server;
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.ResourceFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
@ -30,15 +32,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*
*
*/
@ExtendWith(WorkDirExtension.class)
public class TestQuickStartGenerator
{
public WorkDir workDir;
@Test
public void testGenerator() throws Exception
public void testGenerator(WorkDir workDir) throws Exception
{
Path tmpDir = workDir.getEmptyPathDir();
MavenWebAppContext webApp = new MavenWebAppContext();
webApp.setContextPath("/shouldbeoverridden");
Path rootDir = MavenTestingUtils.getTargetPath("test-classes/root");

View File

@ -32,13 +32,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class TestSelectiveJarResource
{
public WorkDir workDir;
@Test
public void testIncludesNoExcludes() throws Exception
public void testIncludesNoExcludes(WorkDir workDir) throws Exception
{
Path unpackDir = workDir.getEmptyPathDir();
Path unpackDir = workDir.getPath();
Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
{
@ -61,10 +59,9 @@ public class TestSelectiveJarResource
}
@Test
public void testExcludesNoIncludes() throws Exception
public void testExcludesNoIncludes(WorkDir workDir) throws Exception
{
Path unpackDir = workDir.getEmptyPathDir();
Path unpackDir = workDir.getPath();
Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
{
@ -87,10 +84,9 @@ public class TestSelectiveJarResource
}
@Test
public void testIncludesExcludes() throws Exception
public void testIncludesExcludes(WorkDir workDir) throws Exception
{
Path unpackDir = workDir.getEmptyPathDir();
Path unpackDir = workDir.getPath();
Path testJar = MavenTestingUtils.getTestResourcePathFile("selective-jar-test.jar");
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
{

View File

@ -22,14 +22,17 @@ import org.eclipse.jetty.ee10.webapp.WebAppContext;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@ExtendWith(WorkDirExtension.class)
public class LifeCycleCallbackCollectionTest
{
public static class TestServlet extends HttpServlet
@ -174,9 +177,7 @@ public class LifeCycleCallbackCollectionTest
@Test
public void testServletPostConstructPreDestroy(WorkDir workDir) throws Exception
{
// Start with an empty dir
Path testDir = workDir.getEmptyPathDir();
Server server = new Server();
WebAppContext context = new WebAppContext();
Path predestroyTestDir = testDir.resolve("predestroy-test");

View File

@ -31,6 +31,7 @@ import javax.naming.spi.ObjectFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@ -39,6 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@Isolated("jndi entries")
public class TestNamingEntries
{
public class ScopeA

View File

@ -21,6 +21,7 @@ import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
@ -31,6 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;
@Isolated("jndi entries")
public class TestNamingEntryUtil
{
public class MyNamingEntry extends NamingEntry

View File

@ -36,6 +36,7 @@ import org.eclipse.jetty.util.IntrospectionUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@ -51,6 +52,7 @@ import static org.junit.jupiter.api.Assertions.fail;
/**
* PlusDescriptorProcessorTest
*/
@Isolated("jndi entries")
public class PlusDescriptorProcessorTest
{
protected static final Class<?>[] STRING_ARG = new Class[]{String.class};

View File

@ -94,8 +94,6 @@ public class AsyncMiddleManServletTest
{
private static final Logger LOG = LoggerFactory.getLogger(AsyncMiddleManServletTest.class);
private static final String PROXIED_HEADER = "X-Proxied";
public WorkDir workDir;
private HttpClient client;
private Server proxy;
private ServerConnector proxyConnector;
@ -984,11 +982,9 @@ public class AsyncMiddleManServletTest
}
@Test
public void testAfterContentTransformerOverflowingToDisk() throws Exception
public void testAfterContentTransformerOverflowingToDisk(WorkDir workDir) throws Exception
{
// Make sure the temporary directory we use exists and it's empty.
Path targetTestsDir = workDir.getEmptyPathDir();
String key0 = "id";
long value0 = 1;
String key1 = "channel";
@ -1107,10 +1103,9 @@ public class AsyncMiddleManServletTest
@Test
@Disabled("idle timeouts do not work yet")
public void testAfterContentTransformerClosingFilesOnClientRequestException() throws Exception
public void testAfterContentTransformerClosingFilesOnClientRequestException(WorkDir workDir) throws Exception
{
Path targetTestsDir = workDir.getEmptyPathDir();
startServer(new HttpServlet()
{
@Override
@ -1172,10 +1167,9 @@ public class AsyncMiddleManServletTest
}
@Test
public void testAfterContentTransformerClosingFilesOnServerResponseException() throws Exception
public void testAfterContentTransformerClosingFilesOnServerResponseException(WorkDir workDir) throws Exception
{
Path targetTestsDir = workDir.getEmptyPathDir();
CountDownLatch serviceLatch = new CountDownLatch(1);
startServer(new HttpServlet()
{

View File

@ -757,7 +757,7 @@ public class AsyncServletTest
socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
socket.getOutputStream().flush();
String response = IO.toString(socket.getInputStream());
assertTrue(_latch.await(1, TimeUnit.SECONDS));
assertTrue(_latch.await(5, TimeUnit.SECONDS));
return response;
}
catch (Exception e)

View File

@ -35,21 +35,25 @@ import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Credential;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@ExtendWith(WorkDirExtension.class)
public class CustomRequestLogTest
{
private final BlockingQueue<String> _logs = new BlockingArrayQueue<>();
public WorkDir workDir;
private Server _server;
private LocalConnector _connector;
private Path _baseDir;
@ -64,7 +68,6 @@ public class CustomRequestLogTest
RequestLog requestLog = new CustomRequestLog(writer, formatString);
_server.setRequestLog(requestLog);
_baseDir = workDir.getEmptyPathDir();
Files.createDirectory(_baseDir.resolve("servlet"));
Files.createFile(_baseDir.resolve("servlet/info"));
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
@ -105,6 +108,12 @@ public class CustomRequestLogTest
LifeCycle.stop(_server);
}
@BeforeEach
public void setup(WorkDir workDir)
{
_baseDir = workDir.getEmptyPathDir();
}
@Test
public void testLogFilename() throws Exception
{
@ -112,7 +121,7 @@ public class CustomRequestLogTest
_connector.getResponse("GET /context/servlet/info HTTP/1.0\n\n");
String log = _logs.poll(5, TimeUnit.SECONDS);
String expected = workDir.getPath().resolve("servlet/info").toString();
String expected = _baseDir.resolve("servlet/info").toString();
assertThat(log, is("Filename: " + expected));
}

View File

@ -18,6 +18,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.LocalConnector;
@ -39,7 +40,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class DefaultServletRangesTest
{
public static final String DATA = "01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWZYZ!@#$%^&*()_+/.,[]";
public WorkDir testdir;
public WorkDir workDir;
public Path testdir;
private Server server;
private LocalConnector connector;
@ -47,6 +50,7 @@ public class DefaultServletRangesTest
@BeforeEach
public void init() throws Exception
{
testdir = workDir.getEmptyPathDir();
server = new Server();
connector = new LocalConnector(server);
@ -59,8 +63,7 @@ public class DefaultServletRangesTest
server.setHandler(context);
server.addConnector(connector);
testdir.ensureEmpty();
File resBase = testdir.getPathFile("docroot").toFile();
File resBase = testdir.resolve("docroot").toFile();
FS.ensureDirExists(resBase);
File data = new File(resBase, "data.txt");
createFile(data, DATA);

View File

@ -825,7 +825,7 @@ public class DefaultServletTest
assumeMkDirSupported(docRoot, "dir;");
/* create some content outside of the docroot */
Path sekret = workDir.getPath().resolve("sekret");
Path sekret = docRoot.resolve("sekret");
FS.ensureDirExists(sekret);
Path pass = sekret.resolve("pass");
Files.writeString(pass, "Sssh, you shouldn't be seeing this", UTF_8);
@ -951,7 +951,7 @@ public class DefaultServletTest
Path inde = dir.resolve("index.htm");
Path index = dir.resolve("index.html");
Path altRoot = workDir.getPath().resolve("altroot");
Path altRoot = docRoot.resolve("altroot");
Path altDir = altRoot.resolve("dir");
FS.ensureDirExists(altDir);
Path altInde = altDir.resolve("index.htm");

View File

@ -267,7 +267,7 @@ public class MultiPartServletTest
String responseContent = null;
try
{
Response response = listener.get(30, TimeUnit.SECONDS);
Response response = listener.get(60, TimeUnit.SECONDS);
assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST_400));
responseContent = IO.toString(listener.getInputStream());
}

View File

@ -73,8 +73,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@ExtendWith(WorkDirExtension.class)
public class SessionHandlerTest
{
public WorkDir workDir;
public static class SessionConsumer implements Consumer<ManagedSession>
{
private ManagedSession _session;
@ -104,7 +103,7 @@ public class SessionHandlerTest
* Test that a session listener can access classes only visible to the context it is in.
*/
@Test
public void testSessionListenerWithClassloader() throws Exception
public void testSessionListenerWithClassloader(WorkDir workDir) throws Exception
{
Path foodir = workDir.getEmptyPathDir();
Path fooClass = foodir.resolve("Foo.class");
@ -347,6 +346,7 @@ public class SessionHandlerTest
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
String sessionCookie = response.getHeaders().get("Set-Cookie");
assertTrue(sessionCookie != null);
assertThat(sessionCookie, containsString("Path=/"));

View File

@ -16,15 +16,11 @@ package org.eclipse.jetty.ee10.servlet.security;
import java.nio.file.Path;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
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.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@ -36,17 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
public class HashLoginServiceTest
{
@BeforeEach
public void beforeEach()
{
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
}
@AfterEach
public void afterEach()
{
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
}
@Test
public void testAutoCreatedUserStore() throws Exception

View File

@ -13,7 +13,6 @@
package org.eclipse.jetty.ee10.servlet.security;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -110,24 +109,18 @@ public class PropertyUserStoreTest
}
}
public WorkDir testdir;
public WorkDir workDir;
public Path testdir;
@BeforeEach
public void beforeEach()
{
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
}
@AfterEach
public void afterEach()
{
assertThat(FileSystemPool.INSTANCE.mounts(), empty());
testdir = workDir.getEmptyPathDir();
}
private Path initUsersText() throws Exception
{
Path dir = testdir.getPath();
Path users = dir.resolve("users.txt");
Path users = testdir.resolve("users.txt");
Files.deleteIfExists(users);
writeUser(users);
@ -137,10 +130,9 @@ public class PropertyUserStoreTest
private URI initUsersPackedFileText()
throws Exception
{
Path dir = testdir.getPath();
Path users = dir.resolve("users.txt");
Path users = testdir.resolve("users.txt");
writeUser(users);
Path usersJar = dir.resolve("users.jar");
Path usersJar = testdir.resolve("users.jar");
String entryPath = "mountain_goat/pale_ale.txt";
try (InputStream fileInputStream = Files.newInputStream(users))
{
@ -167,11 +159,6 @@ public class PropertyUserStoreTest
return URIUtil.uriJarPrefix(usersJar.toUri(), "!/" + entryPath);
}
private void writeUser(File usersFile) throws IOException
{
writeUser(usersFile.toPath());
}
private void writeUser(Path usersFile) throws IOException
{
try (Writer writer = Files.newBufferedWriter(usersFile, UTF_8))
@ -194,8 +181,6 @@ public class PropertyUserStoreTest
@Test
public void testPropertyUserStoreLoad() throws Exception
{
testdir.ensureEmpty();
final UserCount userCount = new UserCount();
final Path usersFile = initUsersText();
@ -228,8 +213,6 @@ public class PropertyUserStoreTest
@Test
public void testPropertyUserStoreLoadFromJarFile() throws Exception
{
testdir.ensureEmpty();
final UserCount userCount = new UserCount();
final URI usersFile = initUsersPackedFileText();
@ -257,8 +240,6 @@ public class PropertyUserStoreTest
@Test
public void testPropertyUserStoreLoadUpdateUser() throws Exception
{
testdir.ensureEmpty();
final UserCount userCount = new UserCount();
final Path usersFile = initUsersText();
final AtomicInteger loadCount = new AtomicInteger(0);
@ -288,10 +269,10 @@ public class PropertyUserStoreTest
userCount.assertThatUsers(hasItem("skip"));
if (OS.LINUX.isCurrentOs())
Files.createFile(testdir.getPath().toRealPath().resolve("unrelated.txt"),
Files.createFile(testdir.toRealPath().resolve("unrelated.txt"),
PosixFilePermissions.asFileAttribute(EnumSet.noneOf(PosixFilePermission.class)));
else
Files.createFile(testdir.getPath().toRealPath().resolve("unrelated.txt"));
Files.createFile(testdir.toRealPath().resolve("unrelated.txt"));
Scanner scanner = store.getBean(Scanner.class);
CountDownLatch latch = new CountDownLatch(2);
@ -307,8 +288,6 @@ public class PropertyUserStoreTest
@Test
public void testPropertyUserStoreLoadRemoveUser() throws Exception
{
testdir.ensureEmpty();
final UserCount userCount = new UserCount();
// initial user file (3) users
final Path usersFile = initUsersText();

View File

@ -35,7 +35,6 @@ import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.session.DefaultSessionCache;
import org.eclipse.jetty.session.FileSessionDataStore;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.component.LifeCycle;
import org.hamcrest.Matchers;
@ -56,7 +55,7 @@ public abstract class AbstractDoSFilterTest
private ServerConnector _connector;
protected long _requestMaxTime = 200;
public void startServer(WorkDir workDir, Class<? extends Filter> filter) throws Exception
public void startServer(Path workDir, Class<? extends Filter> filter) throws Exception
{
_server = new Server();
_connector = new ServerConnector(_server);
@ -66,7 +65,7 @@ public abstract class AbstractDoSFilterTest
DefaultSessionCache sessionCache = new DefaultSessionCache(context.getSessionHandler());
FileSessionDataStore fileStore = new FileSessionDataStore();
Path p = workDir.getPathFile("sessions");
Path p = workDir.resolve("sessions");
FS.ensureEmpty(p);
fileStore.setStoreDir(p.toFile());
sessionCache.setSessionDataStore(fileStore);

View File

@ -32,24 +32,20 @@ import java.util.zip.InflaterInputStream;
import org.eclipse.jetty.http.HttpTester;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.IO;
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.TypeUtil;
import org.junit.jupiter.api.extension.ExtendWith;
import static java.nio.charset.StandardCharsets.UTF_8;
@ExtendWith(WorkDirExtension.class)
public abstract class AbstractGzipTest
{
protected static final int DEFAULT_OUTPUT_BUFFER_SIZE = new HttpConfiguration().getOutputBufferSize();
protected Path workDir;
public AbstractGzipTest()
{
workDir = MavenTestingUtils.getTargetTestingPath(this.getClass().getName());
FS.ensureEmpty(workDir);
}
protected WorkDir workDir;
protected FilterInputStream newContentEncodingFilterInputStream(String contentEncoding, InputStream inputStream) throws IOException
{

View File

@ -26,6 +26,6 @@ public class CloseableDoSFilterTest extends AbstractDoSFilterTest
@BeforeEach
public void setUp() throws Exception
{
startServer(workDir, CloseableDoSFilter.class);
startServer(workDir.getEmptyPathDir(), CloseableDoSFilter.class);
}
}

View File

@ -163,7 +163,7 @@ public class GzipContentLengthTest extends AbstractGzipTest
LocalConnector localConnector = new LocalConnector(server);
server.addConnector(localConnector);
Path contextDir = workDir.resolve("context");
Path contextDir = workDir.getEmptyPathDir().resolve("context");
FS.ensureDirExists(contextDir);
ServletContextHandler servletContextHandler = new ServletContextHandler();

View File

@ -69,7 +69,7 @@ public class GzipDefaultServletDeferredContentTypeTest extends AbstractGzipTest
LocalConnector localConnector = new LocalConnector(server);
server.addConnector(localConnector);
Path contextDir = workDir.resolve("context");
Path contextDir = workDir.getEmptyPathDir().resolve("context");
FS.ensureDirExists(contextDir);
ServletContextHandler servletContextHandler = new ServletContextHandler();

View File

@ -92,7 +92,7 @@ public class GzipHandlerNoReCompressTest extends AbstractGzipTest
LocalConnector localConnector = new LocalConnector(server);
server.addConnector(localConnector);
Path contextDir = workDir.resolve("context");
Path contextDir = workDir.getEmptyPathDir().resolve("context");
FS.ensureDirExists(contextDir);
ServletContextHandler servletContextHandler = new ServletContextHandler();

View File

@ -81,12 +81,12 @@ public class DeploymentErrorTest
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
ResourceFactory resourceFactory = ResourceFactory.of(server);
// Empty contexts collections
contexts = new ContextHandlerCollection();
//Environment
Environment ee10 = Environment.ensure("ee10");
ee10.setAttribute("contextHandlerClass", "org.eclipse.jetty.ee10.webapp.WebAppContext");
@ -108,7 +108,7 @@ public class DeploymentErrorTest
System.setProperty("test.docroots", docroots.toAbsolutePath().toString());
ContextProvider appProvider = new ContextProvider();
appProvider.setEnvironmentName("ee10");
appProvider.setScanInterval(1);
appProvider.setMonitoredDirResource(resourceFactory.newResource(docroots));
deploymentManager.addAppProvider(appProvider);
@ -120,11 +120,11 @@ public class DeploymentErrorTest
// Setup Configurations
Configurations.setServerDefault(server)
.add("org.eclipse.jetty.ee10.plus.webapp.EnvConfiguration",
"org.eclipse.jetty.ee10.plus.webapp.PlusConfiguration",
"org.eclipse.jetty.ee10.annotations.AnnotationConfiguration",
TrackedConfiguration.class.getName()
);
.add("org.eclipse.jetty.ee10.plus.webapp.EnvConfiguration",
"org.eclipse.jetty.ee10.plus.webapp.PlusConfiguration",
"org.eclipse.jetty.ee10.annotations.AnnotationConfiguration",
TrackedConfiguration.class.getName()
);
server.start();
return docroots;
@ -404,4 +404,4 @@ public class DeploymentErrorTest
}
}
}
}
}

View File

@ -58,17 +58,10 @@ import static org.junit.jupiter.api.Assumptions.assumeFalse;
@ExtendWith(WorkDirExtension.class)
public class KeyStoreScannerTest
{
public WorkDir testdir;
private Server server;
private Path keystoreDir;
private KeyStoreScanner keyStoreScanner;
@BeforeEach
public void before()
{
keystoreDir = testdir.getEmptyPathDir();
}
@FunctionalInterface
public interface Configuration
{
@ -112,6 +105,12 @@ public class KeyStoreScannerTest
server.start();
}
@BeforeEach
public void setup(WorkDir workDir)
{
keystoreDir = workDir.getEmptyPathDir();
}
@AfterEach
public void stop() throws Exception
{

View File

@ -37,11 +37,8 @@ import org.eclipse.jetty.logging.StacklessLogging;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.Callback;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -94,7 +91,7 @@ public abstract class RFC2616BaseTest
* STRICT RFC TESTS
*/
private static final boolean STRICT = false;
private static XmlBasedJettyServer server;
private HttpTesting http;
class TestFile
@ -120,32 +117,25 @@ public abstract class RFC2616BaseTest
}
}
public static void setUpServer(XmlBasedJettyServer testableserver, Class<?> testclazz) throws Exception
public static XmlBasedJettyServer setUpServer(XmlBasedJettyServer testableserver, Class<?> testclazz, Path tmpPath) throws Exception
{
Path testWorkDir = MavenTestingUtils.getTargetTestingPath(testclazz.getName());
FS.ensureDirExists(testWorkDir);
System.setProperty("java.io.tmpdir", testWorkDir.toString());
server = testableserver;
XmlBasedJettyServer server = testableserver;
server.load();
server.getServer().setTempDirectory(tmpPath.toFile());
server.start();
return server;
}
@BeforeEach
public void setUp() throws Exception
{
http = new HttpTesting(getHttpClientSocket(), server.getServerPort());
}
@AfterAll
public static void tearDownServer() throws Exception
{
server.stop();
http = new HttpTesting(getHttpClientSocket(), getServer().getServerPort());
}
public abstract HttpSocket getHttpClientSocket() throws Exception;
public abstract XmlBasedJettyServer getServer();
/**
* Test Date/Time format Specs.
*
@ -1098,7 +1088,7 @@ public abstract class RFC2616BaseTest
specId = "10.3 Redirection HTTP/1.0 - basic";
assertThat(specId, response.getStatus(), is(HttpStatus.FOUND_302));
assertEquals(server.getScheme() + "://myhost:1234/tests/", response.get("Location"), specId);
assertEquals(getServer().getScheme() + "://myhost:1234/tests/", response.get("Location"), specId);
}
/**
@ -1127,12 +1117,12 @@ public abstract class RFC2616BaseTest
HttpTester.Response response = responses.get(0);
String specId = "10.3 Redirection HTTP/1.1 - basic (response 1)";
assertThat(specId, response.getStatus(), is(HttpStatus.FOUND_302));
assertEquals(server.getScheme() + "://localhost:" + server.getServerPort() + "/tests/", response.get("Location"), specId);
assertEquals(getServer().getScheme() + "://localhost:" + getServer().getServerPort() + "/tests/", response.get("Location"), specId);
response = responses.get(1);
specId = "10.3 Redirection HTTP/1.1 - basic (response 2)";
assertThat(specId, response.getStatus(), is(HttpStatus.FOUND_302));
assertEquals(server.getScheme() + "://localhost:" + server.getServerPort() + "/tests/", response.get("Location"), specId);
assertEquals(getServer().getScheme() + "://localhost:" + getServer().getServerPort() + "/tests/", response.get("Location"), specId);
assertEquals("close", response.get("Connection"), specId);
}
@ -1156,7 +1146,7 @@ public abstract class RFC2616BaseTest
String specId = "10.3 Redirection HTTP/1.0 w/content";
assertThat(specId, response.getStatus(), is(HttpStatus.FOUND_302));
assertEquals(server.getScheme() + "://localhost:" + server.getServerPort() + "/tests/R1.txt", response.get("Location"), specId);
assertEquals(getServer().getScheme() + "://localhost:" + getServer().getServerPort() + "/tests/R1.txt", response.get("Location"), specId);
}
/**
@ -1179,7 +1169,7 @@ public abstract class RFC2616BaseTest
String specId = "10.3 Redirection HTTP/1.1 w/content";
assertThat(specId + " [status]", response.getStatus(), is(HttpStatus.FOUND_302));
assertThat(specId + " [location]", response.get("Location"), is(server.getScheme() + "://localhost:" + server.getServerPort() + "/tests/R2.txt"));
assertThat(specId + " [location]", response.get("Location"), is(getServer().getScheme() + "://localhost:" + getServer().getServerPort() + "/tests/R2.txt"));
assertThat(specId + " [connection]", response.get("Connection"), is("close"));
}

View File

@ -13,19 +13,28 @@
package org.eclipse.jetty.ee10.test.rfcs;
import java.nio.file.Path;
import org.eclipse.jetty.ee10.test.support.XmlBasedJettyServer;
import org.eclipse.jetty.ee10.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.ee10.test.support.rawhttp.HttpSocketImpl;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* Perform the RFC2616 tests against a server running with the Jetty NIO Connector and listening on standard HTTP.
*/
@ExtendWith(WorkDirExtension.class)
public class RFC2616NIOHttpTest extends RFC2616BaseTest
{
private static XmlBasedJettyServer xmlBasedJettyServer;
@BeforeAll
public static void setupServer() throws Exception
public static void setupServer(WorkDir workDir) throws Exception
{
XmlBasedJettyServer server = new XmlBasedJettyServer();
server.setScheme(HttpScheme.HTTP.asString());
@ -33,7 +42,7 @@ public class RFC2616NIOHttpTest extends RFC2616BaseTest
server.addXmlConfiguration("RFC2616_Redirects.xml");
server.addXmlConfiguration("RFC2616_Filters.xml");
server.addXmlConfiguration("NIOHttp.xml");
setUpServer(server, RFC2616NIOHttpTest.class);
xmlBasedJettyServer = setUpServer(server, RFC2616NIOHttpTest.class, workDir.getEmptyPathDir());
}
@Override
@ -41,4 +50,16 @@ public class RFC2616NIOHttpTest extends RFC2616BaseTest
{
return new HttpSocketImpl();
}
@AfterAll
public static void tearDownServer() throws Exception
{
xmlBasedJettyServer.stop();
}
@Override
public XmlBasedJettyServer getServer()
{
return xmlBasedJettyServer;
}
}

View File

@ -13,20 +13,31 @@
package org.eclipse.jetty.ee10.test.rfcs;
import java.nio.file.Path;
import org.eclipse.jetty.ee10.test.support.XmlBasedJettyServer;
import org.eclipse.jetty.ee10.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.ee10.test.support.rawhttp.HttpsSocketImpl;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
/**
* Perform the RFC2616 tests against a server running with the Jetty NIO Connector and listening on HTTPS (HTTP over SSL).
*/
@ExtendWith(WorkDirExtension.class)
public class RFC2616NIOHttpsTest extends RFC2616BaseTest
{
private static XmlBasedJettyServer xmlBasedJettyServer;
@BeforeAll
public static void setupServer() throws Exception
public static void setupServer(WorkDir workDir) throws Exception
{
Path tmpPath = workDir.getEmptyPathDir();
XmlBasedJettyServer server = new XmlBasedJettyServer();
server.setScheme(HttpScheme.HTTPS.asString());
server.addXmlConfiguration("RFC2616Base.xml");
@ -34,7 +45,7 @@ public class RFC2616NIOHttpsTest extends RFC2616BaseTest
server.addXmlConfiguration("RFC2616_Filters.xml");
server.addXmlConfiguration("ssl.xml");
server.addXmlConfiguration("NIOHttps.xml");
setUpServer(server, RFC2616NIOHttpsTest.class);
xmlBasedJettyServer = setUpServer(server, RFC2616NIOHttpsTest.class, tmpPath);
}
@Override
@ -42,4 +53,16 @@ public class RFC2616NIOHttpsTest extends RFC2616BaseTest
{
return new HttpsSocketImpl();
}
@AfterAll
public static void tearDownServer() throws Exception
{
xmlBasedJettyServer.stop();
}
@Override
public XmlBasedJettyServer getServer()
{
return xmlBasedJettyServer;
}
}

View File

@ -158,7 +158,7 @@ public class XmlBasedJettyServer
assertEquals(1, serverCount, "Server load count");
this._server = foundServer;
this._server.setStopTimeout(2000);
this._server.setStopTimeout(10000);
}
public String getScheme()

View File

@ -9,6 +9,7 @@
<artifactId>jetty-ee10-test-loginservice</artifactId>
<name>EE10 :: Tests :: Login Service</name>
<properties>
<junit.jupiter.execution.parallel.enabled>false</junit.jupiter.execution.parallel.enabled>
<bundle-symbolic-name>${project.groupId}.loginservice</bundle-symbolic-name>
</properties>
<dependencies>

Some files were not shown because too many files have changed in this diff Show More