[systeminfo] Fix and re-enable tests (#14992)

* [systeminfo] Fix itests after core change
* re-enable test

---------

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Co-authored-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
Mark Herwege 2023-05-17 20:13:24 +02:00 committed by GitHub
parent 353c154c12
commit d5f50ab0de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 35 deletions

View File

@ -40,7 +40,6 @@ import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.openhab.binding.systeminfo.internal.SysteminfoBindingConstants;
import org.openhab.binding.systeminfo.internal.SysteminfoHandlerFactory;
import org.openhab.binding.systeminfo.internal.SysteminfoThingTypeProvider;
import org.openhab.binding.systeminfo.internal.discovery.SysteminfoDiscoveryService;
import org.openhab.binding.systeminfo.internal.handler.SysteminfoHandler;
import org.openhab.binding.systeminfo.internal.model.DeviceNotFoundException;
@ -51,6 +50,7 @@ import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.config.discovery.inbox.Inbox;
import org.openhab.core.config.discovery.inbox.InboxPredicates;
import org.openhab.core.i18n.UnitProvider;
import org.openhab.core.items.GenericItem;
import org.openhab.core.items.ItemNotFoundException;
import org.openhab.core.items.ItemRegistry;
@ -77,7 +77,6 @@ import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.openhab.core.thing.binding.ThingTypeProvider;
import org.openhab.core.thing.binding.builder.ChannelBuilder;
import org.openhab.core.thing.binding.builder.ThingBuilder;
import org.openhab.core.thing.link.ItemChannelLink;
@ -117,14 +116,16 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
*/
private static final int DEFAULT_TEST_INTERVAL_MEDIUM = 3;
private @Nullable Thing systemInfoThing;
private @Nullable Thing systeminfoThing;
private @Nullable GenericItem testItem;
private @Mock @NonNullByDefault({}) OSHISysteminfo mockedSystemInfo;
private @NonNullByDefault({}) SysteminfoHandlerFactory systeminfoHandlerFactory;
private @NonNullByDefault({}) ThingRegistry thingRegistry;
private @NonNullByDefault({}) ItemRegistry itemRegistry;
private @NonNullByDefault({}) SysteminfoThingTypeProvider systemThingTypeProvider;
private @NonNullByDefault({}) ManagedThingProvider managedThingProvider;
private @NonNullByDefault({}) ManagedItemChannelLinkProvider itemChannelLinkProvider;
private @NonNullByDefault({}) UnitProvider unitProvider;
@BeforeEach
public void setUp() {
@ -148,11 +149,6 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
registerService(mockedSystemInfo);
waitForAssert(() -> {
systemThingTypeProvider = getService(ThingTypeProvider.class, SysteminfoThingTypeProvider.class);
assertThat(systemThingTypeProvider, is(notNullValue()));
});
waitForAssert(() -> {
systeminfoHandlerFactory = getService(ThingHandlerFactory.class, SysteminfoHandlerFactory.class);
assertThat(systeminfoHandlerFactory, is(notNullValue()));
@ -182,11 +178,26 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
itemRegistry = getService(ItemRegistry.class);
assertThat(itemRegistry, is(notNullValue()));
});
waitForAssert(() -> {
managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
});
waitForAssert(() -> {
itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertThat(itemChannelLinkProvider, is(notNullValue()));
});
waitForAssert(() -> {
unitProvider = getService(UnitProvider.class);
assertThat(unitProvider, is(notNullValue()));
});
}
@AfterEach
public void tearDown() {
Thing thing = systemInfoThing;
Thing thing = systeminfoThing;
if (thing != null) {
// Remove the systeminfo thing. The handler will be also disposed automatically
Thing removedThing = thingRegistry.forceRemove(thing.getUID());
@ -266,14 +277,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
Thing thing = ThingBuilder.create(thingTypeUID, thingUID).withConfiguration(thingConfiguration)
.withChannel(channel).build();
systemInfoThing = thing;
systeminfoThing = thing;
ManagedThingProvider managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
if (managedThingProvider != null) {
managedThingProvider.add(thing);
}
waitForAssert(() -> {
SysteminfoHandler handler = (SysteminfoHandler) thing.getHandler();
@ -289,7 +295,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
}
private void assertItemState(String acceptedItemType, String itemName, String priority, State expectedState) {
Thing thing = systemInfoThing;
Thing thing = systeminfoThing;
if (thing == null) {
throw new AssertionError("Thing is null");
}
@ -331,7 +337,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
private void intializeItem(ChannelUID channelUID, String itemName, String acceptedItemType) {
GenericItem item = null;
if (acceptedItemType.startsWith("Number")) {
item = new NumberItem(acceptedItemType, itemName);
item = new NumberItem(acceptedItemType, itemName, unitProvider);
} else if ("String".equals(acceptedItemType)) {
item = new StringItem(itemName);
}
@ -341,13 +347,6 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
itemRegistry.add(item);
testItem = item;
ManagedItemChannelLinkProvider itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertThat(itemChannelLinkProvider, is(notNullValue()));
if (itemChannelLinkProvider == null) {
return;
}
itemChannelLinkProvider.add(new ItemChannelLink(itemName, channelUID));
}
@ -369,7 +368,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
private void testInvalidConfiguration() {
waitForAssert(() -> {
Thing thing = systemInfoThing;
Thing thing = systeminfoThing;
if (thing != null) {
assertThat("Invalid configuration is used !", thing.getStatus(), is(equalTo(ThingStatus.OFFLINE)));
assertThat(thing.getStatusInfo().getStatusDetail(),
@ -989,7 +988,9 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
discoveryServiceMock.startScan();
Inbox inbox = getService(Inbox.class);
waitForAssert(() -> {
assertThat(inbox, is(notNullValue()));
});
if (inbox == null) {
return;
@ -1004,11 +1005,11 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
inbox.approve(computerUID, SysteminfoDiscoveryService.DEFAULT_THING_LABEL, null);
waitForAssert(() -> {
systemInfoThing = thingRegistry.get(computerUID);
assertThat(systemInfoThing, is(notNullValue()));
systeminfoThing = thingRegistry.get(computerUID);
assertThat(systeminfoThing, is(notNullValue()));
});
Thing thing = systemInfoThing;
Thing thing = systeminfoThing;
if (thing == null) {
return;
}
@ -1099,7 +1100,7 @@ public class SysteminfoOSGiTest extends JavaOSGiTest {
String acceptedItemType = "Number";
initializeThingWithChannel(DEFAULT_TEST_CHANNEL_ID, acceptedItemType);
Thing thing = systemInfoThing;
Thing thing = systeminfoThing;
if (thing == null) {
throw new AssertionError("Thing is null");
}

View File

@ -35,9 +35,7 @@
-->
<module>org.openhab.binding.nest.tests</module>
<module>org.openhab.binding.ntp.tests</module>
<!-- Systeminfo tests disabled until fixed (NumberItem)
<module>org.openhab.binding.systeminfo.tests</module>
-->
<module>org.openhab.binding.tradfri.tests</module>
<module>org.openhab.binding.wemo.tests</module>
<module>org.openhab.persistence.mapdb.tests</module>