]> git.basschouten.com Git - openhab-addons.git/commitdiff
[systeminfo] Fix and re-enable tests (#14992)
authorMark Herwege <mherwege@users.noreply.github.com>
Wed, 17 May 2023 18:13:24 +0000 (20:13 +0200)
committerGitHub <noreply@github.com>
Wed, 17 May 2023 18:13:24 +0000 (20:13 +0200)
* [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>
itests/org.openhab.binding.systeminfo.tests/src/main/java/org/openhab/binding/systeminfo/test/SysteminfoOSGiTest.java
itests/pom.xml

index 2a8f35967a9baeb96b4e403479f060d63acaf8b2..84f2a6b52c7fd38bdaf8e30bf9645c3727d13869 100644 (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);
-        }
+        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);
-        assertThat(inbox, is(notNullValue()));
+        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");
         }
index 2a0bbacc158eecae45ffdcfab0bad020a07483d2..50c3ae5176ecc7f9294e54d58054ec8887a318f2 100644 (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.systeminfo.tests</module>
     <module>org.openhab.binding.tradfri.tests</module>
     <module>org.openhab.binding.wemo.tests</module>
     <module>org.openhab.persistence.mapdb.tests</module>