diff --git a/src/main/java/io/cryostat/net/web/http/api/v1/TargetRecordingPatchSave.java b/src/main/java/io/cryostat/net/web/http/api/v1/TargetRecordingPatchSave.java index aefb82bd5b..be21681941 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v1/TargetRecordingPatchSave.java +++ b/src/main/java/io/cryostat/net/web/http/api/v1/TargetRecordingPatchSave.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.nio.file.Path; import java.time.temporal.ChronoUnit; import java.util.Map; @@ -58,6 +59,7 @@ import io.cryostat.net.TargetConnectionManager; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.platform.PlatformClient; +import io.cryostat.util.URIUtil; import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.handler.impl.HttpStatusException; @@ -140,10 +142,12 @@ private String saveRecording(JFRConnection connection, IRecordingDescriptor desc serviceRef -> { try { return serviceRef - .getJMXServiceUrl() - .equals(connection.getJMXURL()) + .getServiceUri() + .equals( + URIUtil.convert( + connection.getJMXURL())) && serviceRef.getAlias().isPresent(); - } catch (IOException ioe) { + } catch (URISyntaxException | IOException ioe) { return false; } }) diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/TargetDeleteHandler.java b/src/main/java/io/cryostat/net/web/http/api/v2/TargetDeleteHandler.java index 2184443b80..09268b0a1e 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/TargetDeleteHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/TargetDeleteHandler.java @@ -38,15 +38,16 @@ package io.cryostat.net.web.http.api.v2; import java.io.IOException; -import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import javax.inject.Inject; -import javax.management.remote.JMXServiceURL; import io.cryostat.net.AuthManager; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.net.web.http.api.ApiVersion; import io.cryostat.platform.internal.CustomTargetPlatformClient; +import io.cryostat.util.URIUtil; import com.google.gson.Gson; import io.vertx.core.http.HttpMethod; @@ -105,13 +106,13 @@ public IntermediateResponse handle(RequestParameters params) throws ApiExc if (StringUtils.isBlank(targetId)) { throw new ApiException(400, "Invalid targetId"); } - JMXServiceURL serviceUrl = new JMXServiceURL(targetId); - if (!customTargetPlatformClient.removeTarget(serviceUrl)) { + URI uri = URIUtil.createAbsolute(targetId); + if (!customTargetPlatformClient.removeTarget(uri)) { throw new ApiException(404); } return new IntermediateResponse().body(null); - } catch (MalformedURLException mue) { - throw new ApiException(400, "Invalid targetId", mue); + } catch (URISyntaxException use) { + throw new ApiException(400, "Invalid targetId", use); } catch (IOException ioe) { throw new ApiException(500, "Internal Error", ioe); } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/TargetsPostHandler.java b/src/main/java/io/cryostat/net/web/http/api/v2/TargetsPostHandler.java index 98f2c5e632..4930f71adf 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/TargetsPostHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/TargetsPostHandler.java @@ -38,11 +38,11 @@ package io.cryostat.net.web.http.api.v2; import java.io.IOException; -import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.util.Objects; import javax.inject.Inject; -import javax.management.remote.JMXServiceURL; import io.cryostat.net.AuthManager; import io.cryostat.net.web.http.HttpMimeType; @@ -50,6 +50,7 @@ import io.cryostat.platform.PlatformClient; import io.cryostat.platform.ServiceRef; import io.cryostat.platform.internal.CustomTargetPlatformClient; +import io.cryostat.util.URIUtil; import com.google.gson.Gson; import io.vertx.core.MultiMap; @@ -121,19 +122,20 @@ public IntermediateResponse handle(RequestParameters params) throws if (StringUtils.isBlank(alias)) { throw new ApiException(400, "\"alias\" form parameter must be provided"); } - JMXServiceURL jmxServiceURL = new JMXServiceURL(connectUrl); - if (platformClient.listDiscoverableServices().stream() - .anyMatch(sr -> Objects.equals(jmxServiceURL, sr.getJMXServiceUrl()))) { - throw new ApiException(400, "Duplicate connectUrl"); + URI uri = URIUtil.createAbsolute(connectUrl); + for (ServiceRef serviceRef : platformClient.listDiscoverableServices()) { + if (Objects.equals(uri, serviceRef.getServiceUri())) { + throw new ApiException(400, "Duplicate connectUrl"); + } } - ServiceRef serviceRef = new ServiceRef(jmxServiceURL, alias); + ServiceRef serviceRef = new ServiceRef(uri, alias); boolean v = customTargetPlatformClient.addTarget(serviceRef); if (!v) { throw new ApiException(400, "Duplicate connectUrl"); } return new IntermediateResponse().body(serviceRef); - } catch (MalformedURLException mue) { - throw new ApiException(400, "Invalid connectUrl", mue); + } catch (URISyntaxException use) { + throw new ApiException(400, "Invalid connectUrl", use); } catch (IOException ioe) { throw new ApiException(500, "Internal Error", ioe); } diff --git a/src/main/java/io/cryostat/platform/ServiceRef.java b/src/main/java/io/cryostat/platform/ServiceRef.java index 7762a29867..ed8066f198 100644 --- a/src/main/java/io/cryostat/platform/ServiceRef.java +++ b/src/main/java/io/cryostat/platform/ServiceRef.java @@ -37,13 +37,9 @@ */ package io.cryostat.platform; -import java.net.MalformedURLException; +import java.net.URI; import java.util.Optional; -import javax.management.remote.JMXServiceURL; - -import io.cryostat.core.net.JFRConnectionToolkit; - import com.google.gson.annotations.SerializedName; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -51,25 +47,16 @@ public class ServiceRef { - private final @SerializedName("connectUrl") JMXServiceURL JMXServiceURL; + private final @SerializedName("connectUrl") URI serviceUri; private final String alias; - public ServiceRef(JMXServiceURL jmxServiceUrl, String alias) throws MalformedURLException { - this.JMXServiceURL = jmxServiceUrl; + public ServiceRef(URI uri, String alias) { + this.serviceUri = uri; this.alias = alias; } - public ServiceRef(JMXServiceURL jmxServiceUrl) throws MalformedURLException { - this(jmxServiceUrl, null); - } - - public ServiceRef(JFRConnectionToolkit toolkit, String host, int port, String alias) - throws MalformedURLException { - this(toolkit.createServiceURL(host, port), alias); - } - - public JMXServiceURL getJMXServiceUrl() { - return JMXServiceURL; + public URI getServiceUri() { + return serviceUri; } public Optional getAlias() { diff --git a/src/main/java/io/cryostat/platform/internal/CustomTargetPlatformClient.java b/src/main/java/io/cryostat/platform/internal/CustomTargetPlatformClient.java index e28e7d9807..cca8526be9 100644 --- a/src/main/java/io/cryostat/platform/internal/CustomTargetPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/CustomTargetPlatformClient.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.Reader; +import java.net.URI; import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.ArrayList; @@ -48,7 +49,6 @@ import java.util.TreeSet; import javax.inject.Named; -import javax.management.remote.JMXServiceURL; import io.cryostat.MainModule; import io.cryostat.core.net.discovery.JvmDiscoveryClient.EventKind; @@ -74,12 +74,7 @@ public CustomTargetPlatformClient( FileSystem fs, Gson gson) { super(notificationFactory); - this.targets = - new TreeSet<>( - (u1, u2) -> - u1.getJMXServiceUrl() - .toString() - .compareTo(u2.getJMXServiceUrl().toString())); + this.targets = new TreeSet<>((u1, u2) -> u1.getServiceUri().compareTo(u2.getServiceUri())); this.saveFile = confDir.resolve(SAVEFILE_NAME); this.fs = fs; this.gson = gson; @@ -121,10 +116,10 @@ public boolean removeTarget(ServiceRef serviceRef) throws IOException { return v; } - public boolean removeTarget(JMXServiceURL connectUrl) throws IOException { + public boolean removeTarget(URI connectUrl) throws IOException { ServiceRef ref = null; for (ServiceRef target : targets) { - if (Objects.equals(connectUrl, target.getJMXServiceUrl())) { + if (Objects.equals(connectUrl, target.getServiceUri())) { ref = target; break; } diff --git a/src/main/java/io/cryostat/platform/internal/DefaultPlatformClient.java b/src/main/java/io/cryostat/platform/internal/DefaultPlatformClient.java index d2cb6256e1..86b584c9b8 100644 --- a/src/main/java/io/cryostat/platform/internal/DefaultPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/DefaultPlatformClient.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.net.MalformedURLException; +import java.net.URISyntaxException; import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -48,6 +49,7 @@ import io.cryostat.core.net.discovery.JvmDiscoveryClient.JvmDiscoveryEvent; import io.cryostat.messaging.notifications.NotificationFactory; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; class DefaultPlatformClient extends AbstractPlatformClient implements Consumer { @@ -74,10 +76,10 @@ public void accept(JvmDiscoveryEvent evt) { try { ServiceRef serviceRef = new ServiceRef( - evt.getJvmDescriptor().getJmxServiceUrl(), + URIUtil.convert(evt.getJvmDescriptor().getJmxServiceUrl()), evt.getJvmDescriptor().getMainClass()); notifyAsyncTargetDiscovery(evt.getEventKind(), serviceRef); - } catch (MalformedURLException e) { + } catch (MalformedURLException | URISyntaxException e) { logger.warn(e); } } @@ -88,8 +90,9 @@ public List listDiscoverableServices() { .map( u -> { try { - return new ServiceRef(u.getJmxServiceUrl(), u.getMainClass()); - } catch (MalformedURLException e) { + return new ServiceRef( + URIUtil.convert(u.getJmxServiceUrl()), u.getMainClass()); + } catch (MalformedURLException | URISyntaxException e) { logger.warn(e); return null; } diff --git a/src/main/java/io/cryostat/platform/internal/KubeApiPlatformClient.java b/src/main/java/io/cryostat/platform/internal/KubeApiPlatformClient.java index 173dde0e17..63f2fe61b5 100644 --- a/src/main/java/io/cryostat/platform/internal/KubeApiPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/KubeApiPlatformClient.java @@ -49,6 +49,7 @@ import io.cryostat.core.net.discovery.JvmDiscoveryClient.EventKind; import io.cryostat.messaging.notifications.NotificationFactory; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import dagger.Lazy; import io.fabric8.kubernetes.api.model.EndpointPort; @@ -174,9 +175,11 @@ private List createServiceRefs(EndpointSubset subset, EndpointPort p addr -> { try { return new ServiceRef( - connectionToolkit.get(), - addr.getIp(), - port.getPort(), + URIUtil.convert( + connectionToolkit + .get() + .createServiceURL( + addr.getIp(), port.getPort())), addr.getTargetRef().getName()); } catch (Exception e) { logger.warn(e); diff --git a/src/main/java/io/cryostat/platform/internal/KubeEnvPlatformClient.java b/src/main/java/io/cryostat/platform/internal/KubeEnvPlatformClient.java index 531a8a6d36..0b8b9cb72a 100644 --- a/src/main/java/io/cryostat/platform/internal/KubeEnvPlatformClient.java +++ b/src/main/java/io/cryostat/platform/internal/KubeEnvPlatformClient.java @@ -50,6 +50,7 @@ import io.cryostat.core.sys.Environment; import io.cryostat.platform.PlatformClient; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import dagger.Lazy; @@ -87,7 +88,10 @@ private ServiceRef envToServiceRef(Map.Entry entry) { String alias = matcher.group(1).toLowerCase(); int port = Integer.parseInt(matcher.group(2)); try { - return new ServiceRef(connectionToolkit.get(), entry.getValue(), port, alias); + return new ServiceRef( + URIUtil.convert( + connectionToolkit.get().createServiceURL(entry.getValue(), port)), + alias); } catch (Exception e) { logger.warn(e); return null; diff --git a/src/main/java/io/cryostat/util/RelativeURIException.java b/src/main/java/io/cryostat/util/RelativeURIException.java new file mode 100644 index 0000000000..017ab28096 --- /dev/null +++ b/src/main/java/io/cryostat/util/RelativeURIException.java @@ -0,0 +1,48 @@ +/* + * Copyright The Cryostat Authors + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or data + * (collectively the "Software"), free of charge and under any and all copyright + * rights in the Software, and any and all patent rights owned or freely + * licensable by each licensor hereunder covering either (i) the unmodified + * Software as contributed to or provided by such licensor, or (ii) the Larger + * Works (as defined below), to deal in both + * + * (a) the Software, and + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software (each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * The above copyright notice and either this complete permission notice or at + * a minimum a reference to the UPL must be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.cryostat.util; + +import java.net.URI; +import java.net.URISyntaxException; + +@SuppressWarnings("serial") +public class RelativeURIException extends URISyntaxException { + public RelativeURIException(URI u) { + super(u.toString(), "Not a valid absolute URI"); + } +} diff --git a/src/main/java/io/cryostat/util/URIUtil.java b/src/main/java/io/cryostat/util/URIUtil.java new file mode 100644 index 0000000000..4a041e90e3 --- /dev/null +++ b/src/main/java/io/cryostat/util/URIUtil.java @@ -0,0 +1,59 @@ +/* + * Copyright The Cryostat Authors + * + * The Universal Permissive License (UPL), Version 1.0 + * + * Subject to the condition set forth below, permission is hereby granted to any + * person obtaining a copy of this software, associated documentation and/or data + * (collectively the "Software"), free of charge and under any and all copyright + * rights in the Software, and any and all patent rights owned or freely + * licensable by each licensor hereunder covering either (i) the unmodified + * Software as contributed to or provided by such licensor, or (ii) the Larger + * Works (as defined below), to deal in both + * + * (a) the Software, and + * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if + * one is included with the Software (each a "Larger Work" to which the Software + * is contributed by such licensors), + * + * without restriction, including without limitation the rights to copy, create + * derivative works of, display, perform, and distribute the Software and make, + * use, sell, offer for sale, import, export, have made, and have sold the + * Software and the Larger Work(s), and to sublicense the foregoing rights on + * either these or other terms. + * + * This license is subject to the following condition: + * The above copyright notice and either this complete permission notice or at + * a minimum a reference to the UPL must be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package io.cryostat.util; + +import java.net.URI; +import java.net.URISyntaxException; + +import javax.management.remote.JMXServiceURL; + +public class URIUtil { + private URIUtil() {} + + public static URI createAbsolute(String uri) throws URISyntaxException, RelativeURIException { + URI u = new URI(uri); + if (!u.isAbsolute()) { + throw new RelativeURIException(u); + } + return u; + } + + public static URI convert(JMXServiceURL serviceUrl) throws URISyntaxException { + return new URI(serviceUrl.toString()); + } +} diff --git a/src/test/java/io/cryostat/net/web/WebServerTest.java b/src/test/java/io/cryostat/net/web/WebServerTest.java index 2c1950afb6..65349fd2a7 100644 --- a/src/test/java/io/cryostat/net/web/WebServerTest.java +++ b/src/test/java/io/cryostat/net/web/WebServerTest.java @@ -69,7 +69,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) @@ -154,10 +153,10 @@ void shouldProvideSavedDownloadUrl(String recordingName) void shouldProvideDownloadUrl(String recordingName) throws URISyntaxException, IOException { when(netConf.getWebServerHost()).thenReturn("example.com"); when(netConf.getExternalWebServerPort()).thenReturn(8181); - JMXServiceURL mockJmxUrl = Mockito.mock(JMXServiceURL.class); - when(mockJmxUrl.toString()) - .thenReturn("service:jmx:rmi://localhost:9091/jndi/rmi://fooHost:9091/jmxrmi"); - when(connection.getJMXURL()).thenReturn(mockJmxUrl); + JMXServiceURL jmxUrl = + new JMXServiceURL( + "service:jmx:rmi://localhost:9091/jndi/rmi://fooHost:9091/jmxrmi"); + when(connection.getJMXURL()).thenReturn(jmxUrl); MatcherAssert.assertThat( exporter.getDownloadURL(connection, recordingName), @@ -174,10 +173,10 @@ void shouldProvideDownloadUrlWithHttps(String recordingName) when(httpServer.isSsl()).thenReturn(true); when(netConf.getWebServerHost()).thenReturn("example.com"); when(netConf.getExternalWebServerPort()).thenReturn(8181); - JMXServiceURL mockJmxUrl = Mockito.mock(JMXServiceURL.class); - when(mockJmxUrl.toString()) - .thenReturn("service:jmx:rmi://localhost:9091/jndi/rmi://fooHost:9091/jmxrmi"); - when(connection.getJMXURL()).thenReturn(mockJmxUrl); + JMXServiceURL jmxUrl = + new JMXServiceURL( + "service:jmx:rmi://localhost:9091/jndi/rmi://fooHost:9091/jmxrmi"); + when(connection.getJMXURL()).thenReturn(jmxUrl); MatcherAssert.assertThat( exporter.getDownloadURL(connection, recordingName), @@ -192,10 +191,10 @@ void shouldProvideDownloadUrlWithHttps(String recordingName) void shouldProvideReportUrl(String recordingName) throws URISyntaxException, IOException { when(netConf.getWebServerHost()).thenReturn("example.com"); when(netConf.getExternalWebServerPort()).thenReturn(8181); - JMXServiceURL mockJmxUrl = Mockito.mock(JMXServiceURL.class); - when(mockJmxUrl.toString()) - .thenReturn("service:jmx:rmi://localhost:9091/jndi/rmi://fooHost:9091/jmxrmi"); - when(connection.getJMXURL()).thenReturn(mockJmxUrl); + JMXServiceURL jmxUrl = + new JMXServiceURL( + "service:jmx:rmi://localhost:9091/jndi/rmi://fooHost:9091/jmxrmi"); + when(connection.getJMXURL()).thenReturn(jmxUrl); MatcherAssert.assertThat( exporter.getReportURL(connection, recordingName), @@ -226,10 +225,10 @@ void shouldProvideReportUrlWithHttps(String recordingName) when(httpServer.isSsl()).thenReturn(true); when(netConf.getWebServerHost()).thenReturn("example.com"); when(netConf.getExternalWebServerPort()).thenReturn(8181); - JMXServiceURL mockJmxUrl = Mockito.mock(JMXServiceURL.class); - when(mockJmxUrl.toString()) - .thenReturn("service:jmx:rmi://localhost:9091/jndi/rmi://fooHost:9091/jmxrmi"); - when(connection.getJMXURL()).thenReturn(mockJmxUrl); + JMXServiceURL jmxUrl = + new JMXServiceURL( + "service:jmx:rmi://localhost:9091/jndi/rmi://fooHost:9091/jmxrmi"); + when(connection.getJMXURL()).thenReturn(jmxUrl); MatcherAssert.assertThat( exporter.getReportURL(connection, recordingName), diff --git a/src/test/java/io/cryostat/net/web/http/api/v1/TargetRecordingPatchSaveTest.java b/src/test/java/io/cryostat/net/web/http/api/v1/TargetRecordingPatchSaveTest.java index 084a33e581..4f54e5efb2 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v1/TargetRecordingPatchSaveTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v1/TargetRecordingPatchSaveTest.java @@ -61,6 +61,7 @@ import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.platform.PlatformClient; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import io.vertx.core.http.HttpServerResponse; import io.vertx.ext.web.RoutingContext; @@ -175,15 +176,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable { ServiceRef serviceRef1 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi")), "some.Alias.1"); ServiceRef serviceRef2 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi")), "some.Alias.2"); ServiceRef serviceRef3 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi")), "some.Alias.3"); Mockito.when(platformClient.listDiscoverableServices()) @@ -246,14 +253,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable { ServiceRef serviceRef1 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi")), "some.Alias.1"); ServiceRef serviceRef2 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi")); + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi")), + null); ServiceRef serviceRef3 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi")), "some.Alias.3"); Mockito.when(platformClient.listDiscoverableServices()) @@ -304,11 +318,15 @@ public Object answer(InvocationOnMock invocation) throws Throwable { ServiceRef serviceRef1 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi")), "some.Alias.1"); ServiceRef serviceRef3 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi")), "some.Alias.3"); Mockito.when(platformClient.listDiscoverableServices()) @@ -361,15 +379,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable { ServiceRef serviceRef1 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi")), "some.Alias.1"); ServiceRef serviceRef2 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi")), "some.Alias.2"); ServiceRef serviceRef3 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi")), "some.Alias.3"); Mockito.when(platformClient.listDiscoverableServices()) @@ -419,15 +443,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable { ServiceRef serviceRef1 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi")), "some.Alias.1"); ServiceRef serviceRef2 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi")), "some.Alias.2"); ServiceRef serviceRef3 = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9093/jmxrmi")), "some.Alias.3"); Mockito.when(platformClient.listDiscoverableServices()) diff --git a/src/test/java/io/cryostat/net/web/http/api/v1/TargetsGetHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v1/TargetsGetHandlerTest.java index a5dbeea87c..a0b136f563 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v1/TargetsGetHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v1/TargetsGetHandlerTest.java @@ -48,6 +48,7 @@ import io.cryostat.net.AuthManager; import io.cryostat.platform.PlatformClient; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -107,7 +108,9 @@ public JMXServiceURL answer(InvocationOnMock args) throws Throwable { String.format("/jndi/rmi://%s:%s/jmxrmi", host, port)); } }); - ServiceRef target = new ServiceRef(connectionToolkit, "foo", 1, "foo"); + ServiceRef target = + new ServiceRef( + URIUtil.convert(connectionToolkit.createServiceURL("foo", 1)), "foo"); List targets = Collections.singletonList(target); Mockito.when(platformClient.listDiscoverableServices()).thenReturn(targets); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/TargetDeleteHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/TargetDeleteHandlerTest.java index ce9c82e695..e551055ce7 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/TargetDeleteHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/TargetDeleteHandlerTest.java @@ -38,11 +38,11 @@ package io.cryostat.net.web.http.api.v2; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; -import javax.management.remote.JMXServiceURL; - import io.cryostat.MainModule; import io.cryostat.core.log.Logger; import io.cryostat.net.AuthManager; @@ -116,11 +116,11 @@ void shouldBeOrdered() { } @Test - void testSuccessfulRequest() throws IOException { + void testSuccessfulRequest() throws IOException, URISyntaxException { Map pathParams = new HashMap<>(); RequestParameters requestParameters = Mockito.mock(RequestParameters.class); Mockito.when(requestParameters.getPathParams()).thenReturn(pathParams); - Mockito.when(customTargetPlatformClient.removeTarget(Mockito.any(JMXServiceURL.class))) + Mockito.when(customTargetPlatformClient.removeTarget(Mockito.any(URI.class))) .thenReturn(true); String targetId = "service:jmx:rmi:///jndi/rmi://cryostat:9099/jmxrmi"; @@ -129,15 +129,15 @@ void testSuccessfulRequest() throws IOException { IntermediateResponse response = handler.handle(requestParameters); MatcherAssert.assertThat(response.getStatusCode(), Matchers.equalTo(200)); - ArgumentCaptor urlCaptor = ArgumentCaptor.forClass(JMXServiceURL.class); - Mockito.verify(customTargetPlatformClient).removeTarget(urlCaptor.capture()); - JMXServiceURL captured = urlCaptor.getValue(); - MatcherAssert.assertThat(captured, Matchers.equalTo(new JMXServiceURL(targetId))); + ArgumentCaptor uriCaptor = ArgumentCaptor.forClass(URI.class); + Mockito.verify(customTargetPlatformClient).removeTarget(uriCaptor.capture()); + URI captured = uriCaptor.getValue(); + MatcherAssert.assertThat(captured, Matchers.equalTo(new URI(targetId))); } @ParameterizedTest @NullAndEmptySource - @ValueSource(strings = {"badUrl", "bad:123", "http://example.com/foo"}) + @ValueSource(strings = {"badUrl", "/some/path", ":8181/another", ":1234/with/a?query=param"}) void testRequestWithBadTarget(String targetId) throws IOException { Map pathParams = new HashMap<>(); pathParams.put("targetId", targetId); @@ -155,7 +155,7 @@ void testRequestWithNonexistentTarget() throws IOException { Mockito.when(params.getPathParams()).thenReturn(pathParams); String targetId = "service:jmx:rmi:///jndi/rmi://cryostat:9099/jmxrmi"; pathParams.put("targetId", targetId); - Mockito.when(customTargetPlatformClient.removeTarget(Mockito.any(JMXServiceURL.class))) + Mockito.when(customTargetPlatformClient.removeTarget(Mockito.any(URI.class))) .thenReturn(false); ApiException ex = Assertions.assertThrows(ApiException.class, () -> handler.handle(params)); @@ -171,7 +171,7 @@ void testRequestWithIOException() throws IOException { pathParams.put("targetId", targetId); - Mockito.when(customTargetPlatformClient.removeTarget(Mockito.any(JMXServiceURL.class))) + Mockito.when(customTargetPlatformClient.removeTarget(Mockito.any(URI.class))) .thenThrow(IOException.class); ApiException ex = Assertions.assertThrows(ApiException.class, () -> handler.handle(params)); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/TargetsPostHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/TargetsPostHandlerTest.java index fd01d8f1f5..f108b53877 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/TargetsPostHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/TargetsPostHandlerTest.java @@ -38,11 +38,10 @@ package io.cryostat.net.web.http.api.v2; import java.io.IOException; +import java.net.URI; import java.util.List; import java.util.Optional; -import javax.management.remote.JMXServiceURL; - import io.cryostat.MainModule; import io.cryostat.core.log.Logger; import io.cryostat.net.AuthManager; @@ -121,7 +120,7 @@ void shouldBeOrdered() { } @Test - void testSuccessfulRequest() throws IOException { + void testSuccessfulRequest() throws Exception { MultiMap attrs = MultiMap.caseInsensitiveMultiMap(); RequestParameters requestParameters = Mockito.mock(RequestParameters.class); Mockito.when(requestParameters.getFormAttributes()).thenReturn(attrs); @@ -139,8 +138,7 @@ void testSuccessfulRequest() throws IOException { ArgumentCaptor refCaptor = ArgumentCaptor.forClass(ServiceRef.class); Mockito.verify(customTargetPlatformClient).addTarget(refCaptor.capture()); ServiceRef captured = refCaptor.getValue(); - MatcherAssert.assertThat( - captured.getJMXServiceUrl(), Matchers.equalTo(new JMXServiceURL(connectUrl))); + MatcherAssert.assertThat(captured.getServiceUri(), Matchers.equalTo(new URI(connectUrl))); MatcherAssert.assertThat(captured.getAlias(), Matchers.equalTo(Optional.of(alias))); MatcherAssert.assertThat(response.getBody(), Matchers.equalTo(captured)); } diff --git a/src/test/java/io/cryostat/platform/internal/AbstractPlatformClientTest.java b/src/test/java/io/cryostat/platform/internal/AbstractPlatformClientTest.java index c07a3033cb..fefe0c2bf3 100644 --- a/src/test/java/io/cryostat/platform/internal/AbstractPlatformClientTest.java +++ b/src/test/java/io/cryostat/platform/internal/AbstractPlatformClientTest.java @@ -38,6 +38,7 @@ package io.cryostat.platform.internal; import java.io.IOException; +import java.net.URI; import java.util.Collections; import java.util.List; import java.util.Map; @@ -49,6 +50,7 @@ import io.cryostat.messaging.notifications.NotificationFactory; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -87,7 +89,9 @@ void setup() { void shouldEmitNotification() throws Exception { Mockito.verifyNoInteractions(notificationFactory); - JMXServiceURL serviceUrl = Mockito.mock(JMXServiceURL.class); + URI serviceUrl = + URIUtil.convert( + new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi")); String alias = "com.example.Foo"; ServiceRef serviceRef = new ServiceRef(serviceUrl, alias); EventKind kind = EventKind.FOUND; diff --git a/src/test/java/io/cryostat/platform/internal/CustomTargetPlatformClientTest.java b/src/test/java/io/cryostat/platform/internal/CustomTargetPlatformClientTest.java index c2e173532c..e90598d8e6 100644 --- a/src/test/java/io/cryostat/platform/internal/CustomTargetPlatformClientTest.java +++ b/src/test/java/io/cryostat/platform/internal/CustomTargetPlatformClientTest.java @@ -56,6 +56,7 @@ import io.cryostat.messaging.notifications.NotificationFactory; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import com.google.gson.Gson; import org.hamcrest.MatcherAssert; @@ -88,7 +89,9 @@ class CustomTargetPlatformClientTest { try { SERVICE_REF = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9099/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9099/jmxrmi")), "TestTarget"); } catch (Exception e) { throw new RuntimeException(e); @@ -259,7 +262,7 @@ void testRemoveTargetByUrl() throws IOException { Mockito.when(fs.readFile(saveFile)).thenReturn(reader); client.start(); - Assertions.assertTrue(client.removeTarget(SERVICE_REF.getJMXServiceUrl())); + Assertions.assertTrue(client.removeTarget(SERVICE_REF.getServiceUri())); Mockito.verify(fs) .writeString( @@ -284,7 +287,7 @@ void testRemoveTargetByUrl() throws IOException { @Test void testRemoveNonexistentTargetByUrl() throws IOException { - Assertions.assertFalse(client.removeTarget(SERVICE_REF.getJMXServiceUrl())); + Assertions.assertFalse(client.removeTarget(SERVICE_REF.getServiceUri())); Mockito.verify(fs, Mockito.never()) .writeString( diff --git a/src/test/java/io/cryostat/platform/internal/DefaultPlatformClientTest.java b/src/test/java/io/cryostat/platform/internal/DefaultPlatformClientTest.java index 1460fe14ad..bef3ce8d4b 100644 --- a/src/test/java/io/cryostat/platform/internal/DefaultPlatformClientTest.java +++ b/src/test/java/io/cryostat/platform/internal/DefaultPlatformClientTest.java @@ -60,6 +60,7 @@ import io.cryostat.messaging.notifications.NotificationFactory; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -97,7 +98,8 @@ void testShouldAddListenerAndStartDiscovery() throws Exception { @Test void testDiscoverableServiceMapping() throws Exception { DiscoveredJvmDescriptor desc1 = mock(DiscoveredJvmDescriptor.class); - JMXServiceURL url1 = mock(JMXServiceURL.class); + JMXServiceURL url1 = + new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi"); when(desc1.getMainClass()).thenReturn("com.example.Main"); when(desc1.getJmxServiceUrl()).thenReturn(url1); @@ -105,24 +107,27 @@ void testDiscoverableServiceMapping() throws Exception { when(desc2.getJmxServiceUrl()).thenThrow(MalformedURLException.class); DiscoveredJvmDescriptor desc3 = mock(DiscoveredJvmDescriptor.class); - JMXServiceURL url3 = mock(JMXServiceURL.class); + JMXServiceURL url2 = + new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9092/jmxrmi"); when(desc3.getMainClass()).thenReturn("io.cryostat.Cryostat"); - when(desc3.getJmxServiceUrl()).thenReturn(url3); + when(desc3.getJmxServiceUrl()).thenReturn(url2); when(discoveryClient.getDiscoveredJvmDescriptors()) .thenReturn(List.of(desc1, desc2, desc3)); List results = client.listDiscoverableServices(); - ServiceRef exp1 = new ServiceRef(desc1.getJmxServiceUrl(), desc1.getMainClass()); - ServiceRef exp2 = new ServiceRef(desc3.getJmxServiceUrl(), desc3.getMainClass()); + ServiceRef exp1 = + new ServiceRef(URIUtil.convert(desc1.getJmxServiceUrl()), desc1.getMainClass()); + ServiceRef exp2 = + new ServiceRef(URIUtil.convert(desc3.getJmxServiceUrl()), desc3.getMainClass()); assertThat(results, equalTo(List.of(exp1, exp2))); } @Test void testAcceptDiscoveryEvent() throws Exception { - JMXServiceURL url = mock(JMXServiceURL.class); + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9091/jmxrmi"); String mainClass = "com.example.Main"; DiscoveredJvmDescriptor desc = mock(DiscoveredJvmDescriptor.class); when(desc.getMainClass()).thenReturn(mainClass); @@ -147,11 +152,7 @@ void testAcceptDiscoveryEvent() throws Exception { verifyNoInteractions(notificationFactory); - try { - client.accept(evt); - } catch (Exception e) { - e.printStackTrace(); - } + client.accept(evt); verifyNoInteractions(discoveryClient); @@ -165,7 +166,7 @@ void testAcceptDiscoveryEvent() throws Exception { "kind", EventKind.FOUND, "serviceRef", - new ServiceRef(url, mainClass)))); + new ServiceRef(URIUtil.convert(url), mainClass)))); verify(builder).build(); verify(notification).send(); } diff --git a/src/test/java/io/cryostat/platform/internal/KubeApiPlatformClientTest.java b/src/test/java/io/cryostat/platform/internal/KubeApiPlatformClientTest.java index 98af012eb3..358f62da23 100644 --- a/src/test/java/io/cryostat/platform/internal/KubeApiPlatformClientTest.java +++ b/src/test/java/io/cryostat/platform/internal/KubeApiPlatformClientTest.java @@ -51,6 +51,7 @@ import io.cryostat.messaging.notifications.Notification; import io.cryostat.messaging.notifications.NotificationFactory; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import io.fabric8.kubernetes.api.model.EndpointAddress; import io.fabric8.kubernetes.api.model.EndpointPort; @@ -193,21 +194,21 @@ public JMXServiceURL answer(InvocationOnMock args) throws Throwable { List result = platformClient.listDiscoverableServices(); ServiceRef serv1 = new ServiceRef( - connectionToolkit, - address2.getIp(), - port2.getPort(), + URIUtil.convert( + connectionToolkit.createServiceURL( + address2.getIp(), port2.getPort())), address2.getTargetRef().getName()); ServiceRef serv2 = new ServiceRef( - connectionToolkit, - address3.getIp(), - port2.getPort(), + URIUtil.convert( + connectionToolkit.createServiceURL( + address3.getIp(), port2.getPort())), address3.getTargetRef().getName()); ServiceRef serv3 = new ServiceRef( - connectionToolkit, - address4.getIp(), - port3.getPort(), + URIUtil.convert( + connectionToolkit.createServiceURL( + address4.getIp(), port3.getPort())), address4.getTargetRef().getName()); MatcherAssert.assertThat(result, Matchers.equalTo(Arrays.asList(serv1, serv2, serv3))); @@ -285,9 +286,9 @@ public JMXServiceURL answer(InvocationOnMock args) throws Throwable { ServiceRef serviceRef = new ServiceRef( - connectionToolkit, - address.getIp(), - port.getPort(), + URIUtil.convert( + connectionToolkit.createServiceURL( + address.getIp(), port.getPort())), address.getTargetRef().getName()); Mockito.verify(notificationFactory, Mockito.times(1)).createBuilder(); @@ -353,9 +354,9 @@ public JMXServiceURL answer(InvocationOnMock args) throws Throwable { ServiceRef serviceRef = new ServiceRef( - connectionToolkit, - address.getIp(), - port.getPort(), + URIUtil.convert( + connectionToolkit.createServiceURL( + address.getIp(), port.getPort())), address.getTargetRef().getName()); Mockito.verify(notificationFactory, Mockito.times(1)).createBuilder(); @@ -420,9 +421,9 @@ public JMXServiceURL answer(InvocationOnMock args) throws Throwable { ServiceRef serviceRef = new ServiceRef( - connectionToolkit, - address.getIp(), - port.getPort(), + URIUtil.convert( + connectionToolkit.createServiceURL( + address.getIp(), port.getPort())), address.getTargetRef().getName()); Mockito.verify(notificationFactory, Mockito.times(2)).createBuilder(); diff --git a/src/test/java/io/cryostat/platform/internal/KubeEnvPlatformClientTest.java b/src/test/java/io/cryostat/platform/internal/KubeEnvPlatformClientTest.java index c6140c45c5..105a2292cf 100644 --- a/src/test/java/io/cryostat/platform/internal/KubeEnvPlatformClientTest.java +++ b/src/test/java/io/cryostat/platform/internal/KubeEnvPlatformClientTest.java @@ -41,14 +41,18 @@ import static org.mockito.Mockito.when; import java.net.MalformedURLException; +import java.net.URISyntaxException; import java.util.Collections; import java.util.List; import java.util.Map; +import javax.management.remote.JMXServiceURL; + import io.cryostat.core.log.Logger; import io.cryostat.core.net.JFRConnectionToolkit; import io.cryostat.core.sys.Environment; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -57,7 +61,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.stubbing.Answer; @ExtendWith(MockitoExtension.class) class KubeEnvPlatformClientTest { @@ -90,17 +97,40 @@ void shouldDiscoverNoServicesIfEnvsNotRelevant() { } @Test - void shouldDiscoverServicesByEnv() throws MalformedURLException { + void shouldDiscoverServicesByEnv() throws MalformedURLException, URISyntaxException { when(env.getEnv()) .thenReturn( Map.of( "FOO_PORT_1234_TCP_ADDR", "127.0.0.1", "BAR_PORT_9999_TCP_ADDR", "1.2.3.4", "BAZ_PORT_9876_UDP_ADDR", "5.6.7.8")); - List services = client.listDiscoverableServices(); - ServiceRef serv1 = new ServiceRef(connectionToolkit, "127.0.0.1", 1234, "foo"); - ServiceRef serv2 = new ServiceRef(connectionToolkit, "1.2.3.4", 9999, "bar"); + Mockito.when(connectionToolkit.createServiceURL(Mockito.anyString(), Mockito.anyInt())) + .thenAnswer( + new Answer<>() { + @Override + public JMXServiceURL answer(InvocationOnMock args) + throws Throwable { + String host = args.getArgument(0); + int port = args.getArgument(1); + return new JMXServiceURL( + "rmi", + "", + 0, + "/jndi/rmi://" + host + ":" + port + "/jmxrmi"); + } + }); + + ServiceRef serv1 = + new ServiceRef( + URIUtil.convert(connectionToolkit.createServiceURL("127.0.0.1", 1234)), + "foo"); + ServiceRef serv2 = + new ServiceRef( + URIUtil.convert(connectionToolkit.createServiceURL("1.2.3.4", 9999)), + "bar"); + + List services = client.listDiscoverableServices(); MatcherAssert.assertThat(services, Matchers.containsInAnyOrder(serv1, serv2)); MatcherAssert.assertThat(services, Matchers.hasSize(2)); diff --git a/src/test/java/io/cryostat/platform/internal/MergingPlatformClientTest.java b/src/test/java/io/cryostat/platform/internal/MergingPlatformClientTest.java index 7229a93fd6..a3ebf8fe03 100644 --- a/src/test/java/io/cryostat/platform/internal/MergingPlatformClientTest.java +++ b/src/test/java/io/cryostat/platform/internal/MergingPlatformClientTest.java @@ -39,12 +39,14 @@ import java.io.IOException; import java.net.MalformedURLException; +import java.net.URISyntaxException; import java.util.List; import javax.management.remote.JMXServiceURL; import io.cryostat.platform.PlatformClient; import io.cryostat.platform.ServiceRef; +import io.cryostat.util.URIUtil; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -79,14 +81,18 @@ void testStart() throws IOException { } @Test - void testMergedDiscoverableServices() throws MalformedURLException { + void testMergedDiscoverableServices() throws MalformedURLException, URISyntaxException { ServiceRef serviceA = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9098/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9098/jmxrmi")), "ServiceA"); ServiceRef serviceB = new ServiceRef( - new JMXServiceURL("service:jmx:rmi:///jndi/rmi://cryostat:9099/jmxrmi"), + URIUtil.convert( + new JMXServiceURL( + "service:jmx:rmi:///jndi/rmi://cryostat:9099/jmxrmi")), "ServiceB"); Mockito.when(clientA.listDiscoverableServices()).thenReturn(List.of(serviceA));