From 24b2ca4c328fcc22a1c1534d39ea2970920b1ac4 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 25 Jul 2019 11:43:51 -0500 Subject: [PATCH] Issue #3906 - Introducing Testcase to demonstrate issue Signed-off-by: Joakim Erdfelt --- .../jetty/util/resource/PathResourceTest.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java new file mode 100644 index 00000000000..e12646f5bdc --- /dev/null +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java @@ -0,0 +1,71 @@ +// +// ======================================================================== +// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.util.resource; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.channels.ReadableByteChannel; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +public class PathResourceTest +{ + @Test + public void testNonDefaultFileSystem_GetInputStream() throws URISyntaxException, IOException + { + Path exampleJar = MavenTestingUtils.getTestResourcePathFile("example.jar"); + + URI uri = new URI("jar", exampleJar.toUri().toASCIIString(), null); + System.err.println("URI = " + uri); + + Map env = new HashMap<>(); + env.put("multi-release", "runtime"); + + try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) + { + Path manifestPath = zipfs.getPath("/META-INF/MANIFEST.MF"); + assertThat(manifestPath, is(not(nullValue()))); + + PathResource resource = new PathResource(manifestPath); + + try (ReadableByteChannel channel = resource.getReadableByteChannel()) + { + assertThat("ReadableByteChannel", channel, is(not(nullValue()))); + } + + try (InputStream inputStream = resource.getInputStream()) + { + assertThat("InputStream", inputStream, is(not(nullValue()))); + } + } + } +}