From be3b8f0b9d03bac1503140c739d657e5fa076fff Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 16 Jan 2023 11:33:43 -0600 Subject: [PATCH] Issue #9167 - making assumption in flaky test --- .../util/resource/ResourceFactoryTest.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceFactoryTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceFactoryTest.java index aa8dc944deba..8b772b191cc1 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceFactoryTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceFactoryTest.java @@ -13,9 +13,14 @@ package org.eclipse.jetty.util.resource; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URI; +import java.net.URL; import java.nio.file.Path; +import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -62,8 +67,22 @@ public void testCustomUriSchemeRegistered() } @Test - public void testRegisterHttpsUrlFactory() + public void testRegisterHttpsUrlFactory() throws MalformedURLException { + URI uri = URI.create("https://webtide.com/"); + + // Verify that environment can access the URI. + URL url = uri.toURL(); + try + { + HttpURLConnection http = (HttpURLConnection)url.openConnection(); + Assumptions.assumeTrue(http.getResponseCode() == HttpURLConnection.HTTP_OK); + } + catch (IOException e) + { + Assumptions.abort("Unable to connect to " + uri); + } + ResourceFactory.registerResourceFactory("https", new URLResourceFactory()); // Try as a normal String input Resource resource = ResourceFactory.root().newResource("https://webtide.com/"); @@ -71,7 +90,6 @@ public void testRegisterHttpsUrlFactory() assertThat(resource.getName(), is("https://webtide.com/")); // Try as a formal URI object as input - URI uri = URI.create("https://webtide.com/"); resource = ResourceFactory.root().newResource(uri); assertThat(resource.getURI(), is(URI.create("https://webtide.com/"))); assertThat(resource.getName(), is("https://webtide.com/"));