Skip to content

Commit 3f9c32e

Browse files
committed
fix integration test
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent fcded82 commit 3f9c32e

1 file changed

Lines changed: 45 additions & 52 deletions

File tree

itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/link/ItemChannelLinkTaggingOSGiTest.java

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,26 @@
1515
import static org.junit.jupiter.api.Assertions.*;
1616

1717
import java.io.ByteArrayInputStream;
18+
import java.util.List;
1819
import java.util.Set;
1920

2021
import org.eclipse.jdt.annotation.NonNullByDefault;
2122
import org.junit.jupiter.api.BeforeEach;
22-
import org.junit.jupiter.api.Disabled;
2323
import org.junit.jupiter.api.Test;
2424
import org.openhab.core.items.Item;
2525
import org.openhab.core.items.ItemRegistry;
26+
import org.openhab.core.model.ItemsStandaloneSetup;
2627
import org.openhab.core.model.core.ModelRepository;
28+
import org.openhab.core.model.thing.ThingStandaloneSetup;
2729
import org.openhab.core.test.java.JavaOSGiTest;
30+
import org.openhab.core.thing.Channel;
31+
import org.openhab.core.thing.ChannelUID;
32+
import org.openhab.core.thing.Thing;
2833
import org.openhab.core.thing.ThingRegistry;
34+
import org.openhab.core.thing.ThingTypeUID;
35+
import org.openhab.core.thing.ThingUID;
36+
import org.openhab.core.thing.binding.builder.ChannelBuilder;
37+
import org.openhab.core.thing.binding.builder.ThingBuilder;
2938

3039
/**
3140
* Tests for {@link ItemChannelLinkRegistry} tagging.
@@ -35,32 +44,23 @@
3544
@NonNullByDefault
3645
public class ItemChannelLinkTaggingOSGiTest extends JavaOSGiTest {
3746

38-
private static final String THINGS_MODEL_ID = "test.things";
3947
private static final String ITEMS_MODEL_ID = "test.items";
40-
41-
private static final String THINGS_MODEL = """
42-
Bridge hue:bridge-api2:bridge "Bridge" [ipAddress="123.123.123.123", applicationKey="0123456789ABCDEF"] {
43-
Thing device light "Light" [resourceId="11111111-1111-1111-1111-111111111111"]
44-
Thing device dimmer "Dimmer" [resourceId="22222222-2222-2222-2222-222222222222"]
45-
}
46-
""";
47-
4848
private static final String ITEMS_MODEL = """
49-
String Item_01 {channel="hue:device:bridge:light:color" }
50-
String Item_02 {channel="hue:device:bridge:light:color" [useTags=false] }
51-
String Item_03 {channel="hue:device:bridge:light:color" [useTags="false"] }
52-
String Item_04 "Control, Color" {channel="hue:device:bridge:light:color" [useTags=true] }
53-
String Item_05 "Control, Color" {channel="hue:device:bridge:light:color" [useTags="true"] }
54-
String Item_06 "Control Color, Custom" ["Custom"] {channel="hue:device:bridge:light:color" [useTags=true] }
55-
String Item_07 "'Control', Power, Custom" ["Power", "Custom"] {channel="hue:device:bridge:light:color" }
56-
String Item_08 "'Control', Power, Custom" ["Power", "Custom"] {channel="hue:device:bridge:light:color" [useTags=true] }
57-
String Item_09 "Switch, Custom" ["Switch", "Custom"] {channel="hue:device:bridge:light:color" }
58-
String Item_10 "Switch, Custom" ["Switch", "Custom"] {channel="hue:device:bridge:light:color" [useTags=true] }
59-
String Item_11 "Switch, Power, Custom" ["Switch", "Power", "Custom"] {channel="hue:device:bridge:light:color" }
60-
String Item_12 "Switch, Power, Custom" ["Switch", "Power", "Custom"] {channel="hue:device:bridge:light:color" [useTags=true] }
61-
String Item_13 "Alarm, LowBattery" {channel="hue:device:bridge:dimmer:battery-low" [useTags=true] }
62-
String Item_14 "Control, Color" {channel="hue:device:bridge:light:color" [useTags=true], channel="hue:device:bridge:dimmer:battery-low" [useTags=true] }
63-
String Item_15 "Alarm, LowBattery" {channel="hue:device:bridge:light:color" [useTags=false], channel="hue:device:bridge:dimmer:battery-low" [useTags=true] }
49+
String Item_01 {channel="hue:device:dummy:color" }
50+
String Item_02 {channel="hue:device:dummy:color" [useTags=false] }
51+
String Item_03 {channel="hue:device:dummy:color" [useTags="false"] }
52+
String Item_04 "Control, Color" {channel="hue:device:dummy:color" [useTags=true] }
53+
String Item_05 "Control, Color" {channel="hue:device:dummy:color" [useTags="true"] }
54+
String Item_06 "Control Color, Custom" ["Custom"] {channel="hue:device:dummy:color" [useTags=true] }
55+
String Item_07 "'Control', Power, Custom" ["Power", "Custom"] {channel="hue:device:dummy:color" }
56+
String Item_08 "'Control', Power, Custom" ["Power", "Custom"] {channel="hue:device:dummy:color" [useTags=true] }
57+
String Item_09 "Switch, Custom" ["Switch", "Custom"] {channel="hue:device:dummy:color" }
58+
String Item_10 "Switch, Custom" ["Switch", "Custom"] {channel="hue:device:dummy:color" [useTags=true] }
59+
String Item_11 "Switch, Power, Custom" ["Switch", "Power", "Custom"] {channel="hue:device:dummy:color" }
60+
String Item_12 "Switch, Power, Custom" ["Switch", "Power", "Custom"] {channel="hue:device:dummy:color" [useTags=true] }
61+
String Item_13 "Alarm, LowBattery" {channel="hue:device:dummy:battery-low" [useTags=true] }
62+
String Item_14 "Control, Color" {channel="hue:device:dummy:color" [useTags=true], channel="hue:device:dummy:battery-low" [useTags=true] }
63+
String Item_15 "Alarm, LowBattery" {channel="hue:device:dummy:color" [useTags=false], channel="hue:device:dummy:battery-low" [useTags=true] }
6464
""";
6565

6666
private @NonNullByDefault({}) ItemRegistry itemRegistry;
@@ -72,6 +72,9 @@ public class ItemChannelLinkTaggingOSGiTest extends JavaOSGiTest {
7272
public void setup() {
7373
registerVolatileStorageService();
7474

75+
ItemsStandaloneSetup.doSetup();
76+
ThingStandaloneSetup.doSetup();
77+
7578
itemRegistry = getService(ItemRegistry.class);
7679
assertNotNull(itemRegistry);
7780

@@ -85,35 +88,25 @@ public void setup() {
8588
assertNotNull(modelRepository);
8689
}
8790

88-
/**
89-
* TODO I wrote this to test the channel / item tagging but it fails with the stack trace below ("resource" is null)
90-
* and in spite of many hours trying I was unable to find a solution to make it work. So in the menatime the test is
91-
* currently disabled until some kind maintainer can help me to fix it.
92-
*
93-
* <pre>
94-
* {@code
95-
* TEST org.openhab.core.thing.link.ItemChannelLinkTaggingOSGiTest#assertTagsAreCorrect() <<< ERROR: Cannot invoke
96-
* "org.eclipse.emf.ecore.resource.Resource.load(java.io.InputStream, java.util.Map)" because "resource" is null
97-
* java.lang.NullPointerException: Cannot invoke "org.eclipse.emf.ecore.resource.Resource.load(java.io.InputStream, java.util.Map)" because "resource" is null
98-
* at org.openhab.core.model.core.internal.ModelRepositoryImpl.validateModel(ModelRepositoryImpl.java:280)
99-
* at org.openhab.core.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:108)
100-
* at org.openhab.core.thing.link.ItemChannelLinkTaggingOSGiTest.assertTagsAreCorrect( ItemChannelLinkTaggingOSGiTest.java:107)
101-
* }
102-
* </pre>
103-
*/
10491
@Test
105-
@Disabled
10692
public void assertTagsAreCorrect() {
107-
modelRepository.addOrRefreshModel(THINGS_MODEL_ID, new ByteArrayInputStream(THINGS_MODEL.getBytes())); // <== !!
108-
waitForAssert(() -> {
109-
assertEquals(3, thingRegistry.getAll().size());
110-
});
111-
112-
modelRepository.addOrRefreshModel(ITEMS_MODEL_ID, new ByteArrayInputStream(ITEMS_MODEL.getBytes())); // <== !!
113-
waitForAssert(() -> {
114-
assertEquals(15, itemRegistry.getAll().size());
115-
assertEquals(17, itemChannelLinkRegistry.getAll().size());
116-
});
93+
ThingTypeUID thingTypeUID = new ThingTypeUID("hue", "device");
94+
ThingUID thingUID = new ThingUID(thingTypeUID, "dummy");
95+
96+
Channel colorChannel = ChannelBuilder.create(new ChannelUID(thingUID, "color"), "Color")
97+
.withDefaultTags(Set.of("Control", "Color")).build();
98+
Channel batteryChannel = ChannelBuilder.create(new ChannelUID(thingUID, "battery-low"), "Switch")
99+
.withDefaultTags(Set.of("Alarm", "LowBattery")).build();
100+
101+
Thing thing = ThingBuilder.create(thingTypeUID, thingUID) //
102+
.withChannels(List.of(colorChannel, batteryChannel)).build();
103+
104+
thingRegistry.add(thing);
105+
assertEquals(1, thingRegistry.getAll().size());
106+
107+
modelRepository.addOrRefreshModel(ITEMS_MODEL_ID, new ByteArrayInputStream(ITEMS_MODEL.getBytes()));
108+
assertEquals(15, itemRegistry.getAll().size());
109+
assertEquals(17, itemChannelLinkRegistry.getAll().size());
117110

118111
Item item;
119112

0 commit comments

Comments
 (0)