[mqtt.ruuvigateway] Re-enable itests after core change (#15018)
Also-by: Jan N. Klug <github@klug.nrw> Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
This commit is contained in:
parent
04e7f2f74e
commit
397fc8d1cf
|
@ -104,4 +104,10 @@ Import-Package: \
|
||||||
io.netty.resolver;version='[4.1.92,4.1.93)',\
|
io.netty.resolver;version='[4.1.92,4.1.93)',\
|
||||||
io.netty.transport;version='[4.1.92,4.1.93)',\
|
io.netty.transport;version='[4.1.92,4.1.93)',\
|
||||||
io.netty.transport-native-unix-common;version='[4.1.92,4.1.93)',\
|
io.netty.transport-native-unix-common;version='[4.1.92,4.1.93)',\
|
||||||
org.osgi.service.cm;version='[1.6.0,1.6.1)'
|
jakarta.ws.rs-api;version='[2.1.6,2.1.7)',\
|
||||||
|
net.bytebuddy.byte-buddy;version='[1.12.19,1.12.20)',\
|
||||||
|
net.bytebuddy.byte-buddy-agent;version='[1.12.19,1.12.20)',\
|
||||||
|
org.mockito.mockito-core;version='[4.11.0,4.11.1)',\
|
||||||
|
org.objenesis;version='[3.3.0,3.3.1)',\
|
||||||
|
org.osgi.service.cm;version='[1.6.0,1.6.1)',\
|
||||||
|
org.mockito.junit-jupiter;version='[4.11.0,4.11.1)'
|
|
@ -15,7 +15,9 @@ package org.openhab.binding.mqtt.ruuvigateway;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
import static org.openhab.binding.mqtt.ruuvigateway.internal.RuuviGatewayBindingConstants.*;
|
import static org.openhab.binding.mqtt.ruuvigateway.internal.RuuviGatewayBindingConstants.*;
|
||||||
|
import static org.openhab.core.library.unit.MetricPrefix.HECTO;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -50,15 +52,21 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.CsvSource;
|
import org.junit.jupiter.params.provider.CsvSource;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
import org.openhab.binding.mqtt.discovery.MQTTTopicDiscoveryService;
|
import org.openhab.binding.mqtt.discovery.MQTTTopicDiscoveryService;
|
||||||
import org.openhab.binding.mqtt.ruuvigateway.internal.RuuviGatewayBindingConstants;
|
import org.openhab.binding.mqtt.ruuvigateway.internal.RuuviGatewayBindingConstants;
|
||||||
import org.openhab.binding.mqtt.ruuvigateway.internal.discovery.RuuviGatewayDiscoveryService;
|
import org.openhab.binding.mqtt.ruuvigateway.internal.discovery.RuuviGatewayDiscoveryService;
|
||||||
import org.openhab.binding.mqtt.ruuvigateway.internal.handler.RuuviTagHandler;
|
import org.openhab.binding.mqtt.ruuvigateway.internal.handler.RuuviTagHandler;
|
||||||
import org.openhab.core.config.core.Configuration;
|
import org.openhab.core.config.core.Configuration;
|
||||||
import org.openhab.core.config.discovery.DiscoveryResult;
|
import org.openhab.core.config.discovery.DiscoveryResult;
|
||||||
|
import org.openhab.core.i18n.UnitProvider;
|
||||||
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
|
import org.openhab.core.io.transport.mqtt.MqttBrokerConnection;
|
||||||
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
|
import org.openhab.core.io.transport.mqtt.MqttConnectionObserver;
|
||||||
import org.openhab.core.io.transport.mqtt.MqttConnectionState;
|
import org.openhab.core.io.transport.mqtt.MqttConnectionState;
|
||||||
|
@ -94,7 +102,10 @@ import org.openhab.core.types.UnDefType;
|
||||||
* @author Sami Salonen - Adapted and extended to Ruuvi Gateway tests
|
* @author Sami Salonen - Adapted and extended to Ruuvi Gateway tests
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
public class RuuviGatewayTest extends MqttOSGiTest {
|
public class RuuviGatewayTest extends MqttOSGiTest {
|
||||||
|
protected @Mock @NonNullByDefault({}) UnitProvider mockedUnitProvider;
|
||||||
private static final String BASE_TOPIC_RUUVI = "ruuvi";
|
private static final String BASE_TOPIC_RUUVI = "ruuvi";
|
||||||
private static final Map<String, String> CHANNEL_TO_ITEM_TYPE = new HashMap<>();
|
private static final Map<String, String> CHANNEL_TO_ITEM_TYPE = new HashMap<>();
|
||||||
static {
|
static {
|
||||||
|
@ -132,6 +143,27 @@ public class RuuviGatewayTest extends MqttOSGiTest {
|
||||||
private @NonNullByDefault({}) RuuviGatewayDiscoveryService ruuviDiscoveryService;
|
private @NonNullByDefault({}) RuuviGatewayDiscoveryService ruuviDiscoveryService;
|
||||||
private Set<Thing> things = new HashSet<>();
|
private Set<Thing> things = new HashSet<>();
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
when(mockedUnitProvider.getUnit(any())).then(i -> {
|
||||||
|
Class clazz = i.getArgument(0);
|
||||||
|
if (Temperature.class.equals(clazz)) {
|
||||||
|
return SIUnits.CELSIUS;
|
||||||
|
} else if (Acceleration.class.equals(clazz)) {
|
||||||
|
return Units.METRE_PER_SQUARE_SECOND;
|
||||||
|
} else if (Dimensionless.class.equals(clazz)) {
|
||||||
|
return Units.ONE;
|
||||||
|
} else if (ElectricPotential.class.equals(clazz)) {
|
||||||
|
return Units.VOLT;
|
||||||
|
} else if (Pressure.class.equals(clazz)) {
|
||||||
|
return HECTO(SIUnits.PASCAL);
|
||||||
|
} else if (Power.class.equals(clazz)) {
|
||||||
|
return Units.WATT;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private Bridge createMqttBrokerBridge() {
|
private Bridge createMqttBrokerBridge() {
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
configuration.put("host", "127.0.0.1");
|
configuration.put("host", "127.0.0.1");
|
||||||
|
@ -208,7 +240,7 @@ public class RuuviGatewayTest extends MqttOSGiTest {
|
||||||
private String linkChannelToAutogeneratedItem(ChannelUID channelUID) {
|
private String linkChannelToAutogeneratedItem(ChannelUID channelUID) {
|
||||||
String itemName = itemName(channelUID);
|
String itemName = itemName(channelUID);
|
||||||
String itemType = CHANNEL_TO_ITEM_TYPE.get(channelUID.getId());
|
String itemType = CHANNEL_TO_ITEM_TYPE.get(channelUID.getId());
|
||||||
GenericItem item = new CoreItemFactory().createItem(itemType, itemName);
|
GenericItem item = new CoreItemFactory(mockedUnitProvider).createItem(itemType, itemName);
|
||||||
assertNotNull(item, itemType);
|
assertNotNull(item, itemType);
|
||||||
itemProvider.add(item);
|
itemProvider.add(item);
|
||||||
itemChannelLinkProvider.add(new ItemChannelLink(itemName, channelUID));
|
itemChannelLinkProvider.add(new ItemChannelLink(itemName, channelUID));
|
||||||
|
|
|
@ -28,9 +28,7 @@
|
||||||
<module>org.openhab.binding.modbus.tests</module>
|
<module>org.openhab.binding.modbus.tests</module>
|
||||||
<module>org.openhab.binding.mqtt.homeassistant.tests</module>
|
<module>org.openhab.binding.mqtt.homeassistant.tests</module>
|
||||||
<module>org.openhab.binding.mqtt.homie.tests</module>
|
<module>org.openhab.binding.mqtt.homie.tests</module>
|
||||||
<!-- MQTT ruuvigateway tests disabled until fixed (CoreItemFactory + NumberItem)
|
<module>org.openhab.binding.mqtt.ruuvigateway.tests</module>
|
||||||
<module>org.openhab.binding.mqtt.ruuvigateway.tests</module>
|
|
||||||
-->
|
|
||||||
<module>org.openhab.binding.nest.tests</module>
|
<module>org.openhab.binding.nest.tests</module>
|
||||||
<module>org.openhab.binding.ntp.tests</module>
|
<module>org.openhab.binding.ntp.tests</module>
|
||||||
<module>org.openhab.binding.systeminfo.tests</module>
|
<module>org.openhab.binding.systeminfo.tests</module>
|
||||||
|
|
Loading…
Reference in New Issue