Skip to content

Commit fcded82

Browse files
committed
ready for final review
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
1 parent 9fa2e5e commit fcded82

2 files changed

Lines changed: 243 additions & 1 deletion

File tree

itests/org.openhab.core.thing.tests/itest.bndrun

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,63 @@ Fragment-Host: org.openhab.core.thing
7474
org.openhab.core.transform;version='[5.1.0,5.1.1)',\
7575
biz.aQute.tester.junit-platform;version='[7.1.0,7.1.1)',\
7676
org.ops4j.pax.logging.pax-logging-api;version='[2.2.8,2.2.9)',\
77-
org.openhab.core.semantics;version='[5.1.0,5.1.1)'
77+
org.openhab.core.semantics;version='[5.1.0,5.1.1)',\
78+
com.fasterxml.jackson.core.jackson-annotations;version='[2.18.2,2.18.3)',\
79+
com.fasterxml.jackson.core.jackson-core;version='[2.18.2,2.18.3)',\
80+
com.fasterxml.jackson.core.jackson-databind;version='[2.18.2,2.18.3)',\
81+
com.fasterxml.jackson.dataformat.jackson-dataformat-xml;version='[2.18.2,2.18.3)',\
82+
com.fasterxml.jackson.dataformat.jackson-dataformat-yaml;version='[2.18.2,2.18.3)',\
83+
com.google.guava;version='[33.3.1,33.3.2)',\
84+
com.google.guava.failureaccess;version='[1.0.2,1.0.3)',\
85+
com.google.inject;version='[7.0.0,7.0.1)',\
86+
de.focus_shift.jollyday-core;version='[1.5.4,1.5.5)',\
87+
de.focus_shift.jollyday-jackson;version='[1.5.4,1.5.5)',\
88+
io.github.classgraph.classgraph;version='[4.8.176,4.8.177)',\
89+
org.antlr.runtime;version='[3.2.0,3.2.1)',\
90+
org.eclipse.emf.common;version='[2.24.0,2.24.1)',\
91+
org.eclipse.emf.ecore;version='[2.26.0,2.26.1)',\
92+
org.eclipse.emf.ecore.xmi;version='[2.16.0,2.16.1)',\
93+
org.eclipse.equinox.common;version='[3.17.100,3.17.101)',\
94+
org.eclipse.jetty.alpn.client;version='[9.4.57,9.4.58)',\
95+
org.eclipse.jetty.client;version='[9.4.57,9.4.58)',\
96+
org.eclipse.jetty.http2.client;version='[9.4.57,9.4.58)',\
97+
org.eclipse.jetty.http2.common;version='[9.4.57,9.4.58)',\
98+
org.eclipse.jetty.http2.hpack;version='[9.4.57,9.4.58)',\
99+
org.eclipse.jetty.jaas;version='[9.4.57,9.4.58)',\
100+
org.eclipse.jetty.websocket.api;version='[9.4.57,9.4.58)',\
101+
org.eclipse.jetty.websocket.client;version='[9.4.57,9.4.58)',\
102+
org.eclipse.jetty.websocket.common;version='[9.4.57,9.4.58)',\
103+
org.eclipse.jetty.xml;version='[9.4.57,9.4.58)',\
104+
org.eclipse.xtend.lib;version='[2.37.0,2.37.1)',\
105+
org.eclipse.xtend.lib.macro;version='[2.37.0,2.37.1)',\
106+
org.eclipse.xtext;version='[2.37.0,2.37.1)',\
107+
org.eclipse.xtext.common.types;version='[2.37.0,2.37.1)',\
108+
org.eclipse.xtext.util;version='[2.37.0,2.37.1)',\
109+
org.eclipse.xtext.xbase;version='[2.37.0,2.37.1)',\
110+
org.eclipse.xtext.xbase.lib;version='[2.37.0,2.37.1)',\
111+
org.glassfish.hk2.external.aopalliance-repackaged;version='[3.1.1,3.1.2)',\
112+
org.openhab.core.audio;version='[5.1.0,5.1.1)',\
113+
org.openhab.core.automation;version='[5.1.0,5.1.1)',\
114+
org.openhab.core.automation.module.script;version='[5.1.0,5.1.1)',\
115+
org.openhab.core.automation.module.script.rulesupport;version='[5.1.0,5.1.1)',\
116+
org.openhab.core.ephemeris;version='[5.1.0,5.1.1)',\
117+
org.openhab.core.io.net;version='[5.1.0,5.1.1)',\
118+
org.openhab.core.model.core;version='[5.1.0,5.1.1)',\
119+
org.openhab.core.model.item;version='[5.1.0,5.1.1)',\
120+
org.openhab.core.model.persistence;version='[5.1.0,5.1.1)',\
121+
org.openhab.core.model.persistence.runtime;version='[5.1.0,5.1.1)',\
122+
org.openhab.core.model.rule;version='[5.1.0,5.1.1)',\
123+
org.openhab.core.model.script;version='[5.1.0,5.1.1)',\
124+
org.openhab.core.model.script.runtime;version='[5.1.0,5.1.1)',\
125+
org.openhab.core.model.sitemap;version='[5.1.0,5.1.1)',\
126+
org.openhab.core.model.thing;version='[5.1.0,5.1.1)',\
127+
org.openhab.core.persistence;version='[5.1.0,5.1.1)',\
128+
org.openhab.core.voice;version='[5.1.0,5.1.1)',\
129+
org.ops4j.pax.web.pax-web-api;version='[8.0.30,8.0.31)',\
130+
org.ops4j.pax.web.pax-web-jetty;version='[8.0.30,8.0.31)',\
131+
org.ops4j.pax.web.pax-web-runtime;version='[8.0.30,8.0.31)',\
132+
org.ops4j.pax.web.pax-web-spi;version='[8.0.30,8.0.31)',\
133+
org.ops4j.pax.web.pax-web-tomcat-common;version='[8.0.30,8.0.31)',\
134+
org.threeten.extra;version='[1.8.0,1.8.1)',\
135+
org.yaml.snakeyaml;version='[2.3.0,2.3.1)',\
136+
stax2-api;version='[4.2.2,4.2.3)'
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* Copyright (c) 2010-2025 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.core.thing.link;
14+
15+
import static org.junit.jupiter.api.Assertions.*;
16+
17+
import java.io.ByteArrayInputStream;
18+
import java.util.Set;
19+
20+
import org.eclipse.jdt.annotation.NonNullByDefault;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Disabled;
23+
import org.junit.jupiter.api.Test;
24+
import org.openhab.core.items.Item;
25+
import org.openhab.core.items.ItemRegistry;
26+
import org.openhab.core.model.core.ModelRepository;
27+
import org.openhab.core.test.java.JavaOSGiTest;
28+
import org.openhab.core.thing.ThingRegistry;
29+
30+
/**
31+
* Tests for {@link ItemChannelLinkRegistry} tagging.
32+
*
33+
* @author Andrew Fiddian-Green - Initial contribution
34+
*/
35+
@NonNullByDefault
36+
public class ItemChannelLinkTaggingOSGiTest extends JavaOSGiTest {
37+
38+
private static final String THINGS_MODEL_ID = "test.things";
39+
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+
48+
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] }
64+
""";
65+
66+
private @NonNullByDefault({}) ItemRegistry itemRegistry;
67+
private @NonNullByDefault({}) ThingRegistry thingRegistry;
68+
private @NonNullByDefault({}) ModelRepository modelRepository;
69+
private @NonNullByDefault({}) ItemChannelLinkRegistry itemChannelLinkRegistry;
70+
71+
@BeforeEach
72+
public void setup() {
73+
registerVolatileStorageService();
74+
75+
itemRegistry = getService(ItemRegistry.class);
76+
assertNotNull(itemRegistry);
77+
78+
thingRegistry = getService(ThingRegistry.class);
79+
assertNotNull(thingRegistry);
80+
81+
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
82+
assertNotNull(itemChannelLinkRegistry);
83+
84+
modelRepository = getService(ModelRepository.class);
85+
assertNotNull(modelRepository);
86+
}
87+
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+
*/
104+
@Test
105+
@Disabled
106+
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+
});
117+
118+
Item item;
119+
120+
item = itemRegistry.get("Item_01");
121+
assertNotNull(item);
122+
assertTrue(item.getTags().isEmpty());
123+
124+
item = itemRegistry.get("Item_02");
125+
assertNotNull(item);
126+
assertTrue(item.getTags().isEmpty());
127+
128+
item = itemRegistry.get("Item_03");
129+
assertNotNull(item);
130+
assertTrue(item.getTags().isEmpty());
131+
132+
item = itemRegistry.get("Item_04");
133+
assertNotNull(item);
134+
assertEquals(Set.of("Control", "Color"), item.getTags());
135+
136+
item = itemRegistry.get("Item_05");
137+
assertNotNull(item);
138+
assertEquals(Set.of("Control", "Color"), item.getTags());
139+
140+
item = itemRegistry.get("Item_06");
141+
assertNotNull(item);
142+
assertEquals(Set.of("Control", "Color", "Custom"), item.getTags());
143+
144+
item = itemRegistry.get("Item_07");
145+
assertNotNull(item);
146+
assertTrue(item.getTags().contains("Power"));
147+
assertTrue(item.getTags().contains("Custom"));
148+
149+
item = itemRegistry.get("Item_08");
150+
assertNotNull(item);
151+
assertTrue(item.getTags().contains("Power"));
152+
assertTrue(item.getTags().contains("Custom"));
153+
154+
item = itemRegistry.get("Item_09");
155+
assertNotNull(item);
156+
assertEquals(Set.of("Switch", "Custom"), item.getTags());
157+
158+
item = itemRegistry.get("Item_10");
159+
assertNotNull(item);
160+
assertEquals(Set.of("Switch", "Custom"), item.getTags());
161+
162+
item = itemRegistry.get("Item_11");
163+
assertNotNull(item);
164+
assertEquals(Set.of("Switch", "Power", "Custom"), item.getTags());
165+
166+
item = itemRegistry.get("Item_12");
167+
assertNotNull(item);
168+
assertEquals(Set.of("Switch", "Power", "Custom"), item.getTags());
169+
170+
item = itemRegistry.get("Item_13");
171+
assertNotNull(item);
172+
assertEquals(Set.of("Alarm", "LowBattery"), item.getTags());
173+
174+
item = itemRegistry.get("Item_14");
175+
assertNotNull(item);
176+
assertTrue(item.getTags().equals(Set.of("Control", "Color")) //
177+
|| item.getTags().equals(Set.of("Alarm", "LowBattery")));
178+
179+
item = itemRegistry.get("Item_15");
180+
assertNotNull(item);
181+
assertEquals(Set.of("Alarm", "LowBattery"), item.getTags());
182+
}
183+
}

0 commit comments

Comments
 (0)