Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deconz] Fix tests. Fix #17104 #17108

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
Expand All @@ -47,6 +48,7 @@
import org.openhab.binding.deconz.internal.types.ThermostatMode;
import org.openhab.binding.deconz.internal.types.ThermostatModeGsonTypeAdapter;
import org.openhab.core.config.discovery.DiscoveryListener;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ThingUID;
Expand Down Expand Up @@ -92,6 +94,7 @@ public void discoveryTest() throws IOException {
Mockito.doAnswer(answer -> CompletableFuture.completedFuture(Optional.of(bridgeFullState))).when(bridgeHandler)
.getBridgeFullState();
ThingDiscoveryService discoveryService = new ThingDiscoveryService();
discoveryService.modified(Map.of(DiscoveryService.CONFIG_PROPERTY_BACKGROUND_DISCOVERY, false));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about that, because that is not the default setting. Maybe removing discoveryService.startScan() and relying on the background discovery would be an approach that is closer to a production system.

Copy link
Contributor Author

@andrewfg andrewfg Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I can change it.

.. but on a side note, it seems to me that the Junit test is not really a test of the binding code, but rather of the OH core ..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It ensures that the discovery code creates a DiscoveryResult for every device in the input JSON. I would say that this is binding code.

Copy link
Contributor Author

@andrewfg andrewfg Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. but in any case, removing the startScan() also fails the Junit test (see below) .. so evidently we cannot 'rely on the background discovery' -- of the three options i) foreground scan with no background, ii) background with no foreground, or iii) both background and foreground, it seems to me that i) (my solution) is the most controlled test and therefore the one most likely to pass properly.

[ERROR] Failures:
[ERROR]   DeconzTest.discoveryTest:100
Wanted but not invoked:
discoveryListener.thingDiscovered(
    <any>,
    <any>
);
-> at org.openhab.binding.deconz.DeconzTest.discoveryTest(DeconzTest.java:100)

However, there was exactly 1 interaction with this mock:
discoveryListener.removeOlderResults(
    org.openhab.binding.deconz.internal.discovery.ThingDiscoveryService@329a1f8d,
    0L,
    [deconz:colorcontrol, deconz:dimmablelight, deconz:powersensor, deconz:consumptionsensor, deconz:moisturesensor, deconz:waterleakagesensor, deconz:onofflight, deconz:switch, deconz:vibrationsensor, deconz:openclosesensor, deconz:humiditysensor, deconz:colortemperaturelight, deconz:extendedcolorlight, deconz:windowcovering, deconz:airqualitysensor, deconz:lightsensor, deconz:batterysensor, deconz:pressuresensor, deconz:presencesensor, deconz:alarmsensor, deconz:colorlight, deconz:doorlock, deconz:firesensor, deconz:temperaturesensor, deconz:carbonmonoxidesensor, deconz:daylightsensor, deconz:warningdevice, deconz:thermostat],
    null
);
-> at org.openhab.core.config.discovery.AbstractDiscoveryService.removeOlderResults(AbstractDiscoveryService.java:330)

discoveryService.setThingHandler(bridgeHandler);
discoveryService.initialize();
discoveryService.addDiscoveryListener(discoveryListener);
Expand Down