diff --git a/bundles/org.openhab.binding.mielecloud/src/main/java/org/openhab/binding/mielecloud/internal/config/servlet/CreateBridgeServlet.java b/bundles/org.openhab.binding.mielecloud/src/main/java/org/openhab/binding/mielecloud/internal/config/servlet/CreateBridgeServlet.java index 1097f3cdaa9..fe8dc9c9883 100644 --- a/bundles/org.openhab.binding.mielecloud/src/main/java/org/openhab/binding/mielecloud/internal/config/servlet/CreateBridgeServlet.java +++ b/bundles/org.openhab.binding.mielecloud/src/main/java/org/openhab/binding/mielecloud/internal/config/servlet/CreateBridgeServlet.java @@ -53,7 +53,6 @@ public final class CreateBridgeServlet extends AbstractRedirectionServlet { private static final String DEFAULT_LOCALE = "en"; - private static final long ONLINE_WAIT_TIMEOUT_IN_MILLISECONDS = 5000; private static final long DISCOVERY_COMPLETION_TIMEOUT_IN_MILLISECONDS = 5000; private static final long CHECK_INTERVAL_IN_MILLISECONDS = 100; @@ -62,6 +61,8 @@ public final class CreateBridgeServlet extends AbstractRedirectionServlet { private final Inbox inbox; private final ThingRegistry thingRegistry; + private long onlineWaitTimeoutInMilliseconds = 5000; + /** * Creates a new {@link CreateBridgeServlet}. * @@ -73,6 +74,10 @@ public final class CreateBridgeServlet extends AbstractRedirectionServlet { this.thingRegistry = thingRegistry; } + public void setOnlineWaitTimeoutInMilliseconds(long onlineWaitTimeoutInMilliseconds) { + this.onlineWaitTimeoutInMilliseconds = onlineWaitTimeoutInMilliseconds; + } + @Override protected String getRedirectionDestination(HttpServletRequest request) { String bridgeUidString = request.getParameter(BRIDGE_UID_PARAMETER_NAME); @@ -175,7 +180,7 @@ public final class CreateBridgeServlet extends AbstractRedirectionServlet { private void waitForBridgeToComeOnline(Thing bridge) { try { waitForConditionWithTimeout(() -> bridge.getStatus() == ThingStatus.ONLINE, - ONLINE_WAIT_TIMEOUT_IN_MILLISECONDS); + onlineWaitTimeoutInMilliseconds); waitForConditionWithTimeout(new DiscoveryResultCountDoesNotChangeCondition(), DISCOVERY_COMPLETION_TIMEOUT_IN_MILLISECONDS); } catch (InterruptedException e) { diff --git a/bundles/org.openhab.binding.mielecloud/src/test/java/org/openhab/binding/mielecloud/internal/webservice/sse/ExponentialBackoffWithJitterTest.java b/bundles/org.openhab.binding.mielecloud/src/test/java/org/openhab/binding/mielecloud/internal/webservice/sse/ExponentialBackoffWithJitterTest.java index e1c6dbbf12e..b40ae5b7526 100644 --- a/bundles/org.openhab.binding.mielecloud/src/test/java/org/openhab/binding/mielecloud/internal/webservice/sse/ExponentialBackoffWithJitterTest.java +++ b/bundles/org.openhab.binding.mielecloud/src/test/java/org/openhab/binding/mielecloud/internal/webservice/sse/ExponentialBackoffWithJitterTest.java @@ -75,7 +75,7 @@ public class ExponentialBackoffWithJitterTest { @Test public void whenTheNumberOfFailedAttemptsIsNegativeThenZeroIsAssumedInstead() { // given: - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); when(random.nextLong()).thenReturn(RETRY_INTERVAL); ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME, @@ -91,7 +91,7 @@ public class ExponentialBackoffWithJitterTest { @Test public void whenThereIsNoFailedAttemptThenTheMaximalResultIsMinimumWaitTimePlusRetryInterval() { // given: - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); when(random.nextLong()).thenReturn(RETRY_INTERVAL); ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME, @@ -107,7 +107,7 @@ public class ExponentialBackoffWithJitterTest { @Test public void whenThereIsOneFailedAttemptThenTheMaximalResultIsMinimumWaitTimePlusTwiceTheRetryInterval() { // given: - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); when(random.nextLong()).thenReturn(RETRY_INTERVAL * 2); ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME, @@ -123,7 +123,7 @@ public class ExponentialBackoffWithJitterTest { @Test public void whenThereAreTwoFailedAttemptsThenTheMaximalResultIsMinimumWaitTimePlusFourTimesTheRetryInterval() { // given: - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); when(random.nextLong()).thenReturn(RETRY_INTERVAL * 4); ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME, @@ -139,7 +139,7 @@ public class ExponentialBackoffWithJitterTest { @Test public void whenThereAreTwoFailedAttemptsThenTheMinimalResultIsTheMinimumWaitTime() { // given: - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); when(random.nextLong()).thenReturn(0L); ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME, @@ -155,7 +155,7 @@ public class ExponentialBackoffWithJitterTest { @Test public void whenTheDrawnRandomValueIsNegativeThenItIsProjectedToAPositiveValue() { // given: - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); when(random.nextLong()).thenReturn(-RETRY_INTERVAL * 4 - 1); ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(MINIMUM_WAIT_TIME, @@ -171,7 +171,7 @@ public class ExponentialBackoffWithJitterTest { @Test public void whenTheResultWouldBeLargerThanTheMaximumThenItIsCappedToTheMaximum() { // given: - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); when(random.nextLong()).thenReturn(MAXIMUM_WAIT_TIME - ALTERNATIVE_MINIMUM_WAIT_TIME); ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(ALTERNATIVE_MINIMUM_WAIT_TIME, @@ -187,7 +187,7 @@ public class ExponentialBackoffWithJitterTest { @Test public void whenTheResultWouldBeLargerThanTheAlternativeMaximumThenItIsCappedToTheAlternativeMaximum() { // given: - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); when(random.nextLong()).thenReturn(ALTERNATIVE_MAXIMUM_WAIT_TIME - ALTERNATIVE_MINIMUM_WAIT_TIME); ExponentialBackoffWithJitter backoffStrategy = new ExponentialBackoffWithJitter(ALTERNATIVE_MINIMUM_WAIT_TIME, diff --git a/bundles/org.openhab.binding.netatmo/pom.xml b/bundles/org.openhab.binding.netatmo/pom.xml index 621b9739ab9..0c0e870cf40 100644 --- a/bundles/org.openhab.binding.netatmo/pom.xml +++ b/bundles/org.openhab.binding.netatmo/pom.xml @@ -112,6 +112,14 @@ + + + + com.github.jknack + handlebars + 4.3.0 + + diff --git a/bundles/org.openhab.binding.tr064/pom.xml b/bundles/org.openhab.binding.tr064/pom.xml index 4e1a040008c..e27bd7feb3a 100644 --- a/bundles/org.openhab.binding.tr064/pom.xml +++ b/bundles/org.openhab.binding.tr064/pom.xml @@ -46,6 +46,14 @@ + + + + org.glassfish.jaxb + jaxb-runtime + 2.3.6 + + diff --git a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/ScheduleTests.java b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/ScheduleTests.java index f7eda550288..1d153cdef02 100644 --- a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/ScheduleTests.java +++ b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/ScheduleTests.java @@ -89,7 +89,7 @@ public class ScheduleTests { commonSetup.start(new ResourceConfig().registerInstances(subject)); // Mock random -> always return int=10 or the highest possible int if bounded - Random random = mock(Random.class); + Random random = mock(Random.class, withSettings().withoutAnnotations()); doReturn(10).when(random).nextInt(); doAnswer(a -> { Integer bound = a.getArgument(0); diff --git a/bundles/org.openhab.transform.javascript/src/test/java/org/openhab/transform/javascript/internal/JavaScriptTransformationServiceTest.java b/bundles/org.openhab.transform.javascript/src/test/java/org/openhab/transform/javascript/internal/JavaScriptTransformationServiceTest.java index 7189ee6eb2b..9bd40c29a94 100644 --- a/bundles/org.openhab.transform.javascript/src/test/java/org/openhab/transform/javascript/internal/JavaScriptTransformationServiceTest.java +++ b/bundles/org.openhab.transform.javascript/src/test/java/org/openhab/transform/javascript/internal/JavaScriptTransformationServiceTest.java @@ -13,6 +13,7 @@ package org.openhab.transform.javascript.internal; import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.File; import java.io.IOException; @@ -40,6 +41,8 @@ import org.osgi.framework.BundleContext; @MockitoSettings(strictness = Strictness.WARN) public class JavaScriptTransformationServiceTest { + private static final boolean NASHORN_AVAILABLE = isNashornAvailable(); + private static final String BASE_FOLDER = "target"; private static final String SRC_FOLDER = "conf"; private static final String CONFIG_FOLDER = BASE_FOLDER + File.separator + SRC_FOLDER; @@ -54,8 +57,25 @@ public class JavaScriptTransformationServiceTest { } }; + /** + * Returns if the Nashorn JavaScript engine is available based on the Java specification version property. + * Nashorn has been removed from JDK 15 and onwards. + * + * @return {@code true} if Nashorn is available, {@code false} otherwise + */ + private static boolean isNashornAvailable() { + try { + String javaVersion = System.getProperty("java.specification.version"); + return javaVersion == null ? false : Long.parseLong(javaVersion) < 15; + } catch (NumberFormatException e) { + return false; + } + } + @BeforeEach public void setUp() throws IOException { + assumeTrue(NASHORN_AVAILABLE); + JavaScriptEngineManager manager = new JavaScriptEngineManager(); processor = new TestableJavaScriptTransformationService(manager); copyDirectory(SRC_FOLDER, CONFIG_FOLDER); @@ -63,8 +83,11 @@ public class JavaScriptTransformationServiceTest { @AfterEach public void tearDown() throws IOException { - try (Stream walk = Files.walk(Path.of(CONFIG_FOLDER))) { - walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + Path path = Path.of(CONFIG_FOLDER); + if (Files.exists(path)) { + try (Stream walk = Files.walk(path)) { + walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + } } } diff --git a/itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/config/ConfigFlowTest.java b/itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/config/ConfigFlowTest.java index 17fee8441be..1d21bafb6ce 100644 --- a/itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/config/ConfigFlowTest.java +++ b/itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/config/ConfigFlowTest.java @@ -27,7 +27,6 @@ import org.openhab.binding.mielecloud.internal.handler.MieleBridgeHandler; import org.openhab.binding.mielecloud.internal.handler.MieleHandlerFactory; import org.openhab.binding.mielecloud.internal.util.AbstractConfigFlowTest; import org.openhab.binding.mielecloud.internal.util.MieleCloudBindingIntegrationTestConstants; -import org.openhab.binding.mielecloud.internal.util.ReflectionUtil; import org.openhab.binding.mielecloud.internal.util.Website; import org.openhab.binding.mielecloud.internal.util.WebsiteCrawler; import org.openhab.binding.mielecloud.internal.webservice.MieleWebservice; @@ -124,7 +123,7 @@ public class ConfigFlowTest extends AbstractConfigFlowTest { public void configFlowWaitTimeoutExpiresWhenBridgeDoesNotComeOnline() throws Exception { // given: setUpAuthorizationHandler(); - ReflectionUtil.setPrivateStaticFinal(CreateBridgeServlet.class, "ONLINE_WAIT_TIMEOUT_IN_MILLISECONDS", 0); + getCreateBridgeServlet().setOnlineWaitTimeoutInMilliseconds(0); // when: configureBridgeWithConfigFlow(); diff --git a/itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/util/ReflectionUtil.java b/itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/util/ReflectionUtil.java index ffc6dba2d13..efc5929d9ce 100644 --- a/itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/util/ReflectionUtil.java +++ b/itests/org.openhab.binding.mielecloud.tests/src/main/java/org/openhab/binding/mielecloud/internal/util/ReflectionUtil.java @@ -15,7 +15,6 @@ package org.openhab.binding.mielecloud.internal.util; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -80,29 +79,6 @@ public final class ReflectionUtil { field.set(object, value); } - /** - * Sets an attribute declared as {@code private static final}. - * - * @param clazz The class owning the static attribute. - * @param fieldName The name of the attribute. - * @param value The new value. - * @throws NoSuchFieldException if no field with the given name exists. - * @throws SecurityException if the operation is not allowed. - * @throws IllegalArgumentException if one of the passed parameters is invalid. - * @throws IllegalAccessException if the field is enforcing Java language access control and is inaccessible. - */ - public static void setPrivateStaticFinal(Class clazz, String fieldName, @Nullable Object value) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Field field = clazz.getDeclaredField(fieldName); - field.setAccessible(true); - - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - - field.set(null, value); - } - /** * Invokes a private method on an object. * diff --git a/pom.xml b/pom.xml index a51a6353a5a..299cf0cd22b 100644 --- a/pom.xml +++ b/pom.xml @@ -385,6 +385,10 @@ Import-Package: \\ maven-surefire-plugin 3.0.0-M5 + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + 15 m