From: Jacob Laursen Date: Mon, 1 Jan 2024 15:08:34 +0000 (+0100) Subject: Fix namespace issues (#16169) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=800775c986b3eecd84b4120ff448c3e3d387ecd3;p=openhab-addons.git Fix namespace issues (#16169) Signed-off-by: Jacob Laursen --- diff --git a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/discovery/PlexDiscoveryService.java b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/discovery/PlexDiscoveryService.java deleted file mode 100644 index a7b3659da5..0000000000 --- a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/discovery/PlexDiscoveryService.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.plex.discovery; - -import static org.openhab.binding.plex.internal.PlexBindingConstants.*; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.plex.internal.handler.PlexServerHandler; -import org.openhab.core.config.discovery.AbstractDiscoveryService; -import org.openhab.core.config.discovery.DiscoveryResult; -import org.openhab.core.config.discovery.DiscoveryResultBuilder; -import org.openhab.core.thing.ThingTypeUID; -import org.openhab.core.thing.ThingUID; - -/** - * @author Brian Homeyer - Initial contribution - * @author Aron Beurskens - Binding development - */ -@NonNullByDefault -public class PlexDiscoveryService extends AbstractDiscoveryService { - private final PlexServerHandler bridgeHandler; - - public PlexDiscoveryService(PlexServerHandler bridgeHandler) { - super(SUPPORTED_THING_TYPES_UIDS, 10, false); - this.bridgeHandler = bridgeHandler; - } - - @Override - protected void startScan() { - for (String machineId : bridgeHandler.getAvailablePlayers()) { - ThingUID bridgeUID = bridgeHandler.getThing().getUID(); - ThingTypeUID thingTypeUID = UID_PLAYER; - ThingUID playerThingUid = new ThingUID(UID_PLAYER, bridgeUID, machineId); - - Map properties = new HashMap<>(); - properties.put(CONFIG_PLAYER_ID, machineId); - - DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(playerThingUid).withThingType(thingTypeUID) - .withProperties(properties).withBridge(bridgeUID).withRepresentationProperty(CONFIG_PLAYER_ID) - .withLabel("PLEX Player (" + machineId + ")").build(); - - thingDiscovered(discoveryResult); - } - } -} diff --git a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexHandlerFactory.java b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexHandlerFactory.java index 8bd642cfc5..4af163ede5 100644 --- a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexHandlerFactory.java +++ b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/PlexHandlerFactory.java @@ -18,7 +18,7 @@ import java.util.Hashtable; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.plex.discovery.PlexDiscoveryService; +import org.openhab.binding.plex.internal.discovery.PlexDiscoveryService; import org.openhab.binding.plex.internal.handler.PlexPlayerHandler; import org.openhab.binding.plex.internal.handler.PlexServerHandler; import org.openhab.core.config.discovery.DiscoveryService; diff --git a/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/discovery/PlexDiscoveryService.java b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/discovery/PlexDiscoveryService.java new file mode 100644 index 0000000000..f02c649e53 --- /dev/null +++ b/bundles/org.openhab.binding.plex/src/main/java/org/openhab/binding/plex/internal/discovery/PlexDiscoveryService.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.plex.internal.discovery; + +import static org.openhab.binding.plex.internal.PlexBindingConstants.*; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.binding.plex.internal.handler.PlexServerHandler; +import org.openhab.core.config.discovery.AbstractDiscoveryService; +import org.openhab.core.config.discovery.DiscoveryResult; +import org.openhab.core.config.discovery.DiscoveryResultBuilder; +import org.openhab.core.thing.ThingTypeUID; +import org.openhab.core.thing.ThingUID; + +/** + * @author Brian Homeyer - Initial contribution + * @author Aron Beurskens - Binding development + */ +@NonNullByDefault +public class PlexDiscoveryService extends AbstractDiscoveryService { + private final PlexServerHandler bridgeHandler; + + public PlexDiscoveryService(PlexServerHandler bridgeHandler) { + super(SUPPORTED_THING_TYPES_UIDS, 10, false); + this.bridgeHandler = bridgeHandler; + } + + @Override + protected void startScan() { + for (String machineId : bridgeHandler.getAvailablePlayers()) { + ThingUID bridgeUID = bridgeHandler.getThing().getUID(); + ThingTypeUID thingTypeUID = UID_PLAYER; + ThingUID playerThingUid = new ThingUID(UID_PLAYER, bridgeUID, machineId); + + Map properties = new HashMap<>(); + properties.put(CONFIG_PLAYER_ID, machineId); + + DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(playerThingUid).withThingType(thingTypeUID) + .withProperties(properties).withBridge(bridgeUID).withRepresentationProperty(CONFIG_PLAYER_ID) + .withLabel("PLEX Player (" + machineId + ")").build(); + + thingDiscovered(discoveryResult); + } + } +} diff --git a/bundles/org.openhab.binding.plex/src/test/java/org.openhab.binding.plex/internal/handler/PlexApiConnectorTest.java b/bundles/org.openhab.binding.plex/src/test/java/org.openhab.binding.plex/internal/handler/PlexApiConnectorTest.java deleted file mode 100644 index f872e35f1c..0000000000 --- a/bundles/org.openhab.binding.plex/src/test/java/org.openhab.binding.plex/internal/handler/PlexApiConnectorTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright (c) 2010-2023 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.binding.plex.internal.handler; - -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.assertThat; - -import java.util.concurrent.ScheduledExecutorService; -import java.util.stream.Stream; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jetty.client.HttpClient; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.mockito.Mock; -import org.openhab.binding.plex.internal.config.PlexServerConfiguration; - -/** - * Tests cases for {@link org.openhab.binding.plex.internal.handler.PlexApiConnector}. - * - * @author Brian Homeyer - Initial contribution - * @author Aron Beurskens - Added test - */ -@NonNullByDefault -public class PlexApiConnectorTest { - private @NonNullByDefault({}) @Mock ScheduledExecutorService scheduler; - private @NonNullByDefault({}) @Mock HttpClient httpClient; - - private @NonNullByDefault({}) PlexApiConnector plexApiConnector; - - @BeforeEach - public void setUp() { - plexApiConnector = new PlexApiConnector(scheduler, httpClient); - } - - /** - * Test that the .hasToken check return the correct values. - */ - @ParameterizedTest(name = "{index} => token={0}, result={1}") - @MethodSource("tokenProvider") - public void testHasToken(String token, Boolean result) { - PlexServerConfiguration config = new PlexServerConfiguration(); - config.token = token; - plexApiConnector.setParameters(config); - assertThat(plexApiConnector.hasToken(), is(result)); - } - - private static Stream tokenProvider() { - return Stream.of(Arguments.of("123", true), Arguments.of(" ", false), - Arguments.of("fdsjkghdf-dsjfhs-dsafkshj", true), Arguments.of("", false)); - } -} diff --git a/bundles/org.openhab.binding.plex/src/test/java/org/openhab/binding/plex/internal/handler/PlexApiConnectorTest.java b/bundles/org.openhab.binding.plex/src/test/java/org/openhab/binding/plex/internal/handler/PlexApiConnectorTest.java new file mode 100644 index 0000000000..f872e35f1c --- /dev/null +++ b/bundles/org.openhab.binding.plex/src/test/java/org/openhab/binding/plex/internal/handler/PlexApiConnectorTest.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.plex.internal.handler; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.stream.Stream; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jetty.client.HttpClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Mock; +import org.openhab.binding.plex.internal.config.PlexServerConfiguration; + +/** + * Tests cases for {@link org.openhab.binding.plex.internal.handler.PlexApiConnector}. + * + * @author Brian Homeyer - Initial contribution + * @author Aron Beurskens - Added test + */ +@NonNullByDefault +public class PlexApiConnectorTest { + private @NonNullByDefault({}) @Mock ScheduledExecutorService scheduler; + private @NonNullByDefault({}) @Mock HttpClient httpClient; + + private @NonNullByDefault({}) PlexApiConnector plexApiConnector; + + @BeforeEach + public void setUp() { + plexApiConnector = new PlexApiConnector(scheduler, httpClient); + } + + /** + * Test that the .hasToken check return the correct values. + */ + @ParameterizedTest(name = "{index} => token={0}, result={1}") + @MethodSource("tokenProvider") + public void testHasToken(String token, Boolean result) { + PlexServerConfiguration config = new PlexServerConfiguration(); + config.token = token; + plexApiConnector.setParameters(config); + assertThat(plexApiConnector.hasToken(), is(result)); + } + + private static Stream tokenProvider() { + return Stream.of(Arguments.of("123", true), Arguments.of(" ", false), + Arguments.of("fdsjkghdf-dsjfhs-dsafkshj", true), Arguments.of("", false)); + } +}