Skip to content

Commit

Permalink
Merge pull request #8706 from eclipse/fix/jetty-12-util-windows-tests
Browse files Browse the repository at this point in the history
Jetty 12 - Fixing `jetty-util` Tests on Windows
  • Loading branch information
joakime authored Oct 12, 2022
2 parents 48c085d + 5ee1d91 commit acb13e2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public void testToMappedBufferResource() throws Exception
Path testZip = MavenTestingUtils.getTestResourcePathFile("TestData/test.zip");
Path testTxt = MavenTestingUtils.getTestResourcePathFile("TestData/alphabet.txt");

Resource fileResource = ResourceFactory.root().newResource("file:" + testTxt.toAbsolutePath());
Resource fileResource = ResourceFactory.root().newResource(testTxt.toUri());
ByteBuffer fileBuffer = BufferUtil.toMappedBuffer(fileResource);
assertThat(fileBuffer, not(nullValue()));
assertThat((long)fileBuffer.remaining(), is(fileResource.length()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -25,6 +26,7 @@
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.Assumptions;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -350,8 +352,18 @@ public void testIsArchiveUriTrue(String rawUri)
})
public void testIsClassFileFalse(String input) throws IOException
{
Path testPath = touchTestPath(input);
assertFalse(FileID.isClassFile(testPath), "isClassFile(" + testPath + ")");
try
{
Path testPath = touchTestPath(input);
assertFalse(FileID.isClassFile(testPath), "isClassFile(" + testPath + ")");
}
catch (InvalidPathException e)
{
// Some filesystems don't like things like tab "\t" character.
// Windows NTFS and Fat will throw and InvalidPathException.
// While jarfs, linux ext4, linux zfs, etc won't
Assumptions.assumeFalse(true);
}
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1130,12 +1130,35 @@ public void testToJarFileUri(String inputRawUri, String expectedRawUri)

public static Stream<Arguments> unwrapContainerCases()
{
return Stream.of(
Arguments.of("/path/to/foo.jar", "file:///path/to/foo.jar"),
Arguments.of("/path/to/bogus.txt", "file:///path/to/bogus.txt"),
Arguments.of("file:///path/to/zed.jar", "file:///path/to/zed.jar"),
Arguments.of("jar:file:///path/to/bar.jar!/internal.txt", "file:///path/to/bar.jar")
);
List<Arguments> args = new ArrayList<>();

if (OS.WINDOWS.isCurrentOs())
{
// Windows format (absolute and relative)
args.add(Arguments.of("C:\\path\\to\\foo.jar", "file:///C:/path/to/foo.jar"));
args.add(Arguments.of("D:\\path\\to\\bogus.txt", "file:///D:/path/to/bogus.txt"));
args.add(Arguments.of("\\path\\to\\foo.jar", "file:///C:/path/to/foo.jar"));
args.add(Arguments.of("\\path\\to\\bogus.txt", "file:///C:/path/to/bogus.txt"));
// unix format (relative)
args.add(Arguments.of("C:/path/to/foo.jar", "file:///C:/path/to/foo.jar"));
args.add(Arguments.of("D:/path/to/bogus.txt", "file:///D:/path/to/bogus.txt"));
args.add(Arguments.of("/path/to/foo.jar", "file:///C:/path/to/foo.jar"));
args.add(Arguments.of("/path/to/bogus.txt", "file:///C:/path/to/bogus.txt"));
// URI format (absolute)
args.add(Arguments.of("file:///D:/path/to/zed.jar", "file:///D:/path/to/zed.jar"));
args.add(Arguments.of("jar:file:///E:/path/to/bar.jar!/internal.txt", "file:///E:/path/to/bar.jar"));
}
else
{
// URI (and unix) format (relative)
args.add(Arguments.of("/path/to/foo.jar", "file:///path/to/foo.jar"));
args.add(Arguments.of("/path/to/bogus.txt", "file:///path/to/bogus.txt"));
}
// URI format (absolute)
args.add(Arguments.of("file:///path/to/zed.jar", "file:///path/to/zed.jar"));
args.add(Arguments.of("jar:file:///path/to/bar.jar!/internal.txt", "file:///path/to/bar.jar"));

return args.stream();
}

@ParameterizedTest
Expand All @@ -1162,8 +1185,9 @@ public void testSplitSingleJar()
public void testSplitSinglePath()
{
String input = "/home/user/lib/acme.jar";
Path path = Path.of(input);
List<URI> uris = URIUtil.split(input);
String expected = String.format("jar:file://%s!/", input);
String expected = String.format("jar:%s!/", path.toUri().toASCIIString());
assertThat(uris.get(0).toString(), is(expected));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -1146,18 +1145,19 @@ public void testResolveWindowsSlash() throws Exception
assertThat("Target URI: " + basePath, base, hasNoTargetURI());

Resource r = base.resolve("aa%5C/foo.txt");
assertThat("getURI()", r.getPath().toString(), containsString("aa\\/foo.txt"));
assertThat("getURI()", r.getURI().toASCIIString(), containsString("aa%5C/foo.txt"));

if (org.junit.jupiter.api.condition.OS.WINDOWS.isCurrentOs())
if (WINDOWS.isCurrentOs())
{
assertThat("getPath().toString()", r.getPath().toString(), containsString("aa\\foo.txt"));
assertThat("isAlias()", r.isAlias(), is(true));
assertThat("getTargetURI()", r.getTargetURI(), notNullValue());
assertThat("getTargetURI()", r.getTargetURI().toASCIIString(), containsString("aa/foo.txt"));
assertThat("Exists: " + r, r.exists(), is(true));
}
else
{
assertThat("getPath().toString()", r.getPath().toString(), containsString("aa\\/foo.txt"));
assertThat("isAlias()", r.isAlias(), is(false));
assertThat("Exists: " + r, r.exists(), is(false));
}
Expand Down Expand Up @@ -1191,7 +1191,7 @@ public void testResolveWindowsExtensionLess() throws Exception
Resource r = base.resolve("aa./foo.txt");
assertThat("getURI()", r.getURI().toASCIIString(), containsString("aa./foo.txt"));

if (OS.WINDOWS.isCurrentOs())
if (WINDOWS.isCurrentOs())
{
assertThat("isAlias()", r.isAlias(), is(true));
assertThat("getTargetURI()", r.getTargetURI(), notNullValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void testDumpAndSweep(WorkDir workDir) throws Exception
System.out.println(dump);
assertThat(dump, containsString("FileSystemPool"));
assertThat(dump, containsString("buckets size=1"));
assertThat(dump, containsString("/test.zip#1"));
assertThat(dump, containsString(testZip + "#1"));

Files.delete(testZip);
FileSystemPool.INSTANCE.sweep();
Expand Down

0 comments on commit acb13e2

Please sign in to comment.