From 7f0c38dcc818af966fadaf4dc0bb6f006a36dca6 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 14 Feb 2019 12:12:02 +1100 Subject: [PATCH 1/2] Add support for directly injecting the HTTP URL into tests This is pluggable so we can support multiple clients --- .../deployment/steps/ConfigurationSetup.java | 4 ++ .../main/asciidoc/getting-started-guide.adoc | 17 ++++++ .../shamrock/example/rest/ClientResource.java | 2 +- .../example/test/FaultToleranceTestCase.java | 5 +- .../example/test/OpenApiTestCase.java | 5 +- .../example/test/ValidatorTestCase.java | 6 +- .../example/test/WebsocketTestCase.java | 6 +- .../http/StringTestHTTPResourceProvider.java | 16 +++++ .../test/common/http/TestHTTPResource.java | 25 ++++++++ .../common/http/TestHTTPResourceProvider.java | 18 ++++++ .../common/http/TestHttpResourceManager.java | 61 +++++++++++++++++++ .../http/URITestHTTPResourceProvider.java | 16 +++++ .../http/URLTestHTTPResourceProvider.java | 22 +++++++ ....test.common.http.TestHTTPResourceProvider | 3 + .../junit4/AbstractShamrockRunListener.java | 2 + .../junit4/AbstractShamrockTestRunner.java | 8 +++ .../jboss/shamrock/test/ShamrockUnitTest.java | 5 +- .../test/junit/ShamrockTestExtension.java | 18 +++++- 18 files changed, 230 insertions(+), 9 deletions(-) create mode 100644 test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/StringTestHTTPResourceProvider.java create mode 100644 test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHTTPResource.java create mode 100644 test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHTTPResourceProvider.java create mode 100644 test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHttpResourceManager.java create mode 100644 test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/URITestHTTPResourceProvider.java create mode 100644 test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/URLTestHTTPResourceProvider.java create mode 100644 test-framework/common/src/main/resources/META-INF/services/org.jboss.shamrock.test.common.http.TestHTTPResourceProvider diff --git a/core/deployment/src/main/java/org/jboss/shamrock/deployment/steps/ConfigurationSetup.java b/core/deployment/src/main/java/org/jboss/shamrock/deployment/steps/ConfigurationSetup.java index 9691b4daf63cf..384a978d9489d 100644 --- a/core/deployment/src/main/java/org/jboss/shamrock/deployment/steps/ConfigurationSetup.java +++ b/core/deployment/src/main/java/org/jboss/shamrock/deployment/steps/ConfigurationSetup.java @@ -23,7 +23,10 @@ import io.smallrye.config.SmallRyeConfig; import io.smallrye.config.SmallRyeConfigBuilder; +import io.smallrye.config.SmallRyeConfigProviderResolver; + import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; import org.eclipse.microprofile.config.spi.ConfigBuilder; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.eclipse.microprofile.config.spi.ConfigSource; @@ -152,6 +155,7 @@ public ConfigurationBuildItem initializeConfiguration( for (Class clazz : ServiceUtil.classesNamedIn(extensionClassLoaderBuildItem.getExtensionClassLoader(), "META-INF/shamrock-config-roots.list")) { configDefinition.registerConfigRoot(clazz); } + SmallRyeConfigProviderResolver.instance().registerConfig(src, Thread.currentThread().getContextClassLoader()); configDefinition.loadConfiguration(src); return new ConfigurationBuildItem(configDefinition); } diff --git a/docs/src/main/asciidoc/getting-started-guide.adoc b/docs/src/main/asciidoc/getting-started-guide.adoc index 585306c1ba670..2d235474b848b 100644 --- a/docs/src/main/asciidoc/getting-started-guide.adoc +++ b/docs/src/main/asciidoc/getting-started-guide.adoc @@ -343,6 +343,23 @@ These tests use http://rest-assured.io/[RestAssured], but feel free to use your You can run the test from your IDE directly (be sure you stopped the application first), or from Maven using: `mvn test`. +By default tests will run on port `8081` so as not to conflict with the running application. We automatically +configure RestAssured to use this port. If you want to use a different client you should use the `@TestHTTPResource` +annotation to directly inject the URL of the test into a field on the test class. This field can be of the type +`String`, `URL` or `URI`. This annotation can also be given a value for the test path. For example if I want to test +a Servlet mapped to `/myservlet` I would just add the following to my test: + + +[source,java] +---- +@TestHTTPResource("/myservlet") +URL testUrl; +---- + +The test port can be controlled via the `shamrock.http.test-port` config property. Shamrock also creates a system +property called `test.url` that is set to the base test URL for situations where you cannot use injection. + + == Packaging and run the application The application is packaged using `mvn package`. diff --git a/integration-tests/main/src/main/java/org/jboss/shamrock/example/rest/ClientResource.java b/integration-tests/main/src/main/java/org/jboss/shamrock/example/rest/ClientResource.java index 0f411c5b46233..5b4ba93eeeef4 100644 --- a/integration-tests/main/src/main/java/org/jboss/shamrock/example/rest/ClientResource.java +++ b/integration-tests/main/src/main/java/org/jboss/shamrock/example/rest/ClientResource.java @@ -36,7 +36,7 @@ public class ClientResource { @Path("/manual") public String manual() throws Exception { RestInterface iface = RestClientBuilder.newBuilder() - .baseUrl(new URL("http", "localhost", 8081, "/")) + .baseUrl(new URL(System.getProperty("test.url"))) .build(RestInterface.class); return iface.get(); } diff --git a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/FaultToleranceTestCase.java b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/FaultToleranceTestCase.java index dd978697a5d60..2f64051fd68d8 100644 --- a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/FaultToleranceTestCase.java +++ b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/FaultToleranceTestCase.java @@ -21,6 +21,7 @@ import java.net.URL; import java.net.URLConnection; +import org.jboss.shamrock.test.common.http.TestHTTPResource; import org.jboss.shamrock.test.junit.ShamrockTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -28,9 +29,11 @@ @ShamrockTest public class FaultToleranceTestCase { + @TestHTTPResource("ft") + URL uri; + @Test public void testRetry() throws Exception { - URL uri = new URL("http://localhost:8081/ft"); URLConnection connection = uri.openConnection(); InputStream in = connection.getInputStream(); byte[] buf = new byte[100]; diff --git a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/OpenApiTestCase.java b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/OpenApiTestCase.java index d6d47b1cc7e8d..1489243978f91 100644 --- a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/OpenApiTestCase.java +++ b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/OpenApiTestCase.java @@ -27,6 +27,7 @@ import javax.json.JsonObject; import javax.json.JsonReader; +import org.jboss.shamrock.test.common.http.TestHTTPResource; import org.jboss.shamrock.test.junit.ShamrockTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -37,9 +38,11 @@ @ShamrockTest public class OpenApiTestCase { + @TestHTTPResource("openapi") + URL uri; + @Test public void testOpenAPIJSON() throws Exception { - URL uri = new URL("http://localhost:8081/openapi"); URLConnection connection = uri.openConnection(); connection.setRequestProperty("Accept", "application/json"); InputStream in = connection.getInputStream(); diff --git a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/ValidatorTestCase.java b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/ValidatorTestCase.java index d26332e42b3ec..a292f2bdf9f5e 100644 --- a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/ValidatorTestCase.java +++ b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/ValidatorTestCase.java @@ -25,6 +25,7 @@ import javax.json.Json; +import org.jboss.shamrock.test.common.http.TestHTTPResource; import org.jboss.shamrock.test.junit.ShamrockTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -32,9 +33,11 @@ @ShamrockTest public class ValidatorTestCase { + @TestHTTPResource("validator/manual") + URL uri; + @Test public void testManualValidationFailed() throws Exception { - URL uri = new URL("http://localhost:8081/validator/manual"); URLConnection connection = uri.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/json"); @@ -60,7 +63,6 @@ public void testManualValidationFailed() throws Exception { @Test public void testManualValidationPassed() throws Exception { - URL uri = new URL("http://localhost:8081/validator/manual"); URLConnection connection = uri.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/json"); diff --git a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/WebsocketTestCase.java b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/WebsocketTestCase.java index 75615bc5d0ce7..68d40a7621f0a 100644 --- a/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/WebsocketTestCase.java +++ b/integration-tests/main/src/test/java/org/jboss/shamrock/example/test/WebsocketTestCase.java @@ -27,6 +27,7 @@ import javax.websocket.MessageHandler; import javax.websocket.Session; +import org.jboss.shamrock.test.common.http.TestHTTPResource; import org.jboss.shamrock.test.junit.ShamrockTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -34,11 +35,12 @@ @ShamrockTest public class WebsocketTestCase { + @TestHTTPResource("echo") + URI uri; + @Test public void websocketTest() throws Exception { - final URI uri = new URI("http://localhost:8081/echo"); - LinkedBlockingDeque message = new LinkedBlockingDeque<>(); Session session = ContainerProvider.getWebSocketContainer().connectToServer(new Endpoint() { @Override diff --git a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/StringTestHTTPResourceProvider.java b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/StringTestHTTPResourceProvider.java new file mode 100644 index 0000000000000..d46e01b8bf5f2 --- /dev/null +++ b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/StringTestHTTPResourceProvider.java @@ -0,0 +1,16 @@ +package org.jboss.shamrock.test.common.http; + +import java.lang.reflect.Field; +import java.net.URI; + +public class StringTestHTTPResourceProvider implements TestHTTPResourceProvider { + @Override + public Class getProvidedType() { + return String.class; + } + + @Override + public String provide(URI testUri, Field field) { + return testUri.toASCIIString(); + } +} diff --git a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHTTPResource.java b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHTTPResource.java new file mode 100644 index 0000000000000..61ebc3c57e82d --- /dev/null +++ b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHTTPResource.java @@ -0,0 +1,25 @@ +package org.jboss.shamrock.test.common.http; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Indicates that a field should be injected with a resource that is pre-configured + * to use the correct test URL. + * + * This could be a String or URL object, or some other HTTP/Websocket based client. + * + * This mechanism is plugable, via {@link TestHTTPResourceProvider} + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface TestHTTPResource { + + /** + * + * @return The path part of the URL + */ + String value() default ""; +} diff --git a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHTTPResourceProvider.java b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHTTPResourceProvider.java new file mode 100644 index 0000000000000..5ee5048f29446 --- /dev/null +++ b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHTTPResourceProvider.java @@ -0,0 +1,18 @@ +package org.jboss.shamrock.test.common.http; + +import java.lang.reflect.Field; +import java.net.URI; + +public interface TestHTTPResourceProvider { + + Class getProvidedType(); + + /** + * Create the resource to be injected into the field. + *

+ * Note that there is no need to directly call set() on the field, it is only provided + * to allow you to examine the generic type and any additional annotations. + */ + T provide(URI testUri, Field field); + +} diff --git a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHttpResourceManager.java b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHttpResourceManager.java new file mode 100644 index 0000000000000..228ca903224e6 --- /dev/null +++ b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHttpResourceManager.java @@ -0,0 +1,61 @@ +package org.jboss.shamrock.test.common.http; + +import java.lang.reflect.Field; +import java.net.URI; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceLoader; + +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.ConfigProvider; + +public class TestHttpResourceManager { + + static final String uri; + static final Map, TestHTTPResourceProvider> providers; + + static { + Map, TestHTTPResourceProvider> map = new HashMap<>(); + for (TestHTTPResourceProvider i : ServiceLoader.load(TestHTTPResourceProvider.class)) { + map.put(i.getProvidedType(), i); + } + providers = Collections.unmodifiableMap(map); + Config config = ConfigProvider.getConfig(); + String host = config.getOptionalValue("shamrock.http.host", String.class).orElse("localhost"); + String port = config.getOptionalValue("shamrock.http.test-port", String.class).orElse("8081"); + uri = "http://" + host + ":" + port; + System.setProperty("test.url", uri); + } + + + public static void inject(Object testCase) { + Class c = testCase.getClass(); + while (c != Object.class) { + for(Field f : c.getDeclaredFields()) { + TestHTTPResource resource = f.getAnnotation(TestHTTPResource.class); + if(resource != null) { + TestHTTPResourceProvider provider = providers.get(f.getType()); + if(provider == null) { + throw new RuntimeException("Unable to inject TestHTTPResource field " + f + " as no provider exists for the type"); + } + String path = resource.value(); + String val; + if(path.startsWith("/")) { + val = uri + path; + } else { + val = uri + "/" + path; + } + f.setAccessible(true); + try { + f.set(testCase, provider.provide(new URI(val), f)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + c = c.getSuperclass(); + } + } + +} diff --git a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/URITestHTTPResourceProvider.java b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/URITestHTTPResourceProvider.java new file mode 100644 index 0000000000000..253e28b187682 --- /dev/null +++ b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/URITestHTTPResourceProvider.java @@ -0,0 +1,16 @@ +package org.jboss.shamrock.test.common.http; + +import java.lang.reflect.Field; +import java.net.URI; + +public class URITestHTTPResourceProvider implements TestHTTPResourceProvider { + @Override + public Class getProvidedType() { + return URI.class; + } + + @Override + public URI provide(URI testUri, Field field) { + return testUri; + } +} diff --git a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/URLTestHTTPResourceProvider.java b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/URLTestHTTPResourceProvider.java new file mode 100644 index 0000000000000..94c7693069bf5 --- /dev/null +++ b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/URLTestHTTPResourceProvider.java @@ -0,0 +1,22 @@ +package org.jboss.shamrock.test.common.http; + +import java.lang.reflect.Field; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; + +public class URLTestHTTPResourceProvider implements TestHTTPResourceProvider { + @Override + public Class getProvidedType() { + return URL.class; + } + + @Override + public URL provide(URI testUri, Field field) { + try { + return testUri.toURL(); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } +} diff --git a/test-framework/common/src/main/resources/META-INF/services/org.jboss.shamrock.test.common.http.TestHTTPResourceProvider b/test-framework/common/src/main/resources/META-INF/services/org.jboss.shamrock.test.common.http.TestHTTPResourceProvider new file mode 100644 index 0000000000000..a2c49138cf22e --- /dev/null +++ b/test-framework/common/src/main/resources/META-INF/services/org.jboss.shamrock.test.common.http.TestHTTPResourceProvider @@ -0,0 +1,3 @@ +org.jboss.shamrock.test.common.http.URLTestHTTPResourceProvider +org.jboss.shamrock.test.common.http.URITestHTTPResourceProvider +org.jboss.shamrock.test.common.http.StringTestHTTPResourceProvider \ No newline at end of file diff --git a/test-framework/junit4/src/main/java/org/jboss/shamrock/test/junit4/AbstractShamrockRunListener.java b/test-framework/junit4/src/main/java/org/jboss/shamrock/test/junit4/AbstractShamrockRunListener.java index baaa8e988db3b..b952fef0b9bfa 100644 --- a/test-framework/junit4/src/main/java/org/jboss/shamrock/test/junit4/AbstractShamrockRunListener.java +++ b/test-framework/junit4/src/main/java/org/jboss/shamrock/test/junit4/AbstractShamrockRunListener.java @@ -95,6 +95,8 @@ public void testFinished(Description description) throws Exception { RestAssuredPortManager.clearPort(); } + + protected abstract void startShamrock() throws Exception; protected abstract void stopShamrock() throws Exception; diff --git a/test-framework/junit4/src/main/java/org/jboss/shamrock/test/junit4/AbstractShamrockTestRunner.java b/test-framework/junit4/src/main/java/org/jboss/shamrock/test/junit4/AbstractShamrockTestRunner.java index 538fbb95d88f4..e66e41d9420fe 100644 --- a/test-framework/junit4/src/main/java/org/jboss/shamrock/test/junit4/AbstractShamrockTestRunner.java +++ b/test-framework/junit4/src/main/java/org/jboss/shamrock/test/junit4/AbstractShamrockTestRunner.java @@ -18,6 +18,7 @@ import java.util.function.BiFunction; +import org.jboss.shamrock.test.common.http.TestHttpResourceManager; import org.junit.runner.notification.RunNotifier; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.FrameworkMethod; @@ -54,4 +55,11 @@ protected void runChild(final FrameworkMethod method, RunNotifier notifier) { notifier.fireTestIgnored(describeChild(method)); } } + + @Override + protected Object createTest() throws Exception { + Object instance = super.createTest(); + TestHttpResourceManager.inject(instance); + return instance; + } } diff --git a/test-framework/junit5-internal/src/main/java/org/jboss/shamrock/test/ShamrockUnitTest.java b/test-framework/junit5-internal/src/main/java/org/jboss/shamrock/test/ShamrockUnitTest.java index b03e90cc715da..a7279163ae51b 100644 --- a/test-framework/junit5-internal/src/main/java/org/jboss/shamrock/test/ShamrockUnitTest.java +++ b/test-framework/junit5-internal/src/main/java/org/jboss/shamrock/test/ShamrockUnitTest.java @@ -49,6 +49,7 @@ import org.jboss.shamrock.test.common.PathTestHelper; import org.jboss.shamrock.test.common.RestAssuredPortManager; import org.jboss.shamrock.test.common.TestResourceManager; +import org.jboss.shamrock.test.common.http.TestHttpResourceManager; import org.jboss.shrinkwrap.api.exporter.ExplodedExporter; import org.jboss.shrinkwrap.api.exporter.ZipExporter; import org.jboss.shrinkwrap.api.spec.JavaArchive; @@ -104,7 +105,9 @@ public Object createTestInstance(TestInstanceFactoryContext factoryContext, Exte .setSuperClass(testClass)); Object actualTestInstance = extensionContext.getStore(ExtensionContext.Namespace.GLOBAL).get(testClass.getName()); - + if(actualTestInstance != null) { //happens if a deployment exception is expected + TestHttpResourceManager.inject(actualTestInstance); + } return factory.newInstance(new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { diff --git a/test-framework/junit5/src/main/java/org/jboss/shamrock/test/junit/ShamrockTestExtension.java b/test-framework/junit5/src/main/java/org/jboss/shamrock/test/junit/ShamrockTestExtension.java index a89e73611374f..13242fd673d0a 100644 --- a/test-framework/junit5/src/main/java/org/jboss/shamrock/test/junit/ShamrockTestExtension.java +++ b/test-framework/junit5/src/main/java/org/jboss/shamrock/test/junit/ShamrockTestExtension.java @@ -28,12 +28,17 @@ import org.jboss.shamrock.test.common.NativeImageLauncher; import org.jboss.shamrock.test.common.RestAssuredPortManager; import org.jboss.shamrock.test.common.TestResourceManager; +import org.jboss.shamrock.test.common.http.TestHttpResourceManager; +import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestInstanceFactory; +import org.junit.jupiter.api.extension.TestInstanceFactoryContext; +import org.junit.jupiter.api.extension.TestInstantiationException; -public class ShamrockTestExtension implements BeforeAllCallback, BeforeEachCallback, AfterEachCallback { +public class ShamrockTestExtension implements BeforeAllCallback, BeforeEachCallback, AfterEachCallback, TestInstanceFactory { @Override @@ -82,6 +87,17 @@ public void beforeEach(ExtensionContext context) throws Exception { RestAssuredPortManager.setPort(); } + @Override + public Object createTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext extensionContext) throws TestInstantiationException { + try { + Object instance = factoryContext.getTestClass().newInstance(); + TestHttpResourceManager.inject(instance); + return instance; + } catch (InstantiationException | IllegalAccessException e) { + throw new TestInstantiationException("Failed to create test instance", e); + } + } + static class ExtensionState implements ExtensionContext.Store.CloseableResource { From 323dc91af9204604163940c663a588e801243b97 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 14 Feb 2019 19:02:03 +1100 Subject: [PATCH 2/2] Launch the native image with -Dtest.url set --- .../src/main/resources/META-INF/microprofile-config.properties | 2 +- .../org/jboss/shamrock/test/common/NativeImageLauncher.java | 2 ++ .../shamrock/test/common/http/TestHttpResourceManager.java | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/integration-tests/main/src/main/resources/META-INF/microprofile-config.properties b/integration-tests/main/src/main/resources/META-INF/microprofile-config.properties index f3e179f0bde3c..d0bf4eecb2aeb 100644 --- a/integration-tests/main/src/main/resources/META-INF/microprofile-config.properties +++ b/integration-tests/main/src/main/resources/META-INF/microprofile-config.properties @@ -14,7 +14,7 @@ # limitations under the License. # -org.jboss.shamrock.example.rest.RestInterface/mp-rest/url=http://localhost:8081/ +org.jboss.shamrock.example.rest.RestInterface/mp-rest/url=${test.url} # Disabled by default as it establishes external connections. # Uncomment when you want to test SSL support. #org.jboss.shamrock.example.rest.SslRestInterface/mp-rest/url=https://www.example.com/ diff --git a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/NativeImageLauncher.java b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/NativeImageLauncher.java index 1167602b6476f..252251def40cc 100644 --- a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/NativeImageLauncher.java +++ b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/NativeImageLauncher.java @@ -30,6 +30,7 @@ import java.util.Map; import org.eclipse.microprofile.config.ConfigProvider; +import org.jboss.shamrock.test.common.http.TestHttpResourceManager; public class NativeImageLauncher implements Closeable { @@ -57,6 +58,7 @@ public void start() throws Exception { List args = new ArrayList<>(); args.add(path); args.add("-Dshamrock.http.port=" + port); + args.add("-Dtest.url=" + TestHttpResourceManager.getUri()); System.out.println("Executing " + args); diff --git a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHttpResourceManager.java b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHttpResourceManager.java index 228ca903224e6..5a201d6cbe427 100644 --- a/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHttpResourceManager.java +++ b/test-framework/common/src/main/java/org/jboss/shamrock/test/common/http/TestHttpResourceManager.java @@ -28,6 +28,9 @@ public class TestHttpResourceManager { System.setProperty("test.url", uri); } + public static String getUri() { + return uri; + } public static void inject(Object testCase) { Class c = testCase.getClass();