From b4be270cf52a704f32cf6d3503d5f772bbb1d731 Mon Sep 17 00:00:00 2001 From: MMaiero Date: Fri, 20 Dec 2024 10:07:44 +0100 Subject: [PATCH] fix: tentative test update Signed-off-by: MMaiero --- .../requesthandler/RestTransport.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/kura/test/org.eclipse.kura.core.testutil/src/main/java/org/eclipse/kura/core/testutil/requesthandler/RestTransport.java b/kura/test/org.eclipse.kura.core.testutil/src/main/java/org/eclipse/kura/core/testutil/requesthandler/RestTransport.java index d2e11c95f27..da774015e00 100644 --- a/kura/test/org.eclipse.kura.core.testutil/src/main/java/org/eclipse/kura/core/testutil/requesthandler/RestTransport.java +++ b/kura/test/org.eclipse.kura.core.testutil/src/main/java/org/eclipse/kura/core/testutil/requesthandler/RestTransport.java @@ -28,14 +28,18 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Optional; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import org.apache.commons.io.IOUtils; +import org.eclipse.kura.KuraException; import org.eclipse.kura.configuration.ConfigurableComponent; +import org.eclipse.kura.configuration.ConfigurationService; import org.eclipse.kura.core.testutil.service.ServiceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,6 +74,12 @@ public void init() { } try { + final ConfigurationService configurationService = trackService(ConfigurationService.class); + Map restServiceConfiguration = initialRestServiceConfiguration(); + + ServiceUtil.updateComponentConfiguration(configurationService, "org.eclipse.kura.internal.rest.provider.RestService", restServiceConfiguration).get(30, + TimeUnit.SECONDS); + waitPortOpen("localhost", 8080, 3, TimeUnit.MINUTES); ServiceUtil @@ -78,7 +88,7 @@ public void init() { .get(1, TimeUnit.MINUTES); Thread.sleep(1000); - + initialized = true; } catch (final InterruptedException e) { Thread.currentThread().interrupt(); @@ -87,6 +97,21 @@ public void init() { throw new IllegalStateException(e); } } + + private T trackService(final Class classz) + throws InterruptedException, ExecutionException, TimeoutException { + return ServiceUtil + .trackService(classz, Optional.empty()).get(30, TimeUnit.SECONDS); + } + + private Map initialRestServiceConfiguration() throws KuraException { + + final Map restServiceConfiguration = new HashMap<>(); + + restServiceConfiguration.put("allowed.ports", "[8080,443,4443]"); + + return restServiceConfiguration; + } public static void waitPortOpen(final String host, final int port, final long timeout, final TimeUnit timeoutUnit) throws InterruptedException {